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,30 +1934,6 @@
     1.4      }
     1.5  }
     1.6  
     1.7 -void
     1.8 -SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
     1.9 -{
    1.10 -    CHECK_WINDOW_MAGIC(window,);
    1.11 -    if (min_w <= 0) {
    1.12 -        SDL_InvalidParamError("min_w");
    1.13 -        return;
    1.14 -    }
    1.15 -    if (min_h <= 0) {
    1.16 -        SDL_InvalidParamError("min_h");
    1.17 -        return;
    1.18 -    }
    1.19 -
    1.20 -    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    1.21 -        window->min_w = min_w;
    1.22 -        window->min_h = min_h;
    1.23 -        if (_this->SetWindowMinimumSize) {
    1.24 -            _this->SetWindowMinimumSize(_this, window);
    1.25 -        }
    1.26 -        /* Ensure that window is not smaller than minimal size */
    1.27 -        SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h));
    1.28 -    }
    1.29 -}
    1.30 -
    1.31  int
    1.32  SDL_GetWindowBordersSize(SDL_Window * window, int *top, int *left, int *bottom, int *right)
    1.33  {
    1.34 @@ -1981,6 +1957,36 @@
    1.35  }
    1.36  
    1.37  void
    1.38 +SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
    1.39 +{
    1.40 +    CHECK_WINDOW_MAGIC(window,);
    1.41 +    if (min_w <= 0) {
    1.42 +        SDL_InvalidParamError("min_w");
    1.43 +        return;
    1.44 +    }
    1.45 +    if (min_h <= 0) {
    1.46 +        SDL_InvalidParamError("min_h");
    1.47 +        return;
    1.48 +    }
    1.49 +
    1.50 +    if (min_w >= window->max_w || min_h >= window->max_h) {
    1.51 +        SDL_SetError("SDL_SetWindowMinimumSize(): Tried to set minimum size larger than maximum size");
    1.52 +        return;
    1.53 +    }
    1.54 +
    1.55 +    window->min_w = min_w;
    1.56 +    window->min_h = min_h;
    1.57 +
    1.58 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    1.59 +        if (_this->SetWindowMinimumSize) {
    1.60 +            _this->SetWindowMinimumSize(_this, window);
    1.61 +        }
    1.62 +        /* Ensure that window is not smaller than minimal size */
    1.63 +        SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h));
    1.64 +    }
    1.65 +}
    1.66 +
    1.67 +void
    1.68  SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
    1.69  {
    1.70      CHECK_WINDOW_MAGIC(window,);
    1.71 @@ -2005,9 +2011,15 @@
    1.72          return;
    1.73      }
    1.74  
    1.75 +    if (max_w <= window->min_w || max_h <= window->min_h) {
    1.76 +        SDL_SetError("SDL_SetWindowMaximumSize(): Tried to set maximum size smaller than minimum size");
    1.77 +        return;
    1.78 +    }
    1.79 +
    1.80 +    window->max_w = max_w;
    1.81 +    window->max_h = max_h;
    1.82 +
    1.83      if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    1.84 -        window->max_w = max_w;
    1.85 -        window->max_h = max_h;
    1.86          if (_this->SetWindowMaximumSize) {
    1.87              _this->SetWindowMaximumSize(_this, window);
    1.88          }