diff --git a/Core/Config.cpp b/Core/Config.cpp index 90c70cddb6..7223678f0e 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -804,6 +804,9 @@ static const ConfigSetting controlSettings[] = { ConfigSetting("SystemControls", &g_Config.bSystemControls, true, CfgFlag::DEFAULT), ConfigSetting("RapidFileInterval", &g_Config.iRapidFireInterval, 5, CfgFlag::DEFAULT), + + ConfigSetting("AnalogGesture", &g_Config.bAnalogGesture, false, CfgFlag::PER_GAME), + ConfigSetting("AnalogGestureSensibility", &g_Config.fAnalogGestureSensibility, 1.0f, CfgFlag::PER_GAME), }; static const ConfigSetting networkSettings[] = { diff --git a/Core/Config.h b/Core/Config.h index 6dfc0e1d9b..0a12071223 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -298,6 +298,8 @@ public: float fSwipeSensitivity; float fSwipeSmoothing; int iDoubleTapGesture; + bool bAnalogGesture; + float fAnalogGestureSensibility; // Disable diagonals bool bDisableDpadDiagonals; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 526812f5b6..ab98646210 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -2151,6 +2151,10 @@ void GestureMappingScreen::CreateViews() { vert->Add(new ItemHeader(co->T("Double tap"))); vert->Add(new PopupMultiChoice(&g_Config.iDoubleTapGesture, mc->T("Double tap button"), gestureButton, 0, ARRAY_SIZE(gestureButton), I18NCat::MAPPABLECONTROLS, screenManager()))->SetEnabledPtr(&g_Config.bGestureControlEnabled); + + vert->Add(new ItemHeader(co->T("Analog Stick"))); + vert->Add(new CheckBox(&g_Config.bAnalogGesture, co->T("Enable analog stick gesture"))); + vert->Add(new PopupSliderChoiceFloat(&g_Config.fAnalogGestureSensibility, 0.01f, 5.0f, 1.0f, co->T("Sensitivity"), 0.01f, screenManager(), "x"))->SetEnabledPtr(&g_Config.bAnalogGesture); } RestoreSettingsScreen::RestoreSettingsScreen(const char *title) diff --git a/UI/GamepadEmu.cpp b/UI/GamepadEmu.cpp index 8d5364d422..0651792b06 100644 --- a/UI/GamepadEmu.cpp +++ b/UI/GamepadEmu.cpp @@ -894,7 +894,8 @@ bool GestureGamepad::Touch(const TouchInput &input) { dragPointerId_ = input.id; lastX_ = input.x; lastY_ = input.y; - + downX_ = input.x; + downY_ = input.y; const float now = time_now_d(); if (now - lastTapRelease_ < 0.3f && !haveDoubleTapped_) { if (g_Config.iDoubleTapGesture != 0 ) @@ -911,6 +912,15 @@ bool GestureGamepad::Touch(const TouchInput &input) { deltaY_ += input.y - lastY_; lastX_ = input.x; lastY_ = input.y; + + if (g_Config.bAnalogGesture) { + const float k = g_Config.fAnalogGestureSensibility * 0.02; + float dx = (input.x - downX_)*g_display.dpi_scale_x * k; + float dy = (input.y - downY_)*g_display.dpi_scale_y * k; + dx = std::min(1.0f, std::max(-1.0f, dx)); + dy = std::min(1.0f, std::max(-1.0f, dy)); + __CtrlSetAnalogXY(0, dx, -dy); + } } } if (input.flags & TOUCH_UP) { @@ -924,11 +934,27 @@ bool GestureGamepad::Touch(const TouchInput &input) { controlMapper_->PSPKey(DEVICE_ID_TOUCH, GestureKey::keyList[g_Config.iDoubleTapGesture-1], KEY_UP); haveDoubleTapped_ = false; } + + if (g_Config.bAnalogGesture) + __CtrlSetAnalogXY(0, 0, 0); } } return true; } +void GestureGamepad::Draw(UIContext &dc) { + float opacity = g_Config.iTouchButtonOpacity / 100.0; + if (opacity <= 0.0f) + return; + + uint32_t colorBg = colorAlpha(GetButtonColor(), opacity); + + if (g_Config.bAnalogGesture && dragPointerId_ != -1) { + dc.Draw()->DrawImage(ImageID("I_CIRCLE"), downX_, downY_, 0.7f, colorBg, ALIGN_CENTER); + } +} + + void GestureGamepad::Update() { const float th = 1.0f; float dx = deltaX_ * g_display.dpi_scale_x * g_Config.fSwipeSensitivity; diff --git a/UI/GamepadEmu.h b/UI/GamepadEmu.h index d34f05fcc7..23fc7ffbee 100644 --- a/UI/GamepadEmu.h +++ b/UI/GamepadEmu.h @@ -199,6 +199,7 @@ public: bool Touch(const TouchInput &input) override; void Update() override; + void Draw(UIContext &dc) override; protected: @@ -206,6 +207,8 @@ protected: float lastY_ = 0.0f; float deltaX_ = 0.0f; float deltaY_ = 0.0f; + float downX_; + float downY_; float lastTapRelease_ = 0.0f; float lastTouchDown_ = 0.0f; int dragPointerId_ = -1;