Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
authorSam Lantinga <slouken@libsdl.org>
Mon, 31 Dec 2012 12:15:25 -0800
changeset 6788036f53f2f5aa
parent 6787 95a4c5a5464c
child 6789 7177d421bb07
Added SDL_SetWindowMaximumSize() and SDL_GetWindowMaximumSize()
Also fixed Cocoa implementation so that it affects client area, not the whole window area.
include/SDL_test_common.h
include/SDL_video.h
src/test/SDL_test_common.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/cocoa/SDL_cocoamodes.m
src/video/cocoa/SDL_cocoavideo.m
src/video/cocoa/SDL_cocoawindow.h
src/video/cocoa/SDL_cocoawindow.m
src/video/windows/SDL_windowsevents.c
test/testwm2.c
     1.1 --- a/include/SDL_test_common.h	Mon Dec 31 11:07:46 2012 -0800
     1.2 +++ b/include/SDL_test_common.h	Mon Dec 31 12:15:25 2012 -0800
     1.3 @@ -65,6 +65,10 @@
     1.4      int window_y;
     1.5      int window_w;
     1.6      int window_h;
     1.7 +    int window_minW;
     1.8 +    int window_minH;
     1.9 +    int window_maxW;
    1.10 +    int window_maxH;
    1.11      int depth;
    1.12      int refresh_rate;
    1.13      int num_windows;
     2.1 --- a/include/SDL_video.h	Mon Dec 31 11:07:46 2012 -0800
     2.2 +++ b/include/SDL_video.h	Mon Dec 31 12:15:25 2012 -0800
     2.3 @@ -535,6 +535,7 @@
     2.4   *        automatically matches the size of the display mode.
     2.5   *
     2.6   *  \sa SDL_GetWindowMinimumSize()
     2.7 + *  \sa SDL_SetWindowMaximumSize()
     2.8   */
     2.9  extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window * window,
    2.10                                                        int min_w, int min_h);
    2.11 @@ -542,12 +543,34 @@
    2.12  /**
    2.13   *  \brief Get the minimum size of a window's client area.
    2.14   *
    2.15 + *  \sa SDL_GetWindowMaximumSize()
    2.16   *  \sa SDL_SetWindowMinimumSize()
    2.17   */
    2.18  extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window * window,
    2.19                                                        int *w, int *h);
    2.20  
    2.21  /**
    2.22 + *  \brief Set the maximum size of a window's client area.
    2.23 + *
    2.24 + *  \note You can't change the maximum size of a fullscreen window, it
    2.25 + *        automatically matches the size of the display mode.
    2.26 + *
    2.27 + *  \sa SDL_GetWindowMaximumSize()
    2.28 + *  \sa SDL_SetWindowMinimumSize()
    2.29 + */
    2.30 +extern DECLSPEC void SDLCALL SDL_SetWindowMaximumSize(SDL_Window * window,
    2.31 +                                                      int max_w, int max_h);
    2.32 +    
    2.33 +/**
    2.34 + *  \brief Get the maximum size of a window's client area.
    2.35 + *
    2.36 + *  \sa SDL_GetWindowMinimumSize()
    2.37 + *  \sa SDL_SetWindowMaximumSize()
    2.38 + */
    2.39 +extern DECLSPEC void SDLCALL SDL_GetWindowMaximumSize(SDL_Window * window,
    2.40 +                                                      int *w, int *h);
    2.41 +
    2.42 +/**
    2.43   *  \brief Set the border state of a window.
    2.44   *
    2.45   *  This will add or remove the window's SDL_WINDOW_BORDERLESS flag and
     3.1 --- a/src/test/SDL_test_common.c	Mon Dec 31 11:07:46 2012 -0800
     3.2 +++ b/src/test/SDL_test_common.c	Mon Dec 31 12:15:25 2012 -0800
     3.3 @@ -27,7 +27,7 @@
     3.4  #include <stdio.h>
     3.5  
     3.6  #define VIDEO_USAGE \
     3.7 -"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--log all|error|system|audio|video|render|input] [--display N] [--fullscreen | --fullscreen-desktop | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]"
     3.8 +"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--log all|error|system|audio|video|render|input] [--display N] [--fullscreen | --fullscreen-desktop | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--min-geometry WxH] [--max-geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]"
     3.9  
    3.10  #define AUDIO_USAGE \
    3.11  "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
    3.12 @@ -266,6 +266,44 @@
    3.13          state->window_h = SDL_atoi(h);
    3.14          return 2;
    3.15      }
    3.16 +    if (SDL_strcasecmp(argv[index], "--min-geometry") == 0) {
    3.17 +        char *w, *h;
    3.18 +        ++index;
    3.19 +        if (!argv[index]) {
    3.20 +            return -1;
    3.21 +        }
    3.22 +        w = argv[index];
    3.23 +        h = argv[index];
    3.24 +        while (*h && *h != 'x') {
    3.25 +            ++h;
    3.26 +        }
    3.27 +        if (!*h) {
    3.28 +            return -1;
    3.29 +        }
    3.30 +        *h++ = '\0';
    3.31 +        state->window_minW = SDL_atoi(w);
    3.32 +        state->window_minH = SDL_atoi(h);
    3.33 +        return 2;
    3.34 +    }
    3.35 +    if (SDL_strcasecmp(argv[index], "--max-geometry") == 0) {
    3.36 +        char *w, *h;
    3.37 +        ++index;
    3.38 +        if (!argv[index]) {
    3.39 +            return -1;
    3.40 +        }
    3.41 +        w = argv[index];
    3.42 +        h = argv[index];
    3.43 +        while (*h && *h != 'x') {
    3.44 +            ++h;
    3.45 +        }
    3.46 +        if (!*h) {
    3.47 +            return -1;
    3.48 +        }
    3.49 +        *h++ = '\0';
    3.50 +        state->window_maxW = SDL_atoi(w);
    3.51 +        state->window_maxH = SDL_atoi(h);
    3.52 +        return 2;
    3.53 +    }
    3.54      if (SDL_strcasecmp(argv[index], "--depth") == 0) {
    3.55          ++index;
    3.56          if (!argv[index]) {
    3.57 @@ -751,6 +789,12 @@
    3.58                          SDL_GetError());
    3.59                  return SDL_FALSE;
    3.60              }
    3.61 +            if (state->window_minW || state->window_minH) {
    3.62 +                SDL_SetWindowMinimumSize(state->windows[i], state->window_minW, state->window_minH);
    3.63 +            }
    3.64 +            if (state->window_maxW || state->window_maxH) {
    3.65 +                SDL_SetWindowMaximumSize(state->windows[i], state->window_maxW, state->window_maxH);
    3.66 +            }
    3.67              SDL_GetWindowSize(state->windows[i], &w, &h);
    3.68              if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
    3.69                  (w != state->window_w || h != state->window_h)) {
     4.1 --- a/src/video/SDL_sysvideo.h	Mon Dec 31 11:07:46 2012 -0800
     4.2 +++ b/src/video/SDL_sysvideo.h	Mon Dec 31 12:15:25 2012 -0800
     4.3 @@ -75,6 +75,7 @@
     4.4      int x, y;
     4.5      int w, h;
     4.6      int min_w, min_h;
     4.7 +    int max_w, max_h;
     4.8      Uint32 flags;
     4.9  
    4.10      /* Stored position and size for windowed mode */
    4.11 @@ -184,6 +185,7 @@
    4.12      void (*SetWindowPosition) (_THIS, SDL_Window * window);
    4.13      void (*SetWindowSize) (_THIS, SDL_Window * window);
    4.14      void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
    4.15 +    void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
    4.16      void (*ShowWindow) (_THIS, SDL_Window * window);
    4.17      void (*HideWindow) (_THIS, SDL_Window * window);
    4.18      void (*RaiseWindow) (_THIS, SDL_Window * window);
     5.1 --- a/src/video/SDL_video.c	Mon Dec 31 11:07:46 2012 -0800
     5.2 +++ b/src/video/SDL_video.c	Mon Dec 31 12:15:25 2012 -0800
     5.3 @@ -1641,6 +1641,45 @@
     5.4  }
     5.5  
     5.6  void
     5.7 +SDL_SetWindowMaximumSize(SDL_Window * window, int max_w, int max_h)
     5.8 +{
     5.9 +    CHECK_WINDOW_MAGIC(window, );
    5.10 +    
    5.11 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    5.12 +        window->max_w = max_w;
    5.13 +        window->max_h = max_h;
    5.14 +        if (_this->SetWindowMaximumSize) {
    5.15 +            _this->SetWindowMaximumSize(_this, window);
    5.16 +        }
    5.17 +        /* Ensure that window is not larger than maximal size */
    5.18 +        SDL_SetWindowSize(window, SDL_min(window->w, window->max_w), SDL_min(window->h, window->max_h));
    5.19 +    }
    5.20 +}
    5.21 +
    5.22 +void
    5.23 +SDL_GetWindowMaximumSize(SDL_Window * window, int *max_w, int *max_h)
    5.24 +{
    5.25 +    int dummy;
    5.26 +    
    5.27 +    if (!max_w) {
    5.28 +        max_w = &dummy;
    5.29 +    }
    5.30 +    if (!max_h) {
    5.31 +        max_h = &dummy;
    5.32 +    }
    5.33 +    
    5.34 +    *max_w = 0;
    5.35 +    *max_h = 0;
    5.36 +    
    5.37 +    CHECK_WINDOW_MAGIC(window, );
    5.38 +    
    5.39 +    if (_this && window && window->magic == &_this->window_magic) {
    5.40 +        *max_w = window->max_w;
    5.41 +        *max_h = window->max_h;
    5.42 +    }
    5.43 +}
    5.44 +
    5.45 +void
    5.46  SDL_ShowWindow(SDL_Window * window)
    5.47  {
    5.48      CHECK_WINDOW_MAGIC(window, );
     6.1 --- a/src/video/cocoa/SDL_cocoamodes.m	Mon Dec 31 11:07:46 2012 -0800
     6.2 +++ b/src/video/cocoa/SDL_cocoamodes.m	Mon Dec 31 12:15:25 2012 -0800
     6.3 @@ -220,7 +220,7 @@
     6.4      #endif
     6.5  }
     6.6  
     6.7 -static char *
     6.8 +static const char *
     6.9  Cocoa_GetDisplayName(CGDirectDisplayID displayID)
    6.10  {
    6.11      NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
    6.12 @@ -299,7 +299,7 @@
    6.13              displaydata->display = displays[i];
    6.14  
    6.15              SDL_zero(display);
    6.16 -            display.name = Cocoa_GetDisplayName(displays[i]);
    6.17 +            display.name = (char *)Cocoa_GetDisplayName(displays[i]);
    6.18              if (!GetDisplayMode (_this, moderef, &mode)) {
    6.19                  Cocoa_ReleaseDisplayMode(_this, moderef);
    6.20                  SDL_free(displaydata);
     7.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Mon Dec 31 11:07:46 2012 -0800
     7.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Mon Dec 31 12:15:25 2012 -0800
     7.3 @@ -96,6 +96,7 @@
     7.4      device->SetWindowPosition = Cocoa_SetWindowPosition;
     7.5      device->SetWindowSize = Cocoa_SetWindowSize;
     7.6      device->SetWindowMinimumSize = Cocoa_SetWindowMinimumSize;
     7.7 +    device->SetWindowMaximumSize = Cocoa_SetWindowMaximumSize;
     7.8      device->ShowWindow = Cocoa_ShowWindow;
     7.9      device->HideWindow = Cocoa_HideWindow;
    7.10      device->RaiseWindow = Cocoa_RaiseWindow;
     8.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Mon Dec 31 11:07:46 2012 -0800
     8.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Mon Dec 31 12:15:25 2012 -0800
     8.3 @@ -95,6 +95,7 @@
     8.4  extern void Cocoa_SetWindowPosition(_THIS, SDL_Window * window);
     8.5  extern void Cocoa_SetWindowSize(_THIS, SDL_Window * window);
     8.6  extern void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window);
     8.7 +extern void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window);
     8.8  extern void Cocoa_ShowWindow(_THIS, SDL_Window * window);
     8.9  extern void Cocoa_HideWindow(_THIS, SDL_Window * window);
    8.10  extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
     9.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Mon Dec 31 11:07:46 2012 -0800
     9.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Mon Dec 31 12:15:25 2012 -0800
     9.3 @@ -740,7 +740,22 @@
     9.4      minSize.width = window->min_w;
     9.5      minSize.height = window->min_h;
     9.6          
     9.7 -    [windata->nswindow setMinSize:minSize];
     9.8 +    [windata->nswindow setContentMinSize:minSize];
     9.9 +    
    9.10 +    [pool release];
    9.11 +}
    9.12 +
    9.13 +void
    9.14 +Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
    9.15 +{
    9.16 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    9.17 +    SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
    9.18 +        
    9.19 +    NSSize maxSize;
    9.20 +    maxSize.width = window->max_w;
    9.21 +    maxSize.height = window->max_h;
    9.22 +        
    9.23 +    [windata->nswindow setContentMaxSize:maxSize];
    9.24      
    9.25      [pool release];
    9.26  }
    10.1 --- a/src/video/windows/SDL_windowsevents.c	Mon Dec 31 11:07:46 2012 -0800
    10.2 +++ b/src/video/windows/SDL_windowsevents.c	Mon Dec 31 12:15:25 2012 -0800
    10.3 @@ -447,6 +447,7 @@
    10.4              int x, y;
    10.5              int w, h;
    10.6              int min_w, min_h;
    10.7 +            int max_w, max_h;
    10.8              int style;
    10.9              BOOL menu;
   10.10  
   10.11 @@ -462,11 +463,14 @@
   10.12              /* Calculate current size of our window */
   10.13              SDL_GetWindowSize(data->window, &w, &h);
   10.14              SDL_GetWindowMinimumSize(data->window, &min_w, &min_h);
   10.15 +            SDL_GetWindowMaximumSize(data->window, &max_w, &max_h);
   10.16  
   10.17              /* Store in min_w and min_h difference between current size and minimal 
   10.18                 size so we don't need to call AdjustWindowRectEx twice */
   10.19              min_w -= w;
   10.20              min_h -= h;
   10.21 +            max_w -= w;
   10.22 +            max_h -= h;
   10.23  
   10.24              size.top = 0;
   10.25              size.left = 0;
   10.26 @@ -489,6 +493,8 @@
   10.27              if (SDL_GetWindowFlags(data->window) & SDL_WINDOW_RESIZABLE) {
   10.28                  info->ptMinTrackSize.x = w + min_w;
   10.29                  info->ptMinTrackSize.y = h + min_h;
   10.30 +                info->ptMaxTrackSize.x = w + max_w;
   10.31 +                info->ptMaxTrackSize.y = h + max_h;
   10.32              } else {
   10.33                  info->ptMaxSize.x = w;
   10.34                  info->ptMaxSize.y = h;
    11.1 --- a/test/testwm2.c	Mon Dec 31 11:07:46 2012 -0800
    11.2 +++ b/test/testwm2.c	Mon Dec 31 12:15:25 2012 -0800
    11.3 @@ -80,6 +80,15 @@
    11.4              SDLTest_CommonEvent(state, &event, &done);
    11.5  
    11.6              if (event.type == SDL_WINDOWEVENT) {
    11.7 +                if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
    11.8 +                    SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
    11.9 +                    if (window) {
   11.10 +                        printf("Window %d resized to %dx%d\n",
   11.11 +                            event.window.windowID,
   11.12 +                            event.window.data1,
   11.13 +                            event.window.data2);
   11.14 +                    }
   11.15 +                }
   11.16                  if (event.window.event == SDL_WINDOWEVENT_MOVED) {
   11.17                      SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
   11.18                      if (window) {