Return an error if trying to set a window minimum size larger than the maximum size, or vice versa
authorSam Lantinga <slouken@libsdl.org>
Fri, 27 Jan 2017 21:16:38 -0800
changeset 108607f08396c7581
parent 10859 d933657c72d3
child 10861 71d8f9afb690
Return an error if trying to set a window minimum size larger than the maximum size, or vice versa
src/video/SDL_video.c
     1.1 --- a/src/video/SDL_video.c	Fri Jan 27 18:06:50 2017 -0800
     1.2 +++ b/src/video/SDL_video.c	Fri Jan 27 21:16:38 2017 -0800
     1.3 @@ -1934,6 +1934,28 @@
     1.4      }
     1.5  }
     1.6  
     1.7 +int
     1.8 +SDL_GetWindowBordersSize(SDL_Window * window, int *top, int *left, int *bottom, int *right)
     1.9 +{
    1.10 +    int dummy = 0;
    1.11 +
    1.12 +    if (!top) { top = &dummy; }
    1.13 +    if (!left) { left = &dummy; }
    1.14 +    if (!right) { right = &dummy; }
    1.15 +    if (!bottom) { bottom = &dummy; }
    1.16 +
    1.17 +    /* Always initialize, so applications don't have to care */
    1.18 +    *top = *left = *bottom = *right = 0;
    1.19 +
    1.20 +    CHECK_WINDOW_MAGIC(window, -1);
    1.21 +
    1.22 +    if (!_this->GetWindowBordersSize) {
    1.23 +        return SDL_Unsupported();
    1.24 +    }
    1.25 +
    1.26 +    return _this->GetWindowBordersSize(_this, window, top, left, bottom, right);
    1.27 +}
    1.28 +
    1.29  void
    1.30  SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
    1.31  {
    1.32 @@ -1947,9 +1969,15 @@
    1.33          return;
    1.34      }
    1.35  
    1.36 +    if (min_w >= window->max_w || min_h >= window->max_h) {
    1.37 +        SDL_SetError("SDL_SetWindowMinimumSize(): Tried to set minimum size larger than maximum size");
    1.38 +        return;
    1.39 +    }
    1.40 +
    1.41 +    window->min_w = min_w;
    1.42 +    window->min_h = min_h;
    1.43 +
    1.44      if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    1.45 -        window->min_w = min_w;
    1.46 -        window->min_h = min_h;
    1.47          if (_this->SetWindowMinimumSize) {
    1.48              _this->SetWindowMinimumSize(_this, window);
    1.49          }
    1.50 @@ -1958,28 +1986,6 @@
    1.51      }
    1.52  }
    1.53  
    1.54 -int
    1.55 -SDL_GetWindowBordersSize(SDL_Window * window, int *top, int *left, int *bottom, int *right)
    1.56 -{
    1.57 -    int dummy = 0;
    1.58 -
    1.59 -    if (!top) { top = &dummy; }
    1.60 -    if (!left) { left = &dummy; }
    1.61 -    if (!right) { right = &dummy; }
    1.62 -    if (!bottom) { bottom = &dummy; }
    1.63 -
    1.64 -    /* Always initialize, so applications don't have to care */
    1.65 -    *top = *left = *bottom = *right = 0;
    1.66 -
    1.67 -    CHECK_WINDOW_MAGIC(window, -1);
    1.68 -
    1.69 -    if (!_this->GetWindowBordersSize) {
    1.70 -        return SDL_Unsupported();
    1.71 -    }
    1.72 -
    1.73 -    return _this->GetWindowBordersSize(_this, window, top, left, bottom, right);
    1.74 -}
    1.75 -
    1.76  void
    1.77  SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
    1.78  {
    1.79 @@ -2005,9 +2011,15 @@
    1.80          return;
    1.81      }
    1.82  
    1.83 +    if (max_w <= window->min_w || max_h <= window->min_h) {
    1.84 +        SDL_SetError("SDL_SetWindowMaximumSize(): Tried to set maximum size smaller than minimum size");
    1.85 +        return;
    1.86 +    }
    1.87 +
    1.88 +    window->max_w = max_w;
    1.89 +    window->max_h = max_h;
    1.90 +
    1.91      if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    1.92 -        window->max_w = max_w;
    1.93 -        window->max_h = max_h;
    1.94          if (_this->SetWindowMaximumSize) {
    1.95              _this->SetWindowMaximumSize(_this, window);
    1.96          }