[client] imgui: improve method for high DPI

We now give ImGui the true logical size of the window and tell it to scale
the framebuffer. To fix the blurry fonts, we continue to load fonts at the
scale necessary for the DPI and use FontGlobalScale to shrink the fonts back
to the logical size. The font rectangle is then expanded by the framebuffer
scaling, resulting in good text rendering.

This method has the advantage of not messing up the sizes of resizable
overlays when moving across monitors.
This commit is contained in:
Quantum 2021-07-29 21:46:50 -04:00 committed by Geoffrey McRae
parent 0402dd521a
commit f1b1da60ea
2 changed files with 16 additions and 6 deletions

View file

@ -70,7 +70,7 @@ void app_updateCursorPos(double x, double y)
g_cursor.valid = true; g_cursor.valid = true;
if (g_state.overlayInput) if (g_state.overlayInput)
g_state.io->MousePos = (ImVec2) { x * g_state.windowScale, y * g_state.windowScale }; g_state.io->MousePos = (ImVec2) { x, y };
} }
void app_handleFocusEvent(bool focused) void app_handleFocusEvent(bool focused)
@ -723,6 +723,14 @@ int app_renderOverlay(struct Rect * rects, int maxRects)
const int written = const int written =
overlay->ops->render(overlay->udata, false, buffer, MAX_OVERLAY_RECTS); overlay->ops->render(overlay->udata, false, buffer, MAX_OVERLAY_RECTS);
for (int i = 0; i < written; ++i)
{
buffer[i].x *= g_state.windowScale;
buffer[i].y *= g_state.windowScale;
buffer[i].w *= g_state.windowScale;
buffer[i].h *= g_state.windowScale;
}
// It is an error to run out of rectangles, because we will not be able to // It is an error to run out of rectangles, because we will not be able to
// correctly calculate the damage of the next frame. // correctly calculate the damage of the next frame.
assert(written >= 0); assert(written >= 0);

View file

@ -181,12 +181,14 @@ static int renderThread(void * unused)
if (resize) if (resize)
{ {
g_state.io->DisplaySize = (ImVec2) { g_state.io->DisplaySize = (ImVec2) {
.x = g_state.windowW * g_state.windowScale, .x = g_state.windowW,
.y = g_state.windowH * g_state.windowScale .y = g_state.windowH,
}; };
g_state.io->DisplayFramebufferScale = (ImVec2) {
imGuiResetStyle(); .x = g_state.windowScale,
ImGuiStyle_ScaleAllSizes(g_state.style, g_state.windowScale); .y = g_state.windowScale,
};
g_state.io->FontGlobalScale = 1.0f / g_state.windowScale;
ImFontAtlas_Clear(g_state.io->Fonts); ImFontAtlas_Clear(g_state.io->Fonts);
ImFontAtlas_AddFontFromFileTTF(g_state.io->Fonts, g_state.fontName, ImFontAtlas_AddFontFromFileTTF(g_state.io->Fonts, g_state.fontName,