From d3721c3f4687f5fe8669928511e6b67ff4e2b97a Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Wed, 30 Nov 2022 13:39:32 +0100 Subject: [PATCH] Fix render resolution at different UI scales (#514) --- src/Cafe/HW/Latte/Core/LatteOverlay.cpp | 4 +- src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp | 4 +- src/Cafe/HW/Latte/Core/LatteShaderCache.cpp | 2 +- src/Cafe/HW/Latte/Core/LatteThread.cpp | 2 +- .../Latte/Renderer/OpenGL/OpenGLRenderer.cpp | 4 +- src/Cafe/HW/Latte/Renderer/Renderer.cpp | 4 +- .../HW/Latte/Renderer/Vulkan/CocoaSurface.mm | 17 ++++++++- .../Latte/Renderer/Vulkan/SwapchainInfoVk.cpp | 18 +++------ .../Latte/Renderer/Vulkan/VulkanRenderer.cpp | 17 ++++----- .../HW/Latte/Renderer/Vulkan/VulkanRenderer.h | 2 +- src/gui/MainWindow.cpp | 25 +++++++++++-- src/gui/MainWindow.h | 3 +- src/gui/PadViewFrame.cpp | 29 ++++++++++++--- src/gui/PadViewFrame.h | 3 +- src/gui/canvas/VulkanCanvas.cpp | 2 +- src/gui/guiWrapper.cpp | 37 +++++++++++++++---- src/gui/guiWrapper.h | 8 +++- src/input/emulated/VPADController.cpp | 4 +- 18 files changed, 128 insertions(+), 57 deletions(-) diff --git a/src/Cafe/HW/Latte/Core/LatteOverlay.cpp b/src/Cafe/HW/Latte/Core/LatteOverlay.cpp index 441ec169..9801c1d3 100644 --- a/src/Cafe/HW/Latte/Core/LatteOverlay.cpp +++ b/src/Cafe/HW/Latte/Core/LatteOverlay.cpp @@ -513,9 +513,9 @@ void LatteOverlay_render(bool pad_view) sint32 w = 0, h = 0; if (pad_view && gui_isPadWindowOpen()) - gui_getPadWindowSize(&w, &h); + gui_getPadWindowPhysSize(w, h); else - gui_getWindowSize(&w, &h); + gui_getWindowPhysSize(w, h); if (w == 0 || h == 0) return; diff --git a/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp b/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp index 092c859d..6b794de9 100644 --- a/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp +++ b/src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp @@ -848,9 +848,9 @@ void LatteRenderTarget_getScreenImageArea(sint32* x, sint32* y, sint32* width, s { int w, h; if(padView && gui_isPadWindowOpen()) - gui_getPadWindowSize(&w, &h); + gui_getPadWindowPhysSize(w, h); else - gui_getWindowSize(&w, &h); + gui_getWindowPhysSize(w, h); sint32 scaledOutputX; sint32 scaledOutputY; diff --git a/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp b/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp index e4f4efce..048df102 100644 --- a/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp +++ b/src/Cafe/HW/Latte/Core/LatteShaderCache.cpp @@ -418,7 +418,7 @@ void LatteShaderCache_ShowProgress(const std::function & loadUpdateF continue; int w, h; - gui_getWindowSize(&w, &h); + gui_getWindowPhysSize(w, h); const Vector2f window_size{ (float)w,(float)h }; ImGui_GetFont(window_size.y / 32.0f); // = 24 by default diff --git a/src/Cafe/HW/Latte/Core/LatteThread.cpp b/src/Cafe/HW/Latte/Core/LatteThread.cpp index f14112b4..4641e7e6 100644 --- a/src/Cafe/HW/Latte/Core/LatteThread.cpp +++ b/src/Cafe/HW/Latte/Core/LatteThread.cpp @@ -117,7 +117,7 @@ int Latte_ThreadEntry() { SetThreadName("LatteThread"); sint32 w,h; - gui_getWindowSize(&w,&h); + gui_getWindowPhysSize(w,h); // imgui ImGui::CreateContext(); diff --git a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp index 74d6e0b9..3b3b8b44 100644 --- a/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/OpenGL/OpenGLRenderer.cpp @@ -556,9 +556,9 @@ void OpenGLRenderer::DrawBackbufferQuad(LatteTextureView* texView, RendererOutpu { int windowWidth, windowHeight; if (padView) - gui_getPadWindowSize(&windowWidth, &windowHeight); + gui_getPadWindowPhysSize(windowWidth, windowHeight); else - gui_getWindowSize(&windowWidth, &windowHeight); + gui_getWindowPhysSize(windowWidth, windowHeight); g_renderer->renderTarget_setViewport(0, 0, windowWidth, windowHeight, 0.0f, 1.0f); g_renderer->ClearColorbuffer(padView); } diff --git a/src/Cafe/HW/Latte/Renderer/Renderer.cpp b/src/Cafe/HW/Latte/Renderer/Renderer.cpp index 8f99c069..d5376f3a 100644 --- a/src/Cafe/HW/Latte/Renderer/Renderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Renderer.cpp @@ -36,9 +36,9 @@ bool Renderer::ImguiBegin(bool mainWindow) { sint32 w = 0, h = 0; if(mainWindow) - gui_getWindowSize(&w, &h); + gui_getWindowPhysSize(w, h); else if(gui_isPadWindowOpen()) - gui_getPadWindowSize(&w, &h); + gui_getPadWindowPhysSize(w, h); else return false; diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/CocoaSurface.mm b/src/Cafe/HW/Latte/Renderer/Vulkan/CocoaSurface.mm index 0dc3b3ec..61184da7 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/CocoaSurface.mm +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/CocoaSurface.mm @@ -13,8 +13,23 @@ +(Class) layerClass { return [CAMetalLayer class]; } --(CALayer*) makeBackingLayer { return [self.class.layerClass layer]; } +// copied from https://github.com/KhronosGroup/MoltenVK/blob/master/Demos/Cube/macOS/DemoViewController.m +-(CALayer*) makeBackingLayer +{ + CALayer* layer = [self.class.layerClass layer]; + CGSize viewScale = [self convertSizeToBacking: CGSizeMake(1.0, 1.0)]; + layer.contentsScale = MIN(viewScale.width, viewScale.height); + return layer; +} + +-(BOOL) layer: (CALayer *)layer shouldInheritContentsScale: (CGFloat)newScale fromWindow: (NSWindow *)window +{ + if (newScale == layer.contentsScale) { return NO; } + + layer.contentsScale = newScale; + return YES; +} @end VkSurfaceKHR CreateCocoaSurface(VkInstance instance, void* handle) diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp index ad3b71d4..dd55c048 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/SwapchainInfoVk.cpp @@ -208,20 +208,14 @@ bool SwapchainInfoVk::AcquireImage(uint64 timeout) VkSemaphore acquireSemaphore = m_acquireSemaphores[m_acquireIndex]; VkResult result = vkAcquireNextImageKHR(m_logicalDevice, swapchain, timeout, acquireSemaphore, m_imageAvailableFence, &swapchainImageIndex); - if (result == VK_TIMEOUT) + if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) + m_shouldRecreate = true; + if (result < 0) { - return false; - } - else if (result != VK_SUCCESS) - { - if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) - m_shouldRecreate = true; - - if (result == VK_ERROR_OUT_OF_DATE_KHR) - return false; - - if (result != VK_ERROR_OUT_OF_DATE_KHR && result != VK_SUBOPTIMAL_KHR) + swapchainImageIndex = -1; + if (result != VK_ERROR_OUT_OF_DATE_KHR) throw std::runtime_error(fmt::format("Failed to acquire next image: {}", result)); + return false; } m_currentSemaphore = acquireSemaphore; m_awaitableFence = m_imageAvailableFence; diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp index d5e0718b..540ed66b 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp @@ -643,7 +643,7 @@ VulkanRenderer* VulkanRenderer::GetInstance() return (VulkanRenderer*)g_renderer.get(); } -void VulkanRenderer::Initialize(const Vector2i& size, bool mainWindow) +void VulkanRenderer::InitializeSurface(const Vector2i& size, bool mainWindow) { auto& windowHandleInfo = mainWindow ? gui_getWindowInfo().canvas_main : gui_getWindowInfo().canvas_pad; @@ -2564,20 +2564,20 @@ void VulkanRenderer::RecreateSwapchain(bool mainWindow, bool skipCreate) if (mainWindow) { ImGui_ImplVulkan_Shutdown(); - gui_getWindowSize(&size.x, &size.y); + gui_getWindowPhysSize(size.x, size.y); } else { - gui_getPadWindowSize(&size.x, &size.y); + gui_getPadWindowPhysSize(size.x, size.y); } + chainInfo.swapchainImageIndex = -1; chainInfo.Cleanup(); chainInfo.m_desiredExtent = size; if(!skipCreate) { chainInfo.Create(m_physicalDevice, m_logicalDevice); } - chainInfo.swapchainImageIndex = -1; if (mainWindow) ImguiInit(); @@ -2644,13 +2644,12 @@ void VulkanRenderer::SwapBuffer(bool mainWindow) presentInfo.pWaitSemaphores = &presentSemaphore; VkResult result = vkQueuePresentKHR(m_presentQueue, &presentInfo); - if (result != VK_SUCCESS) + if (result < 0 && result != VK_ERROR_OUT_OF_DATE_KHR) { - if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) - chainInfo.m_shouldRecreate = true; - else - throw std::runtime_error(fmt::format("Failed to present image: {}", result)); + throw std::runtime_error(fmt::format("Failed to present image: {}", result)); } + if(result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR) + chainInfo.m_shouldRecreate = true; chainInfo.hasDefinedSwapchainImage = false; diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h index 84b74b99..2f65f326 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h @@ -182,7 +182,7 @@ public: void GetDeviceFeatures(); void DetermineVendor(); - void Initialize(const Vector2i& size, bool mainWindow); + void InitializeSurface(const Vector2i& size, bool mainWindow); const std::unique_ptr& GetChainInfoPtr(bool mainWindow) const; SwapchainInfoVk& GetChainInfo(bool mainWindow) const; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 7b275ef7..7b17823d 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -157,6 +157,7 @@ wxBEGIN_EVENT_TABLE(MainWindow, wxFrame) EVT_TIMER(MAINFRAME_ID_TIMER1, MainWindow::OnTimer) EVT_CLOSE(MainWindow::OnClose) EVT_SIZE(MainWindow::OnSizeEvent) +EVT_DPI_CHANGED(MainWindow::OnDPIChangedEvent) EVT_MOVE(MainWindow::OnMove) // file menu EVT_MENU(MAINFRAME_MENU_ID_FILE_LOAD, MainWindow::OnFileMenu) @@ -1310,7 +1311,8 @@ void MainWindow::OnMouseMove(wxMouseEvent& event) auto& instance = InputManager::instance(); std::unique_lock lock(instance.m_main_mouse.m_mutex); - instance.m_main_mouse.position = { event.GetPosition().x, event.GetPosition().y }; + auto physPos = ToPhys(event.GetPosition()); + instance.m_main_mouse.position = { physPos.x, physPos.y }; lock.unlock(); if (!IsFullScreen()) @@ -1328,7 +1330,8 @@ void MainWindow::OnMouseLeft(wxMouseEvent& event) std::scoped_lock lock(instance.m_main_mouse.m_mutex); instance.m_main_mouse.left_down = event.ButtonDown(wxMOUSE_BTN_LEFT); - instance.m_main_mouse.position = { event.GetPosition().x, event.GetPosition().y }; + auto physPos = ToPhys(event.GetPosition()); + instance.m_main_mouse.position = { physPos.x, physPos.y }; if (event.ButtonDown(wxMOUSE_BTN_LEFT)) instance.m_main_mouse.left_down_toggle = true; @@ -1341,7 +1344,8 @@ void MainWindow::OnMouseRight(wxMouseEvent& event) std::scoped_lock lock(instance.m_main_mouse.m_mutex); instance.m_main_mouse.right_down = event.ButtonDown(wxMOUSE_BTN_RIGHT); - instance.m_main_mouse.position = { event.GetPosition().x, event.GetPosition().y }; + auto physPos = ToPhys(event.GetPosition()); + instance.m_main_mouse.position = { physPos.x, physPos.y }; if(event.ButtonDown(wxMOUSE_BTN_RIGHT)) instance.m_main_mouse.right_down_toggle = true; @@ -1441,7 +1445,8 @@ void MainWindow::OnGesturePan(wxPanGestureEvent& event) { auto& instance = InputManager::instance(); std::scoped_lock lock(instance.m_main_touch.m_mutex); - instance.m_main_touch.position = { event.GetPosition().x, event.GetPosition().y }; + auto physPos = ToPhys(event.GetPosition()); + instance.m_main_touch.position = { physPos.x, physPos.y }; instance.m_main_touch.left_down = event.IsGestureStart() || !event.IsGestureEnd(); if (event.IsGestureStart() || !event.IsGestureEnd()) instance.m_main_touch.left_down_toggle = true; @@ -1516,6 +1521,8 @@ void MainWindow::OnSizeEvent(wxSizeEvent& event) const wxSize client_size = GetClientSize(); g_window_info.width = client_size.GetWidth(); g_window_info.height = client_size.GetHeight(); + g_window_info.phys_width = ToPhys(client_size.GetWidth()); + g_window_info.phys_height = ToPhys(client_size.GetHeight()); if (m_debugger_window && m_debugger_window->IsShown()) m_debugger_window->OnParentMove(GetPosition(), event.GetSize()); @@ -1525,6 +1532,16 @@ void MainWindow::OnSizeEvent(wxSizeEvent& event) VsyncDriver_notifyWindowPosChanged(); } +void MainWindow::OnDPIChangedEvent(wxDPIChangedEvent& event) +{ + event.Skip(); + const wxSize client_size = GetClientSize(); + g_window_info.width = client_size.GetWidth(); + g_window_info.height = client_size.GetHeight(); + g_window_info.phys_width = ToPhys(client_size.GetWidth()); + g_window_info.phys_height = ToPhys(client_size.GetHeight()); +} + void MainWindow::OnMove(wxMoveEvent& event) { if (!IsMaximized() && !gui_isFullScreen()) diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index 38f44939..9e0d47bf 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -78,6 +78,7 @@ public: PadViewFrame* GetPadView() const { return m_padView; } void OnSizeEvent(wxSizeEvent& event); + void OnDPIChangedEvent(wxDPIChangedEvent& event); void OnMove(wxMoveEvent& event); void OnDebuggerClose(wxCloseEvent& event); @@ -231,4 +232,4 @@ private: wxDECLARE_EVENT_TABLE(); }; -extern MainWindow* g_mainFrame; \ No newline at end of file +extern MainWindow* g_mainFrame; diff --git a/src/gui/PadViewFrame.cpp b/src/gui/PadViewFrame.cpp index ba020b5f..2704eebe 100644 --- a/src/gui/PadViewFrame.cpp +++ b/src/gui/PadViewFrame.cpp @@ -37,6 +37,7 @@ PadViewFrame::PadViewFrame(wxFrame* parent) Maximize(); Bind(wxEVT_SIZE, &PadViewFrame::OnSizeEvent, this); + Bind(wxEVT_DPI_CHANGED, &PadViewFrame::OnDPIChangedEvent, this); Bind(wxEVT_MOVE, &PadViewFrame::OnMoveEvent, this); Bind(wxEVT_MOTION, &PadViewFrame::OnMouseMove, this); @@ -55,6 +56,8 @@ bool PadViewFrame::Initialize() const wxSize client_size = GetClientSize(); g_window_info.pad_width = client_size.GetWidth(); g_window_info.pad_height = client_size.GetHeight(); + g_window_info.phys_pad_width = ToPhys(client_size.GetWidth()); + g_window_info.phys_pad_height = ToPhys(client_size.GetHeight()); return true; } @@ -98,10 +101,22 @@ void PadViewFrame::OnSizeEvent(wxSizeEvent& event) const wxSize client_size = GetClientSize(); g_window_info.pad_width = client_size.GetWidth(); g_window_info.pad_height = client_size.GetHeight(); + g_window_info.phys_pad_width = ToPhys(client_size.GetWidth()); + g_window_info.phys_pad_height = ToPhys(client_size.GetHeight()); event.Skip(); } +void PadViewFrame::OnDPIChangedEvent(wxDPIChangedEvent& event) +{ + event.Skip(); + const wxSize client_size = GetClientSize(); + g_window_info.pad_width = client_size.GetWidth(); + g_window_info.pad_height = client_size.GetHeight(); + g_window_info.phys_pad_width = ToPhys(client_size.GetWidth()); + g_window_info.phys_pad_height = ToPhys(client_size.GetHeight()); +} + void PadViewFrame::OnMoveEvent(wxMoveEvent& event) { if (!IsMaximized() && !IsFullScreen()) @@ -130,7 +145,8 @@ void PadViewFrame::OnGesturePan(wxPanGestureEvent& event) auto& instance = InputManager::instance(); std::scoped_lock lock(instance.m_pad_touch.m_mutex); - instance.m_pad_touch.position = { event.GetPosition().x, event.GetPosition().y }; + auto physPos = ToPhys(event.GetPosition()); + instance.m_pad_touch.position = { physPos.x, physPos.y }; instance.m_pad_touch.left_down = event.IsGestureStart() || !event.IsGestureEnd(); if (event.IsGestureStart() || !event.IsGestureEnd()) instance.m_pad_touch.left_down_toggle = true; @@ -149,7 +165,8 @@ void PadViewFrame::OnMouseMove(wxMouseEvent& event) auto& instance = InputManager::instance(); std::scoped_lock lock(instance.m_pad_touch.m_mutex); - instance.m_pad_mouse.position = { event.GetPosition().x, event.GetPosition().y }; + auto physPos = ToPhys(event.GetPosition()); + instance.m_pad_mouse.position = { physPos.x, physPos.y }; event.Skip(); } @@ -160,7 +177,8 @@ void PadViewFrame::OnMouseLeft(wxMouseEvent& event) std::scoped_lock lock(instance.m_pad_mouse.m_mutex); instance.m_pad_mouse.left_down = event.ButtonDown(wxMOUSE_BTN_LEFT); - instance.m_pad_mouse.position = { event.GetPosition().x, event.GetPosition().y }; + auto physPos = ToPhys(event.GetPosition()); + instance.m_pad_mouse.position = { physPos.x, physPos.y }; if (event.ButtonDown(wxMOUSE_BTN_LEFT)) instance.m_pad_mouse.left_down_toggle = true; @@ -172,7 +190,8 @@ void PadViewFrame::OnMouseRight(wxMouseEvent& event) std::scoped_lock lock(instance.m_pad_mouse.m_mutex); instance.m_pad_mouse.right_down = event.ButtonDown(wxMOUSE_BTN_LEFT); - instance.m_pad_mouse.position = { event.GetPosition().x, event.GetPosition().y }; + auto physPos = ToPhys(event.GetPosition()); + instance.m_pad_mouse.position = { physPos.x, physPos.y }; if (event.ButtonDown(wxMOUSE_BTN_RIGHT)) instance.m_pad_mouse.right_down_toggle = true; } @@ -187,4 +206,4 @@ void PadViewFrame::AsyncSetTitle(std::string_view windowTitle) wxCommandEvent set_title_event(wxEVT_SET_WINDOW_TITLE); set_title_event.SetString(wxHelper::FromUtf8(windowTitle)); QueueEvent(set_title_event.Clone()); -} \ No newline at end of file +} diff --git a/src/gui/PadViewFrame.h b/src/gui/PadViewFrame.h index e808ad1d..f5b364c6 100644 --- a/src/gui/PadViewFrame.h +++ b/src/gui/PadViewFrame.h @@ -26,9 +26,10 @@ private: void OnMouseLeft(wxMouseEvent& event); void OnMouseRight(wxMouseEvent& event); void OnSizeEvent(wxSizeEvent& event); + void OnDPIChangedEvent(wxDPIChangedEvent& event); void OnMoveEvent(wxMoveEvent& event); void OnGesturePan(wxPanGestureEvent& event); void OnSetWindowTitle(wxCommandEvent& event); wxWindow* m_render_canvas = nullptr; -}; \ No newline at end of file +}; diff --git a/src/gui/canvas/VulkanCanvas.cpp b/src/gui/canvas/VulkanCanvas.cpp index 408bb1b7..ebf5a85a 100644 --- a/src/gui/canvas/VulkanCanvas.cpp +++ b/src/gui/canvas/VulkanCanvas.cpp @@ -23,7 +23,7 @@ VulkanCanvas::VulkanCanvas(wxWindow* parent, const wxSize& size, bool is_main_wi g_renderer = std::make_unique(); auto vulkan_renderer = VulkanRenderer::GetInstance(); - vulkan_renderer->Initialize({size.x, size.y}, is_main_window); + vulkan_renderer->InitializeSurface({size.x, size.y}, is_main_window); } catch(const std::exception& ex) { diff --git a/src/gui/guiWrapper.cpp b/src/gui/guiWrapper.cpp index 0f1b6df8..6d1aed13 100644 --- a/src/gui/guiWrapper.cpp +++ b/src/gui/guiWrapper.cpp @@ -137,23 +137,44 @@ void gui_updateWindowTitles(bool isIdle, bool isLoading, double fps) } } -void gui_getWindowSize(int* w, int* h) +void gui_getWindowSize(int& w, int& h) { - *w = g_window_info.width; - *h = g_window_info.height; + w = g_window_info.width; + h = g_window_info.height; } -void gui_getPadWindowSize(int* w, int* h) + +void gui_getPadWindowSize(int& w, int& h) { if (g_window_info.pad_open) { - *w = g_window_info.pad_width; - *h = g_window_info.pad_height; + w = g_window_info.pad_width; + h = g_window_info.pad_height; } else { - *w = 0; - *h = 0; + w = 0; + h = 0; + } +} + +void gui_getWindowPhysSize(int& w, int& h) +{ + w = g_window_info.phys_width; + h = g_window_info.phys_height; +} + +void gui_getPadWindowPhysSize(int& w, int& h) +{ + if (g_window_info.pad_open) + { + w = g_window_info.phys_pad_width; + h = g_window_info.phys_pad_height; + } + else + { + w = 0; + h = 0; } } diff --git a/src/gui/guiWrapper.h b/src/gui/guiWrapper.h index 19b125d1..fd5eceea 100644 --- a/src/gui/guiWrapper.h +++ b/src/gui/guiWrapper.h @@ -56,9 +56,11 @@ struct WindowInfo std::atomic_bool app_active; // our app is active/has focus std::atomic_int32_t width, height; // client size of main window + std::atomic_int32_t phys_width, phys_height; // client size of main window in physical pixels std::atomic_bool pad_open; // if separate pad view is open std::atomic_int32_t pad_width, pad_height; // client size of pad window + std::atomic_int32_t phys_pad_width, phys_pad_height; // client size of pad window in physical pixels std::atomic_bool pad_maximized = false; std::atomic_int32_t restored_pad_x = -1, restored_pad_y = -1; @@ -112,8 +114,10 @@ void gui_create(); WindowInfo& gui_getWindowInfo(); void gui_updateWindowTitles(bool isIdle, bool isLoading, double fps); -void gui_getWindowSize(int* w, int* h); -void gui_getPadWindowSize(int* w, int* h); +void gui_getWindowSize(int& w, int& h); +void gui_getPadWindowSize(int& w, int& h); +void gui_getWindowPhysSize(int& w, int& h); +void gui_getPadWindowPhysSize(int& w, int& h); bool gui_isPadWindowOpen(); bool gui_isKeyDown(uint32 key); bool gui_isKeyDown(PlatformKeyCodes key); diff --git a/src/input/emulated/VPADController.cpp b/src/input/emulated/VPADController.cpp index a3ff1a1c..dd9e5535 100644 --- a/src/input/emulated/VPADController.cpp +++ b/src/input/emulated/VPADController.cpp @@ -287,9 +287,9 @@ void VPADController::update_motion(VPADStatus_t& status) int w, h; if (pad_view) - gui_getPadWindowSize(&w, &h); + gui_getPadWindowPhysSize(w, h); else - gui_getWindowSize(&w, &h); + gui_getWindowPhysSize(w, h); float wx = mousePos.x / w; float wy = mousePos.y / h;