Add SetWindowMaxSize for desktop and web (#3309)
* Add SetWindowMaxSize for desktop and web * Remove SizeInt and respective adjustments
This commit is contained in:
parent
2b1849e57d
commit
719365f209
@ -961,6 +961,7 @@ RLAPI void SetWindowTitle(const char *title); // Set title f
|
|||||||
RLAPI void SetWindowPosition(int x, int y); // Set window position on screen (only PLATFORM_DESKTOP)
|
RLAPI void SetWindowPosition(int x, int y); // Set window position on screen (only PLATFORM_DESKTOP)
|
||||||
RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window
|
RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window
|
||||||
RLAPI void SetWindowMinSize(int width, int height); // Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
|
RLAPI void SetWindowMinSize(int width, int height); // Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
|
||||||
|
RLAPI void SetWindowMaxSize(int width, int height); // Set window maximum dimensions (for FLAG_WINDOW_RESIZABLE)
|
||||||
RLAPI void SetWindowSize(int width, int height); // Set window dimensions
|
RLAPI void SetWindowSize(int width, int height); // Set window dimensions
|
||||||
RLAPI void SetWindowOpacity(float opacity); // Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
|
RLAPI void SetWindowOpacity(float opacity); // Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
|
||||||
RLAPI void SetWindowFocused(void); // Set window focused (only PLATFORM_DESKTOP)
|
RLAPI void SetWindowFocused(void); // Set window focused (only PLATFORM_DESKTOP)
|
||||||
|
72
src/rcore.c
72
src/rcore.c
@ -395,9 +395,11 @@ typedef struct CoreData {
|
|||||||
Size currentFbo; // Current render width and height (depends on active fbo)
|
Size currentFbo; // Current render width and height (depends on active fbo)
|
||||||
Size render; // Framebuffer width and height (render area, including black bars if required)
|
Size render; // Framebuffer width and height (render area, including black bars if required)
|
||||||
Point renderOffset; // Offset from render area (must be divided by 2)
|
Point renderOffset; // Offset from render area (must be divided by 2)
|
||||||
|
Size windowMin; // Window minimum width and height (for resizable window)
|
||||||
|
Size windowMax; // Window maximum width and height (for resizable window)
|
||||||
Matrix screenScale; // Matrix to scale screen (framebuffer rendering)
|
Matrix screenScale; // Matrix to scale screen (framebuffer rendering)
|
||||||
|
|
||||||
char **dropFilepaths; // Store dropped files paths pointers (provided by GLFW)
|
char **dropFilepaths; // Store dropped files paths pointers (provided by GLFW)
|
||||||
unsigned int dropFileCount; // Count dropped files strings
|
unsigned int dropFileCount; // Count dropped files strings
|
||||||
|
|
||||||
} Window;
|
} Window;
|
||||||
@ -1787,9 +1789,36 @@ void SetWindowMonitor(int monitor)
|
|||||||
// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
|
// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
|
||||||
void SetWindowMinSize(int width, int height)
|
void SetWindowMinSize(int width, int height)
|
||||||
{
|
{
|
||||||
|
CORE.Window.windowMin.width = width;
|
||||||
|
CORE.Window.windowMin.height = height;
|
||||||
#if defined(PLATFORM_DESKTOP)
|
#if defined(PLATFORM_DESKTOP)
|
||||||
const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
int minWidth = (CORE.Window.windowMin.width == 0) ? GLFW_DONT_CARE : CORE.Window.windowMin.width;
|
||||||
glfwSetWindowSizeLimits(CORE.Window.handle, width, height, mode->width, mode->height);
|
int minHeight = (CORE.Window.windowMin.height == 0) ? GLFW_DONT_CARE : CORE.Window.windowMin.height;
|
||||||
|
int maxWidth = (CORE.Window.windowMax.width == 0) ? GLFW_DONT_CARE : CORE.Window.windowMax.width;
|
||||||
|
int maxHeight = (CORE.Window.windowMax.height == 0) ? GLFW_DONT_CARE : CORE.Window.windowMax.height;
|
||||||
|
glfwSetWindowSizeLimits(CORE.Window.handle, minWidth, minHeight, maxWidth, maxHeight);
|
||||||
|
#endif
|
||||||
|
#if defined(PLATFORM_WEB)
|
||||||
|
// Trigger the resize event once to update the window minimum width and height
|
||||||
|
if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) != 0) EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set window maximum dimensions (FLAG_WINDOW_RESIZABLE)
|
||||||
|
void SetWindowMaxSize(int width, int height)
|
||||||
|
{
|
||||||
|
CORE.Window.windowMax.width = width;
|
||||||
|
CORE.Window.windowMax.height = height;
|
||||||
|
#if defined(PLATFORM_DESKTOP)
|
||||||
|
int minWidth = (CORE.Window.windowMin.width == 0) ? GLFW_DONT_CARE : CORE.Window.windowMin.width;
|
||||||
|
int minHeight = (CORE.Window.windowMin.height == 0) ? GLFW_DONT_CARE : CORE.Window.windowMin.height;
|
||||||
|
int maxWidth = (CORE.Window.windowMax.width == 0) ? GLFW_DONT_CARE : CORE.Window.windowMax.width;
|
||||||
|
int maxHeight = (CORE.Window.windowMax.height == 0) ? GLFW_DONT_CARE : CORE.Window.windowMax.height;
|
||||||
|
glfwSetWindowSizeLimits(CORE.Window.handle, minWidth, minHeight, maxWidth, maxHeight);
|
||||||
|
#endif
|
||||||
|
#if defined(PLATFORM_WEB)
|
||||||
|
// Trigger the resize event once to update the window maximum width and height
|
||||||
|
if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) != 0) EmscriptenResizeCallback(EMSCRIPTEN_EVENT_RESIZE, NULL, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3182,7 +3211,7 @@ bool DirectoryExists(const char *dirPath)
|
|||||||
int GetFileLength(const char *fileName)
|
int GetFileLength(const char *fileName)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
// NOTE: On Unix-like systems, it can by used the POSIX system call: stat(),
|
// NOTE: On Unix-like systems, it can by used the POSIX system call: stat(),
|
||||||
// but depending on the platform that call could not be available
|
// but depending on the platform that call could not be available
|
||||||
//struct stat result = { 0 };
|
//struct stat result = { 0 };
|
||||||
@ -3195,11 +3224,11 @@ int GetFileLength(const char *fileName)
|
|||||||
{
|
{
|
||||||
fseek(file, 0L, SEEK_END);
|
fseek(file, 0L, SEEK_END);
|
||||||
long int fileSize = ftell(file);
|
long int fileSize = ftell(file);
|
||||||
|
|
||||||
// Check for size overflow (INT_MAX)
|
// Check for size overflow (INT_MAX)
|
||||||
if (fileSize > 2147483647) TRACELOG(LOG_WARNING, "[%s] File size overflows expected limit, do not use GetFileLength()", fileName);
|
if (fileSize > 2147483647) TRACELOG(LOG_WARNING, "[%s] File size overflows expected limit, do not use GetFileLength()", fileName);
|
||||||
else size = (int)fileSize;
|
else size = (int)fileSize;
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3765,12 +3794,12 @@ bool IsKeyPressed(int key)
|
|||||||
bool IsKeyPressedRepeat(int key)
|
bool IsKeyPressedRepeat(int key)
|
||||||
{
|
{
|
||||||
bool repeat = false;
|
bool repeat = false;
|
||||||
|
|
||||||
if ((key > 0) && (key < MAX_KEYBOARD_KEYS))
|
if ((key > 0) && (key < MAX_KEYBOARD_KEYS))
|
||||||
{
|
{
|
||||||
if (CORE.Input.Keyboard.keyRepeatInFrame[key] == 1) repeat = true;
|
if (CORE.Input.Keyboard.keyRepeatInFrame[key] == 1) repeat = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return repeat;
|
return repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3778,12 +3807,12 @@ bool IsKeyPressedRepeat(int key)
|
|||||||
bool IsKeyDown(int key)
|
bool IsKeyDown(int key)
|
||||||
{
|
{
|
||||||
bool down = false;
|
bool down = false;
|
||||||
|
|
||||||
if ((key > 0) && (key < MAX_KEYBOARD_KEYS))
|
if ((key > 0) && (key < MAX_KEYBOARD_KEYS))
|
||||||
{
|
{
|
||||||
if (CORE.Input.Keyboard.currentKeyState[key] == 1) down = true;
|
if (CORE.Input.Keyboard.currentKeyState[key] == 1) down = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return down;
|
return down;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3791,7 +3820,7 @@ bool IsKeyDown(int key)
|
|||||||
bool IsKeyReleased(int key)
|
bool IsKeyReleased(int key)
|
||||||
{
|
{
|
||||||
bool released = false;
|
bool released = false;
|
||||||
|
|
||||||
if ((key > 0) && (key < MAX_KEYBOARD_KEYS))
|
if ((key > 0) && (key < MAX_KEYBOARD_KEYS))
|
||||||
{
|
{
|
||||||
if ((CORE.Input.Keyboard.previousKeyState[key] == 1) && (CORE.Input.Keyboard.currentKeyState[key] == 0)) released = true;
|
if ((CORE.Input.Keyboard.previousKeyState[key] == 1) && (CORE.Input.Keyboard.currentKeyState[key] == 0)) released = true;
|
||||||
@ -3804,12 +3833,12 @@ bool IsKeyReleased(int key)
|
|||||||
bool IsKeyUp(int key)
|
bool IsKeyUp(int key)
|
||||||
{
|
{
|
||||||
bool up = false;
|
bool up = false;
|
||||||
|
|
||||||
if ((key > 0) && (key < MAX_KEYBOARD_KEYS))
|
if ((key > 0) && (key < MAX_KEYBOARD_KEYS))
|
||||||
{
|
{
|
||||||
if (CORE.Input.Keyboard.currentKeyState[key] == 0) up = true;
|
if (CORE.Input.Keyboard.currentKeyState[key] == 0) up = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return up;
|
return up;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3887,7 +3916,7 @@ const char *GetGamepadName(int gamepad)
|
|||||||
if (CORE.Input.Gamepad.ready[gamepad]) name = glfwGetJoystickName(gamepad);
|
if (CORE.Input.Gamepad.ready[gamepad]) name = glfwGetJoystickName(gamepad);
|
||||||
#endif
|
#endif
|
||||||
#if defined(PLATFORM_DRM)
|
#if defined(PLATFORM_DRM)
|
||||||
if (CORE.Input.Gamepad.ready[gamepad])
|
if (CORE.Input.Gamepad.ready[gamepad])
|
||||||
{
|
{
|
||||||
ioctl(CORE.Input.Gamepad.streamId[gamepad], JSIOCGNAME(64), &CORE.Input.Gamepad.name[gamepad]);
|
ioctl(CORE.Input.Gamepad.streamId[gamepad], JSIOCGNAME(64), &CORE.Input.Gamepad.name[gamepad]);
|
||||||
name = CORE.Input.Gamepad.name[gamepad];
|
name = CORE.Input.Gamepad.name[gamepad];
|
||||||
@ -4061,7 +4090,7 @@ int GetMouseY(void)
|
|||||||
Vector2 GetMousePosition(void)
|
Vector2 GetMousePosition(void)
|
||||||
{
|
{
|
||||||
Vector2 position = { 0 };
|
Vector2 position = { 0 };
|
||||||
|
|
||||||
// TODO: Review touch position on PLATFORM_WEB
|
// TODO: Review touch position on PLATFORM_WEB
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID) //|| defined(PLATFORM_WEB)
|
#if defined(PLATFORM_ANDROID) //|| defined(PLATFORM_WEB)
|
||||||
@ -4220,6 +4249,12 @@ static bool InitGraphicsDevice(int width, int height)
|
|||||||
CORE.Window.screen.height = height; // User desired height
|
CORE.Window.screen.height = height; // User desired height
|
||||||
CORE.Window.screenScale = MatrixIdentity(); // No draw scaling required by default
|
CORE.Window.screenScale = MatrixIdentity(); // No draw scaling required by default
|
||||||
|
|
||||||
|
// Set the window minimum and maximum default values to 0
|
||||||
|
CORE.Window.windowMin.width = 0;
|
||||||
|
CORE.Window.windowMin.height = 0;
|
||||||
|
CORE.Window.windowMax.width = 0;
|
||||||
|
CORE.Window.windowMax.height = 0;
|
||||||
|
|
||||||
// NOTE: Framebuffer (render area - CORE.Window.render.width, CORE.Window.render.height) could include black bars...
|
// NOTE: Framebuffer (render area - CORE.Window.render.width, CORE.Window.render.height) could include black bars...
|
||||||
// ...in top-down or left-right to match display aspect ratio (no weird scaling)
|
// ...in top-down or left-right to match display aspect ratio (no weird scaling)
|
||||||
|
|
||||||
@ -6178,6 +6213,13 @@ static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *
|
|||||||
// so the size of the canvas object is explicitly retrieved below
|
// so the size of the canvas object is explicitly retrieved below
|
||||||
int width = GetWindowInnerWidth();
|
int width = GetWindowInnerWidth();
|
||||||
int height = GetWindowInnerHeight();
|
int height = GetWindowInnerHeight();
|
||||||
|
|
||||||
|
if (width < CORE.Window.windowMin.width) width = CORE.Window.windowMin.width;
|
||||||
|
else if (width > CORE.Window.windowMax.width && CORE.Window.windowMax.width > 0) width = CORE.Window.windowMax.width;
|
||||||
|
|
||||||
|
if (height < CORE.Window.windowMin.height) height = CORE.Window.windowMin.height;
|
||||||
|
else if (height > CORE.Window.windowMax.height && CORE.Window.windowMax.height > 0) height = CORE.Window.windowMax.height;
|
||||||
|
|
||||||
emscripten_set_canvas_element_size("#canvas",width,height);
|
emscripten_set_canvas_element_size("#canvas",width,height);
|
||||||
|
|
||||||
SetupViewport(width, height); // Reset viewport and projection matrix for new size
|
SetupViewport(width, height); // Reset viewport and projection matrix for new size
|
||||||
|
Loading…
Reference in New Issue
Block a user