Merge pull request #11918 from TellowKrinkle/DPIScale
Improved DPI change handling
This commit is contained in:
commit
1aef85a985
|
@ -437,6 +437,10 @@ bool RenderWidget::event(QEvent* event)
|
||||||
case QEvent::Move:
|
case QEvent::Move:
|
||||||
SetCursorLocked(m_cursor_locked);
|
SetCursorLocked(m_cursor_locked);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// According to https://bugreports.qt.io/browse/QTBUG-95925 the recommended practice for
|
||||||
|
// handling DPI change is responding to paint events
|
||||||
|
case QEvent::Paint:
|
||||||
case QEvent::Resize:
|
case QEvent::Resize:
|
||||||
{
|
{
|
||||||
SetCursorLocked(m_cursor_locked);
|
SetCursorLocked(m_cursor_locked);
|
||||||
|
@ -446,9 +450,18 @@ bool RenderWidget::event(QEvent* event)
|
||||||
|
|
||||||
QScreen* screen = window()->windowHandle()->screen();
|
QScreen* screen = window()->windowHandle()->screen();
|
||||||
|
|
||||||
const auto dpr = screen->devicePixelRatio();
|
const float dpr = screen->devicePixelRatio();
|
||||||
|
const int width = new_size.width() * dpr;
|
||||||
|
const int height = new_size.height() * dpr;
|
||||||
|
|
||||||
emit SizeChanged(new_size.width() * dpr, new_size.height() * dpr);
|
if (m_last_window_width != width || m_last_window_height != height ||
|
||||||
|
m_last_window_scale != dpr)
|
||||||
|
{
|
||||||
|
m_last_window_width = width;
|
||||||
|
m_last_window_height = height;
|
||||||
|
m_last_window_scale = dpr;
|
||||||
|
emit SizeChanged(width, height);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Happens when we add/remove the widget from the main window instead of the dedicated one
|
// Happens when we add/remove the widget from the main window instead of the dedicated one
|
||||||
|
|
|
@ -47,6 +47,9 @@ private:
|
||||||
static constexpr int MOUSE_HIDE_DELAY = 3000;
|
static constexpr int MOUSE_HIDE_DELAY = 3000;
|
||||||
QTimer* m_mouse_timer;
|
QTimer* m_mouse_timer;
|
||||||
QPoint m_last_mouse{};
|
QPoint m_last_mouse{};
|
||||||
|
int m_last_window_width = 0;
|
||||||
|
int m_last_window_height = 0;
|
||||||
|
float m_last_window_scale = 0;
|
||||||
bool m_cursor_locked = false;
|
bool m_cursor_locked = false;
|
||||||
bool m_lock_cursor_on_next_activation = false;
|
bool m_lock_cursor_on_next_activation = false;
|
||||||
bool m_dont_lock_cursor_on_show = false;
|
bool m_dont_lock_cursor_on_show = false;
|
||||||
|
|
|
@ -55,7 +55,6 @@ bool OnScreenUI::Initialize(u32 width, u32 height, float scale)
|
||||||
// Don't create an ini file. TODO: Do we want this in the future?
|
// Don't create an ini file. TODO: Do we want this in the future?
|
||||||
ImGui::GetIO().IniFilename = nullptr;
|
ImGui::GetIO().IniFilename = nullptr;
|
||||||
SetScale(scale);
|
SetScale(scale);
|
||||||
ImGui::GetStyle().WindowRounding = 7.0f;
|
|
||||||
|
|
||||||
PortableVertexDeclaration vdecl = {};
|
PortableVertexDeclaration vdecl = {};
|
||||||
vdecl.position = {ComponentFormat::Float, 2, offsetof(ImDrawVert, pos), true, false};
|
vdecl.position = {ComponentFormat::Float, 2, offsetof(ImDrawVert, pos), true, false};
|
||||||
|
@ -343,6 +342,10 @@ void OnScreenUI::SetScale(float backbuffer_scale)
|
||||||
ImGui::GetIO().DisplayFramebufferScale.x = backbuffer_scale;
|
ImGui::GetIO().DisplayFramebufferScale.x = backbuffer_scale;
|
||||||
ImGui::GetIO().DisplayFramebufferScale.y = backbuffer_scale;
|
ImGui::GetIO().DisplayFramebufferScale.y = backbuffer_scale;
|
||||||
ImGui::GetIO().FontGlobalScale = backbuffer_scale;
|
ImGui::GetIO().FontGlobalScale = backbuffer_scale;
|
||||||
|
// ScaleAllSizes scales in-place, so calling it twice will double-apply the scale
|
||||||
|
// Reset the style first so that the scale is applied to the base style, not an already-scaled one
|
||||||
|
ImGui::GetStyle() = {};
|
||||||
|
ImGui::GetStyle().WindowRounding = 7.0f;
|
||||||
ImGui::GetStyle().ScaleAllSizes(backbuffer_scale);
|
ImGui::GetStyle().ScaleAllSizes(backbuffer_scale);
|
||||||
|
|
||||||
m_backbuffer_scale = backbuffer_scale;
|
m_backbuffer_scale = backbuffer_scale;
|
||||||
|
|
|
@ -176,6 +176,8 @@ void Presenter::SetBackbuffer(SurfaceInfo info)
|
||||||
m_backbuffer_height = info.height;
|
m_backbuffer_height = info.height;
|
||||||
m_backbuffer_scale = info.scale;
|
m_backbuffer_scale = info.scale;
|
||||||
m_backbuffer_format = info.format;
|
m_backbuffer_format = info.format;
|
||||||
|
if (m_onscreen_ui)
|
||||||
|
m_onscreen_ui->SetScale(info.scale);
|
||||||
UpdateDrawRectangle();
|
UpdateDrawRectangle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue