From afb82e3998007d277c21d3089785f072f3ed9ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20H=C3=B6glund?= Date: Fri, 28 Aug 2015 01:22:45 +0200 Subject: [PATCH] Add axis event listener to the analog test screen. --- UI/ControlMappingScreen.cpp | 15 +++++++++++++++ UI/ControlMappingScreen.h | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index fb267b0850..eee16c1e9f 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -432,6 +432,21 @@ bool AnalogTestScreen::key(const KeyInput &key) { return true; } +bool AnalogTestScreen::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. + char buf[512]; + if (axis.value > AXIS_BIND_THRESHOLD || axis.value < -AXIS_BIND_THRESHOLD) { + int value = axis.value > AXIS_BIND_THRESHOLD ? 1 : -1; + snprintf(buf, sizeof(buf), "Axis: %d (value %1.3f) Device ID: %d", + axis.axisId, axis.value, axis.deviceId); + lastKeyEvent_->SetText(buf); + return true; + } + return false; +} + void AnalogTestScreen::CreateViews() { using namespace UI; diff --git a/UI/ControlMappingScreen.h b/UI/ControlMappingScreen.h index a569cfc9ce..dc205632cb 100644 --- a/UI/ControlMappingScreen.h +++ b/UI/ControlMappingScreen.h @@ -74,9 +74,10 @@ public: AnalogTestScreen() {} bool key(const KeyInput &key) override; + bool axis(const AxisInput &axis) override; protected: virtual void CreateViews() override; UI::TextView *lastKeyEvent_; -}; \ No newline at end of file +};