From 44e28491052816295ad12a8bedd5b7ddc202fedf Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 5 Apr 2020 11:46:04 -0700 Subject: [PATCH 1/4] UI: Make display layout editor support 1x PSP. When your window is at 1x PSP, we adjust DPI which the layout editor was confused by. --- UI/DisplayLayoutScreen.cpp | 68 ++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/UI/DisplayLayoutScreen.cpp b/UI/DisplayLayoutScreen.cpp index c7a6a18222..77c80ac978 100644 --- a/UI/DisplayLayoutScreen.cpp +++ b/UI/DisplayLayoutScreen.cpp @@ -18,6 +18,7 @@ #include #include "base/colorutil.h" +#include "base/display.h" #include "gfx/texture_atlas.h" #include "gfx_es2/draw_buffer.h" #include "i18n/i18n.h" @@ -38,6 +39,27 @@ static const float orgRatio = 1.764706f; static float local_dp_xres; static float local_dp_yres; +static float ScaleSettingToUI() { + float scale = g_Config.fSmallDisplayZoomLevel * 8.0f; + // Account for 1x display doubling dps. + if (g_dpi_scale_x > 1.0f) { + scale *= g_dpi_scale_x; + } + return scale; +} + +static void UpdateScaleSetting(float scale) { + // Account for 1x display doubling dps. + if (g_dpi_scale_x > 1.0f) { + scale /= g_dpi_scale_x; + } + g_Config.fSmallDisplayZoomLevel = scale; +} + +static void UpdateScaleSettingFromUI(float scale) { + UpdateScaleSetting(scale / 8.0f); +} + class DragDropDisplay : public MultiTouchDisplay { public: DragDropDisplay(float &x, float &y, ImageID img, float &scale) @@ -145,7 +167,7 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) { if (newScale < 8.0f) newScale = 8.0f; picked_->SetScale(newScale); scaleUpdate_ = picked_->GetScale(); - g_Config.fSmallDisplayZoomLevel = scaleUpdate_ / 8.0f; + UpdateScaleSettingFromUI(scaleUpdate_); } } if ((touch.flags & TOUCH_DOWN) && picked_ == 0) { @@ -191,8 +213,8 @@ UI::EventReturn DisplayLayoutScreen::OnZoomTypeChange(UI::EventParams &e) { if (g_Config.iSmallDisplayZoomType < (int)SmallDisplayZoom::MANUAL) { const Bounds &bounds = screenManager()->getUIContext()->GetBounds(); float autoBound = bounds.w / 480.0f; - g_Config.fSmallDisplayZoomLevel = autoBound; - displayRepresentationScale_ = g_Config.fSmallDisplayZoomLevel * 8.0f; + UpdateScaleSetting(autoBound); + displayRepresentationScale_ = ScaleSettingToUI(); g_Config.fSmallDisplayOffsetX = 0.5f; g_Config.fSmallDisplayOffsetY = 0.5f; } @@ -239,12 +261,12 @@ void DisplayLayoutScreen::CreateViews() { root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT)); - const float previewWidth = local_dp_xres / 2.0f; - const float previewHeight = local_dp_yres / 2.0f; + const float previewWidth = bounds.w / 2.0f; + const float previewHeight = bounds.h / 2.0f; // Just visual boundaries of the screen, should be easier to use than imagination - const float horizPreviewPadding = local_dp_xres / 4.0f; - const float vertPreviewPadding = local_dp_yres / 4.0f; + const float horizPreviewPadding = bounds.w / 4.0f; + const float vertPreviewPadding = bounds.h / 4.0f; const float horizBoundariesWidth = 4.0f; // This makes it have at least 10.0f padding below at 1x. const float vertBoundariesHeight = 52.0f; @@ -260,7 +282,7 @@ void DisplayLayoutScreen::CreateViews() { zoom_->OnChoice.Handle(this, &DisplayLayoutScreen::OnZoomTypeChange); static const char *displayRotation[] = { "Landscape", "Portrait", "Landscape Reversed", "Portrait Reversed" }; - rotation_ = new PopupMultiChoice(&g_Config.iInternalScreenRotation, gr->T("Rotation"), displayRotation, 1, ARRAY_SIZE(displayRotation), co->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, previewWidth - 200.0f, 10, NONE, local_dp_yres - 64 - 10)); + rotation_ = new PopupMultiChoice(&g_Config.iInternalScreenRotation, gr->T("Rotation"), displayRotation, 1, ARRAY_SIZE(displayRotation), co->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, previewWidth - 200.0f, 10, NONE, bounds.h - 64 - 10)); rotation_->SetEnabledFunc([] { return g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; }); @@ -269,39 +291,43 @@ void DisplayLayoutScreen::CreateViews() { if (displayRotEnable && (g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL || g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL180)) { bRotated = true; } - displayRepresentationScale_ = g_Config.fSmallDisplayZoomLevel * 8.0f; // Visual representation image is just icon size and have to be scaled 8 times to match PSP native resolution which is used as 1.0 for zoom + // Visual representation image is just icon size and have to be scaled 8 times to match PSP native resolution which is used as 1.0 for zoom + displayRepresentationScale_ = ScaleSettingToUI(); HighlightLabel *label = nullptr; mode_ = nullptr; if (g_Config.iSmallDisplayZoomType >= (int)SmallDisplayZoom::AUTO) { // Scaling if (g_Config.iSmallDisplayZoomType == (int)SmallDisplayZoom::AUTO) { - label = new HighlightLabel(gr->T("Auto Scaling"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, local_dp_xres / 2.0f, local_dp_yres / 2.0f, NONE, NONE, true)); - float autoBound = local_dp_yres / 270.0f; + label = new HighlightLabel(gr->T("Auto Scaling"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, bounds.w / 2.0f, bounds.h / 2.0f, NONE, NONE, true)); + float autoBound = bounds.h / 270.0f; // Case of screen rotated ~ only works with buffered rendering if (bRotated) { - autoBound = local_dp_yres / 480.0f; - } - else { // Without rotation in common cases like 1080p we cut off 2 pixels of height, this reflects other cases + autoBound = bounds.h / 480.0f; + } else { // Without rotation in common cases like 1080p we cut off 2 pixels of height, this reflects other cases float resCommonWidescreen = autoBound - floor(autoBound); if (resCommonWidescreen != 0.0f) { - float ratio = local_dp_xres / local_dp_yres; + float ratio = bounds.w / bounds.h; if (ratio < orgRatio) { - autoBound = local_dp_xres / 480.0f; + autoBound = bounds.w / 480.0f; } else { - autoBound = local_dp_yres / 272.0f; + autoBound = bounds.h / 272.0f; } } } - g_Config.fSmallDisplayZoomLevel = autoBound; - displayRepresentationScale_ = g_Config.fSmallDisplayZoomLevel * 8.0f; + UpdateScaleSetting(autoBound); + displayRepresentationScale_ = ScaleSettingToUI(); g_Config.fSmallDisplayOffsetX = 0.5f; g_Config.fSmallDisplayOffsetY = 0.5f; } else { // Manual Scaling Choice *center = new Choice(di->T("Center"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 74)); center->OnClick.Handle(this, &DisplayLayoutScreen::OnCenter); root_->Add(center); - PopupSliderChoiceFloat *zoomlvl = new PopupSliderChoiceFloat(&g_Config.fSmallDisplayZoomLevel, 1.0f, 10.0f, di->T("Zoom"), 1.0f, screenManager(), di->T("* PSP res"), new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10 + 64 + 64)); + float minZoom = 1.0f; + if (g_dpi_scale_x > 1.0f) { + minZoom /= g_dpi_scale_x; + } + PopupSliderChoiceFloat *zoomlvl = new PopupSliderChoiceFloat(&g_Config.fSmallDisplayZoomLevel, minZoom, 10.0f, di->T("Zoom"), 1.0f, screenManager(), di->T("* PSP res"), new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10 + 64 + 64)); root_->Add(zoomlvl); mode_ = new ChoiceStrip(ORIENT_VERTICAL, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 158 + 64 + 10)); mode_->AddChoice(di->T("Move")); @@ -311,7 +337,7 @@ void DisplayLayoutScreen::CreateViews() { displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), displayRepresentationScale_); displayRepresentation_->SetVisibility(V_VISIBLE); } else { // Stretching - label = new HighlightLabel(gr->T("Stretching"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, local_dp_xres / 2.0f, local_dp_yres / 2.0f, NONE, NONE, true)); + label = new HighlightLabel(gr->T("Stretching"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, bounds.w / 2.0f, bounds.h / 2.0f, NONE, NONE, true)); displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), displayRepresentationScale_); displayRepresentation_->SetVisibility(V_INVISIBLE); float width = previewWidth; From 801617bfc6063f8043d9b05c40cf370e8041692f Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 5 Apr 2020 11:56:07 -0700 Subject: [PATCH 2/4] UI: Prevent drag drift in layout editor. Fixes #12797. --- UI/DisplayLayoutScreen.cpp | 56 ++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/UI/DisplayLayoutScreen.cpp b/UI/DisplayLayoutScreen.cpp index 77c80ac978..10a5a15fa8 100644 --- a/UI/DisplayLayoutScreen.cpp +++ b/UI/DisplayLayoutScreen.cpp @@ -35,10 +35,6 @@ static const int leftColumnWidth = 200; static const float orgRatio = 1.764706f; -// Ugly hackery, need to rework some stuff to get around this -static float local_dp_xres; -static float local_dp_yres; - static float ScaleSettingToUI() { float scale = g_Config.fSmallDisplayZoomLevel * 8.0f; // Account for 1x display doubling dps. @@ -62,33 +58,32 @@ static void UpdateScaleSettingFromUI(float scale) { class DragDropDisplay : public MultiTouchDisplay { public: - DragDropDisplay(float &x, float &y, ImageID img, float &scale) - : MultiTouchDisplay(img, scale, new UI::AnchorLayoutParams(x * local_dp_xres, y * local_dp_yres, UI::NONE, UI::NONE, true)), - x_(x), y_(y), theScale_(scale) { + DragDropDisplay(float &x, float &y, ImageID img, float &scale, const Bounds &screenBounds) + : MultiTouchDisplay(img, scale, new UI::AnchorLayoutParams(x * screenBounds.w, y * screenBounds.h, UI::NONE, UI::NONE, true)), + x_(x), y_(y), theScale_(scale), screenBounds_(screenBounds) { scale_ = theScale_; } virtual void SaveDisplayPosition() { - x_ = bounds_.centerX() / local_dp_xres; - y_ = bounds_.centerY() / local_dp_yres; + x_ = bounds_.centerX() / screenBounds_.w; + y_ = bounds_.centerY() / screenBounds_.h; scale_ = theScale_; } virtual float GetScale() const { return theScale_; } virtual void SetScale(float s) { theScale_ = s; scale_ = s; } - private: - +private: float &x_, &y_; float &theScale_; + const Bounds &screenBounds_; }; DisplayLayoutScreen::DisplayLayoutScreen() { - picked_ = 0; + picked_ = nullptr; mode_ = nullptr; }; - bool DisplayLayoutScreen::touch(const TouchInput &touch) { UIScreen::touch(touch); @@ -100,17 +95,18 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) { } const Bounds &screen_bounds = screenManager()->getUIContext()->GetBounds(); - if ((touch.flags & TOUCH_MOVE) && picked_ != 0) { + if ((touch.flags & TOUCH_MOVE) && picked_ != nullptr) { int touchX = touch.x - offsetTouchX; int touchY = touch.y - offsetTouchY; if (mode == 0) { - const Bounds &bounds = picked_->GetBounds(); + const auto &prevParams = picked_->GetLayoutParams()->As(); + Point newPos(prevParams->left, prevParams->top); int limitX = g_Config.fSmallDisplayZoomLevel * 120; int limitY = g_Config.fSmallDisplayZoomLevel * 68; - const int quarterResX = local_dp_xres / 4; - const int quarterResY = local_dp_yres / 4; + const int quarterResX = screen_bounds.w / 4; + const int quarterResY = screen_bounds.h / 4; if (bRotated) { //swap X/Y limit for rotated display @@ -131,10 +127,10 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) { if (touchY > windowUpperEdge - 8 + limitY && touchY < windowUpperEdge + 8 + limitY) { touchY = windowUpperEdge + limitY; stickToEdgeY = true; } if (touchY > windowLowerEdge - 8 - limitY && touchY < windowLowerEdge + 8 - limitY) { touchY = windowLowerEdge - limitY; stickToEdgeY = true; } - const int minX = local_dp_xres / 2; - const int maxX = local_dp_xres + minX; - const int minY = local_dp_yres / 2; - const int maxY = local_dp_yres + minY; + const int minX = screen_bounds.w / 2; + const int maxX = screen_bounds.w + minX; + const int minY = screen_bounds.h / 2; + const int maxY = screen_bounds.h + minY; // Display visualization disappear outside of those bounds, so we have to limit if (touchX < -minX) touchX = -minX; if (touchX > maxX) touchX = maxX; @@ -145,15 +141,14 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) { if (quarterResX > limitX) limitX = quarterResX; if (quarterResY > limitY) limitY = quarterResY; - int newX = bounds.centerX(), newY = bounds.centerY(); // Allow moving zoomed in display freely as long as at least noticeable portion of the screen is occupied if (touchX > minX - limitX - 10 && touchX < minX + limitX + 10) { - newX = touchX; + newPos.x = touchX; } if (touchY > minY - limitY - 10 && touchY < minY + limitY + 10) { - newY = touchY; + newPos.y = touchY; } - picked_->ReplaceLayoutParams(new UI::AnchorLayoutParams(newX, newY, NONE, NONE, true)); + picked_->ReplaceLayoutParams(new AnchorLayoutParams(newPos.x, newPos.y, NONE, NONE, true)); } else if (mode == 1) { // Resize. Vertical = scaling, horizontal = spacing; // Up should be bigger so let's negate in that direction @@ -183,11 +178,9 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) { } if ((touch.flags & TOUCH_UP) && picked_ != 0) { const Bounds &bounds = picked_->GetBounds(); - float saveX_ = touch.x; - float saveY_ = touch.y; startScale_ = picked_->GetScale(); picked_->SaveDisplayPosition(); - picked_ = 0; + picked_ = nullptr; } return true; } @@ -250,9 +243,6 @@ public: void DisplayLayoutScreen::CreateViews() { const Bounds &bounds = screenManager()->getUIContext()->GetBounds(); - local_dp_xres = bounds.w; - local_dp_yres = bounds.h; - using namespace UI; auto di = GetI18NCategory("Dialog"); @@ -334,11 +324,11 @@ void DisplayLayoutScreen::CreateViews() { mode_->AddChoice(di->T("Resize")); mode_->SetSelection(0); } - displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), displayRepresentationScale_); + displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), displayRepresentationScale_, bounds); displayRepresentation_->SetVisibility(V_VISIBLE); } else { // Stretching label = new HighlightLabel(gr->T("Stretching"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, bounds.w / 2.0f, bounds.h / 2.0f, NONE, NONE, true)); - displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), displayRepresentationScale_); + displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), displayRepresentationScale_, bounds); displayRepresentation_->SetVisibility(V_INVISIBLE); float width = previewWidth; float height = previewHeight; From 0a353cc9fad716f2a48a4cc72b505a3e78684651 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 5 Apr 2020 12:30:59 -0700 Subject: [PATCH 3/4] UI: General cleanup in layout editor. --- UI/DisplayLayoutScreen.cpp | 145 +++++++++++++++++-------------------- UI/DisplayLayoutScreen.h | 23 +++--- 2 files changed, 78 insertions(+), 90 deletions(-) diff --git a/UI/DisplayLayoutScreen.cpp b/UI/DisplayLayoutScreen.cpp index 10a5a15fa8..7bbeaa2f9e 100644 --- a/UI/DisplayLayoutScreen.cpp +++ b/UI/DisplayLayoutScreen.cpp @@ -15,6 +15,7 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include #include #include "base/colorutil.h" @@ -35,8 +36,9 @@ static const int leftColumnWidth = 200; static const float orgRatio = 1.764706f; +static const float UI_DISPLAY_SCALE = 8.0f; static float ScaleSettingToUI() { - float scale = g_Config.fSmallDisplayZoomLevel * 8.0f; + float scale = g_Config.fSmallDisplayZoomLevel * UI_DISPLAY_SCALE; // Account for 1x display doubling dps. if (g_dpi_scale_x > 1.0f) { scale *= g_dpi_scale_x; @@ -53,35 +55,35 @@ static void UpdateScaleSetting(float scale) { } static void UpdateScaleSettingFromUI(float scale) { - UpdateScaleSetting(scale / 8.0f); + UpdateScaleSetting(scale / UI_DISPLAY_SCALE); } class DragDropDisplay : public MultiTouchDisplay { public: - DragDropDisplay(float &x, float &y, ImageID img, float &scale, const Bounds &screenBounds) + DragDropDisplay(float &x, float &y, ImageID img, float scale, const Bounds &screenBounds) : MultiTouchDisplay(img, scale, new UI::AnchorLayoutParams(x * screenBounds.w, y * screenBounds.h, UI::NONE, UI::NONE, true)), - x_(x), y_(y), theScale_(scale), screenBounds_(screenBounds) { - scale_ = theScale_; + x_(x), y_(y), screenBounds_(screenBounds) { + UpdateScale(scale); } - virtual void SaveDisplayPosition() { + void SaveDisplayPosition() { x_ = bounds_.centerX() / screenBounds_.w; y_ = bounds_.centerY() / screenBounds_.h; - scale_ = theScale_; } - virtual float GetScale() const { return theScale_; } - virtual void SetScale(float s) { theScale_ = s; scale_ = s; } + void UpdateScale(float s) { + scale_ = s; + } + float Scale() { + return scale_; + } private: float &x_, &y_; - float &theScale_; const Bounds &screenBounds_; }; DisplayLayoutScreen::DisplayLayoutScreen() { - picked_ = nullptr; - mode_ = nullptr; }; bool DisplayLayoutScreen::touch(const TouchInput &touch) { @@ -95,11 +97,11 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) { } const Bounds &screen_bounds = screenManager()->getUIContext()->GetBounds(); - if ((touch.flags & TOUCH_MOVE) && picked_ != nullptr) { - int touchX = touch.x - offsetTouchX; - int touchY = touch.y - offsetTouchY; + if ((touch.flags & TOUCH_MOVE) != 0 && dragging_) { + int touchX = touch.x - offsetTouchX_; + int touchY = touch.y - offsetTouchY_; if (mode == 0) { - const auto &prevParams = picked_->GetLayoutParams()->As(); + const auto &prevParams = displayRepresentation_->GetLayoutParams()->As(); Point newPos(prevParams->left, prevParams->top); int limitX = g_Config.fSmallDisplayZoomLevel * 120; @@ -108,11 +110,9 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) { const int quarterResX = screen_bounds.w / 4; const int quarterResY = screen_bounds.h / 4; - if (bRotated) { + if (bRotated_) { //swap X/Y limit for rotated display - int limitTemp = limitX; - limitX = limitY; - limitY = limitTemp; + std::swap(limitX, limitY); } // Check where each edge of the screen is @@ -121,11 +121,12 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) { const int windowUpperEdge = quarterResY; const int windowLowerEdge = windowUpperEdge * 3; // And stick display when close to any edge - stickToEdgeX = false; stickToEdgeY = false; - if (touchX > windowLeftEdge - 8 + limitX && touchX < windowLeftEdge + 8 + limitX) { touchX = windowLeftEdge + limitX; stickToEdgeX = true; } - if (touchX > windowRightEdge - 8 - limitX && touchX < windowRightEdge + 8 - limitX) { touchX = windowRightEdge - limitX; stickToEdgeX = true; } - if (touchY > windowUpperEdge - 8 + limitY && touchY < windowUpperEdge + 8 + limitY) { touchY = windowUpperEdge + limitY; stickToEdgeY = true; } - if (touchY > windowLowerEdge - 8 - limitY && touchY < windowLowerEdge + 8 - limitY) { touchY = windowLowerEdge - limitY; stickToEdgeY = true; } + stickToEdgeX_ = false; + stickToEdgeY_ = false; + if (touchX > windowLeftEdge - 8 + limitX && touchX < windowLeftEdge + 8 + limitX) { touchX = windowLeftEdge + limitX; stickToEdgeX_ = true; } + if (touchX > windowRightEdge - 8 - limitX && touchX < windowRightEdge + 8 - limitX) { touchX = windowRightEdge - limitX; stickToEdgeX_ = true; } + if (touchY > windowUpperEdge - 8 + limitY && touchY < windowUpperEdge + 8 + limitY) { touchY = windowUpperEdge + limitY; stickToEdgeY_ = true; } + if (touchY > windowLowerEdge - 8 - limitY && touchY < windowLowerEdge + 8 - limitY) { touchY = windowLowerEdge - limitY; stickToEdgeY_ = true; } const int minX = screen_bounds.w / 2; const int maxX = screen_bounds.w + minX; @@ -148,39 +149,30 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) { if (touchY > minY - limitY - 10 && touchY < minY + limitY + 10) { newPos.y = touchY; } - picked_->ReplaceLayoutParams(new AnchorLayoutParams(newPos.x, newPos.y, NONE, NONE, true)); + displayRepresentation_->ReplaceLayoutParams(new AnchorLayoutParams(newPos.x, newPos.y, NONE, NONE, true)); } else if (mode == 1) { - // Resize. Vertical = scaling, horizontal = spacing; - // Up should be bigger so let's negate in that direction - float diffX = (touchX - startX_); + // Resize. Vertical = scaling; Up should be bigger so let's negate in that direction float diffY = -(touchY - startY_); float movementScale = 0.5f; float newScale = startScale_ + diffY * movementScale; // Desired scale * 8.0 since the visualization is tiny size and multiplied by 8. - if (newScale > 80.0f) newScale = 80.0f; - if (newScale < 8.0f) newScale = 8.0f; - picked_->SetScale(newScale); - scaleUpdate_ = picked_->GetScale(); - UpdateScaleSettingFromUI(scaleUpdate_); + newScale = clamp_value(newScale, UI_DISPLAY_SCALE, UI_DISPLAY_SCALE * 10.0f); + displayRepresentation_->UpdateScale(newScale); + UpdateScaleSettingFromUI(newScale); } } - if ((touch.flags & TOUCH_DOWN) && picked_ == 0) { - picked_ = displayRepresentation_; - if (picked_) { - const Bounds &bounds = picked_->GetBounds(); - startX_ = bounds.centerX(); - startY_ = bounds.centerY(); - offsetTouchX = touch.x - startX_; - offsetTouchY = touch.y - startY_; - startScale_ = picked_->GetScale(); - } + if ((touch.flags & TOUCH_DOWN) != 0 && !dragging_) { + dragging_ = true; + const Bounds &bounds = displayRepresentation_->GetBounds(); + startY_ = bounds.centerY(); + offsetTouchX_ = touch.x - bounds.centerX(); + offsetTouchY_ = touch.y - bounds.centerY(); + startScale_ = displayRepresentation_->Scale(); } - if ((touch.flags & TOUCH_UP) && picked_ != 0) { - const Bounds &bounds = picked_->GetBounds(); - startScale_ = picked_->GetScale(); - picked_->SaveDisplayPosition(); - picked_ = nullptr; + if ((touch.flags & TOUCH_UP) != 0 && dragging_) { + displayRepresentation_->SaveDisplayPosition(); + dragging_ = false; } return true; } @@ -194,9 +186,9 @@ void DisplayLayoutScreen::onFinish(DialogResult reason) { } UI::EventReturn DisplayLayoutScreen::OnCenter(UI::EventParams &e) { - if (!stickToEdgeX || (stickToEdgeX && stickToEdgeY)) + if (!stickToEdgeX_ || (stickToEdgeX_ && stickToEdgeY_)) g_Config.fSmallDisplayOffsetX = 0.5f; - if (!stickToEdgeY || (stickToEdgeX && stickToEdgeY)) + if (!stickToEdgeY_ || (stickToEdgeX_ && stickToEdgeY_)) g_Config.fSmallDisplayOffsetY = 0.5f; RecreateViews(); return UI::EVENT_DONE; @@ -207,7 +199,7 @@ UI::EventReturn DisplayLayoutScreen::OnZoomTypeChange(UI::EventParams &e) { const Bounds &bounds = screenManager()->getUIContext()->GetBounds(); float autoBound = bounds.w / 480.0f; UpdateScaleSetting(autoBound); - displayRepresentationScale_ = ScaleSettingToUI(); + displayRepresentation_->UpdateScale(ScaleSettingToUI()); g_Config.fSmallDisplayOffsetX = 0.5f; g_Config.fSmallDisplayOffsetY = 0.5f; } @@ -267,22 +259,11 @@ void DisplayLayoutScreen::CreateViews() { root_->Add(new Boundary(new AnchorLayoutParams(previewWidth, vertBoundariesHeight, horizPreviewPadding, vertPreviewPadding - vertBoundariesHeight, NONE, NONE))); root_->Add(new Boundary(new AnchorLayoutParams(previewWidth, vertBoundariesHeight, horizPreviewPadding, NONE, NONE, vertPreviewPadding - vertBoundariesHeight))); - static const char *zoomLevels[] = { "Stretching", "Partial Stretch", "Auto Scaling", "Manual Scaling" }; - zoom_ = new PopupMultiChoice(&g_Config.iSmallDisplayZoomType, di->T("Options"), zoomLevels, 0, ARRAY_SIZE(zoomLevels), gr->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, previewWidth - 200.0f, NONE, NONE, 10)); - zoom_->OnChoice.Handle(this, &DisplayLayoutScreen::OnZoomTypeChange); - - static const char *displayRotation[] = { "Landscape", "Portrait", "Landscape Reversed", "Portrait Reversed" }; - rotation_ = new PopupMultiChoice(&g_Config.iInternalScreenRotation, gr->T("Rotation"), displayRotation, 1, ARRAY_SIZE(displayRotation), co->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, previewWidth - 200.0f, 10, NONE, bounds.h - 64 - 10)); - rotation_->SetEnabledFunc([] { - return g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; - }); bool displayRotEnable = (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE); - bRotated = false; + bRotated_ = false; if (displayRotEnable && (g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL || g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL180)) { - bRotated = true; + bRotated_ = true; } - // Visual representation image is just icon size and have to be scaled 8 times to match PSP native resolution which is used as 1.0 for zoom - displayRepresentationScale_ = ScaleSettingToUI(); HighlightLabel *label = nullptr; mode_ = nullptr; @@ -291,7 +272,7 @@ void DisplayLayoutScreen::CreateViews() { label = new HighlightLabel(gr->T("Auto Scaling"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, bounds.w / 2.0f, bounds.h / 2.0f, NONE, NONE, true)); float autoBound = bounds.h / 270.0f; // Case of screen rotated ~ only works with buffered rendering - if (bRotated) { + if (bRotated_) { autoBound = bounds.h / 480.0f; } else { // Without rotation in common cases like 1080p we cut off 2 pixels of height, this reflects other cases float resCommonWidescreen = autoBound - floor(autoBound); @@ -306,7 +287,6 @@ void DisplayLayoutScreen::CreateViews() { } } UpdateScaleSetting(autoBound); - displayRepresentationScale_ = ScaleSettingToUI(); g_Config.fSmallDisplayOffsetX = 0.5f; g_Config.fSmallDisplayOffsetY = 0.5f; } else { // Manual Scaling @@ -324,11 +304,11 @@ void DisplayLayoutScreen::CreateViews() { mode_->AddChoice(di->T("Resize")); mode_->SetSelection(0); } - displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), displayRepresentationScale_, bounds); + displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), ScaleSettingToUI(), bounds); displayRepresentation_->SetVisibility(V_VISIBLE); } else { // Stretching label = new HighlightLabel(gr->T("Stretching"), new AnchorLayoutParams(WRAP_CONTENT, 64.0f, bounds.w / 2.0f, bounds.h / 2.0f, NONE, NONE, true)); - displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), displayRepresentationScale_, bounds); + displayRepresentation_ = new DragDropDisplay(g_Config.fSmallDisplayOffsetX, g_Config.fSmallDisplayOffsetY, ImageID("I_PSP_DISPLAY"), ScaleSettingToUI(), bounds); displayRepresentation_->SetVisibility(V_INVISIBLE); float width = previewWidth; float height = previewHeight; @@ -337,16 +317,16 @@ void DisplayLayoutScreen::CreateViews() { stretched->SetEnabled(false); root_->Add(stretched); } else { // Partially stretched - float origRatio = !bRotated ? 480.0f / 272.0f : 272.0f / 480.0f; + float origRatio = !bRotated_ ? 480.0f / 272.0f : 272.0f / 480.0f; float frameRatio = width / height; if (origRatio > frameRatio) { height = width / origRatio; - if (!bRotated && g_Config.iSmallDisplayZoomType == (int)SmallDisplayZoom::PARTIAL_STRETCH) { + if (!bRotated_ && g_Config.iSmallDisplayZoomType == (int)SmallDisplayZoom::PARTIAL_STRETCH) { height = (272.0f + height) / 2.0f; } } else { width = height * origRatio; - if (bRotated && g_Config.iSmallDisplayZoomType == (int)SmallDisplayZoom::PARTIAL_STRETCH) { + if (bRotated_ && g_Config.iSmallDisplayZoomType == (int)SmallDisplayZoom::PARTIAL_STRETCH) { width = (272.0f + height) / 2.0f; } } @@ -355,12 +335,10 @@ void DisplayLayoutScreen::CreateViews() { root_->Add(stretched); } } - if (bRotated) { + if (bRotated_) { displayRepresentation_->SetAngle(90.0f); } - Choice *back = new Choice(di->T("Back"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10)); - back->OnClick.Handle(this, &UIScreen::OnBack); root_->Add(displayRepresentation_); if (mode_) { root_->Add(mode_); @@ -368,7 +346,20 @@ void DisplayLayoutScreen::CreateViews() { if (label) { root_->Add(label); } - root_->Add(zoom_); - root_->Add(rotation_); + + static const char *zoomLevels[] = { "Stretching", "Partial Stretch", "Auto Scaling", "Manual Scaling" }; + auto zoom = new PopupMultiChoice(&g_Config.iSmallDisplayZoomType, di->T("Options"), zoomLevels, 0, ARRAY_SIZE(zoomLevels), gr->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, previewWidth - 200.0f, NONE, NONE, 10)); + zoom->OnChoice.Handle(this, &DisplayLayoutScreen::OnZoomTypeChange); + root_->Add(zoom); + + static const char *displayRotation[] = { "Landscape", "Portrait", "Landscape Reversed", "Portrait Reversed" }; + auto rotation = new PopupMultiChoice(&g_Config.iInternalScreenRotation, gr->T("Rotation"), displayRotation, 1, ARRAY_SIZE(displayRotation), co->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, previewWidth - 200.0f, 10, NONE, bounds.h - 64 - 10)); + rotation->SetEnabledFunc([] { + return g_Config.iRenderingMode != FB_NON_BUFFERED_MODE; + }); + root_->Add(rotation); + + Choice *back = new Choice(di->T("Back"), "", false, new AnchorLayoutParams(leftColumnWidth, WRAP_CONTENT, 10, NONE, NONE, 10)); + back->OnClick.Handle(this, &UIScreen::OnBack); root_->Add(back); } diff --git a/UI/DisplayLayoutScreen.h b/UI/DisplayLayoutScreen.h index 45d0906930..1a38ea706f 100644 --- a/UI/DisplayLayoutScreen.h +++ b/UI/DisplayLayoutScreen.h @@ -39,19 +39,16 @@ protected: virtual UI::EventReturn OnZoomTypeChange(UI::EventParams &e); private: - DragDropDisplay *picked_; - DragDropDisplay *displayRepresentation_; - UI::ChoiceStrip *mode_; - UI::PopupMultiChoice *zoom_; - UI::PopupMultiChoice *rotation_; - bool bRotated; - bool stickToEdgeX; - bool stickToEdgeY; + DragDropDisplay *displayRepresentation_ = nullptr; + UI::ChoiceStrip *mode_ = nullptr; + bool dragging_ = false; + bool bRotated_ = false; + bool stickToEdgeX_ = false; + bool stickToEdgeY_ = false; // Touch down state for drag to resize etc - float startX_; - float startY_; - float startScale_, scaleUpdate_; - float displayRepresentationScale_; - int offsetTouchX, offsetTouchY; + float startY_ = 0.0f; + float startScale_ = 1.0f; + int offsetTouchX_ = 0; + int offsetTouchY_ = 0; }; From e291a1d833d1ec78656224d93ef8d1b32ae73188 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 5 Apr 2020 12:50:13 -0700 Subject: [PATCH 4/4] UI: Small cleanup in touch control layout editor. --- UI/TouchControlLayoutScreen.cpp | 156 ++++++++++++-------------------- 1 file changed, 59 insertions(+), 97 deletions(-) diff --git a/UI/TouchControlLayoutScreen.cpp b/UI/TouchControlLayoutScreen.cpp index c970b0f1c0..3e454c5190 100644 --- a/UI/TouchControlLayoutScreen.cpp +++ b/UI/TouchControlLayoutScreen.cpp @@ -33,19 +33,15 @@ static const int leftColumnWidth = 140; -// Ugly hackery, need to rework some stuff to get around this -static float local_dp_xres; -static float local_dp_yres; - static u32 GetButtonColor() { return g_Config.iTouchButtonStyle != 0 ? 0xFFFFFF : 0xc0b080; } class DragDropButton : public MultiTouchButton { public: - DragDropButton(ConfigTouchPos &pos, ImageID bgImg, ImageID img) - : MultiTouchButton(bgImg, bgImg, img, pos.scale, new UI::AnchorLayoutParams(fromFullscreenCoord(pos.x), pos.y * local_dp_yres, UI::NONE, UI::NONE, true)), - x_(pos.x), y_(pos.y), theScale_(pos.scale) { + DragDropButton(ConfigTouchPos &pos, ImageID bgImg, ImageID img, const Bounds &screenBounds) + : MultiTouchButton(bgImg, bgImg, img, pos.scale, new UI::AnchorLayoutParams(fromFullscreenCoord(pos.x, screenBounds), pos.y * screenBounds.h, UI::NONE, UI::NONE, true)), + x_(pos.x), y_(pos.y), theScale_(pos.scale), screenBounds_(screenBounds) { scale_ = theScale_; } @@ -57,7 +53,7 @@ public: virtual void SavePosition() { x_ = toFullscreenCoord(bounds_.centerX()); - y_ = bounds_.centerY() / local_dp_yres; + y_ = bounds_.centerY() / screenBounds_.h; scale_ = theScale_; } @@ -76,22 +72,23 @@ protected: private: // convert from screen coordinates (leftColumnWidth to dp_xres) to actual fullscreen coordinates (0 to 1.0) inline float toFullscreenCoord(int screenx) { - return (float)(screenx - leftColumnWidth) / (local_dp_xres - leftColumnWidth); + return (float)(screenx - leftColumnWidth) / (screenBounds_.w - leftColumnWidth); } // convert from external fullscreen coordinates(0 to 1.0) to the current partial coordinates (leftColumnWidth to dp_xres) - inline int fromFullscreenCoord(float controllerX) { - return leftColumnWidth + (local_dp_xres - leftColumnWidth) * controllerX; + inline int fromFullscreenCoord(float controllerX, const Bounds &screenBounds) { + return leftColumnWidth + (screenBounds.w - leftColumnWidth) * controllerX; }; float &x_, &y_; float &theScale_; + const Bounds &screenBounds_; }; class PSPActionButtons : public DragDropButton { public: - PSPActionButtons(ConfigTouchPos &pos, float &spacing) - : DragDropButton(pos, ImageID::invalid(), ImageID::invalid()), spacing_(spacing) { + PSPActionButtons(ConfigTouchPos &pos, float &spacing, const Bounds &screenBounds) + : DragDropButton(pos, ImageID::invalid(), ImageID::invalid(), screenBounds), spacing_(spacing) { using namespace UI; roundId_ = g_Config.iTouchButtonStyle ? ImageID("I_ROUND_LINE") : ImageID("I_ROUND"); }; @@ -169,8 +166,8 @@ private: class PSPDPadButtons : public DragDropButton { public: - PSPDPadButtons(ConfigTouchPos &pos, float &spacing) - : DragDropButton(pos, ImageID::invalid(), ImageID::invalid()), spacing_(spacing) { + PSPDPadButtons(ConfigTouchPos &pos, float &spacing, const Bounds &screenBounds) + : DragDropButton(pos, ImageID::invalid(), ImageID::invalid(), screenBounds), spacing_(spacing) { } void Draw(UIContext &dc) override { @@ -342,9 +339,6 @@ void TouchControlLayoutScreen::CreateViews() { const Bounds &bounds = screenManager()->getUIContext()->GetBounds(); InitPadLayout(bounds.w, bounds.h); - local_dp_xres = bounds.w; - local_dp_yres = bounds.h; - using namespace UI; auto co = GetI18NCategory("Controls"); @@ -397,7 +391,7 @@ void TouchControlLayoutScreen::CreateViews() { controls_.clear(); - PSPActionButtons *actionButtons = new PSPActionButtons(g_Config.touchActionButtonCenter, g_Config.fActionButtonSpacing); + PSPActionButtons *actionButtons = new PSPActionButtons(g_Config.touchActionButtonCenter, g_Config.fActionButtonSpacing, bounds); actionButtons->setCircleVisibility(g_Config.bShowTouchCircle); actionButtons->setCrossVisibility(g_Config.bShowTouchCross); actionButtons->setTriangleVisibility(g_Config.bShowTouchTriangle); @@ -414,86 +408,54 @@ void TouchControlLayoutScreen::CreateViews() { const ImageID comboKeyImages[5] = { ImageID("I_1"), ImageID("I_2"), ImageID("I_3"), ImageID("I_4"), ImageID("I_5") }; - if (g_Config.touchDpad.show) { - controls_.push_back(new PSPDPadButtons(g_Config.touchDpad, g_Config.fDpadSpacing)); - } - - if (g_Config.touchSelectKey.show) { - controls_.push_back(new DragDropButton(g_Config.touchSelectKey, rectImage, ImageID("I_SELECT"))); - } - - if (g_Config.touchStartKey.show) { - controls_.push_back(new DragDropButton(g_Config.touchStartKey, rectImage, ImageID("I_START"))); - } - - if (g_Config.touchUnthrottleKey.show) { - DragDropButton *unthrottle = new DragDropButton(g_Config.touchUnthrottleKey, rectImage, ImageID("I_ARROW")); - unthrottle->SetAngle(180.0f); - controls_.push_back(unthrottle); - } - - if (g_Config.touchSpeed1Key.show) { - DragDropButton *speed1 = new DragDropButton(g_Config.touchSpeed1Key, rectImage, ImageID("I_ARROW")); - speed1->SetAngle(170.0f, 180.0f); - controls_.push_back(speed1); - } - - if (g_Config.touchSpeed2Key.show) { - DragDropButton *speed2 = new DragDropButton(g_Config.touchSpeed2Key, rectImage, ImageID("I_ARROW")); - speed2->SetAngle(190.0f, 180.0f); - controls_.push_back(speed2); - } - - if (g_Config.touchRapidFireKey.show) { - DragDropButton *rapidFire = new DragDropButton(g_Config.touchRapidFireKey, rectImage, ImageID("I_ARROW")); - rapidFire->SetAngle(90.0f, 180.0f); - controls_.push_back(rapidFire); - } - - if (g_Config.touchAnalogRotationCWKey.show) { - DragDropButton *analogRotationCW = new DragDropButton(g_Config.touchAnalogRotationCWKey, rectImage, ImageID("I_ARROW")); - analogRotationCW->SetAngle(190.0f, 180.0f); - controls_.push_back(analogRotationCW); - } - - if (g_Config.touchAnalogRotationCCWKey.show) { - DragDropButton *analogRotationCCW = new DragDropButton(g_Config.touchAnalogRotationCCWKey, rectImage, ImageID("I_ARROW")); - analogRotationCCW->SetAngle(350.0f, 180.0f); - controls_.push_back(analogRotationCCW); - } - - if (g_Config.touchLKey.show) { - controls_.push_back(new DragDropButton(g_Config.touchLKey, shoulderImage, ImageID("I_L"))); - } - - if (g_Config.touchRKey.show) { - DragDropButton *rbutton = new DragDropButton(g_Config.touchRKey, shoulderImage, ImageID("I_R")); - rbutton->FlipImageH(true); - controls_.push_back(rbutton); - } - - if (g_Config.touchAnalogStick.show) { - controls_.push_back(new DragDropButton(g_Config.touchAnalogStick, stickBg, stickImage)); - } - if (g_Config.touchRightAnalogStick.show) { - controls_.push_back(new DragDropButton(g_Config.touchRightAnalogStick, stickBg, stickImage)); - } - if (g_Config.touchCombo0.show) { - controls_.push_back(new DragDropButton(g_Config.touchCombo0, roundImage, comboKeyImages[0])); - } - if (g_Config.touchCombo1.show) { - controls_.push_back(new DragDropButton(g_Config.touchCombo1, roundImage, comboKeyImages[1])); - } - if (g_Config.touchCombo2.show) { - controls_.push_back(new DragDropButton(g_Config.touchCombo2, roundImage, comboKeyImages[2])); - } - if (g_Config.touchCombo3.show) { - controls_.push_back(new DragDropButton(g_Config.touchCombo3, roundImage, comboKeyImages[3])); - } - if (g_Config.touchCombo4.show) { - controls_.push_back(new DragDropButton(g_Config.touchCombo4, roundImage, comboKeyImages[4])); + auto addDragDropButton = [&](ConfigTouchPos &pos, ImageID bgImg, ImageID img) { + DragDropButton *b = nullptr; + if (pos.show) { + b = new DragDropButton(pos, bgImg, img, bounds); + controls_.push_back(b); + } + return b; }; + if (g_Config.touchDpad.show) { + controls_.push_back(new PSPDPadButtons(g_Config.touchDpad, g_Config.fDpadSpacing, bounds)); + } + + addDragDropButton(g_Config.touchSelectKey, rectImage, ImageID("I_SELECT")); + addDragDropButton(g_Config.touchStartKey, rectImage, ImageID("I_START")); + + if (auto *unthrottle = addDragDropButton(g_Config.touchUnthrottleKey, rectImage, ImageID("I_ARROW"))) { + unthrottle->SetAngle(180.0f); + } + if (auto *speed1 = addDragDropButton(g_Config.touchSpeed1Key, rectImage, ImageID("I_ARROW"))) { + speed1->SetAngle(170.0f, 180.0f); + } + if (auto *speed2 = addDragDropButton(g_Config.touchSpeed2Key, rectImage, ImageID("I_ARROW"))) { + speed2->SetAngle(190.0f, 180.0f); + } + if (auto *rapidFire = addDragDropButton(g_Config.touchRapidFireKey, rectImage, ImageID("I_ARROW"))) { + rapidFire->SetAngle(90.0f, 180.0f); + } + if (auto *analogRotationCW = addDragDropButton(g_Config.touchAnalogRotationCWKey, rectImage, ImageID("I_ARROW"))) { + analogRotationCW->SetAngle(190.0f, 180.0f); + } + if (auto *analogRotationCCW = addDragDropButton(g_Config.touchAnalogRotationCCWKey, rectImage, ImageID("I_ARROW"))) { + analogRotationCCW->SetAngle(350.0f, 180.0f); + } + + addDragDropButton(g_Config.touchLKey, shoulderImage, ImageID("I_L")); + if (auto *rbutton = addDragDropButton(g_Config.touchRKey, shoulderImage, ImageID("I_R"))) { + rbutton->FlipImageH(true); + } + + addDragDropButton(g_Config.touchAnalogStick, stickBg, stickImage); + addDragDropButton(g_Config.touchRightAnalogStick, stickBg, stickImage); + addDragDropButton(g_Config.touchCombo0, roundImage, comboKeyImages[0]); + addDragDropButton(g_Config.touchCombo1, roundImage, comboKeyImages[1]); + addDragDropButton(g_Config.touchCombo2, roundImage, comboKeyImages[2]); + addDragDropButton(g_Config.touchCombo3, roundImage, comboKeyImages[3]); + addDragDropButton(g_Config.touchCombo4, roundImage, comboKeyImages[4]); + for (size_t i = 0; i < controls_.size(); i++) { root_->Add(controls_[i]); }