Fix render resolution at different UI scales (#514)

This commit is contained in:
goeiecool9999 2022-11-30 13:39:32 +01:00 committed by GitHub
parent a3476c7b7c
commit d3721c3f46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 128 additions and 57 deletions

View file

@ -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())

View file

@ -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;
extern MainWindow* g_mainFrame;

View file

@ -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());
}
}

View file

@ -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;
};
};

View file

@ -23,7 +23,7 @@ VulkanCanvas::VulkanCanvas(wxWindow* parent, const wxSize& size, bool is_main_wi
g_renderer = std::make_unique<VulkanRenderer>();
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)
{

View file

@ -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;
}
}

View file

@ -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);