added functions for window scaling
This commit is contained in:
parent
d5361d45fe
commit
ce4f3b7c6c
|
|
@ -16,6 +16,9 @@ RLAPI bool IsWindowResized(void); // Check if wi
|
||||||
RLAPI bool IsWindowState(unsigned int flag); // Check if one specific window flag is enabled
|
RLAPI bool IsWindowState(unsigned int flag); // Check if one specific window flag is enabled
|
||||||
RLAPI void SetWindowState(unsigned int flags); // Set window configuration state using flags
|
RLAPI void SetWindowState(unsigned int flags); // Set window configuration state using flags
|
||||||
RLAPI void ClearWindowState(unsigned int flags); // Clear window configuration state flags
|
RLAPI void ClearWindowState(unsigned int flags); // Clear window configuration state flags
|
||||||
|
RLAPI void SetWindowScale(float scaleFactor); // Set window scale factor
|
||||||
|
RLAPI void SaveWindowScale(void); // Save window scale to defaults
|
||||||
|
RLAPI void RestoreWindowScale(void); // Load window scale from defaults
|
||||||
RLAPI void ToggleFullscreen(void); // Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP)
|
RLAPI void ToggleFullscreen(void); // Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP)
|
||||||
RLAPI void MaximizeWindow(void); // Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
|
RLAPI void MaximizeWindow(void); // Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
|
||||||
RLAPI void MinimizeWindow(void); // Set window state: minimized, if resizable (only PLATFORM_DESKTOP)
|
RLAPI void MinimizeWindow(void); // Set window state: minimized, if resizable (only PLATFORM_DESKTOP)
|
||||||
|
|
|
||||||
57
src/core.c
57
src/core.c
|
|
@ -1035,11 +1035,7 @@ void ToggleFullscreen(void)
|
||||||
CORE.Window.flags ^= FLAG_FULLSCREEN_MODE;
|
CORE.Window.flags ^= FLAG_FULLSCREEN_MODE;
|
||||||
if (CORE.Window.fullscreen)
|
if (CORE.Window.fullscreen)
|
||||||
{
|
{
|
||||||
CORE.Window.defaultScreenScaleX = CORE.Window.screenScaleX;
|
SaveWindowScale();
|
||||||
CORE.Window.defaultScreenScaleY = CORE.Window.screenScaleY;
|
|
||||||
CORE.Window.defaultScreen = CORE.Window.screen;
|
|
||||||
CORE.Window.defaultRender = CORE.Window.render;
|
|
||||||
CORE.Window.defaultScreenScale = CORE.Window.screenScale;
|
|
||||||
// Store previous window position (in case we exit fullscreen)
|
// Store previous window position (in case we exit fullscreen)
|
||||||
glfwGetWindowPos(CORE.Window.handle, &CORE.Window.position.x, &CORE.Window.position.y);
|
glfwGetWindowPos(CORE.Window.handle, &CORE.Window.position.x, &CORE.Window.position.y);
|
||||||
|
|
||||||
|
|
@ -1070,9 +1066,7 @@ void ToggleFullscreen(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
||||||
CORE.Window.screenScaleX = 1.0f;
|
SetWindowScale(1.0f);
|
||||||
CORE.Window.screenScaleY = 1.0f;
|
|
||||||
CORE.Window.screenScale = MatrixIdentity();
|
|
||||||
glfwSetWindowMonitor(CORE.Window.handle, monitor, 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, mode->refreshRate);
|
glfwSetWindowMonitor(CORE.Window.handle, monitor, 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, mode->refreshRate);
|
||||||
|
|
||||||
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
|
// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
|
||||||
|
|
@ -1080,11 +1074,7 @@ void ToggleFullscreen(void)
|
||||||
if (CORE.Window.flags & FLAG_VSYNC_HINT) glfwSwapInterval(1);
|
if (CORE.Window.flags & FLAG_VSYNC_HINT) glfwSwapInterval(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CORE.Window.screenScaleX = CORE.Window.defaultScreenScaleX;
|
RestoreWindowScale();
|
||||||
CORE.Window.screenScaleY = CORE.Window.defaultScreenScaleY;
|
|
||||||
CORE.Window.screen = CORE.Window.defaultScreen;
|
|
||||||
CORE.Window.render = CORE.Window.defaultRender;
|
|
||||||
CORE.Window.screenScale = CORE.Window.defaultScreenScale;
|
|
||||||
glfwSetWindowMonitor(CORE.Window.handle, NULL, CORE.Window.position.x, CORE.Window.position.y, (int)((float)CORE.Window.screen.width * CORE.Window.screenScaleX), (int)((float)CORE.Window.screen.height * CORE.Window.screenScaleY), GLFW_DONT_CARE);
|
glfwSetWindowMonitor(CORE.Window.handle, NULL, CORE.Window.position.x, CORE.Window.position.y, (int)((float)CORE.Window.screen.width * CORE.Window.screenScaleX), (int)((float)CORE.Window.screen.height * CORE.Window.screenScaleY), GLFW_DONT_CARE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1130,6 +1120,39 @@ void ToggleFullscreen(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set window scale factor
|
||||||
|
void SetWindowScale(float scaleFactor)
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
CORE.Window.screenScaleX = scaleFactor;
|
||||||
|
CORE.Window.screenScaleY = scaleFactor;
|
||||||
|
CORE.Window.screenScale = (scaleFactor == 1.0f) ? MatrixIdentity(): MatrixScale(scaleFactor, scaleFactor, 1.0f);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save window scale to defaults
|
||||||
|
void SaveWindowScale()
|
||||||
|
{
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
CORE.Window.defaultScreenScaleX = CORE.Window.screenScaleX;
|
||||||
|
CORE.Window.defaultScreenScaleY = CORE.Window.screenScaleY;
|
||||||
|
CORE.Window.defaultScreen = CORE.Window.screen;
|
||||||
|
CORE.Window.defaultRender = CORE.Window.render;
|
||||||
|
CORE.Window.defaultScreenScale = CORE.Window.screenScale;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load window scale from defaults
|
||||||
|
void RestoreWindowScale() {
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
CORE.Window.screenScaleX = CORE.Window.defaultScreenScaleX;
|
||||||
|
CORE.Window.screenScaleY = CORE.Window.defaultScreenScaleY;
|
||||||
|
CORE.Window.screen = CORE.Window.defaultScreen;
|
||||||
|
CORE.Window.render = CORE.Window.defaultRender;
|
||||||
|
CORE.Window.screenScale = CORE.Window.defaultScreenScale;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
|
// Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
|
||||||
void MaximizeWindow(void)
|
void MaximizeWindow(void)
|
||||||
{
|
{
|
||||||
|
|
@ -4095,16 +4118,12 @@ static void SetupWindowContentScale(int width, int height)
|
||||||
glfwGetWindowContentScale(CORE.Window.handle, screenScaleX, screenScaleY);
|
glfwGetWindowContentScale(CORE.Window.handle, screenScaleX, screenScaleY);
|
||||||
CORE.Window.screenScale = MatrixScale(CORE.Window.screenScaleX, CORE.Window.screenScaleY, 1.0f);
|
CORE.Window.screenScale = MatrixScale(CORE.Window.screenScaleX, CORE.Window.screenScaleY, 1.0f);
|
||||||
} else {
|
} else {
|
||||||
CORE.Window.screenScaleX = 1.0f;
|
SetWindowScale(1.0f);
|
||||||
CORE.Window.screenScaleY = 1.0f;
|
|
||||||
CORE.Window.screenScale = MatrixIdentity();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CORE.Window.screenScaleX = 1.0f;
|
SetWindowScale(1.0f);
|
||||||
CORE.Window.screenScaleY = 1.0f;
|
|
||||||
CORE.Window.screenScale = MatrixIdentity();
|
|
||||||
}
|
}
|
||||||
if (width == 0) {
|
if (width == 0) {
|
||||||
width = (int)(((float)CORE.Window.defaultScreen.width)/CORE.Window.screenScaleX);
|
width = (int)(((float)CORE.Window.defaultScreen.width)/CORE.Window.screenScaleX);
|
||||||
|
|
|
||||||
|
|
@ -902,6 +902,9 @@ RLAPI bool IsWindowResized(void); // Check if wi
|
||||||
RLAPI bool IsWindowState(unsigned int flag); // Check if one specific window flag is enabled
|
RLAPI bool IsWindowState(unsigned int flag); // Check if one specific window flag is enabled
|
||||||
RLAPI void SetWindowState(unsigned int flags); // Set window configuration state using flags
|
RLAPI void SetWindowState(unsigned int flags); // Set window configuration state using flags
|
||||||
RLAPI void ClearWindowState(unsigned int flags); // Clear window configuration state flags
|
RLAPI void ClearWindowState(unsigned int flags); // Clear window configuration state flags
|
||||||
|
RLAPI void SetWindowScale(float scaleFactor); // Set window scale factor
|
||||||
|
RLAPI void SaveWindowScale(void); // Save window scale to defaults
|
||||||
|
RLAPI void RestoreWindowScale(void); // Load window scale from defaults
|
||||||
RLAPI void ToggleFullscreen(void); // Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP)
|
RLAPI void ToggleFullscreen(void); // Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP)
|
||||||
RLAPI void MaximizeWindow(void); // Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
|
RLAPI void MaximizeWindow(void); // Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
|
||||||
RLAPI void MinimizeWindow(void); // Set window state: minimized, if resizable (only PLATFORM_DESKTOP)
|
RLAPI void MinimizeWindow(void); // Set window state: minimized, if resizable (only PLATFORM_DESKTOP)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user