mirror of
https://github.com/raysan5/raylib.git
synced 2026-02-20 20:49:17 -05:00
Compare commits
2 Commits
180c3c13ba
...
059ebaa6ad
| Author | SHA1 | Date | |
|---|---|---|---|
| 059ebaa6ad | |||
| d01f158bd5 |
@ -78,7 +78,7 @@ int main(void)
|
|||||||
DrawText(TextFormat("WINDOW POSITION: %ix%i", (int)windowPos.x, (int)windowPos.y), 50, 90, 20, DARKGRAY);
|
DrawText(TextFormat("WINDOW POSITION: %ix%i", (int)windowPos.x, (int)windowPos.y), 50, 90, 20, DARKGRAY);
|
||||||
DrawText(TextFormat("SCREEN SIZE: %ix%i", GetScreenWidth(), GetScreenHeight()), 50, 130, 20, DARKGRAY);
|
DrawText(TextFormat("SCREEN SIZE: %ix%i", GetScreenWidth(), GetScreenHeight()), 50, 130, 20, DARKGRAY);
|
||||||
DrawText(TextFormat("RENDER SIZE: %ix%i", GetRenderWidth(), GetRenderHeight()), 50, 170, 20, DARKGRAY);
|
DrawText(TextFormat("RENDER SIZE: %ix%i", GetRenderWidth(), GetRenderHeight()), 50, 170, 20, DARKGRAY);
|
||||||
DrawText(TextFormat("SCALE FACTOR: %.1fx%.1f", scaleDpi.x, scaleDpi.y), 50, 210, 20, GRAY);
|
DrawText(TextFormat("SCALE FACTOR: %.2fx%.2f", scaleDpi.x, scaleDpi.y), 50, 210, 20, GRAY);
|
||||||
|
|
||||||
// Draw reference rectangles, top-left and bottom-right corners
|
// Draw reference rectangles, top-left and bottom-right corners
|
||||||
DrawRectangle(0, 0, 30, 60, RED);
|
DrawRectangle(0, 0, 30, 60, RED);
|
||||||
|
|||||||
@ -1649,35 +1649,43 @@ int InitPlatform(void)
|
|||||||
TRACELOG(LOG_INFO, "DISPLAY: Trying to enable VSYNC");
|
TRACELOG(LOG_INFO, "DISPLAY: Trying to enable VSYNC");
|
||||||
}
|
}
|
||||||
|
|
||||||
int fbWidth = CORE.Window.screen.width;
|
|
||||||
int fbHeight = CORE.Window.screen.height;
|
|
||||||
|
|
||||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
|
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI))
|
||||||
{
|
{
|
||||||
// NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling
|
// Set screen size to logical pixel size, considering content scaling
|
||||||
// Framebuffer scaling is activated with: glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_TRUE);
|
Vector2 scaleDpi = GetWindowScaleDPI();
|
||||||
|
CORE.Window.render.width = (int)(CORE.Window.screen.width*scaleDpi.x);
|
||||||
// Get current framebuffer size, on high-dpi it could be bigger than screen size
|
CORE.Window.render.height = (int)(CORE.Window.screen.height*scaleDpi.y);
|
||||||
glfwGetFramebufferSize(platform.handle, &fbWidth, &fbHeight);
|
//TRACELOG(LOG_INFO, "DPI SCALING: %.2f, %.2f", scaleDpi.x, scaleDpi.y);
|
||||||
|
|
||||||
// Screen scaling matrix is required in case desired screen area is different from display area
|
// Screen scaling matrix is required in case desired screen area is different from display area
|
||||||
CORE.Window.screenScale = MatrixScale((float)fbWidth/CORE.Window.screen.width, (float)fbHeight/CORE.Window.screen.height, 1.0f);
|
CORE.Window.screenScale = MatrixScale(scaleDpi.x, scaleDpi.y, 1.0f);
|
||||||
|
|
||||||
|
// NOTE: On APPLE platforms system manage window and input scaling
|
||||||
|
// Framebuffer scaling is activated with: glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_TRUE);
|
||||||
|
|
||||||
|
// Screen scaling matrix is required in case desired screen area is different from display area
|
||||||
|
CORE.Window.screenScale = MatrixScale(scaleDpi.x, scaleDpi.y, 1.0f);
|
||||||
|
|
||||||
#if !defined(__APPLE__)
|
#if !defined(__APPLE__)
|
||||||
// Mouse input scaling for the new screen size
|
// Mouse input scaling for the new screen size
|
||||||
SetMouseScale((float)CORE.Window.screen.width/fbWidth, (float)CORE.Window.screen.height/fbHeight);
|
SetMouseScale(1.0f/scaleDpi.x, 1.0f/scaleDpi.y);
|
||||||
|
|
||||||
|
// Force window size (and framebuffer) refresh
|
||||||
|
glfwSetWindowSize(platform.handle, CORE.Window.render.width, CORE.Window.render.height);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
else CORE.Window.render = CORE.Window.screen;
|
||||||
|
|
||||||
CORE.Window.render.width = fbWidth;
|
// Current active framebuffer size is main framebuffer size
|
||||||
CORE.Window.render.height = fbHeight;
|
CORE.Window.currentFbo = CORE.Window.render;
|
||||||
CORE.Window.currentFbo.width = fbWidth;
|
|
||||||
CORE.Window.currentFbo.height = fbHeight;
|
|
||||||
|
|
||||||
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully");
|
TRACELOG(LOG_INFO, "DISPLAY: Device initialized successfully %s",
|
||||||
|
FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_HIGHDPI)? "(HighDPI)" : "");
|
||||||
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
|
TRACELOG(LOG_INFO, " > Display size: %i x %i", CORE.Window.display.width, CORE.Window.display.height);
|
||||||
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
|
TRACELOG(LOG_INFO, " > Screen size: %i x %i", CORE.Window.screen.width, CORE.Window.screen.height);
|
||||||
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
TRACELOG(LOG_INFO, " > Render size: %i x %i", CORE.Window.render.width, CORE.Window.render.height);
|
||||||
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
TRACELOG(LOG_INFO, " > Viewport offsets: %i, %i", CORE.Window.renderOffset.x, CORE.Window.renderOffset.y);
|
||||||
|
//TRACELOG(LOG_INFO, " > Content Scaling: %.2f, %.2f", scaleDpi.x, scaleDpi.y);
|
||||||
|
|
||||||
// Try to center window on screen but avoiding window-bar outside of screen
|
// Try to center window on screen but avoiding window-bar outside of screen
|
||||||
int monitorCount = 0;
|
int monitorCount = 0;
|
||||||
@ -1691,13 +1699,17 @@ int InitPlatform(void)
|
|||||||
int monitorHeight = 0;
|
int monitorHeight = 0;
|
||||||
glfwGetMonitorWorkarea(monitor, &monitorX, &monitorY, &monitorWidth, &monitorHeight);
|
glfwGetMonitorWorkarea(monitor, &monitorX, &monitorY, &monitorWidth, &monitorHeight);
|
||||||
|
|
||||||
// TODO: Here CORE.Window.render.width/height should be used instead of
|
// NOTE: It seems on macOS monitor size is not correct
|
||||||
// CORE.Window.screen.width/height to center the window correctly when the high dpi flag is enabled
|
//TRACELOG(LOG_WARNING, "Monitor info: [%i, %i, %i, %i]", monitorX, monitorY, monitorWidth, monitorHeight);
|
||||||
CORE.Window.position.x = monitorX + (monitorWidth - (int)CORE.Window.screen.width)/2;
|
|
||||||
CORE.Window.position.y = monitorY + (monitorHeight - (int)CORE.Window.screen.height)/2;
|
|
||||||
//if (CORE.Window.position.x < monitorX) CORE.Window.position.x = monitorX;
|
|
||||||
//if (CORE.Window.position.y < monitorY) CORE.Window.position.y = monitorY;
|
|
||||||
|
|
||||||
|
// Center window into current monitor
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
CORE.Window.position.x = monitorX + (monitorWidth - CORE.Window.screen.width)/2;
|
||||||
|
CORE.Window.position.y = monitorY + (monitorHeight - CORE.Window.screen.height)/2;
|
||||||
|
#else
|
||||||
|
CORE.Window.position.x = monitorX + (monitorWidth - CORE.Window.render.width)/2;
|
||||||
|
CORE.Window.position.y = monitorY + (monitorHeight - CORE.Window.render.height)/2;
|
||||||
|
#endif
|
||||||
SetWindowPosition(CORE.Window.position.x, CORE.Window.position.y);
|
SetWindowPosition(CORE.Window.position.x, CORE.Window.position.y);
|
||||||
|
|
||||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) MinimizeWindow();
|
if (FLAG_IS_SET(CORE.Window.flags, FLAG_WINDOW_MINIMIZED)) MinimizeWindow();
|
||||||
@ -1828,8 +1840,9 @@ static void FramebufferSizeCallback(GLFWwindow *window, int width, int height)
|
|||||||
SetupViewport(width, height);
|
SetupViewport(width, height);
|
||||||
|
|
||||||
// Set render size
|
// Set render size
|
||||||
CORE.Window.currentFbo.width = width;
|
CORE.Window.render.width = width;
|
||||||
CORE.Window.currentFbo.height = height;
|
CORE.Window.render.height = height;
|
||||||
|
CORE.Window.currentFbo = CORE.Window.render;
|
||||||
CORE.Window.resizedLastFrame = true;
|
CORE.Window.resizedLastFrame = true;
|
||||||
|
|
||||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
if (FLAG_IS_SET(CORE.Window.flags, FLAG_FULLSCREEN_MODE))
|
||||||
@ -1875,8 +1888,9 @@ static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float s
|
|||||||
{
|
{
|
||||||
//TRACELOG(LOG_INFO, "GLFW3: Window content scale changed, scale: [%.2f,%.2f]", scalex, scaley);
|
//TRACELOG(LOG_INFO, "GLFW3: Window content scale changed, scale: [%.2f,%.2f]", scalex, scaley);
|
||||||
|
|
||||||
float fbWidth = (float)CORE.Window.screen.width*scalex;
|
CORE.Window.render.width = (int)((float)CORE.Window.screen.width*scalex);
|
||||||
float fbHeight = (float)CORE.Window.screen.height*scaley;
|
CORE.Window.render.height = (int)((float)CORE.Window.screen.height*scaley);
|
||||||
|
CORE.Window.currentFbo = CORE.Window.render;
|
||||||
|
|
||||||
// NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling
|
// NOTE: On APPLE platforms system should manage window/input scaling and also framebuffer scaling
|
||||||
// Framebuffer scaling is activated with: glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_TRUE);
|
// Framebuffer scaling is activated with: glfwWindowHint(GLFW_SCALE_FRAMEBUFFER, GLFW_TRUE);
|
||||||
@ -1886,10 +1900,6 @@ static void WindowContentScaleCallback(GLFWwindow *window, float scalex, float s
|
|||||||
// Mouse input scaling for the new screen size
|
// Mouse input scaling for the new screen size
|
||||||
SetMouseScale(1.0f/scalex, 1.0f/scaley);
|
SetMouseScale(1.0f/scalex, 1.0f/scaley);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CORE.Window.render.width = (int)fbWidth;
|
|
||||||
CORE.Window.render.height = (int)fbHeight;
|
|
||||||
CORE.Window.currentFbo = CORE.Window.render;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GLFW3: Window position callback, runs when window position changes
|
// GLFW3: Window position callback, runs when window position changes
|
||||||
|
|||||||
Reference in New Issue
Block a user