Skip to content

Commit 6d562e5

Browse files
committed
REVIEWED: HiggDPI content scaling on changing monitors with different DPI #5335 #5356
Note that high-dpi awareness must be enabled by users and `CORE.Window.render` reports the scaled framebuffer size, while `CORE.Window.screen` reports the logical size. `ToggleBorderlessWindow()` has also been reviewed to be consistent with scaling, if monitor physical display size is reported as 1920x1080 but there is a content scale of 1.5, then the borderless fullscreen window will be 1280x720, with the 1920x1080 framebuffer
1 parent 7553e9d commit 6d562e5

File tree

3 files changed

+118
-68
lines changed

3 files changed

+118
-68
lines changed

examples/core/core_highdpi_testbed.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ int main(void)
3030
SetConfigFlags(FLAG_WINDOW_HIGHDPI | FLAG_WINDOW_RESIZABLE);
3131
InitWindow(screenWidth, screenHeight, "raylib [core] example - highdpi testbed");
3232

33+
Vector2 scaleDpi = GetWindowScaleDPI();
34+
Vector2 mousePos = GetMousePosition();
35+
int currentMonitor = GetCurrentMonitor();
36+
3337
int gridSpacing = 40; // Grid spacing in pixels
3438

3539
SetTargetFPS(60);
@@ -40,7 +44,9 @@ int main(void)
4044
{
4145
// Update
4246
//----------------------------------------------------------------------------------
43-
// TODO: Update variables / Implement example logic at this point
47+
mousePos = GetMousePosition();
48+
currentMonitor = GetCurrentMonitor();
49+
scaleDpi = GetWindowScaleDPI();
4450
//----------------------------------------------------------------------------------
4551

4652
// Draw
@@ -50,11 +56,30 @@ int main(void)
5056
ClearBackground(RAYWHITE);
5157

5258
// Draw grid
53-
for (int h = 0; h < 20; h++) DrawLine(0, h*gridSpacing, GetRenderWidth(), h*gridSpacing, LIGHTGRAY);
54-
for (int v = 0; v < 40; v++) DrawLine(v*gridSpacing, 0, v*gridSpacing, GetScreenHeight(), LIGHTGRAY);
59+
for (int h = 0; h < 20; h++)
60+
{
61+
DrawText(TextFormat("%02i", h*gridSpacing), 4, h*gridSpacing - 4, 10, GRAY);
62+
DrawLine(24, h*gridSpacing, GetScreenWidth(), h*gridSpacing, LIGHTGRAY);
63+
}
64+
for (int v = 0; v < 40; v++)
65+
{
66+
DrawText(TextFormat("%02i", v*gridSpacing), v*gridSpacing - 10, 4, 10, GRAY);
67+
DrawLine(v*gridSpacing, 20, v*gridSpacing, GetScreenHeight(), LIGHTGRAY);
68+
}
5569

5670
// Draw UI info
57-
DrawText(TextFormat("SCREEN SIZE: %ix%i", GetScreenWidth(), GetScreenHeight()), 10, 10, 20, BLACK);
71+
DrawText(TextFormat("CURRENT MONITOR: %i/%i (%ix%i)", currentMonitor + 1, GetMonitorCount(),
72+
GetMonitorWidth(currentMonitor), GetMonitorHeight(currentMonitor)), 50, 50, 20, DARKGRAY);
73+
DrawText(TextFormat("SCREEN SIZE: %ix%i", GetScreenWidth(), GetScreenHeight()), 50, 90, 20, DARKGRAY);
74+
DrawText(TextFormat("RENDER SIZE: %ix%i", GetRenderWidth(), GetRenderHeight()), 50, 130, 20, DARKGRAY);
75+
DrawText(TextFormat("SCALE FACTOR: %.1fx%.1f", scaleDpi.x, scaleDpi.y), 50, 170, 20, GRAY);
76+
77+
// Draw mouse position
78+
DrawCircleV(GetMousePosition(), 20, MAROON);
79+
DrawRectangle(mousePos.x - 25, mousePos.y, 50, 2, BLACK);
80+
DrawRectangle(mousePos.x, mousePos.y - 25, 2, 50, BLACK);
81+
DrawText(TextFormat("[%i,%i]", GetMouseX(), GetMouseY()), mousePos.x - 44,
82+
(mousePos.y > GetScreenHeight() - 60)? mousePos.y - 46 : mousePos.y + 30, 20, BLACK);
5883

5984
EndDrawing();
6085
//----------------------------------------------------------------------------------

0 commit comments

Comments
 (0)