@@ -395,9 +395,11 @@ typedef struct CoreData {
395395 Size currentFbo ; // Current render width and height (depends on active fbo)
396396 Size render ; // Framebuffer width and height (render area, including black bars if required)
397397 Point renderOffset ; // Offset from render area (must be divided by 2)
398+ Size windowMin ; // Window minimum width and height (for resizable window)
399+ Size windowMax ; // Window maximum width and height (for resizable window)
398400 Matrix screenScale ; // Matrix to scale screen (framebuffer rendering)
399401
400- char * * dropFilepaths ; // Store dropped files paths pointers (provided by GLFW)
402+ char * * dropFilepaths ; // Store dropped files paths pointers (provided by GLFW)
401403 unsigned int dropFileCount ; // Count dropped files strings
402404
403405 } Window ;
@@ -1787,9 +1789,36 @@ void SetWindowMonitor(int monitor)
17871789// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
17881790void SetWindowMinSize (int width , int height )
17891791{
1792+ CORE .Window .windowMin .width = width ;
1793+ CORE .Window .windowMin .height = height ;
17901794#if defined(PLATFORM_DESKTOP )
1791- const GLFWvidmode * mode = glfwGetVideoMode (glfwGetPrimaryMonitor ());
1792- glfwSetWindowSizeLimits (CORE .Window .handle , width , height , mode -> width , mode -> height );
1795+ int minWidth = (CORE .Window .windowMin .width == 0 ) ? GLFW_DONT_CARE : CORE .Window .windowMin .width ;
1796+ int minHeight = (CORE .Window .windowMin .height == 0 ) ? GLFW_DONT_CARE : CORE .Window .windowMin .height ;
1797+ int maxWidth = (CORE .Window .windowMax .width == 0 ) ? GLFW_DONT_CARE : CORE .Window .windowMax .width ;
1798+ int maxHeight = (CORE .Window .windowMax .height == 0 ) ? GLFW_DONT_CARE : CORE .Window .windowMax .height ;
1799+ glfwSetWindowSizeLimits (CORE .Window .handle , minWidth , minHeight , maxWidth , maxHeight );
1800+ #endif
1801+ #if defined(PLATFORM_WEB )
1802+ // Trigger the resize event once to update the window minimum width and height
1803+ if ((CORE .Window .flags & FLAG_WINDOW_RESIZABLE ) != 0 ) EmscriptenResizeCallback (EMSCRIPTEN_EVENT_RESIZE , NULL , NULL );
1804+ #endif
1805+ }
1806+
1807+ // Set window maximum dimensions (FLAG_WINDOW_RESIZABLE)
1808+ void SetWindowMaxSize (int width , int height )
1809+ {
1810+ CORE .Window .windowMax .width = width ;
1811+ CORE .Window .windowMax .height = height ;
1812+ #if defined(PLATFORM_DESKTOP )
1813+ int minWidth = (CORE .Window .windowMin .width == 0 ) ? GLFW_DONT_CARE : CORE .Window .windowMin .width ;
1814+ int minHeight = (CORE .Window .windowMin .height == 0 ) ? GLFW_DONT_CARE : CORE .Window .windowMin .height ;
1815+ int maxWidth = (CORE .Window .windowMax .width == 0 ) ? GLFW_DONT_CARE : CORE .Window .windowMax .width ;
1816+ int maxHeight = (CORE .Window .windowMax .height == 0 ) ? GLFW_DONT_CARE : CORE .Window .windowMax .height ;
1817+ glfwSetWindowSizeLimits (CORE .Window .handle , minWidth , minHeight , maxWidth , maxHeight );
1818+ #endif
1819+ #if defined(PLATFORM_WEB )
1820+ // Trigger the resize event once to update the window maximum width and height
1821+ if ((CORE .Window .flags & FLAG_WINDOW_RESIZABLE ) != 0 ) EmscriptenResizeCallback (EMSCRIPTEN_EVENT_RESIZE , NULL , NULL );
17931822#endif
17941823}
17951824
@@ -3182,7 +3211,7 @@ bool DirectoryExists(const char *dirPath)
31823211int GetFileLength (const char * fileName )
31833212{
31843213 int size = 0 ;
3185-
3214+
31863215 // NOTE: On Unix-like systems, it can by used the POSIX system call: stat(),
31873216 // but depending on the platform that call could not be available
31883217 //struct stat result = { 0 };
@@ -3195,11 +3224,11 @@ int GetFileLength(const char *fileName)
31953224 {
31963225 fseek (file , 0L , SEEK_END );
31973226 long int fileSize = ftell (file );
3198-
3227+
31993228 // Check for size overflow (INT_MAX)
32003229 if (fileSize > 2147483647 ) TRACELOG (LOG_WARNING , "[%s] File size overflows expected limit, do not use GetFileLength()" , fileName );
32013230 else size = (int )fileSize ;
3202-
3231+
32033232 fclose (file );
32043233 }
32053234
@@ -3765,33 +3794,33 @@ bool IsKeyPressed(int key)
37653794bool IsKeyPressedRepeat (int key )
37663795{
37673796 bool repeat = false;
3768-
3797+
37693798 if ((key > 0 ) && (key < MAX_KEYBOARD_KEYS ))
37703799 {
37713800 if (CORE .Input .Keyboard .keyRepeatInFrame [key ] == 1 ) repeat = true;
37723801 }
3773-
3802+
37743803 return repeat ;
37753804}
37763805
37773806// Check if a key is being pressed (key held down)
37783807bool IsKeyDown (int key )
37793808{
37803809 bool down = false;
3781-
3810+
37823811 if ((key > 0 ) && (key < MAX_KEYBOARD_KEYS ))
37833812 {
37843813 if (CORE .Input .Keyboard .currentKeyState [key ] == 1 ) down = true;
37853814 }
3786-
3815+
37873816 return down ;
37883817}
37893818
37903819// Check if a key has been released once
37913820bool IsKeyReleased (int key )
37923821{
37933822 bool released = false;
3794-
3823+
37953824 if ((key > 0 ) && (key < MAX_KEYBOARD_KEYS ))
37963825 {
37973826 if ((CORE .Input .Keyboard .previousKeyState [key ] == 1 ) && (CORE .Input .Keyboard .currentKeyState [key ] == 0 )) released = true;
@@ -3804,12 +3833,12 @@ bool IsKeyReleased(int key)
38043833bool IsKeyUp (int key )
38053834{
38063835 bool up = false;
3807-
3836+
38083837 if ((key > 0 ) && (key < MAX_KEYBOARD_KEYS ))
38093838 {
38103839 if (CORE .Input .Keyboard .currentKeyState [key ] == 0 ) up = true;
38113840 }
3812-
3841+
38133842 return up ;
38143843}
38153844
@@ -3887,7 +3916,7 @@ const char *GetGamepadName(int gamepad)
38873916 if (CORE .Input .Gamepad .ready [gamepad ]) name = glfwGetJoystickName (gamepad );
38883917#endif
38893918#if defined(PLATFORM_DRM )
3890- if (CORE .Input .Gamepad .ready [gamepad ])
3919+ if (CORE .Input .Gamepad .ready [gamepad ])
38913920 {
38923921 ioctl (CORE .Input .Gamepad .streamId [gamepad ], JSIOCGNAME (64 ), & CORE .Input .Gamepad .name [gamepad ]);
38933922 name = CORE .Input .Gamepad .name [gamepad ];
@@ -4061,7 +4090,7 @@ int GetMouseY(void)
40614090Vector2 GetMousePosition (void )
40624091{
40634092 Vector2 position = { 0 };
4064-
4093+
40654094 // TODO: Review touch position on PLATFORM_WEB
40664095
40674096#if defined(PLATFORM_ANDROID ) //|| defined(PLATFORM_WEB)
@@ -4220,6 +4249,12 @@ static bool InitGraphicsDevice(int width, int height)
42204249 CORE .Window .screen .height = height ; // User desired height
42214250 CORE .Window .screenScale = MatrixIdentity (); // No draw scaling required by default
42224251
4252+ // Set the window minimum and maximum default values to 0
4253+ CORE .Window .windowMin .width = 0 ;
4254+ CORE .Window .windowMin .height = 0 ;
4255+ CORE .Window .windowMax .width = 0 ;
4256+ CORE .Window .windowMax .height = 0 ;
4257+
42234258 // NOTE: Framebuffer (render area - CORE.Window.render.width, CORE.Window.render.height) could include black bars...
42244259 // ...in top-down or left-right to match display aspect ratio (no weird scaling)
42254260
@@ -6178,6 +6213,13 @@ static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *
61786213 // so the size of the canvas object is explicitly retrieved below
61796214 int width = GetWindowInnerWidth ();
61806215 int height = GetWindowInnerHeight ();
6216+
6217+ if (width < CORE .Window .windowMin .width ) width = CORE .Window .windowMin .width ;
6218+ else if (width > CORE .Window .windowMax .width && CORE .Window .windowMax .width > 0 ) width = CORE .Window .windowMax .width ;
6219+
6220+ if (height < CORE .Window .windowMin .height ) height = CORE .Window .windowMin .height ;
6221+ else if (height > CORE .Window .windowMax .height && CORE .Window .windowMax .height > 0 ) height = CORE .Window .windowMax .height ;
6222+
61816223 emscripten_set_canvas_element_size ("#canvas" ,width ,height );
61826224
61836225 SetupViewport (width , height ); // Reset viewport and projection matrix for new size
0 commit comments