diff --git a/Core/Config.cpp b/Core/Config.cpp index 27a5b7507d24..81088e215f32 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -941,6 +941,10 @@ static ConfigSetting controlSettings[] = { ConfigSetting("AnalogRotationCWKeyX", "AnalogRotationKeyCWY", "AnalogRotationKeyCWScale", "ShowAnalogRotationCWKey", &g_Config.touchAnalogRotationCWKey, defaultTouchPosHide, true, true), ConfigSetting("AnalogRotationCCWKeyX", "AnalogRotationKeyCCWY", "AnalogRotationKeyCCWScale", "ShowAnalogRotationCCWKey", &g_Config.touchAnalogRotationCCWKey, defaultTouchPosHide, true, true), + ConfigSetting("LeftStickHeadScale", &g_Config.fLeftStickHeadScale, 1.0f, true, true), + ConfigSetting("RightStickHeadScale", &g_Config.fRightStickHeadScale, 1.0f, true, true), + ConfigSetting("HideStickBackground", &g_Config.bHideStickBackground, false, true, true), + #ifdef _WIN32 ConfigSetting("DInputAnalogDeadzone", &g_Config.fDInputAnalogDeadzone, 0.1f, true, true), ConfigSetting("DInputAnalogInverseMode", &g_Config.iDInputAnalogInverseMode, 0, true, true), @@ -1780,6 +1784,8 @@ void Config::ResetControlLayout() { reset(g_Config.touchRapidFireKey); reset(g_Config.touchAnalogRotationCWKey); reset(g_Config.touchAnalogRotationCCWKey); + g_Config.fLeftStickHeadScale = 1.0f; + g_Config.fRightStickHeadScale = 1.0f; } void Config::GetReportingInfo(UrlEncoder &data) { diff --git a/Core/Config.h b/Core/Config.h index be0fe9589c89..4eb3da37339f 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -356,6 +356,10 @@ struct Config { ConfigTouchPos touchAnalogRotationCWKey; ConfigTouchPos touchAnalogRotationCCWKey; + float fLeftStickHeadScale; + float fRightStickHeadScale; + bool bHideStickBackground; + // Controls Visibility bool bShowTouchControls; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 393e33cd9fe5..22eb8ddfc35a 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -680,6 +680,10 @@ void GameSettingsScreen::CreateViews() { CheckBox *floatingAnalog = controlsSettings->Add(new CheckBox(&g_Config.bAutoCenterTouchAnalog, co->T("Auto-centering analog stick"))); floatingAnalog->SetEnabledPtr(&g_Config.bShowTouchControls); + // Hide stick background, usefull when increasing the size + CheckBox *hideStickBackground = controlsSettings->Add(new CheckBox(&g_Config.bHideStickBackground, co->T("Hide touch analog stick background circle"))); + hideStickBackground->SetEnabledPtr(&g_Config.bShowTouchControls); + // Combo key setup Choice *comboKey = controlsSettings->Add(new Choice(co->T("Combo Key Setup"))); comboKey->OnClick.Handle(this, &GameSettingsScreen::OnComboKey); diff --git a/UI/GamepadEmu.cpp b/UI/GamepadEmu.cpp index d38bac4b9240..d40936287732 100644 --- a/UI/GamepadEmu.cpp +++ b/UI/GamepadEmu.cpp @@ -429,10 +429,12 @@ void PSPStick::Draw(UIContext &dc) { float dx, dy; __CtrlPeekAnalog(stick_, &dx, &dy); - dc.Draw()->DrawImage(bgImg_, stickX, stickY, 1.0f * scale_, colorBg, ALIGN_CENTER); + if (!g_Config.bHideStickBackground) + dc.Draw()->DrawImage(bgImg_, stickX, stickY, 1.0f * scale_, colorBg, ALIGN_CENTER); + float headScale = stick_ ? g_Config.fRightStickHeadScale : g_Config.fLeftStickHeadScale; if (dragPointerId_ != -1 && g_Config.iTouchButtonStyle == 2 && stickDownImg_ != stickImageIndex_) - dc.Draw()->DrawImage(stickDownImg_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f * scale_, downBg, ALIGN_CENTER); - dc.Draw()->DrawImage(stickImageIndex_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f * scale_, colorBg, ALIGN_CENTER); + dc.Draw()->DrawImage(stickDownImg_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f * scale_ * headScale, downBg, ALIGN_CENTER); + dc.Draw()->DrawImage(stickImageIndex_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f * scale_ * headScale, colorBg, ALIGN_CENTER); } void PSPStick::Touch(const TouchInput &input) { @@ -445,8 +447,14 @@ void PSPStick::Touch(const TouchInput &input) { __CtrlSetAnalogY(0.0f, stick_); return; } + auto InputInHeadRange = [&]() { + float x = bounds_.centerX()-input.x; + float y = bounds_.centerY()-input.y; + float r = stick_size_*scale_* (stick_ ? g_Config.fRightStickHeadScale : g_Config.fLeftStickHeadScale); + return x*x + y*y < r*r; + }; if (input.flags & TOUCH_DOWN) { - if (dragPointerId_ == -1 && bounds_.Contains(input.x, input.y)) { + if (dragPointerId_ == -1 && InputInHeadRange()) { if (g_Config.bAutoCenterTouchAnalog) { centerX_ = input.x; centerY_ = input.y; @@ -528,10 +536,11 @@ void PSPCustomStick::Draw(UIContext &dc) { dx = posX_; dy = -posY_; - dc.Draw()->DrawImage(bgImg_, stickX, stickY, 1.0f * scale_, colorBg, ALIGN_CENTER); + if (!g_Config.bHideStickBackground) + dc.Draw()->DrawImage(bgImg_, stickX, stickY, 1.0f * scale_, colorBg, ALIGN_CENTER); if (dragPointerId_ != -1 && g_Config.iTouchButtonStyle == 2 && stickDownImg_ != stickImageIndex_) - dc.Draw()->DrawImage(stickDownImg_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f * scale_, downBg, ALIGN_CENTER); - dc.Draw()->DrawImage(stickImageIndex_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f * scale_, colorBg, ALIGN_CENTER); + dc.Draw()->DrawImage(stickDownImg_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f*scale_*g_Config.fRightStickHeadScale, downBg, ALIGN_CENTER); + dc.Draw()->DrawImage(stickImageIndex_, stickX + dx * stick_size_ * scale_, stickY - dy * stick_size_ * scale_, 1.0f*scale_*g_Config.fRightStickHeadScale, colorBg, ALIGN_CENTER); } void PSPCustomStick::Touch(const TouchInput &input) { @@ -544,8 +553,14 @@ void PSPCustomStick::Touch(const TouchInput &input) { posY_ = 0.0f; return; } + auto InputInHeadRange = [&]() { + float x = bounds_.centerX()-input.x; + float y = bounds_.centerY()-input.y; + float r = stick_size_*scale_*g_Config.fRightStickHeadScale; + return x*x + y*y < r*r; + }; if (input.flags & TOUCH_DOWN) { - if (dragPointerId_ == -1 && bounds_.Contains(input.x, input.y)) { + if (dragPointerId_ == -1 && InputInHeadRange()) { if (g_Config.bAutoCenterTouchAnalog) { centerX_ = input.x; centerY_ = input.y; diff --git a/UI/TouchControlLayoutScreen.cpp b/UI/TouchControlLayoutScreen.cpp index 25a5a07df020..958db8acfb18 100644 --- a/UI/TouchControlLayoutScreen.cpp +++ b/UI/TouchControlLayoutScreen.cpp @@ -196,6 +196,35 @@ class PSPDPadButtons : public DragDropButton { float &spacing_; }; +class PSPStickDragDrop : public DragDropButton { +public: + PSPStickDragDrop(ConfigTouchPos &pos, const char *key, ImageID bgImg, ImageID img, const Bounds &screenBounds, float &spacing) + : DragDropButton(pos, key, bgImg, img, screenBounds), spacing_(spacing) { + } + + void Draw(UIContext &dc) override { + float opacity = g_Config.iTouchButtonOpacity / 100.0f; + + uint32_t colorBg = colorAlpha(GetButtonColor(), opacity); + uint32_t downBg = colorAlpha(0x00FFFFFF, opacity * 0.5f); + + const ImageID stickImage = g_Config.iTouchButtonStyle ? ImageID("I_STICK_LINE") : ImageID("I_STICK"); + const ImageID stickBg = g_Config.iTouchButtonStyle ? ImageID("I_STICK_BG_LINE") : ImageID("I_STICK_BG"); + + dc.Draw()->DrawImage(stickBg, bounds_.centerX(), bounds_.centerY(), scale_, colorBg, ALIGN_CENTER); + dc.Draw()->DrawImage(stickImage, bounds_.centerX(), bounds_.centerY(), scale_ * spacing_, colorBg, ALIGN_CENTER); + } + + float GetSpacing() const override { return spacing_; } + void SetSpacing(float s) override { + // In mapping spacing is clamped between 0.5 and 3.0 and passed to this method + spacing_ = s/3; + } + +private: + float &spacing_; +}; + class SnapGrid : public UI::View { public: SnapGrid(int leftMargin, int rightMargin, int topMargin, int bottomMargin, u32 color) { @@ -398,8 +427,12 @@ void ControlLayoutView::CreateViews() { rbutton->FlipImageH(true); } - addDragDropButton(g_Config.touchAnalogStick, "Left analog stick", stickBg, stickImage); - addDragDropButton(g_Config.touchRightAnalogStick, "Right analog stick", stickBg, stickImage); + if (g_Config.touchAnalogStick.show) { + controls_.push_back(new PSPStickDragDrop(g_Config.touchAnalogStick, "Left analog stick", stickBg, stickImage, bounds, g_Config.fLeftStickHeadScale)); + } + if (g_Config.touchRightAnalogStick.show) { + controls_.push_back(new PSPStickDragDrop(g_Config.touchRightAnalogStick, "Right analog stick", stickBg, stickImage, bounds, g_Config.fRightStickHeadScale)); + } addDragDropButton(g_Config.touchCombo0, "Combo 1 button", roundImage, comboKeyImages[0]); addDragDropButton(g_Config.touchCombo1, "Combo 2 button", roundImage, comboKeyImages[1]); addDragDropButton(g_Config.touchCombo2, "Combo 3 button", roundImage, comboKeyImages[2]);