Skip to content

Commit 92c37ba

Browse files
authored
Merge pull request #20079 from hrydgard/touch-control-layout-game-background
Touch control layout editor: Resize the game image to fit the editing surface
2 parents 20290b0 + c90552c commit 92c37ba

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

GPU/Common/PresentationCommon.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ struct Vertex {
4444
uint32_t rgba;
4545
};
4646

47-
extern Bounds g_imguiCentralNodeBounds;
47+
static bool g_overrideScreenBounds;
48+
static Bounds g_screenBounds;
49+
50+
void SetOverrideScreenFrame(const Bounds *bounds) {
51+
g_overrideScreenBounds = bounds != nullptr;
52+
if (bounds) {
53+
g_screenBounds = *bounds;
54+
}
55+
}
4856

4957
FRect GetScreenFrame(float pixelWidth, float pixelHeight) {
5058
FRect rc = FRect{
@@ -70,12 +78,12 @@ FRect GetScreenFrame(float pixelWidth, float pixelHeight) {
7078
rc.h -= (top + bottom);
7179
}
7280

73-
if (g_Config.bShowImDebugger) {
81+
if (g_overrideScreenBounds) {
7482
// Set rectangle to match central node. Here we ignore bIgnoreScreenInsets.
75-
rc.x = g_imguiCentralNodeBounds.x;
76-
rc.y = g_imguiCentralNodeBounds.y;
77-
rc.w = g_imguiCentralNodeBounds.w;
78-
rc.h = g_imguiCentralNodeBounds.h;
83+
rc.x = g_screenBounds.x;
84+
rc.y = g_screenBounds.y;
85+
rc.w = g_screenBounds.w;
86+
rc.h = g_screenBounds.h;
7987
}
8088

8189
return rc;

GPU/Common/PresentationCommon.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ struct FRect {
4646
float h;
4747
};
4848

49+
struct Bounds; // from geom2d
50+
4951
FRect GetScreenFrame(float pixelWidth, float pixelHeight);
52+
void SetOverrideScreenFrame(const Bounds *bounds);
5053
void CalculateDisplayOutputRect(FRect *rc, float origW, float origH, const FRect &frame, int rotation);
5154

5255
namespace Draw {

UI/EmuScreen.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ using namespace std::placeholders;
5757
#include "Core/MemFault.h"
5858
#include "Core/Reporting.h"
5959
#include "Core/System.h"
60+
#include "GPU/Common/PresentationCommon.h"
6061
#include "Core/FileSystems/VirtualDiscFileSystem.h"
6162
#include "GPU/GPUState.h"
6263
#include "GPU/GPUCommon.h"
@@ -1787,7 +1788,8 @@ void EmuScreen::runImDebugger() {
17871788
ImGuiDockNode* node = ImGui::DockBuilderGetCentralNode(dockID);
17881789

17891790
// Not elegant! But don't know how else to pass through the bounds, without making a mess.
1790-
g_imguiCentralNodeBounds = Bounds(node->Pos.x, node->Pos.y, node->Size.x, node->Size.y);
1791+
Bounds centralNode(node->Pos.x, node->Pos.y, node->Size.x, node->Size.y);
1792+
SetOverrideScreenFrame(&centralNode);
17911793

17921794
if (!io.WantCaptureKeyboard) {
17931795
// Draw a focus rectangle to indicate inputs will be passed through.

UI/GamepadEmu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ namespace CustomKeyData {
327327
{ ImageID::invalid(), VIRTKEY_AXIS_Y_MAX },
328328
{ ImageID::invalid(), VIRTKEY_PREVIOUS_SLOT },
329329
{ ImageID::invalid(), VIRTKEY_TOGGLE_TOUCH_CONTROLS },
330+
{ ImageID::invalid(), VIRTKEY_TOGGLE_DEBUGGER },
330331
};
331332
static_assert(ARRAY_SIZE(customKeyList) <= 64, "Too many key for a uint64_t bit mask");
332333
};
@@ -370,6 +371,7 @@ namespace GestureKey {
370371
VIRTKEY_AXIS_Y_MIN,
371372
VIRTKEY_AXIS_X_MAX,
372373
VIRTKEY_AXIS_Y_MAX,
374+
VIRTKEY_TOGGLE_DEBUGGER,
373375
};
374376
}
375377

UI/NativeApp.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
#include "Core/ThreadPools.h"
113113

114114
#include "GPU/GPUCommon.h"
115+
#include "GPU/Common/PresentationCommon.h"
115116
#include "UI/AudioCommon.h"
116117
#include "UI/BackgroundAudio.h"
117118
#include "UI/ControlMappingScreen.h"
@@ -1025,6 +1026,8 @@ void NativeFrame(GraphicsContext *graphicsContext) {
10251026
ProcessWheelRelease(NKCODE_EXT_MOUSEWHEEL_UP, startTime, false);
10261027
ProcessWheelRelease(NKCODE_EXT_MOUSEWHEEL_DOWN, startTime, false);
10271028

1029+
SetOverrideScreenFrame(nullptr);
1030+
10281031
// it's ok to call this redundantly with DoFrame from EmuScreen
10291032
Achievements::Idle();
10301033

UI/TouchControlLayoutScreen.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "Common/Log.h"
3030
#include "Core/Config.h"
3131
#include "Core/System.h"
32+
#include "GPU/Common/PresentationCommon.h"
3233
#include "UI/GamepadEmu.h"
3334
#include "UI/TouchControlLayoutScreen.h"
3435
#include "UI/TouchControlVisibilityScreen.h"
@@ -609,13 +610,23 @@ UI::EventReturn TouchControlLayoutScreen::OnMode(UI::EventParams &e) {
609610
void TouchControlLayoutScreen::update() {
610611
UIDialogScreenWithGameBackground::update();
611612

613+
if (!layoutView_) {
614+
return;
615+
}
616+
612617
// TODO: We really, really need a cleaner solution for creating sub-views
613618
// of custom compound controls.
614-
if (layoutView_) {
615-
if (!layoutView_->HasCreatedViews()) {
616-
layoutView_->CreateViews();
617-
}
619+
if (!layoutView_->HasCreatedViews()) {
620+
layoutView_->CreateViews();
618621
}
622+
623+
Bounds bounds = layoutView_->GetBounds();
624+
// Convert virtual pixels to real pixels.
625+
bounds.x /= g_display.dpi_scale;
626+
bounds.y /= g_display.dpi_scale;
627+
bounds.w /= g_display.dpi_scale;
628+
bounds.h /= g_display.dpi_scale;
629+
SetOverrideScreenFrame(&bounds);
619630
}
620631

621632
void TouchControlLayoutScreen::CreateViews() {

0 commit comments

Comments
 (0)