From a56e56cf531fe0ae9919f331d5d3bd3396b5a02d Mon Sep 17 00:00:00 2001 From: iota97 Date: Tue, 31 Dec 2019 11:08:48 +0100 Subject: [PATCH] Auto switch option --- Core/Config.cpp | 2 +- Core/Config.h | 3 +-- UI/NativeApp.cpp | 27 +++++++++++++++++++++------ UI/TiltAnalogSettingsScreen.cpp | 3 ++- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 838c6cc8b2..c35b57a660 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -857,7 +857,7 @@ static ConfigSetting controlSettings[] = { #ifdef MOBILE_DEVICE ConfigSetting("TiltBaseX", &g_Config.fTiltBaseX, 0.0f, true, true), ConfigSetting("TiltBaseY", &g_Config.fTiltBaseY, 0.0f, true, true), - ConfigSetting("TiltVertical", &g_Config.TiltVertical, false, true, true), + ConfigSetting("TiltOrientation", &g_Config.iTiltOrientation, 0, true, true), ConfigSetting("InvertTiltX", &g_Config.bInvertTiltX, false, true, true), ConfigSetting("InvertTiltY", &g_Config.bInvertTiltY, true, true, true), ConfigSetting("TiltSensitivityX", &g_Config.iTiltSensitivityX, 100, true, true), diff --git a/Core/Config.h b/Core/Config.h index ca2e8b3938..86d25983fb 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -266,8 +266,7 @@ public: //the base x and y tilt. this inclination is treated as (0,0) and the tilt input //considers this orientation to be equal to no movement of the analog stick. float fTiltBaseX, fTiltBaseY; - //tilt vertically will use Z accelerometer axis as X (X would require phone on flat plane) - bool TiltVertical; + int iTiltOrientation; //whether the x axes and y axes should invert directions (left becomes right, top becomes bottom.) bool bInvertTiltX, bInvertTiltY; //the sensitivity of the tilt in the x direction diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 8e4c7b8b56..40ebcf4ea4 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1260,6 +1260,13 @@ bool NativeAxis(const AxisInput &axis) { // This is static, since we need to remember where we last were (in terms of orientation) static Tilt currentTilt; + // tilt on x or y? + static bool TiltVertical; + if (g_Config.iTiltOrientation == 0) + TiltVertical = false; + else if (g_Config.iTiltOrientation == 1) + TiltVertical = true; + // x and y are flipped if we are in landscape orientation. The events are // sent with respect to the portrait coordinate system, while we // take all events in landscape. @@ -1268,8 +1275,12 @@ bool NativeAxis(const AxisInput &axis) { switch (axis.axisId) { //TODO: make this generic. case JOYSTICK_AXIS_ACCELEROMETER_X: - if (g_Config.TiltVertical) // use Z axis instead - return false; + if (TiltVertical) { + if (fabs(axis.value) < 0.8f && g_Config.iTiltOrientation == 2) // Auto tilt switch + TiltVertical = false; + else + return false; // Tilt on Z instead + } if (portrait) { currentTilt.x_ = axis.value; } else { @@ -1286,12 +1297,16 @@ bool NativeAxis(const AxisInput &axis) { break; case JOYSTICK_AXIS_ACCELEROMETER_Z: - if (!g_Config.TiltVertical) // use X axis instead - return false; + if (!TiltVertical) { + if (fabs(axis.value) < 0.8f && g_Config.iTiltOrientation == 2) // Auto tilt switch + TiltVertical = true; + else + return false; // Tilt on X instead + } if (portrait) { - currentTilt.x_ = axis.value; + currentTilt.x_ = -axis.value; } else { - currentTilt.y_ = axis.value; + currentTilt.y_ = -axis.value; } break; diff --git a/UI/TiltAnalogSettingsScreen.cpp b/UI/TiltAnalogSettingsScreen.cpp index 16fc40f5d3..09a463760c 100644 --- a/UI/TiltAnalogSettingsScreen.cpp +++ b/UI/TiltAnalogSettingsScreen.cpp @@ -35,7 +35,8 @@ void TiltAnalogSettingsScreen::CreateViews() { settings->Add(new ItemHeader(co->T("Invert Axes"))); settings->Add(new CheckBox(&g_Config.bInvertTiltX, co->T("Invert Tilt along X axis"))); settings->Add(new CheckBox(&g_Config.bInvertTiltY, co->T("Invert Tilt along Y axis"))); - settings->Add(new CheckBox(&g_Config.TiltVertical, co->T("Tilt along Z axis instead of X"))); + static const char* tiltMode[] = { "Screen parallel to ground", "Screen orthogonal to ground", "Auto-switch" }; + settings->Add(new PopupMultiChoice(&g_Config.iTiltOrientation, co->T("Base tilt position"), tiltMode, 0, ARRAY_SIZE(tiltMode), co->GetName(), screenManager())); settings->Add(new ItemHeader(co->T("Sensitivity"))); //TODO: allow values greater than 100? I'm not sure if that's needed.