From b1b4679fe654bab43bf0096d1067d4921b29db52 Mon Sep 17 00:00:00 2001 From: Sacha Date: Tue, 5 Nov 2013 14:52:31 +1000 Subject: [PATCH] Scale touch controls to screen resolution. Include a migration method for users who were on the old static system. Scaling up may still look weird due to the hacky method of placement which is unchanged by this commit. Next step of resolution independence would be to have the button scaling affected by resolution too. Tested on a few devices. Mobile users should see no changes at all. --- Core/Config.cpp | 85 ++++++++++++++++++++------------- Core/Config.h | 16 +++---- UI/GamepadEmu.cpp | 80 +++++++++++++++---------------- UI/TouchControlLayoutScreen.cpp | 66 ++++++++++++------------- 4 files changed, 134 insertions(+), 113 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 73ed515c97..fc33429f88 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -237,23 +237,44 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { //requires pixel coordinates which is not known right now. //will be initialized in GamepadEmu::CreatePadLayout control->Get("ActionButtonSpacing", &iActionButtonSpacing, -1); - control->Get("ActionButtonCenterX", &iActionButtonCenterX, -1); - control->Get("ActionButtonCenterY", &iActionButtonCenterY, -1); + control->Get("ActionButtonCenterX", &fActionButtonCenterX, -1.0); + control->Get("ActionButtonCenterY", &fActionButtonCenterY, -1.0); control->Get("DPadRadius", &iDpadRadius, -1); - control->Get("DPadX", &iDpadX, -1); - control->Get("DPadY", &iDpadY, -1); - control->Get("StartKeyX", &iStartKeyX, -1); - control->Get("StartKeyY", &iStartKeyY, -1); - control->Get("SelectKeyX", &iSelectKeyX, -1); - control->Get("SelectKeyY", &iSelectKeyY, -1); - control->Get("UnthrottleKeyX", &iUnthrottleKeyX, -1); - control->Get("UnthrottleKeyY", &iUnthrottleKeyY, -1); - control->Get("LKeyX", &iLKeyX, -1); - control->Get("LKeyY", &iLKeyY, -1); - control->Get("RKeyX", &iRKeyX, -1); - control->Get("RKeyY", &iRKeyY, -1); - control->Get("AnalogStickX", &iAnalogStickX, -1); - control->Get("AnalogStickY", &iAnalogStickY, -1); + control->Get("DPadX", &fDpadX, -1.0); + control->Get("DPadY", &fDpadY, -1.0); + control->Get("StartKeyX", &fStartKeyX, -1.0); + control->Get("StartKeyY", &fStartKeyY, -1.0); + control->Get("SelectKeyX", &fSelectKeyX, -1.0); + control->Get("SelectKeyY", &fSelectKeyY, -1.0); + control->Get("UnthrottleKeyX", &fUnthrottleKeyX, -1.0); + control->Get("UnthrottleKeyY", &fUnthrottleKeyY, -1.0); + control->Get("LKeyX", &fLKeyX, -1.0); + control->Get("LKeyY", &fLKeyY, -1.0); + control->Get("RKeyX", &fRKeyX, -1.0); + control->Get("RKeyY", &fRKeyY, -1.0); + control->Get("AnalogStickX", &fAnalogStickX, -1.0); + control->Get("AnalogStickY", &fAnalogStickY, -1.0); + + // MIGRATION: For users who had the old static touch layout, aren't I nice? + if (fDpadX > 1.0 || fDpadY > 1.0) // Likely the rest are too! + { + fActionButtonCenterX /= dp_xres; + fActionButtonCenterY /= dp_yres; + fDpadX /= dp_xres; + fDpadY /= dp_yres; + fStartKeyX /= dp_xres; + fStartKeyY /= dp_yres; + fSelectKeyX /= dp_xres; + fSelectKeyY /= dp_yres; + fUnthrottleKeyX /= dp_xres; + fUnthrottleKeyY /= dp_yres; + fLKeyX /= dp_xres; + fLKeyY /= dp_yres; + fRKeyX /= dp_xres; + fRKeyY /= dp_yres; + fAnalogStickX /= dp_xres; + fAnalogStickY /= dp_yres; + } IniFile::Section *pspConfig = iniFile.GetOrCreateSection("SystemParam"); pspConfig->Get("NickName", &sNickName, "PPSSPP"); @@ -434,23 +455,23 @@ void Config::Save() { control->Set("TouchButtonOpacity", iTouchButtonOpacity); control->Set("ButtonScale", fButtonScale); control->Set("ActionButtonSpacing", iActionButtonSpacing); - control->Set("ActionButtonCenterX", iActionButtonCenterX); - control->Set("ActionButtonCenterY", iActionButtonCenterY); + control->Set("ActionButtonCenterX", fActionButtonCenterX); + control->Set("ActionButtonCenterY", fActionButtonCenterY); control->Set("DPadRadius", iDpadRadius); - control->Set("DPadX", iDpadX); - control->Set("DPadY", iDpadY); - control->Set("StartKeyX", iStartKeyX); - control->Set("StartKeyY", iStartKeyY); - control->Set("SelectKeyX", iSelectKeyX); - control->Set("SelectKeyY", iSelectKeyY); - control->Set("UnthrottleKeyX", iUnthrottleKeyX); - control->Set("UnthrottleKeyY", iUnthrottleKeyY); - control->Set("LKeyX", iLKeyX); - control->Set("LKeyY", iLKeyY); - control->Set("RKeyX", iRKeyX); - control->Set("RKeyY", iRKeyY); - control->Set("AnalogStickX", iAnalogStickX); - control->Set("AnalogStickY", iAnalogStickY); + control->Set("DPadX", fDpadX); + control->Set("DPadY", fDpadY); + control->Set("StartKeyX", fStartKeyX); + control->Set("StartKeyY", fStartKeyY); + control->Set("SelectKeyX", fSelectKeyX); + control->Set("SelectKeyY", fSelectKeyY); + control->Set("UnthrottleKeyX", fUnthrottleKeyX); + control->Set("UnthrottleKeyY", fUnthrottleKeyY); + control->Set("LKeyX", fLKeyX); + control->Set("LKeyY", fLKeyY); + control->Set("RKeyX", fRKeyX); + control->Set("RKeyY", fRKeyY); + control->Set("AnalogStickX", fAnalogStickX); + control->Set("AnalogStickY", fAnalogStickY); IniFile::Section *pspConfig = iniFile.GetOrCreateSection("SystemParam"); diff --git a/Core/Config.h b/Core/Config.h index d28168d366..233eb633ee 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -137,20 +137,20 @@ public: //space between PSP buttons int iActionButtonSpacing; //the PSP button's center (triangle, circle, square, cross) - int iActionButtonCenterX, iActionButtonCenterY; + float fActionButtonCenterX, fActionButtonCenterY; //radius of the D-pad (PSP cross) int iDpadRadius; //the D-pad (PSP cross) position - int iDpadX, iDpadY; + float fDpadX, fDpadY; //the start key position - int iStartKeyX, iStartKeyY; + float fStartKeyX, fStartKeyY; //the select key position; - int iSelectKeyX, iSelectKeyY; - int iUnthrottleKeyX, iUnthrottleKeyY; - int iLKeyX, iLKeyY; - int iRKeyX, iRKeyY; + float fSelectKeyX, fSelectKeyY; + float fUnthrottleKeyX, fUnthrottleKeyY; + float fLKeyX, fLKeyY; + float fRKeyX, fRKeyY; //position of the analog stick - int iAnalogStickX, iAnalogStickY; + float fAnalogStickX, fAnalogStickY; // Controls Visibility bool bShowTouchControls; diff --git a/UI/GamepadEmu.cpp b/UI/GamepadEmu.cpp index 7eca53adb1..ebef4af128 100644 --- a/UI/GamepadEmu.cpp +++ b/UI/GamepadEmu.cpp @@ -286,10 +286,10 @@ void InitPadLayout() { int Action_button_center_X = dp_xres - Action_button_spacing * 2; int Action_button_center_Y = dp_yres - Action_button_spacing * 2; - if(g_Config.iActionButtonCenterX == -1 || g_Config.iActionButtonCenterY == -1 ) { + if(g_Config.fActionButtonCenterX == -1.0 || g_Config.fActionButtonCenterY == -1.0 ) { //setup defaults - g_Config.iActionButtonCenterX = Action_button_center_X; - g_Config.iActionButtonCenterY = Action_button_center_Y; + g_Config.fActionButtonCenterX = (float)Action_button_center_X / dp_xres; + g_Config.fActionButtonCenterY = (float)Action_button_center_Y / dp_yres; } @@ -307,10 +307,10 @@ void InitPadLayout() { D_pad_Y -= 200 * scale; } - if(g_Config.iDpadX == -1 || g_Config.iDpadY == -1 ) { + if(g_Config.fDpadX == -1.0 || g_Config.fDpadY == -1.0 ) { //setup defaults - g_Config.iDpadX = D_pad_X; - g_Config.iDpadY = D_pad_Y; + g_Config.fDpadX = (float)D_pad_X / dp_xres; + g_Config.fDpadY = (float)D_pad_Y / dp_yres; } //analog stick------------------------------------------------------- @@ -318,9 +318,9 @@ void InitPadLayout() { int analog_stick_X = D_pad_X; int analog_stick_Y = dp_yres - 80 * scale; - if (g_Config.iAnalogStickX == -1 || g_Config.iAnalogStickY == -1 ) { - g_Config.iAnalogStickX = analog_stick_X; - g_Config.iAnalogStickY = analog_stick_Y; + if (g_Config.fAnalogStickX == -1.0 || g_Config.fAnalogStickY == -1.0 ) { + g_Config.fAnalogStickX = (float)analog_stick_X / dp_xres; + g_Config.fAnalogStickY = (float)analog_stick_Y / dp_yres; } //select, start, throttle-------------------------------------------- @@ -330,42 +330,42 @@ void InitPadLayout() { int start_key_X = dp_xres / 2 + (bottom_key_spacing) * scale; int start_key_Y = dp_yres - 60 * scale; - if (g_Config.iStartKeyX == -1 || g_Config.iStartKeyY == -1 ) { - g_Config.iStartKeyX = start_key_X; - g_Config.iStartKeyY = start_key_Y; + if (g_Config.fStartKeyX == -1.0 || g_Config.fStartKeyY == -1.0 ) { + g_Config.fStartKeyX = (float)start_key_X / dp_xres; + g_Config.fStartKeyY = (float)start_key_Y / dp_yres; } int select_key_X = dp_xres / 2; int select_key_Y = dp_yres - 60 * scale; - if (g_Config.iSelectKeyX == -1 || g_Config.iSelectKeyY == -1 ) { - g_Config.iSelectKeyX = select_key_X; - g_Config.iSelectKeyY = select_key_Y; + if (g_Config.fSelectKeyX == -1.0 || g_Config.fSelectKeyY == -1.0 ) { + g_Config.fSelectKeyX = (float)select_key_X / dp_xres; + g_Config.fSelectKeyY = (float)select_key_Y / dp_yres; } int unthrottle_key_X = dp_xres / 2 - (bottom_key_spacing) * scale; int unthrottle_key_Y = dp_yres - 60 * scale; - if (g_Config.iUnthrottleKeyX == -1 || g_Config.iUnthrottleKeyY == -1 ) { - g_Config.iUnthrottleKeyX = unthrottle_key_X; - g_Config.iUnthrottleKeyY = unthrottle_key_Y; + if (g_Config.fUnthrottleKeyX == -1.0 || g_Config.fUnthrottleKeyY == -1.0 ) { + g_Config.fUnthrottleKeyX = (float)unthrottle_key_X / dp_xres; + g_Config.fUnthrottleKeyY = (float)unthrottle_key_Y / dp_yres; } //L and R------------------------------------------------------------ int l_key_X = 70 * scale; int l_key_Y = 40 * scale; - if (g_Config.iLKeyX == -1 || g_Config.iLKeyY == -1 ) { - g_Config.iLKeyX = l_key_X; - g_Config.iLKeyY = l_key_Y; + if (g_Config.fLKeyX == -1.0 || g_Config.fLKeyY == -1.0 ) { + g_Config.fLKeyX = (float)l_key_X / dp_xres; + g_Config.fLKeyY = (float)l_key_Y / dp_yres; } int r_key_X = dp_xres - 60 * scale; int r_key_Y = 40 * scale; - if (g_Config.iRKeyX == -1 || g_Config.iRKeyY == -1 ) { - g_Config.iRKeyX = r_key_X; - g_Config.iRKeyY = r_key_Y; + if (g_Config.fRKeyX == -1.0 || g_Config.fRKeyY == -1.0 ) { + g_Config.fRKeyX = (float)r_key_X / dp_xres; + g_Config.fRKeyY = (float)r_key_Y / dp_yres; } }; @@ -382,8 +382,8 @@ UI::ViewGroup *CreatePadLayout(bool *pause) { //space between the PSP buttons (traingle, circle, square and cross) const int Action_button_spacing = g_Config.iActionButtonSpacing; //position of the circle button (the PSP circle button). It is the farthest to the left - int Action_button_center_X = g_Config.iActionButtonCenterX; - int Action_button_center_Y = g_Config.iActionButtonCenterY; + int Action_button_center_X = g_Config.fActionButtonCenterX * dp_xres; + int Action_button_center_Y = g_Config.fActionButtonCenterY * dp_yres; const int Action_circle_button_X = Action_button_center_X + Action_button_spacing; const int Action_circle_button_Y = Action_button_center_Y; @@ -401,31 +401,31 @@ UI::ViewGroup *CreatePadLayout(bool *pause) { //radius to the D-pad const int D_pad_Radius = g_Config.iDpadRadius; - int D_pad_X = g_Config.iDpadX; - int D_pad_Y = g_Config.iDpadY; + int D_pad_X = g_Config.fDpadX * dp_xres; + int D_pad_Y = g_Config.fDpadY * dp_yres; //select, start, throttle-------------------------------------------- //space between the bottom keys (space between select, start and un-throttle) - int start_key_X = g_Config.iStartKeyX; - int start_key_Y = g_Config.iStartKeyY; + int start_key_X = g_Config.fStartKeyX * dp_xres; + int start_key_Y = g_Config.fStartKeyY * dp_yres; - int select_key_X = g_Config.iSelectKeyX; - int select_key_Y = g_Config.iSelectKeyY; + int select_key_X = g_Config.fSelectKeyX * dp_xres; + int select_key_Y = g_Config.fSelectKeyY * dp_yres; - int unthrottle_key_X = g_Config.iUnthrottleKeyX; - int unthrottle_key_Y = g_Config.iUnthrottleKeyY; + int unthrottle_key_X = g_Config.fUnthrottleKeyX * dp_xres; + int unthrottle_key_Y = g_Config.fUnthrottleKeyY * dp_yres; //L and R------------------------------------------------------------ - int l_key_X = g_Config.iLKeyX; - int l_key_Y = g_Config.iLKeyY; + int l_key_X = g_Config.fLKeyX * dp_xres; + int l_key_Y = g_Config.fLKeyY * dp_yres; - int r_key_X = g_Config.iRKeyX; - int r_key_Y = g_Config.iRKeyY; + int r_key_X = g_Config.fRKeyX * dp_xres; + int r_key_Y = g_Config.fRKeyY * dp_yres; //analog stick------------------------------------------------------- - int analog_stick_X = g_Config.iAnalogStickX; - int analog_stick_Y = g_Config.iAnalogStickY; + int analog_stick_X = g_Config.fAnalogStickX * dp_xres; + int analog_stick_Y = g_Config.fAnalogStickY * dp_yres; const int halfW = dp_xres / 2; diff --git a/UI/TouchControlLayoutScreen.cpp b/UI/TouchControlLayoutScreen.cpp index c232cd7c1f..4e4fcb32d2 100644 --- a/UI/TouchControlLayoutScreen.cpp +++ b/UI/TouchControlLayoutScreen.cpp @@ -32,18 +32,18 @@ static const int leftMargin = 140; // convert from screen coordinates (leftMargin to dp_xres) to actual fullscreen coordinates (0 to dp_xres) static inline int toFullscreenCoord(int screenx) { - return ((float)dp_xres / (dp_xres - leftMargin)) * (screenx - leftMargin); + return ((float)1.0 / (dp_xres - leftMargin)) * (screenx - leftMargin); } // convert from external fullscreen coordinates(0 to dp_xres) to the current partial coordinates (leftMargin to dp_xres) -static inline int fromFullscreenCoord(int controllerX) { - return leftMargin + ((dp_xres - leftMargin) / (float)dp_xres) * controllerX; +static inline int fromFullscreenCoord(float controllerX) { + return leftMargin + (dp_xres - leftMargin) * controllerX; }; class DragDropButton : public MultiTouchButton { public: - DragDropButton(int &x, int &y, int bgImg, int img, float scale) - : MultiTouchButton(bgImg, img, scale, new UI::AnchorLayoutParams(fromFullscreenCoord(x), y, UI::NONE, UI::NONE, true)), + DragDropButton(float &x, float &y, int bgImg, int img, float scale) + : MultiTouchButton(bgImg, img, scale, new UI::AnchorLayoutParams(fromFullscreenCoord(x), y*dp_yres, UI::NONE, UI::NONE, true)), x_(x), y_(y) { scale_ = scale; } @@ -56,16 +56,16 @@ public: void SavePosition() { x_ = toFullscreenCoord(bounds_.centerX()); - y_ = bounds_.centerY(); + y_ = bounds_.centerY() / dp_yres; } private: - int &x_, &y_; + float &x_, &y_; }; class PSPActionButtons : public DragDropButton { public: - PSPActionButtons(int &x, int &y, int actionButtonSpacing, float scale) + PSPActionButtons(float &x, float &y, int actionButtonSpacing, float scale) : DragDropButton(x, y, -1, -1, scale), actionButtonSpacing_(actionButtonSpacing) { using namespace UI; roundId_ = I_ROUND; @@ -145,7 +145,7 @@ private: class PSPDPadButtons : public DragDropButton { public: - PSPDPadButtons(int &x, int &y, int DpadRadius, float scale) + PSPDPadButtons(float &x, float &y, int DpadRadius, float scale) : DragDropButton(x, y, -1, -1, scale), DpadRadius_(DpadRadius) { } @@ -236,23 +236,23 @@ UI::EventReturn TouchControlLayoutScreen::OnVisibility(UI::EventParams &e) { UI::EventReturn TouchControlLayoutScreen::OnReset(UI::EventParams &e) { g_Config.iActionButtonSpacing = -1; - g_Config.iActionButtonCenterX = -1; - g_Config.iActionButtonCenterY = -1; + g_Config.fActionButtonCenterX = -1.0; + g_Config.fActionButtonCenterY = -1.0; g_Config.iDpadRadius = -1; - g_Config.iDpadX = -1; - g_Config.iDpadY = -1; - g_Config.iStartKeyX = -1; - g_Config.iStartKeyY = -1; - g_Config.iSelectKeyX = -1; - g_Config.iSelectKeyY = -1; - g_Config.iUnthrottleKeyX = -1; - g_Config.iUnthrottleKeyY = -1; - g_Config.iLKeyX = -1; - g_Config.iLKeyY = -1; - g_Config.iRKeyX = -1; - g_Config.iRKeyY = -1; - g_Config.iAnalogStickX = -1; - g_Config.iAnalogStickY = -1; + g_Config.fDpadX = -1.0; + g_Config.fDpadY = -1.0; + g_Config.fStartKeyX = -1.0; + g_Config.fStartKeyY = -1.0; + g_Config.fSelectKeyX = -1.0; + g_Config.fSelectKeyY = -1.0; + g_Config.fUnthrottleKeyX = -1.0; + g_Config.fUnthrottleKeyY = -1.0; + g_Config.fLKeyX = -1.0; + g_Config.fLKeyY = -1.0; + g_Config.fRKeyX = -1.0; + g_Config.fRKeyY = -1.0; + g_Config.fAnalogStickX = -1.0; + g_Config.fAnalogStickY = -1.0; InitPadLayout(); RecreateViews(); return UI::EVENT_DONE; @@ -302,7 +302,7 @@ void TouchControlLayoutScreen::CreateViews() { float scale = g_Config.fButtonScale; controls_.clear(); - PSPActionButtons *actionButtons = new PSPActionButtons(g_Config.iActionButtonCenterX, g_Config.iActionButtonCenterY, g_Config.iActionButtonSpacing, scale); + PSPActionButtons *actionButtons = new PSPActionButtons(g_Config.fActionButtonCenterX, g_Config.fActionButtonCenterY, g_Config.iActionButtonSpacing, scale); actionButtons->setCircleVisibility(g_Config.bShowTouchCircle); actionButtons->setCrossVisibility(g_Config.bShowTouchCross); actionButtons->setTriangleVisibility(g_Config.bShowTouchTriangle); @@ -311,35 +311,35 @@ void TouchControlLayoutScreen::CreateViews() { controls_.push_back(actionButtons); if (g_Config.bShowTouchDpad) { - controls_.push_back(new PSPDPadButtons(g_Config.iDpadX, g_Config.iDpadY, g_Config.iDpadRadius, scale)); + controls_.push_back(new PSPDPadButtons(g_Config.fDpadX, g_Config.fDpadY, g_Config.iDpadRadius, scale)); } if (g_Config.bShowTouchSelect) { - controls_.push_back(new DragDropButton(g_Config.iSelectKeyX, g_Config.iSelectKeyY, I_RECT, I_SELECT, scale)); + controls_.push_back(new DragDropButton(g_Config.fSelectKeyX, g_Config.fSelectKeyY, I_RECT, I_SELECT, scale)); } if (g_Config.bShowTouchStart) { - controls_.push_back(new DragDropButton(g_Config.iStartKeyX, g_Config.iStartKeyY, I_RECT, I_START, scale)); + controls_.push_back(new DragDropButton(g_Config.fStartKeyX, g_Config.fStartKeyY, I_RECT, I_START, scale)); } if (g_Config.bShowTouchUnthrottle) { - DragDropButton *unthrottle = new DragDropButton(g_Config.iUnthrottleKeyX, g_Config.iUnthrottleKeyY, I_RECT, I_ARROW, scale); + DragDropButton *unthrottle = new DragDropButton(g_Config.fUnthrottleKeyX, g_Config.fUnthrottleKeyY, I_RECT, I_ARROW, scale); unthrottle->SetAngle(180.0f); controls_.push_back(unthrottle); } if (g_Config.bShowTouchLTrigger) { - controls_.push_back(new DragDropButton(g_Config.iLKeyX, g_Config.iLKeyY, I_SHOULDER, I_L, scale)); + controls_.push_back(new DragDropButton(g_Config.fLKeyX, g_Config.fLKeyY, I_SHOULDER, I_L, scale)); } if (g_Config.bShowTouchRTrigger) { - DragDropButton *rbutton = new DragDropButton(g_Config.iRKeyX, g_Config.iRKeyY, I_SHOULDER, I_R, scale); + DragDropButton *rbutton = new DragDropButton(g_Config.fRKeyX, g_Config.fRKeyY, I_SHOULDER, I_R, scale); rbutton->FlipImageH(true); controls_.push_back(rbutton); } if (g_Config.bShowTouchAnalogStick) { - controls_.push_back(new DragDropButton(g_Config.iAnalogStickX, g_Config.iAnalogStickY, I_STICKBG, I_STICK, scale)); + controls_.push_back(new DragDropButton(g_Config.fAnalogStickX, g_Config.fAnalogStickY, I_STICKBG, I_STICK, scale)); }; for (size_t i = 0; i < controls_.size(); i++) {