From f99a651c6ae02fda9dc7e12a05d940832554fdd5 Mon Sep 17 00:00:00 2001 From: iota97 Date: Thu, 19 Dec 2019 00:41:32 +0100 Subject: [PATCH] Touch controll grid snap --- Core/Config.cpp | 4 ++++ Core/Config.h | 5 +++++ UI/TouchControlLayoutScreen.cpp | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 73e529f59a..1fc75131f0 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -854,6 +854,10 @@ static ConfigSetting controlSettings[] = { ConfigSetting("TouchButtonHideSeconds", &g_Config.iTouchButtonHideSeconds, 20, true, true), ConfigSetting("AutoCenterTouchAnalog", &g_Config.bAutoCenterTouchAnalog, false, true, true), + // Snap touch control position + ConfigSetting("TouchSnapToGrid", &g_Config.bTouchSnapToGrid, false, true, true), + ConfigSetting("TouchSnapGridSize", &g_Config.iTouchSnapGridSize, 64, true, true), + // -1.0f means uninitialized, set in GamepadEmu::CreatePadLayout(). ConfigSetting("ActionButtonSpacing2", &g_Config.fActionButtonSpacing, 1.0f, true, true), ConfigSetting("ActionButtonCenterX", "ActionButtonCenterY", "ActionButtonScale", nullptr, &g_Config.touchActionButtonCenter, defaultTouchPosShow, true, true), diff --git a/Core/Config.h b/Core/Config.h index 0c58923417..2fe185fcd7 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -275,6 +275,11 @@ public: int iTouchButtonStyle; int iTouchButtonOpacity; int iTouchButtonHideSeconds; + + // Snap touch control position + bool bTouchSnapToGrid; + int iTouchSnapGridSize; + // Floating analog stick (recenters on thumb on press). bool bAutoCenterTouchAnalog; diff --git a/UI/TouchControlLayoutScreen.cpp b/UI/TouchControlLayoutScreen.cpp index 24574ed951..98b019b724 100644 --- a/UI/TouchControlLayoutScreen.cpp +++ b/UI/TouchControlLayoutScreen.cpp @@ -243,9 +243,15 @@ bool TouchControlLayoutScreen::touch(const TouchInput &touch) { // if the leftmost point of the control is ahead of the margin, // move it. Otherwise, don't. newX = touch.x; + // Snap to grid + if (g_Config.bTouchSnapToGrid) + newX -= (int)(touch.x-bounds.centerX()) % g_Config.iTouchSnapGridSize; } if (touch.y > minTouchY && touch.y < maxTouchY) { newY = touch.y; + // Snap to grid + if (g_Config.bTouchSnapToGrid) + newY -= (int)(touch.y-bounds.centerY()) % g_Config.iTouchSnapGridSize; } pickedControl_->ReplaceLayoutParams(new UI::AnchorLayoutParams(newX, newY, NONE, NONE, true)); } else if (mode == 1) { @@ -324,11 +330,14 @@ void TouchControlLayoutScreen::CreateViews() { Choice *reset = new Choice(di->T("Reset"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 84)); Choice *back = new Choice(di->T("Back"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10)); - Choice *visibility = new Choice(co->T("Visibility"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 158)); + Choice *visibility = new Choice(co->T("Visibility"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 298)); // controlsSettings->Add(new PopupSliderChoiceFloat(&g_Config.fButtonScale, 0.80, 2.0, co->T("Button Scaling"), screenManager())) // ->OnChange.Handle(this, &GameSettingsScreen::OnChangeControlScaling); - mode_ = new ChoiceStrip(ORIENT_VERTICAL, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 158 + 64 + 10)); + CheckBox *snap = new CheckBox(&g_Config.bTouchSnapToGrid, di->T("Snap"), "", new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 228)); + PopupSliderChoice *gridSize = new PopupSliderChoice(&g_Config.iTouchSnapGridSize, 1, 256, di->T("Grid"), screenManager(), "", new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 158)); + + mode_ = new ChoiceStrip(ORIENT_VERTICAL, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 140 + 158 + 64 + 10)); mode_->AddChoice(di->T("Move")); mode_->AddChoice(di->T("Resize")); mode_->SetSelection(0); @@ -338,6 +347,8 @@ void TouchControlLayoutScreen::CreateViews() { visibility->OnClick.Handle(this, &TouchControlLayoutScreen::OnVisibility); root_->Add(mode_); root_->Add(visibility); + root_->Add(snap); + root_->Add(gridSize); root_->Add(reset); root_->Add(back);