From fc3f7da3af55c0669bb15f27daad49bde5a7ffdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 6 Jul 2023 11:48:25 +0200 Subject: [PATCH] TouchTestScreen: Have 8 entries logged instead of 2. --- Common/UI/UIScreen.h | 8 +++--- UI/ControlMappingScreen.cpp | 49 ++++++++++++++++++++++--------------- UI/ControlMappingScreen.h | 7 ++++-- android/jni/app-android.cpp | 2 +- 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/Common/UI/UIScreen.h b/Common/UI/UIScreen.h index 60eb1749b0..0a75c06541 100644 --- a/Common/UI/UIScreen.h +++ b/Common/UI/UIScreen.h @@ -43,12 +43,12 @@ public: void deviceRestored() override; virtual void touch(const TouchInput &touch); - virtual bool key(const KeyInput &touch); - virtual void axis(const AxisInput &touch); + virtual bool key(const KeyInput &key); + virtual void axis(const AxisInput &axis); void UnsyncTouch(const TouchInput &touch) override; - bool UnsyncKey(const KeyInput &touch) override; - void UnsyncAxis(const AxisInput &touch) override; + bool UnsyncKey(const KeyInput &key) override; + void UnsyncAxis(const AxisInput &axis) override; TouchInput transformTouch(const TouchInput &touch) override; diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 0747181e1c..63a45081d5 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -630,6 +630,7 @@ void TouchTestScreen::touch(const TouchInput &touch) { } } +// TODO: Move this screen out into its own file. void TouchTestScreen::CreateViews() { using namespace UI; @@ -638,9 +639,7 @@ void TouchTestScreen::CreateViews() { root_ = new LinearLayout(ORIENT_VERTICAL); LinearLayout *theTwo = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f)); - lastLastKeyEvent_ = theTwo->Add(new TextView("-", new LayoutParams(FILL_PARENT, WRAP_CONTENT))); - lastLastKeyEvent_->SetTextColor(0x80FFFFFF); // semi-transparent - lastKeyEvent_ = theTwo->Add(new TextView("-", new LayoutParams(FILL_PARENT, WRAP_CONTENT))); + lastKeyEvents_ = theTwo->Add(new TextView("-", new LayoutParams(FILL_PARENT, WRAP_CONTENT))); root_->Add(theTwo); @@ -671,38 +670,48 @@ extern int display_xres; extern int display_yres; #endif +void TouchTestScreen::UpdateLogView() { + while (keyEventLog_.size() > 8) { + keyEventLog_.erase(keyEventLog_.begin()); + } + + std::string text; + for (auto &iter : keyEventLog_) { + text += iter + "\n"; + } + + if (lastKeyEvents_) { + lastKeyEvents_->SetText(text); + } +} + bool TouchTestScreen::key(const KeyInput &key) { + UIScreen::key(key); char buf[512]; snprintf(buf, sizeof(buf), "Keycode: %d Device ID: %d [%s%s%s%s]", key.keyCode, key.deviceId, (key.flags & KEY_IS_REPEAT) ? "REP" : "", (key.flags & KEY_UP) ? "UP" : "", (key.flags & KEY_DOWN) ? "DOWN" : "", (key.flags & KEY_CHAR) ? "CHAR" : ""); - if (lastLastKeyEvent_ && lastKeyEvent_) { - lastLastKeyEvent_->SetText(lastKeyEvent_->GetText()); - lastKeyEvent_->SetText(buf); - } + keyEventLog_.push_back(buf); + UpdateLogView(); return true; } void TouchTestScreen::axis(const AxisInput &axis) { - // This is mainly to catch axis events that would otherwise get translated - // into arrow keys, since seeing keyboard arrow key events appear when using - // a controller would be confusing for the user. + // This just filters out accelerometer events. We show everything else. if (IgnoreAxisForMapping(axis.axisId)) return; - const float AXIS_LOG_THRESHOLD = AXIS_BIND_THRESHOLD * 0.5f; - if (axis.value > AXIS_LOG_THRESHOLD || axis.value < -AXIS_LOG_THRESHOLD) { - char buf[512]; - snprintf(buf, sizeof(buf), "Axis: %d (value %1.3f) Device ID: %d", - axis.axisId, axis.value, axis.deviceId); - // Null-check just in case they weren't created yet. - if (lastLastKeyEvent_ && lastKeyEvent_) { - lastLastKeyEvent_->SetText(lastKeyEvent_->GetText()); - lastKeyEvent_->SetText(buf); - } + char buf[512]; + snprintf(buf, sizeof(buf), "Axis: %d (value %1.3f) Device ID: %d", + axis.axisId, axis.value, axis.deviceId); + + keyEventLog_.push_back(buf); + if (keyEventLog_.size() > 8) { + keyEventLog_.erase(keyEventLog_.begin()); } + UpdateLogView(); } void TouchTestScreen::render() { diff --git a/UI/ControlMappingScreen.h b/UI/ControlMappingScreen.h index 1885473da3..f912319949 100644 --- a/UI/ControlMappingScreen.h +++ b/UI/ControlMappingScreen.h @@ -22,6 +22,7 @@ #include #include #include +#include #include "Common/UI/View.h" #include "Common/UI/UIScreen.h" @@ -165,10 +166,12 @@ protected: }; TrackedTouch touches_[MAX_TOUCH_POINTS]{}; - UI::TextView *lastKeyEvent_ = nullptr; - UI::TextView *lastLastKeyEvent_ = nullptr; + std::vector keyEventLog_; + + UI::TextView *lastKeyEvents_ = nullptr; void CreateViews() override; + void UpdateLogView(); UI::EventReturn OnImmersiveModeChange(UI::EventParams &e); UI::EventReturn OnRenderingBackend(UI::EventParams &e); diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index e1b05a58e3..c312a01bb8 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -1207,8 +1207,8 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_joystickAxis( return; AxisInput axis; - axis.axisId = (InputAxis)axisId; axis.deviceId = (InputDeviceID)deviceId; + axis.axisId = (InputAxis)axisId; axis.value = value; NativeAxis(axis);