Qt: Improve imgui hidpi scaling

This commit is contained in:
Connor McLaughlin 2020-01-07 18:52:33 +10:00
parent 168eb5fe2d
commit 686df4a203
2 changed files with 12 additions and 4 deletions

View file

@ -12,8 +12,8 @@
#include "spu.h" #include "spu.h"
#include "system.h" #include "system.h"
#include "timers.h" #include "timers.h"
#include <cstring>
#include <cmath> #include <cmath>
#include <cstring>
#include <imgui.h> #include <imgui.h>
Log_SetChannel(HostInterface); Log_SetChannel(HostInterface);
@ -113,8 +113,10 @@ void HostInterface::DrawFPSWindow()
if (!(show_fps | show_vps | show_speed)) if (!(show_fps | show_vps | show_speed))
return; return;
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x - 175.0f, 0.0f), ImGuiCond_Always); const ImVec2 window_size =
ImGui::SetNextWindowSize(ImVec2(175.0f, 16.0f)); ImVec2(175.0f * ImGui::GetIO().DisplayFramebufferScale.x, 16.0f * ImGui::GetIO().DisplayFramebufferScale.y);
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x - window_size.x, 0.0f), ImGuiCond_Always);
ImGui::SetNextWindowSize(window_size);
if (!ImGui::Begin("FPSWindow", nullptr, if (!ImGui::Begin("FPSWindow", nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse |

View file

@ -45,6 +45,12 @@ bool QtDisplayWindow::createImGuiContext()
io.DisplaySize.x = static_cast<float>(m_window_width); io.DisplaySize.x = static_cast<float>(m_window_width);
io.DisplaySize.y = static_cast<float>(m_window_height); io.DisplaySize.y = static_cast<float>(m_window_height);
const float framebuffer_scale = static_cast<float>(devicePixelRatio());
io.DisplayFramebufferScale.x = framebuffer_scale;
io.DisplayFramebufferScale.y = framebuffer_scale;
io.FontGlobalScale = framebuffer_scale;
ImGui::GetStyle().ScaleAllSizes(framebuffer_scale);
return true; return true;
} }
@ -95,7 +101,7 @@ void QtDisplayWindow::keyReleaseEvent(QKeyEvent* event)
void QtDisplayWindow::resizeEvent(QResizeEvent* event) void QtDisplayWindow::resizeEvent(QResizeEvent* event)
{ {
QWindow::resizeEvent(event); QWindow::resizeEvent(event);
const int width = static_cast<int>(static_cast<qreal>(event->size().width()) * devicePixelRatio()); const int width = static_cast<int>(static_cast<qreal>(event->size().width()) * devicePixelRatio());
const int height = static_cast<int>(static_cast<qreal>(event->size().height()) * devicePixelRatio()); const int height = static_cast<int>(static_cast<qreal>(event->size().height()) * devicePixelRatio());
emit windowResizedEvent(width, height); emit windowResizedEvent(width, height);