SetMinimumWindowSize for OS X
authorstopiccot
Sun, 18 Nov 2012 15:45:12 +0300
changeset 6681 5a0396a933b5
parent 6680 9d3df1f5c542
child 6682 a0cbe4e5a07a
SetMinimumWindowSize for OS X
.hgignore
include/SDL_video.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/cocoa/SDL_cocoavideo.m
src/video/cocoa/SDL_cocoawindow.h
src/video/cocoa/SDL_cocoawindow.m
--- a/.hgignore	Wed Nov 21 23:00:06 2012 -0500
+++ b/.hgignore	Sun Nov 18 15:45:12 2012 +0300
@@ -23,6 +23,10 @@
 *.pbxuser
 (^|/)build($|/)
 .DS_Store
+Xcode/SDL/SDL.xcodeproj/xcuserdata
+Xcode/SDL/SDL.xcodeproj/project.xcworkspace/xcuserdata
+Xcode/SDL/SDLTest.xcodeproj/xcuserdata
+Xcode/SDL/SDLTest.xcodeproj/project.xcworkspace/xcuserdata
 
 # for Visual C++
 Debug
--- a/include/SDL_video.h	Wed Nov 21 23:00:06 2012 -0500
+++ b/include/SDL_video.h	Sun Nov 18 15:45:12 2012 +0300
@@ -517,6 +517,25 @@
  */
 extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w,
                                                int *h);
+    
+/**
+ *  \brief Set the minimum size of a window's client area.
+ *
+ *  \note You can't change the minimum size of a fullscreen window, it
+ *        automatically matches the size of the display mode.
+ *
+ *  \sa SDL_GetWindowMinimumSize()
+ */
+extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window * window,
+                                                      int min_w, int min_h);
+    
+/**
+ *  \brief Get the minimum size of a window's client area.
+ *
+ *  \sa SDL_SetWindowMinimumSize()
+ */
+extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window * window,
+                                                      int *w, int *h);
 
 /**
  *  \brief Set the border state of a window.
--- a/src/video/SDL_sysvideo.h	Wed Nov 21 23:00:06 2012 -0500
+++ b/src/video/SDL_sysvideo.h	Sun Nov 18 15:45:12 2012 +0300
@@ -74,6 +74,7 @@
     char *title;
     int x, y;
     int w, h;
+    int min_w, min_h;
     Uint32 flags;
 
     /* Stored position and size for windowed mode */
@@ -181,6 +182,7 @@
     void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
     void (*SetWindowPosition) (_THIS, SDL_Window * window);
     void (*SetWindowSize) (_THIS, SDL_Window * window);
+    void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
     void (*ShowWindow) (_THIS, SDL_Window * window);
     void (*HideWindow) (_THIS, SDL_Window * window);
     void (*RaiseWindow) (_THIS, SDL_Window * window);
--- a/src/video/SDL_video.c	Wed Nov 21 23:00:06 2012 -0500
+++ b/src/video/SDL_video.c	Sun Nov 18 15:45:12 2012 +0300
@@ -1563,19 +1563,47 @@
     CHECK_WINDOW_MAGIC(window, );
 
     if (_this && window && window->magic == &_this->window_magic) {
-        if (w) {
-            *w = window->w;
-        }
-        if (h) {
-            *h = window->h;
+        *w = window->w;
+        *h = window->h;
+    }
+}
+
+void
+SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
+{
+    CHECK_WINDOW_MAGIC(window, );
+    
+    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+        window->min_w = min_w;
+        window->min_h = min_h;
+        if (_this->SetWindowMinimumSize) {
+            _this->SetWindowMinimumSize(_this, window);
         }
-    } else {
-        if (w) {
-            *w = 0;
-        }
-        if (h) {
-            *h = 0;
-        }
+        /* Ensure that window is not smaller than minimal size */
+        SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h));
+    }
+}
+
+void
+SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
+{
+    int dummy;
+    
+    if (!min_w) {
+        min_w = &dummy;
+    }
+    if (!min_h) {
+        min_h = &dummy;
+    }
+    
+    *min_w = 0;
+    *min_h = 0;
+    
+    CHECK_WINDOW_MAGIC(window, );
+    
+    if (_this && window && window->magic == &_this->window_magic) {
+        *min_w = window->min_w;
+        *min_h = window->min_h;
     }
 }
 
--- a/src/video/cocoa/SDL_cocoavideo.m	Wed Nov 21 23:00:06 2012 -0500
+++ b/src/video/cocoa/SDL_cocoavideo.m	Sun Nov 18 15:45:12 2012 +0300
@@ -95,6 +95,7 @@
     device->SetWindowIcon = Cocoa_SetWindowIcon;
     device->SetWindowPosition = Cocoa_SetWindowPosition;
     device->SetWindowSize = Cocoa_SetWindowSize;
+    device->SetWindowMinimumSize = Cocoa_SetWindowMinimumSize;
     device->ShowWindow = Cocoa_ShowWindow;
     device->HideWindow = Cocoa_HideWindow;
     device->RaiseWindow = Cocoa_RaiseWindow;
--- a/src/video/cocoa/SDL_cocoawindow.h	Wed Nov 21 23:00:06 2012 -0500
+++ b/src/video/cocoa/SDL_cocoawindow.h	Sun Nov 18 15:45:12 2012 +0300
@@ -94,6 +94,7 @@
 extern void Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
 extern void Cocoa_SetWindowPosition(_THIS, SDL_Window * window);
 extern void Cocoa_SetWindowSize(_THIS, SDL_Window * window);
+extern void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window);
 extern void Cocoa_ShowWindow(_THIS, SDL_Window * window);
 extern void Cocoa_HideWindow(_THIS, SDL_Window * window);
 extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
--- a/src/video/cocoa/SDL_cocoawindow.m	Wed Nov 21 23:00:06 2012 -0500
+++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Nov 18 15:45:12 2012 +0300
@@ -731,6 +731,21 @@
 }
 
 void
+Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
+{
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
+        
+    NSSize minSize;
+    minSize.width = window->min_w;
+    minSize.height = window->min_h;
+        
+    [windata->nswindow setMinSize:minSize];
+    
+    [pool release];
+}
+
+void
 Cocoa_ShowWindow(_THIS, SDL_Window * window)
 {
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];