From b80df6c36001ce8165a22813eef266d123cd099a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 22 Nov 2022 14:16:24 +0100 Subject: [PATCH 1/2] Add transparent background to the existing Display Layout Editor. --- UI/DisplayLayoutScreen.cpp | 5 ++++- UI/DisplayLayoutScreen.h | 5 ++--- UI/EmuScreen.cpp | 2 +- UI/GameSettingsScreen.cpp | 10 ++++------ UI/GameSettingsScreen.h | 1 - UI/MiscScreens.cpp | 4 ++-- UI/MiscScreens.h | 1 + UI/PauseScreen.cpp | 9 +++++++++ 8 files changed, 23 insertions(+), 14 deletions(-) diff --git a/UI/DisplayLayoutScreen.cpp b/UI/DisplayLayoutScreen.cpp index e2ea500884..881eb9b262 100644 --- a/UI/DisplayLayoutScreen.cpp +++ b/UI/DisplayLayoutScreen.cpp @@ -90,9 +90,12 @@ std::string DragDropDisplay::DescribeText() const { return u->T("Screen representation"); } -DisplayLayoutScreen::DisplayLayoutScreen() { +DisplayLayoutScreen::DisplayLayoutScreen(const Path &filename) : UIDialogScreenWithGameBackground(filename) { // Ignore insets - just couldn't get the logic to work. ignoreInsets_ = true; + + // Show background at full brightness + darkenGameBackground_ = false; } bool DisplayLayoutScreen::touch(const TouchInput &touch) { diff --git a/UI/DisplayLayoutScreen.h b/UI/DisplayLayoutScreen.h index 06730742d4..6fc613f574 100644 --- a/UI/DisplayLayoutScreen.h +++ b/UI/DisplayLayoutScreen.h @@ -23,9 +23,9 @@ class DragDropDisplay; -class DisplayLayoutScreen : public UIDialogScreenWithBackground { +class DisplayLayoutScreen : public UIDialogScreenWithGameBackground { public: - DisplayLayoutScreen(); + DisplayLayoutScreen(const Path &filename); virtual void CreateViews() override; virtual bool touch(const TouchInput &touch) override; virtual void dialogFinished(const Screen *dialog, DialogResult result) override; @@ -49,5 +49,4 @@ private: float startScale_ = 1.0f; int offsetTouchX_ = 0; int offsetTouchY_ = 0; - }; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 2571e2fd23..a0b898663c 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -489,7 +489,7 @@ void EmuScreen::sendMessage(const char *message, const char *value) { screenManager()->push(new ControlMappingScreen()); } else if (!strcmp(message, "display layout editor") && screenManager()->topScreen() == this) { UpdateUIState(UISTATE_PAUSEMENU); - screenManager()->push(new DisplayLayoutScreen()); + screenManager()->push(new DisplayLayoutScreen(gamePath_)); } else if (!strcmp(message, "settings") && screenManager()->topScreen() == this) { UpdateUIState(UISTATE_PAUSEMENU); screenManager()->push(new GameSettingsScreen(gamePath_)); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index d3d2e60202..f22627e100 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -463,7 +463,10 @@ void GameSettingsScreen::CreateViews() { #endif // Display Layout Editor: To avoid overlapping touch controls on large tablets, meet geeky demands for integer zoom/unstretched image etc. displayEditor_ = graphicsSettings->Add(new Choice(gr->T("Display layout editor"))); - displayEditor_->OnClick.Handle(this, &GameSettingsScreen::OnDisplayLayoutEditor); + displayEditor_->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn { + screenManager()->push(new DisplayLayoutScreen(gamePath_)); + return UI::EVENT_DONE; + }); #if PPSSPP_PLATFORM(ANDROID) // Hide insets option if no insets, or OS too old. @@ -1332,11 +1335,6 @@ UI::EventReturn GameSettingsScreen::OnFullscreenMultiChange(UI::EventParams &e) return UI::EVENT_DONE; } -UI::EventReturn GameSettingsScreen::OnDisplayLayoutEditor(UI::EventParams &e) { - screenManager()->push(new DisplayLayoutScreen()); - return UI::EVENT_DONE; -}; - UI::EventReturn GameSettingsScreen::OnResolutionChange(UI::EventParams &e) { if (g_Config.iAndroidHwScale == 1) { RecreateActivity(); diff --git a/UI/GameSettingsScreen.h b/UI/GameSettingsScreen.h index 2fd7d6e59d..5dbe9a682f 100644 --- a/UI/GameSettingsScreen.h +++ b/UI/GameSettingsScreen.h @@ -105,7 +105,6 @@ private: UI::EventReturn OnChangeBackground(UI::EventParams &e); UI::EventReturn OnFullscreenChange(UI::EventParams &e); UI::EventReturn OnFullscreenMultiChange(UI::EventParams &e); - UI::EventReturn OnDisplayLayoutEditor(UI::EventParams &e); UI::EventReturn OnResolutionChange(UI::EventParams &e); UI::EventReturn OnHwScaleChange(UI::EventParams &e); UI::EventReturn OnRestoreDefaultSettings(UI::EventParams &e); diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index f26562157e..487effe1b4 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -419,7 +419,7 @@ void HandleCommonMessages(const char *message, const char *value, ScreenManager manager->push(new ControlMappingScreen()); } else if (!strcmp(message, "display layout editor") && isActiveScreen && std::string(activeScreen->tag()) != "DisplayLayout") { UpdateUIState(UISTATE_MENU); - manager->push(new DisplayLayoutScreen()); + manager->push(new DisplayLayoutScreen(Path())); } else if (!strcmp(message, "settings") && isActiveScreen && std::string(activeScreen->tag()) != "GameSettings") { UpdateUIState(UISTATE_MENU); manager->push(new GameSettingsScreen(Path())); @@ -474,7 +474,7 @@ void UIDialogScreenWithGameBackground::DrawBackground(UIContext &dc) { using namespace Draw; float x, y, z; screenManager()->getFocusPosition(x, y, z); - DrawGameBackground(dc, gamePath_, x, y, z, true); + DrawGameBackground(dc, gamePath_, x, y, z, darkenGameBackground_); } void UIDialogScreenWithGameBackground::sendMessage(const char *message, const char *value) { diff --git a/UI/MiscScreens.h b/UI/MiscScreens.h index 216def14f7..2790f85c37 100644 --- a/UI/MiscScreens.h +++ b/UI/MiscScreens.h @@ -73,6 +73,7 @@ public: void sendMessage(const char *message, const char *value) override; protected: Path gamePath_; + bool darkenGameBackground_ = true; }; class PromptScreen : public UIDialogScreenWithBackground { diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index 929e0d1d7d..c45d6b7920 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -49,6 +49,7 @@ #include "UI/MainScreen.h" #include "UI/OnScreenDisplay.h" #include "UI/GameInfoCache.h" +#include "UI/DisplayLayoutScreen.h" static void AfterSaveStateAction(SaveState::Status status, const std::string &message, void *) { if (!message.empty() && (!g_Config.bDumpFrames || !g_Config.bDumpVideoOutput)) { @@ -260,6 +261,7 @@ void GamePauseScreen::CreateViews() { static const int NUM_SAVESLOTS = 5; using namespace UI; + Margins scrollMargins(0, 20, 0, 0); Margins actionMenuMargins(0, 20, 15, 0); auto gr = GetI18NCategory("Graphics"); @@ -314,6 +316,8 @@ void GamePauseScreen::CreateViews() { root_->SetDefaultFocusView(continueChoice); continueChoice->OnClick.Handle(this, &UIScreen::OnBack); + rightColumnItems->Add(new Spacer(25.0)); + std::string gameId = g_paramSFO.GetDiscID(); if (g_Config.hasGameConfig(gameId)) { rightColumnItems->Add(new Choice(pa->T("Game Settings")))->OnClick.Handle(this, &GamePauseScreen::OnGameSettings); @@ -322,6 +326,11 @@ void GamePauseScreen::CreateViews() { rightColumnItems->Add(new Choice(pa->T("Settings")))->OnClick.Handle(this, &GamePauseScreen::OnGameSettings); rightColumnItems->Add(new Choice(pa->T("Create Game Config")))->OnClick.Handle(this, &GamePauseScreen::OnCreateConfig); } + UI::Choice *displayEditor_ = rightColumnItems->Add(new Choice(gr->T("Display layout editor"))); + displayEditor_->OnClick.Add([&](UI::EventParams &) -> UI::EventReturn { + screenManager()->push(new DisplayLayoutScreen(gamePath_)); + return UI::EVENT_DONE; + }); if (g_Config.bEnableCheats) { rightColumnItems->Add(new Choice(pa->T("Cheats")))->OnClick.Handle(this, &GamePauseScreen::OnCwCheat); } From 57864f62cea12a07375b47b96409538c5cb359a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 22 Nov 2022 17:45:17 +0100 Subject: [PATCH 2/2] Rework the display layout editor to ditch the preview thing. We lose the snapping in the refactor because I ended up rewriting the whole dragging mechanism, might reintroduce later. --- CMakeLists.txt | 2 - UI/DisplayLayoutEditor.cpp | 58 ------- UI/DisplayLayoutEditor.h | 53 ------- UI/DisplayLayoutScreen.cpp | 256 +++++++++--------------------- UI/DisplayLayoutScreen.h | 29 ++-- UI/MiscScreens.cpp | 12 +- UI/UI.vcxproj | 2 - UI/UI.vcxproj.filters | 2 - UWP/UI_UWP/UI_UWP.vcxproj | 2 - UWP/UI_UWP/UI_UWP.vcxproj.filters | 2 - android/jni/Android.mk | 1 - 11 files changed, 95 insertions(+), 324 deletions(-) delete mode 100644 UI/DisplayLayoutEditor.cpp delete mode 100644 UI/DisplayLayoutEditor.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ac021cf474..2072a5d003 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1247,8 +1247,6 @@ list(APPEND NativeAppSource UI/ChatScreen.cpp UI/DevScreens.cpp UI/DevScreens.h - UI/DisplayLayoutEditor.cpp - UI/DisplayLayoutEditor.h UI/DisplayLayoutScreen.cpp UI/DisplayLayoutScreen.h UI/EmuScreen.h diff --git a/UI/DisplayLayoutEditor.cpp b/UI/DisplayLayoutEditor.cpp deleted file mode 100644 index f6556ca39a..0000000000 --- a/UI/DisplayLayoutEditor.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2012- PPSSPP Project. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 2.0 or later versions. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official git repository and contact information can be found at -// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - -#include - -#include "Common/UI/Context.h" -#include "UI/DisplayLayoutEditor.h" - -void MultiTouchDisplay::GetContentDimensions(const UIContext &dc, float &w, float &h) const { - const AtlasImage *image = dc.Draw()->GetAtlas()->getImage(img_); - if (image) { - w = image->w * scale_; - h = image->h * scale_; - } else { - w = 0.0f; - h = 0.0f; - } -} - -void MultiTouchDisplay::Touch(const TouchInput &input) { - if ((input.flags & TOUCH_DOWN) && bounds_.Contains(input.x, input.y)) { - pointerDownMask_ |= 1 << input.id; - } - if (input.flags & TOUCH_MOVE) { - if (bounds_.Contains(input.x, input.y)) - pointerDownMask_ |= 1 << input.id; - else - pointerDownMask_ &= ~(1 << input.id); - } - if (input.flags & TOUCH_UP) { - pointerDownMask_ &= ~(1 << input.id); - } - if (input.flags & TOUCH_RELEASE_ALL) { - pointerDownMask_ = 0; - } -} - - -void MultiTouchDisplay::Draw(UIContext &dc) { - float opacity = 0.5f; - float scale = scale_; - uint32_t color = colorAlpha(0xFFFFFF, opacity); - dc.Draw()->DrawImageRotated(img_, bounds_.centerX(), bounds_.centerY(), scale, angle_ * (M_PI * 2 / 360.0f), color, flipImageH_); -} diff --git a/UI/DisplayLayoutEditor.h b/UI/DisplayLayoutEditor.h deleted file mode 100644 index 6855c127ca..0000000000 --- a/UI/DisplayLayoutEditor.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2012- PPSSPP Project. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 2.0 or later versions. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official git repository and contact information can be found at -// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. - -#pragma once - -#include "Common/Render/TextureAtlas.h" -#include "Common/Render/DrawBuffer.h" -#include "Common/UI/View.h" -#include "Common/UI/ViewGroup.h" - -class MultiTouchDisplay : public UI::View { -public: - MultiTouchDisplay(ImageID img, float scale, UI::LayoutParams *layoutParams) - : UI::View(layoutParams), pointerDownMask_(0), scale_(scale), img_(img), angle_(0.0f), flipImageH_(false) { - } - virtual void Touch(const TouchInput &input) override; - virtual void Draw(UIContext &dc) override; - virtual void GetContentDimensions(const UIContext &dc, float &w, float &h) const override; - // chainable - MultiTouchDisplay *FlipImageH(bool flip) { flipImageH_ = flip; return this; } - MultiTouchDisplay *SetAngle(float angle) { angle_ = angle; return this; } - -protected: - uint32_t pointerDownMask_; - float scale_; - -private: - ImageID img_; - float angle_; - bool flipImageH_; -}; - -class PSPDisplay : public MultiTouchDisplay { -public: - PSPDisplay(ImageID img, float scale, UI::LayoutParams *layoutParams) - : MultiTouchDisplay(img, scale, layoutParams) { - } -}; - diff --git a/UI/DisplayLayoutScreen.cpp b/UI/DisplayLayoutScreen.cpp index 881eb9b262..de32079916 100644 --- a/UI/DisplayLayoutScreen.cpp +++ b/UI/DisplayLayoutScreen.cpp @@ -23,6 +23,8 @@ #include "Common/Render/DrawBuffer.h" #include "Common/UI/Context.h" #include "Common/UI/View.h" +#include "Common/Math/math_util.h" +#include "Common/System/Display.h" #include "Common/Data/Color/RGBAUtil.h" #include "Common/Data/Text/I18n.h" @@ -30,64 +32,24 @@ #include "Core/Config.h" #include "Core/ConfigValues.h" #include "Core/System.h" -#include "DisplayLayoutEditor.h" #include "GPU/Common/FramebufferManagerCommon.h" +#include "GPU/Common/PresentationCommon.h" static const int leftColumnWidth = 200; -static const float orgRatio = 1.764706f; +static const float orgRatio = 1.764706f; // 480.0 / 272.0 -static const float UI_DISPLAY_SCALE = 8.0f; -static float ScaleSettingToUI() { - 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; - } - 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 / UI_DISPLAY_SCALE); -} - -class DragDropDisplay : public MultiTouchDisplay { -public: - 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), screenBounds_(screenBounds) { - UpdateScale(scale); - } - - std::string DescribeText() const override; - - void SaveDisplayPosition() { - x_ = bounds_.centerX() / screenBounds_.w; - y_ = bounds_.centerY() / screenBounds_.h; - } - - void UpdateScale(float s) { - scale_ = s; - } - float Scale() { - return scale_; - } - -private: - float &x_, &y_; - const Bounds &screenBounds_; +enum Mode { + MODE_MOVE, + MODE_RESIZE, }; -std::string DragDropDisplay::DescribeText() const { - auto u = GetI18NCategory("UI Elements"); - return u->T("Screen representation"); +static Bounds FRectToBounds(FRect rc) { + Bounds b; + b.x = rc.x * g_dpi_scale_x; + b.y = rc.y * g_dpi_scale_y; + b.w = rc.w * g_dpi_scale_x; + b.h = rc.h * g_dpi_scale_y; + return b; } DisplayLayoutScreen::DisplayLayoutScreen(const Path &filename) : UIDialogScreenWithGameBackground(filename) { @@ -98,6 +60,25 @@ DisplayLayoutScreen::DisplayLayoutScreen(const Path &filename) : UIDialogScreenW darkenGameBackground_ = false; } +void DisplayLayoutScreen::DrawBackground(UIContext &dc) { + if (PSP_IsInited() && !g_Config.bSkipBufferEffects) { + // We normally rely on the PSP screen. + UIDialogScreenWithGameBackground::DrawBackground(dc); + } else { + // But if it's not present (we're not in game, or skip buffer effects is used), + // we have to draw a substitute ourselves. + + // TODO: Clean this up a bit, this GetScreenFrame/CenterDisplay combo is too common. + FRect screenFrame = GetScreenFrame(pixel_xres, pixel_yres); + FRect rc; + CenterDisplayOutputRect(&rc, 480.0f, 272.0f, screenFrame, g_Config.iInternalScreenRotation); + + dc.Flush(); + ImageID bg = ImageID("I_PSP_DISPLAY"); + dc.Draw()->DrawImageStretch(bg, FRectToBounds(rc), 0x7FFFFFFF); + } +} + bool DisplayLayoutScreen::touch(const TouchInput &touch) { UIScreen::touch(touch); @@ -108,89 +89,42 @@ bool DisplayLayoutScreen::touch(const TouchInput &touch) { mode = -1; } - const Bounds &screen_bounds = screenManager()->getUIContext()->GetBounds(); + const Bounds &screenBounds = screenManager()->getUIContext()->GetBounds(); if ((touch.flags & TOUCH_MOVE) != 0 && dragging_) { - int touchX = touch.x - offsetTouchX_; - int touchY = touch.y - offsetTouchY_; - if (mode == 0) { - const auto &prevParams = displayRepresentation_->GetLayoutParams()->As(); - Point newPos(prevParams->left, prevParams->top); + float relativeTouchX = touch.x - startX_; + float relativeTouchY = touch.y - startY_; - int limitX = g_Config.fSmallDisplayZoomLevel * 120; - int limitY = g_Config.fSmallDisplayZoomLevel * 68; - - const int quarterResX = screen_bounds.w / 4; - const int quarterResY = screen_bounds.h / 4; - - if (bRotated_) { - //swap X/Y limit for rotated display - std::swap(limitX, limitY); - } - - // Check where each edge of the screen is - const int windowLeftEdge = quarterResX; - const int windowRightEdge = windowLeftEdge * 3; - 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; } - - 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; - if (touchY < -minY) touchY = -minY; - if (touchY > maxY) touchY = maxY; - - // Limit small display on much larger output a bit differently - if (quarterResX > limitX) limitX = quarterResX; - if (quarterResY > limitY) limitY = quarterResY; - - // 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) { - newPos.x = touchX; - } - if (touchY > minY - limitY - 10 && touchY < minY + limitY + 10) { - newPos.y = touchY; - } - displayRepresentation_->ReplaceLayoutParams(new AnchorLayoutParams(newPos.x, newPos.y, NONE, NONE, true)); - } else if (mode == 1) { + switch (mode) { + case MODE_MOVE: + { + g_Config.fSmallDisplayOffsetX = startDisplayOffsetX_ + relativeTouchX * 0.5f / screenBounds.w; + g_Config.fSmallDisplayOffsetY = startDisplayOffsetY_ + relativeTouchY * 0.5f / screenBounds.h; + break; + } + case MODE_RESIZE: + { // 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. - newScale = clamp_value(newScale, UI_DISPLAY_SCALE, UI_DISPLAY_SCALE * 10.0f); - displayRepresentation_->UpdateScale(newScale); - UpdateScaleSettingFromUI(newScale); + float diffYProp = -relativeTouchY * 0.007f; + g_Config.fSmallDisplayZoomLevel = startScale_ * powf(2.0f, diffYProp); + break; + } } } + 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(); + startX_ = touch.x; + startY_ = touch.y; + startDisplayOffsetX_ = g_Config.fSmallDisplayOffsetX; + startDisplayOffsetY_ = g_Config.fSmallDisplayOffsetY; + startScale_ = g_Config.fSmallDisplayZoomLevel; } + if ((touch.flags & TOUCH_UP) != 0 && dragging_) { - displayRepresentation_->SaveDisplayPosition(); dragging_ = false; } - return true; -} -void DisplayLayoutScreen::resized() { - RecreateViews(); + return true; } void DisplayLayoutScreen::onFinish(DialogResult reason) { @@ -198,22 +132,23 @@ void DisplayLayoutScreen::onFinish(DialogResult reason) { } UI::EventReturn DisplayLayoutScreen::OnCenter(UI::EventParams &e) { - if (!stickToEdgeX_ || (stickToEdgeX_ && stickToEdgeY_)) - g_Config.fSmallDisplayOffsetX = 0.5f; - if (!stickToEdgeY_ || (stickToEdgeX_ && stickToEdgeY_)) - g_Config.fSmallDisplayOffsetY = 0.5f; + g_Config.fSmallDisplayOffsetX = 0.5f; + g_Config.fSmallDisplayOffsetY = 0.5f; RecreateViews(); return UI::EVENT_DONE; }; 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; - UpdateScaleSetting(autoBound); - displayRepresentation_->UpdateScale(ScaleSettingToUI()); + switch (g_Config.iSmallDisplayZoomType) { + case (int)SmallDisplayZoom::AUTO: + case (int)SmallDisplayZoom::PARTIAL_STRETCH: + case (int)SmallDisplayZoom::STRETCH: g_Config.fSmallDisplayOffsetX = 0.5f; g_Config.fSmallDisplayOffsetY = 0.5f; + break; + default: + // Not SmallDisplayZoom::MANUAL + break; } RecreateViews(); return UI::EVENT_DONE; @@ -223,20 +158,6 @@ void DisplayLayoutScreen::dialogFinished(const Screen *dialog, DialogResult resu RecreateViews(); } -class Boundary : public UI::View { -public: - Boundary(UI::LayoutParams *layoutParams) : UI::View(layoutParams) { - } - - std::string DescribeText() const override { - return ""; - } - - void Draw(UIContext &dc) override { - dc.Draw()->DrawImageCenterTexel(dc.theme->whiteImage, bounds_.x, bounds_.y, bounds_.x2(), bounds_.y2(), dc.theme->itemDownStyle.background.color); - } -}; - // Stealing StickyChoice's layout and text rendering. class HighlightLabel : public UI::StickyChoice { public: @@ -259,25 +180,9 @@ void DisplayLayoutScreen::CreateViews() { root_ = new AnchorLayout(new LayoutParams(FILL_PARENT, FILL_PARENT)); - 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 = 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; - // We manually implement insets here for the buttons. This file defied refactoring :( float leftInset = System_GetPropertyFloat(SYSPROP_DISPLAY_SAFE_INSET_LEFT); - // Left side, right, top, bottom. - root_->Add(new Boundary(new AnchorLayoutParams(horizBoundariesWidth, FILL_PARENT, horizPreviewPadding - horizBoundariesWidth, 0, NONE, 0))); - root_->Add(new Boundary(new AnchorLayoutParams(horizBoundariesWidth, FILL_PARENT, horizPreviewPadding + previewWidth, 0, NONE, 0))); - root_->Add(new Boundary(new AnchorLayoutParams(previewWidth, vertBoundariesHeight, horizPreviewPadding, vertPreviewPadding - vertBoundariesHeight, NONE, NONE))); - root_->Add(new Boundary(new AnchorLayoutParams(previewWidth, vertBoundariesHeight, horizPreviewPadding, vertPreviewPadding + previewHeight, NONE, NONE))); - bool displayRotEnable = !g_Config.bSkipBufferEffects || g_Config.bSoftwareRendering; bRotated_ = false; if (displayRotEnable && (g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL || g_Config.iInternalScreenRotation == ROTATION_LOCKED_VERTICAL180)) { @@ -305,7 +210,7 @@ void DisplayLayoutScreen::CreateViews() { } } } - UpdateScaleSetting(autoBound); + g_Config.fSmallDisplayZoomLevel = autoBound; g_Config.fSmallDisplayOffsetX = 0.5f; g_Config.fSmallDisplayOffsetY = 0.5f; } else { // Manual Scaling @@ -323,19 +228,11 @@ void DisplayLayoutScreen::CreateViews() { mode_->AddChoice(di->T("Resize")); mode_->SetSelection(0, false); } - 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"), ScaleSettingToUI(), bounds); - displayRepresentation_->SetVisibility(V_INVISIBLE); - float width = previewWidth; - float height = previewHeight; - if (g_Config.iSmallDisplayZoomType == (int)SmallDisplayZoom::STRETCH) { - Choice *stretched = new Choice("", "", false, new AnchorLayoutParams(width, height, width - width / 2.0f, NONE, NONE, height - height / 2.0f)); - stretched->SetEnabled(false); - root_->Add(stretched); - } else { // Partially stretched + float width = bounds.w; + float height = bounds.h; + if (g_Config.iSmallDisplayZoomType != (int)SmallDisplayZoom::STRETCH) { float origRatio = !bRotated_ ? 480.0f / 272.0f : 272.0f / 480.0f; float frameRatio = width / height; if (origRatio > frameRatio) { @@ -349,16 +246,9 @@ void DisplayLayoutScreen::CreateViews() { width = (272.0f + height) / 2.0f; } } - Choice *stretched = new Choice("", "", false, new AnchorLayoutParams(width, height, previewWidth - width / 2.0f, NONE, NONE, previewHeight - height / 2.0f)); - stretched->SetEnabled(false); - root_->Add(stretched); } } - if (bRotated_) { - displayRepresentation_->SetAngle(90.0f); - } - root_->Add(displayRepresentation_); if (mode_) { root_->Add(mode_); } @@ -367,12 +257,12 @@ void DisplayLayoutScreen::CreateViews() { } 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)); + auto zoom = new PopupMultiChoice(&g_Config.iSmallDisplayZoomType, di->T("Options"), zoomLevels, 0, ARRAY_SIZE(zoomLevels), gr->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, bounds.w / 2.0f - 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)); + auto rotation = new PopupMultiChoice(&g_Config.iInternalScreenRotation, gr->T("Rotation"), displayRotation, 1, ARRAY_SIZE(displayRotation), co->GetName(), screenManager(), new AnchorLayoutParams(400, WRAP_CONTENT, bounds.w / 2.0f - 200.0f, 10, NONE, bounds.h - 64 - 10)); rotation->SetEnabledFunc([] { return !g_Config.bSkipBufferEffects || g_Config.bSoftwareRendering; }); diff --git a/UI/DisplayLayoutScreen.h b/UI/DisplayLayoutScreen.h index 6fc613f574..acf4cc51c8 100644 --- a/UI/DisplayLayoutScreen.h +++ b/UI/DisplayLayoutScreen.h @@ -21,16 +21,20 @@ #include "Common/UI/ViewGroup.h" #include "MiscScreens.h" -class DragDropDisplay; - class DisplayLayoutScreen : public UIDialogScreenWithGameBackground { public: DisplayLayoutScreen(const Path &filename); - virtual void CreateViews() override; - virtual bool touch(const TouchInput &touch) override; - virtual void dialogFinished(const Screen *dialog, DialogResult result) override; - virtual void onFinish(DialogResult reason) override; - virtual void resized() override; + void CreateViews() override; + bool touch(const TouchInput &touch) override; + void dialogFinished(const Screen *dialog, DialogResult result) override; + void onFinish(DialogResult reason) override; + + void DrawBackground(UIContext &dc) override; + + void resized() override { + RecreateViews(); + } + const char *tag() const override { return "DisplayLayout"; } protected: @@ -38,15 +42,14 @@ protected: virtual UI::EventReturn OnZoomTypeChange(UI::EventParams &e); private: - 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_ = 0.0f; float startY_ = 0.0f; - float startScale_ = 1.0f; - int offsetTouchX_ = 0; - int offsetTouchY_ = 0; + float startScale_ = -1.0f; + float startDisplayOffsetX_ = -1.0f; + float startDisplayOffsetY_ = -1.0f; }; diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index 487effe1b4..0516286f5d 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -356,7 +356,7 @@ void DrawBackground(UIContext &dc, float alpha, float x, float y, float z) { } } -void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, float z, bool darkenGame) { +void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, float z, bool darkenBackground) { using namespace Draw; using namespace UI; @@ -377,9 +377,11 @@ void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, f dc.RebindTexture(); dc.Begin(); - uint32_t color = colorAlpha(colorBlend(dc.GetTheme().backgroundColor, 0, 0.5f), 0.45f); - dc.FillRect(UI::Drawable(color), dc.GetBounds()); - dc.Flush(); + if (darkenBackground) { + uint32_t color = colorAlpha(colorBlend(dc.GetTheme().backgroundColor, 0, 0.5f), 0.45f); + dc.FillRect(UI::Drawable(color), dc.GetBounds()); + dc.Flush(); + } return; } @@ -391,8 +393,6 @@ void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, f GameInfoTex *pic = ginfo ? ginfo->GetBGPic() : nullptr; if (pic) { dc.GetDrawContext()->BindTexture(0, pic->texture->GetTexture()); - } - if (pic) { uint32_t color = whiteAlpha(ease((time_now_d() - pic->timeLoaded) * 3)) & 0xFFc0c0c0; dc.Draw()->DrawTexRect(dc.GetBounds(), 0,0,1,1, color); dc.Flush(); diff --git a/UI/UI.vcxproj b/UI/UI.vcxproj index edf77d026e..df884f757b 100644 --- a/UI/UI.vcxproj +++ b/UI/UI.vcxproj @@ -42,7 +42,6 @@ - @@ -75,7 +74,6 @@ - diff --git a/UI/UI.vcxproj.filters b/UI/UI.vcxproj.filters index 3f03e3242f..3743fe242f 100644 --- a/UI/UI.vcxproj.filters +++ b/UI/UI.vcxproj.filters @@ -63,7 +63,6 @@ Screens - Screens @@ -144,7 +143,6 @@ Screens - Screens diff --git a/UWP/UI_UWP/UI_UWP.vcxproj b/UWP/UI_UWP/UI_UWP.vcxproj index 57358dde23..e2698447e0 100644 --- a/UWP/UI_UWP/UI_UWP.vcxproj +++ b/UWP/UI_UWP/UI_UWP.vcxproj @@ -386,7 +386,6 @@ - @@ -422,7 +421,6 @@ - diff --git a/UWP/UI_UWP/UI_UWP.vcxproj.filters b/UWP/UI_UWP/UI_UWP.vcxproj.filters index fde9770206..e26481b823 100644 --- a/UWP/UI_UWP/UI_UWP.vcxproj.filters +++ b/UWP/UI_UWP/UI_UWP.vcxproj.filters @@ -8,7 +8,6 @@ - @@ -44,7 +43,6 @@ - diff --git a/android/jni/Android.mk b/android/jni/Android.mk index a8b6090dfe..2fc73c6168 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -689,7 +689,6 @@ LOCAL_SRC_FILES := \ $(SRC)/UI/DiscordIntegration.cpp \ $(SRC)/UI/ChatScreen.cpp \ $(SRC)/UI/DevScreens.cpp \ - $(SRC)/UI/DisplayLayoutEditor.cpp \ $(SRC)/UI/DisplayLayoutScreen.cpp \ $(SRC)/UI/EmuScreen.cpp \ $(SRC)/UI/MainScreen.cpp \