temp stash, macos fixes for pixelratio

This commit is contained in:
CrackedPixel 2026-02-20 12:28:10 -06:00
parent 0671639faa
commit 2de4454e79

View File

@ -763,11 +763,33 @@ void SetWindowMaxSize(int width, int height)
// Set window dimensions // Set window dimensions
void SetWindowSize(int width, int height) void SetWindowSize(int width, int height)
{
printf("SetWindowSize 1\n");
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
{
#if defined(__APPLE__)
#endif
}
else
{ {
CORE.Window.screen.width = width; CORE.Window.screen.width = width;
CORE.Window.screen.height = height; CORE.Window.screen.height = height;
}
RGFW_window_resize(platform.window, width, height); RGFW_window_resize(platform.window, CORE.Window.screen.width, CORE.Window.screen.height);
// printf("SetWindowSize 3\n");
// if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) {
// #if defined(__APPLE__)
// Vector2 scaleDpi = GetWindowScaleDPI();
// CORE.Window.screenScale = MatrixScale(2.0f, 2.0f, 1.0f);
// CORE.Window.render.width = CORE.Window.screen.width * 2;
// CORE.Window.render.height = CORE.Window.screen.height * 2;
// CORE.Window.currentFbo.width = CORE.Window.render.width;
// CORE.Window.currentFbo.height = CORE.Window.render.height;
// #endif
// }
} }
// Set window opacity, value opacity is between 0.0 and 1.0 // Set window opacity, value opacity is between 0.0 and 1.0
@ -901,7 +923,21 @@ Vector2 GetWindowScaleDPI(void)
if (platform.window) monitor = RGFW_window_getMonitor(platform.window); if (platform.window) monitor = RGFW_window_getMonitor(platform.window);
else monitor = RGFW_getPrimaryMonitor(); else monitor = RGFW_getPrimaryMonitor();
#if defined(__APPLE__)
return (Vector2){ 1.0f / monitor->scaleX, 1.0f / monitor->scaleX };
#else
return (Vector2){ monitor->scaleX, monitor->scaleX }; return (Vector2){ monitor->scaleX, monitor->scaleX };
#endif
}
float GetMonitorPixelRatio(void)
{
RGFW_monitor *monitor = NULL;
if (platform.window) monitor = RGFW_window_getMonitor(platform.window);
else monitor = RGFW_getPrimaryMonitor();
return monitor->pixelRatio;
} }
// Set clipboard text content // Set clipboard text content
@ -1179,10 +1215,32 @@ void PollInputEvents(void)
// Window events are also polled (Minimized, maximized, close...) // Window events are also polled (Minimized, maximized, close...)
case RGFW_windowResized: case RGFW_windowResized:
{ {
SetupViewport(platform.window->w, platform.window->h); #if defined(__APPLE__)
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
{
SetupViewport(platform.window->w * platform.monitor->pixelRatio, platform.window->h * platform.monitor->pixelRatio);
CORE.Window.screenScale = MatrixScale(platform.monitor->pixelRatio, platform.monitor->pixelRatio, 1.0f);
CORE.Window.screen.width = platform.window->w;
CORE.Window.screen.height = platform.window->h;
CORE.Window.render.width = CORE.Window.screen.width * platform.monitor->pixelRatio;
CORE.Window.render.height = CORE.Window.screen.height * platform.monitor->pixelRatio;
}
else
{
SetupViewport(platform.window->w, platform.window->h);
CORE.Window.screen.width = platform.window->w;
CORE.Window.screen.height = platform.window->h;
CORE.Window.render.width = CORE.Window.screen.width;
CORE.Window.render.height = CORE.Window.screen.height;
}
CORE.Window.currentFbo.width = CORE.Window.render.width;
CORE.Window.currentFbo.height = CORE.Window.render.height;
#else
SetupViewport(platform.window->w, platform.window->h);
// if we are doing automatic DPI scaling, then the "screen" size is divided by the window scale // if we are doing automatic DPI scaling, then the "screen" size is divided by the window scale
if (IsWindowState(FLAG_WINDOW_HIGHDPI)) if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
{ {
CORE.Window.screen.width = (int)(platform.window->w/GetWindowScaleDPI().x); CORE.Window.screen.width = (int)(platform.window->w/GetWindowScaleDPI().x);
CORE.Window.screen.height = (int)(platform.window->h/GetWindowScaleDPI().y); CORE.Window.screen.height = (int)(platform.window->h/GetWindowScaleDPI().y);
@ -1195,6 +1253,7 @@ void PollInputEvents(void)
CORE.Window.currentFbo.width = platform.window->w; CORE.Window.currentFbo.width = platform.window->w;
CORE.Window.currentFbo.height = platform.window->h; CORE.Window.currentFbo.height = platform.window->h;
#endif
CORE.Window.resizedLastFrame = true; CORE.Window.resizedLastFrame = true;
} break; } break;
case RGFW_windowMaximized: case RGFW_windowMaximized:
@ -1460,8 +1519,15 @@ int InitPlatform(void)
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
{ {
#if defined(__APPLE__)
// // apple is 0.66, 0.5, etc
// CORE.Window.screen.width = CORE.Window.screen.width / GetWindowScaleDPI().x;
// CORE.Window.screen.height = CORE.Window.screen.height / GetWindowScaleDPI().y;
#else
// // other platforms are 1.5, 2.0, etc
CORE.Window.screen.width = CORE.Window.screen.width * GetWindowScaleDPI().x; CORE.Window.screen.width = CORE.Window.screen.width * GetWindowScaleDPI().x;
CORE.Window.screen.height = CORE.Window.screen.height * GetWindowScaleDPI().y; CORE.Window.screen.height = CORE.Window.screen.height * GetWindowScaleDPI().y;
#endif
} }
RGFW_setGlobalHints_OpenGL(hints); RGFW_setGlobalHints_OpenGL(hints);
@ -1500,6 +1566,7 @@ int InitPlatform(void)
// must be set to NULL to not interfere // must be set to NULL to not interfere
RGFW_window_setExitKey(platform.window, RGFW_keyNULL); RGFW_window_setExitKey(platform.window, RGFW_keyNULL);
RGFW_window_makeCurrentWindow_OpenGL(platform.window); RGFW_window_makeCurrentWindow_OpenGL(platform.window);
platform.monitor = RGFW_window_getMonitor(platform.window);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -1515,11 +1582,19 @@ int InitPlatform(void)
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) { if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)) {
Vector2 scaleDpi = GetWindowScaleDPI(); Vector2 scaleDpi = GetWindowScaleDPI();
SetMouseScale(1.0f/scaleDpi.x, 1.0f/scaleDpi.y); #if defined(__APPLE__)
CORE.Window.screenScale = MatrixScale(platform.monitor->pixelRatio, platform.monitor->pixelRatio, 1.0f);
CORE.Window.render.width = CORE.Window.screen.width * platform.monitor->pixelRatio;
CORE.Window.render.height = CORE.Window.screen.height * platform.monitor->pixelRatio;
CORE.Window.currentFbo.width = CORE.Window.render.width;
CORE.Window.currentFbo.height = CORE.Window.render.height;
#else
SetMouseScale(1.0f/scaleDpi.x, 1.0f/scaleDpi.y);
CORE.Window.screenScale = MatrixScale(scaleDpi.x, scaleDpi.y, 1.0f); CORE.Window.screenScale = MatrixScale(scaleDpi.x, scaleDpi.y, 1.0f);
CORE.Window.screen.width /= scaleDpi.x; CORE.Window.screen.width /= scaleDpi.x;
CORE.Window.screen.height /= scaleDpi.y; CORE.Window.screen.height /= scaleDpi.y;
#endif
} }
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully"); TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");