SetMinimumWindowSize for OS X
authorstopiccot
Sun, 18 Nov 2012 15:45:12 +0300
changeset 66815a0396a933b5
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
     1.1 --- a/.hgignore	Wed Nov 21 23:00:06 2012 -0500
     1.2 +++ b/.hgignore	Sun Nov 18 15:45:12 2012 +0300
     1.3 @@ -23,6 +23,10 @@
     1.4  *.pbxuser
     1.5  (^|/)build($|/)
     1.6  .DS_Store
     1.7 +Xcode/SDL/SDL.xcodeproj/xcuserdata
     1.8 +Xcode/SDL/SDL.xcodeproj/project.xcworkspace/xcuserdata
     1.9 +Xcode/SDL/SDLTest.xcodeproj/xcuserdata
    1.10 +Xcode/SDL/SDLTest.xcodeproj/project.xcworkspace/xcuserdata
    1.11  
    1.12  # for Visual C++
    1.13  Debug
     2.1 --- a/include/SDL_video.h	Wed Nov 21 23:00:06 2012 -0500
     2.2 +++ b/include/SDL_video.h	Sun Nov 18 15:45:12 2012 +0300
     2.3 @@ -517,6 +517,25 @@
     2.4   */
     2.5  extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w,
     2.6                                                 int *h);
     2.7 +    
     2.8 +/**
     2.9 + *  \brief Set the minimum size of a window's client area.
    2.10 + *
    2.11 + *  \note You can't change the minimum size of a fullscreen window, it
    2.12 + *        automatically matches the size of the display mode.
    2.13 + *
    2.14 + *  \sa SDL_GetWindowMinimumSize()
    2.15 + */
    2.16 +extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window * window,
    2.17 +                                                      int min_w, int min_h);
    2.18 +    
    2.19 +/**
    2.20 + *  \brief Get the minimum size of a window's client area.
    2.21 + *
    2.22 + *  \sa SDL_SetWindowMinimumSize()
    2.23 + */
    2.24 +extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window * window,
    2.25 +                                                      int *w, int *h);
    2.26  
    2.27  /**
    2.28   *  \brief Set the border state of a window.
     3.1 --- a/src/video/SDL_sysvideo.h	Wed Nov 21 23:00:06 2012 -0500
     3.2 +++ b/src/video/SDL_sysvideo.h	Sun Nov 18 15:45:12 2012 +0300
     3.3 @@ -74,6 +74,7 @@
     3.4      char *title;
     3.5      int x, y;
     3.6      int w, h;
     3.7 +    int min_w, min_h;
     3.8      Uint32 flags;
     3.9  
    3.10      /* Stored position and size for windowed mode */
    3.11 @@ -181,6 +182,7 @@
    3.12      void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
    3.13      void (*SetWindowPosition) (_THIS, SDL_Window * window);
    3.14      void (*SetWindowSize) (_THIS, SDL_Window * window);
    3.15 +    void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
    3.16      void (*ShowWindow) (_THIS, SDL_Window * window);
    3.17      void (*HideWindow) (_THIS, SDL_Window * window);
    3.18      void (*RaiseWindow) (_THIS, SDL_Window * window);
     4.1 --- a/src/video/SDL_video.c	Wed Nov 21 23:00:06 2012 -0500
     4.2 +++ b/src/video/SDL_video.c	Sun Nov 18 15:45:12 2012 +0300
     4.3 @@ -1563,19 +1563,47 @@
     4.4      CHECK_WINDOW_MAGIC(window, );
     4.5  
     4.6      if (_this && window && window->magic == &_this->window_magic) {
     4.7 -        if (w) {
     4.8 -            *w = window->w;
     4.9 +        *w = window->w;
    4.10 +        *h = window->h;
    4.11 +    }
    4.12 +}
    4.13 +
    4.14 +void
    4.15 +SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
    4.16 +{
    4.17 +    CHECK_WINDOW_MAGIC(window, );
    4.18 +    
    4.19 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    4.20 +        window->min_w = min_w;
    4.21 +        window->min_h = min_h;
    4.22 +        if (_this->SetWindowMinimumSize) {
    4.23 +            _this->SetWindowMinimumSize(_this, window);
    4.24          }
    4.25 -        if (h) {
    4.26 -            *h = window->h;
    4.27 -        }
    4.28 -    } else {
    4.29 -        if (w) {
    4.30 -            *w = 0;
    4.31 -        }
    4.32 -        if (h) {
    4.33 -            *h = 0;
    4.34 -        }
    4.35 +        /* Ensure that window is not smaller than minimal size */
    4.36 +        SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h));
    4.37 +    }
    4.38 +}
    4.39 +
    4.40 +void
    4.41 +SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
    4.42 +{
    4.43 +    int dummy;
    4.44 +    
    4.45 +    if (!min_w) {
    4.46 +        min_w = &dummy;
    4.47 +    }
    4.48 +    if (!min_h) {
    4.49 +        min_h = &dummy;
    4.50 +    }
    4.51 +    
    4.52 +    *min_w = 0;
    4.53 +    *min_h = 0;
    4.54 +    
    4.55 +    CHECK_WINDOW_MAGIC(window, );
    4.56 +    
    4.57 +    if (_this && window && window->magic == &_this->window_magic) {
    4.58 +        *min_w = window->min_w;
    4.59 +        *min_h = window->min_h;
    4.60      }
    4.61  }
    4.62  
     5.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Wed Nov 21 23:00:06 2012 -0500
     5.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Sun Nov 18 15:45:12 2012 +0300
     5.3 @@ -95,6 +95,7 @@
     5.4      device->SetWindowIcon = Cocoa_SetWindowIcon;
     5.5      device->SetWindowPosition = Cocoa_SetWindowPosition;
     5.6      device->SetWindowSize = Cocoa_SetWindowSize;
     5.7 +    device->SetWindowMinimumSize = Cocoa_SetWindowMinimumSize;
     5.8      device->ShowWindow = Cocoa_ShowWindow;
     5.9      device->HideWindow = Cocoa_HideWindow;
    5.10      device->RaiseWindow = Cocoa_RaiseWindow;
     6.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Wed Nov 21 23:00:06 2012 -0500
     6.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Sun Nov 18 15:45:12 2012 +0300
     6.3 @@ -94,6 +94,7 @@
     6.4  extern void Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
     6.5  extern void Cocoa_SetWindowPosition(_THIS, SDL_Window * window);
     6.6  extern void Cocoa_SetWindowSize(_THIS, SDL_Window * window);
     6.7 +extern void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window);
     6.8  extern void Cocoa_ShowWindow(_THIS, SDL_Window * window);
     6.9  extern void Cocoa_HideWindow(_THIS, SDL_Window * window);
    6.10  extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
     7.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Wed Nov 21 23:00:06 2012 -0500
     7.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Sun Nov 18 15:45:12 2012 +0300
     7.3 @@ -731,6 +731,21 @@
     7.4  }
     7.5  
     7.6  void
     7.7 +Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
     7.8 +{
     7.9 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    7.10 +    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
    7.11 +        
    7.12 +    NSSize minSize;
    7.13 +    minSize.width = window->min_w;
    7.14 +    minSize.height = window->min_h;
    7.15 +        
    7.16 +    [windata->nswindow setMinSize:minSize];
    7.17 +    
    7.18 +    [pool release];
    7.19 +}
    7.20 +
    7.21 +void
    7.22  Cocoa_ShowWindow(_THIS, SDL_Window * window)
    7.23  {
    7.24      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];