Merge pull request #17420 from hrydgard/analog-mapping-glitch-fix

Fix glitch when mapping analog inputs, caused by multiple TriggerFinish
This commit is contained in:
Henrik Rydgård 2023-05-06 17:12:02 +02:00 committed by GitHub
commit d5ac88ecec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 8 deletions

View File

@ -149,7 +149,7 @@ TouchInput UIScreen::transformTouch(const TouchInput &touch) {
} }
void UIScreen::touch(const TouchInput &touch) { void UIScreen::touch(const TouchInput &touch) {
if (root_) { if (root_ && !ignoreInput_) {
if (ClickDebug && (touch.flags & TOUCH_DOWN)) { if (ClickDebug && (touch.flags & TOUCH_DOWN)) {
INFO_LOG(SYSTEM, "Touch down!"); INFO_LOG(SYSTEM, "Touch down!");
std::vector<UI::View *> views; std::vector<UI::View *> views;
@ -164,13 +164,21 @@ void UIScreen::touch(const TouchInput &touch) {
} }
bool UIScreen::key(const KeyInput &key) { bool UIScreen::key(const KeyInput &key) {
if (root_) { if (root_ && !ignoreInput_) {
return UI::KeyEvent(key, root_); return UI::KeyEvent(key, root_);
} }
return false; return false;
} }
void UIScreen::axis(const AxisInput &axis) {
if (root_ && !ignoreInput_) {
UI::AxisEvent(axis, root_);
}
}
void UIScreen::TriggerFinish(DialogResult result) { void UIScreen::TriggerFinish(DialogResult result) {
// From here on, this dialog cannot receive input.
ignoreInput_ = true;
screenManager()->finishDialog(this, result); screenManager()->finishDialog(this, result);
} }
@ -196,12 +204,6 @@ void UIDialogScreen::sendMessage(const char *msg, const char *value) {
} }
} }
void UIScreen::axis(const AxisInput &axis) {
if (root_) {
UI::AxisEvent(axis, root_);
}
}
UI::EventReturn UIScreen::OnBack(UI::EventParams &e) { UI::EventReturn UIScreen::OnBack(UI::EventParams &e) {
TriggerFinish(DR_BACK); TriggerFinish(DR_BACK);
return UI::EVENT_DONE; return UI::EVENT_DONE;
@ -313,6 +315,7 @@ void PopupScreen::SetPopupOffset(float y) {
void PopupScreen::TriggerFinish(DialogResult result) { void PopupScreen::TriggerFinish(DialogResult result) {
if (CanComplete(result)) { if (CanComplete(result)) {
ignoreInput_ = true;
finishFrame_ = frames_; finishFrame_ = frames_;
finishResult_ = result; finishResult_ = result;

View File

@ -50,6 +50,7 @@ protected:
Vec3 scale_ = Vec3(1.0f); Vec3 scale_ = Vec3(1.0f);
float alpha_ = 1.0f; float alpha_ = 1.0f;
bool ignoreInsets_ = false; bool ignoreInsets_ = false;
bool ignoreInput_ = false;
private: private:
void DoRecreateViews(); void DoRecreateViews();

View File

@ -337,6 +337,8 @@ void KeyMappingNewKeyDialog::CreatePopupContents(UI::ViewGroup *parent) {
} }
bool KeyMappingNewKeyDialog::key(const KeyInput &key) { bool KeyMappingNewKeyDialog::key(const KeyInput &key) {
if (ignoreInput_)
return true;
if (time_now_d() < delayUntil_) if (time_now_d() < delayUntil_)
return true; return true;
if (key.flags & KEY_DOWN) { if (key.flags & KEY_DOWN) {
@ -390,6 +392,8 @@ void KeyMappingNewMouseKeyDialog::CreatePopupContents(UI::ViewGroup *parent) {
bool KeyMappingNewMouseKeyDialog::key(const KeyInput &key) { bool KeyMappingNewMouseKeyDialog::key(const KeyInput &key) {
if (mapped_) if (mapped_)
return false; return false;
if (ignoreInput_)
return true;
if (key.flags & KEY_DOWN) { if (key.flags & KEY_DOWN) {
if (key.keyCode == NKCODE_ESCAPE) { if (key.keyCode == NKCODE_ESCAPE) {
TriggerFinish(DR_OK); TriggerFinish(DR_OK);
@ -428,6 +432,8 @@ void KeyMappingNewKeyDialog::axis(const AxisInput &axis) {
return; return;
if (IgnoreAxisForMapping(axis.axisId)) if (IgnoreAxisForMapping(axis.axisId))
return; return;
if (ignoreInput_)
return;
if (axis.value > AXIS_BIND_THRESHOLD) { if (axis.value > AXIS_BIND_THRESHOLD) {
InputMapping mapping(axis.deviceId, axis.axisId, 1); InputMapping mapping(axis.deviceId, axis.axisId, 1);