mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-12-23 14:21:57 +00:00
[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:
parent
0402dd521a
commit
f1b1da60ea
2 changed files with 16 additions and 6 deletions
|
@ -70,7 +70,7 @@ void app_updateCursorPos(double x, double y)
|
|||
g_cursor.valid = true;
|
||||
|
||||
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)
|
||||
|
@ -723,6 +723,14 @@ int app_renderOverlay(struct Rect * rects, int maxRects)
|
|||
const int written =
|
||||
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
|
||||
// correctly calculate the damage of the next frame.
|
||||
assert(written >= 0);
|
||||
|
|
|
@ -181,12 +181,14 @@ static int renderThread(void * unused)
|
|||
if (resize)
|
||||
{
|
||||
g_state.io->DisplaySize = (ImVec2) {
|
||||
.x = g_state.windowW * g_state.windowScale,
|
||||
.y = g_state.windowH * g_state.windowScale
|
||||
.x = g_state.windowW,
|
||||
.y = g_state.windowH,
|
||||
};
|
||||
|
||||
imGuiResetStyle();
|
||||
ImGuiStyle_ScaleAllSizes(g_state.style, g_state.windowScale);
|
||||
g_state.io->DisplayFramebufferScale = (ImVec2) {
|
||||
.x = g_state.windowScale,
|
||||
.y = g_state.windowScale,
|
||||
};
|
||||
g_state.io->FontGlobalScale = 1.0f / g_state.windowScale;
|
||||
|
||||
ImFontAtlas_Clear(g_state.io->Fonts);
|
||||
ImFontAtlas_AddFontFromFileTTF(g_state.io->Fonts, g_state.fontName,
|
||||
|
|
Loading…
Reference in a new issue