Added SDL_SetWindowResizable(). (thanks, Ethan!)
authorRyan C. Gordon <icculus@icculus.org>
Thu, 29 Sep 2016 22:52:41 -0400
changeset 10385ad12658bc7ae
parent 10384 bac107c32a37
child 10386 89656c085088
Added SDL_SetWindowResizable(). (thanks, Ethan!)
include/SDL_video.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.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
src/video/haiku/SDL_BWin.h
src/video/haiku/SDL_bvideo.cc
src/video/haiku/SDL_bwindow.cc
src/video/haiku/SDL_bwindow.h
src/video/mir/SDL_mirvideo.c
src/video/windows/SDL_windowsvideo.c
src/video/windows/SDL_windowswindow.c
src/video/windows/SDL_windowswindow.h
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11window.c
src/video/x11/SDL_x11window.h
     1.1 --- a/include/SDL_video.h	Thu Sep 29 16:52:48 2016 -0700
     1.2 +++ b/include/SDL_video.h	Thu Sep 29 22:52:41 2016 -0400
     1.3 @@ -83,6 +83,7 @@
     1.4   *  \sa SDL_SetWindowPosition()
     1.5   *  \sa SDL_SetWindowSize()
     1.6   *  \sa SDL_SetWindowBordered()
     1.7 + *  \sa SDL_SetWindowResizable()
     1.8   *  \sa SDL_SetWindowTitle()
     1.9   *  \sa SDL_ShowWindow()
    1.10   */
    1.11 @@ -707,6 +708,23 @@
    1.12                                                     SDL_bool bordered);
    1.13  
    1.14  /**
    1.15 + *  \brief Set the user-resizable state of a window.
    1.16 + *
    1.17 + *  This will add or remove the window's SDL_WINDOW_RESIZABLE flag and
    1.18 + *  allow/disallow user resizing of the window. This is a no-op if the
    1.19 + *  window's resizable state already matches the requested state.
    1.20 + *
    1.21 + *  \param window The window of which to change the resizable state.
    1.22 + *  \param resizable SDL_TRUE to allow resizing, SDL_FALSE to disallow.
    1.23 + *
    1.24 + *  \note You can't change the resizable state of a fullscreen window.
    1.25 + *
    1.26 + *  \sa SDL_GetWindowFlags()
    1.27 + */
    1.28 +extern DECLSPEC void SDLCALL SDL_SetWindowResizable(SDL_Window * window,
    1.29 +                                                    SDL_bool resizable);
    1.30 +
    1.31 +/**
    1.32   *  \brief Show a window.
    1.33   *
    1.34   *  \sa SDL_HideWindow()
     2.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Thu Sep 29 16:52:48 2016 -0700
     2.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Thu Sep 29 22:52:41 2016 -0400
     2.3 @@ -606,3 +606,4 @@
     2.4  #define SDL_RenderSetIntegerScale SDL_RenderSetIntegerScale_REAL
     2.5  #define SDL_RenderGetIntegerScale SDL_RenderGetIntegerScale_REAL
     2.6  #define SDL_DequeueAudio SDL_DequeueAudio_REAL
     2.7 +#define SDL_SetWindowResizable SDL_SetWindowResizable_REAL
     3.1 --- a/src/dynapi/SDL_dynapi_procs.h	Thu Sep 29 16:52:48 2016 -0700
     3.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Thu Sep 29 22:52:41 2016 -0400
     3.3 @@ -640,3 +640,4 @@
     3.4  SDL_DYNAPI_PROC(int,SDL_RenderSetIntegerScale,(SDL_Renderer *a, SDL_bool b),(a,b),return)
     3.5  SDL_DYNAPI_PROC(SDL_bool,SDL_RenderGetIntegerScale,(SDL_Renderer *a),(a),return)
     3.6  SDL_DYNAPI_PROC(Uint32,SDL_DequeueAudio,(SDL_AudioDeviceID a, void *b, Uint32 c),(a,b,c),return)
     3.7 +SDL_DYNAPI_PROC(void,SDL_SetWindowResizable,(SDL_Window *a, SDL_bool b),(a,b),)
     4.1 --- a/src/video/SDL_sysvideo.h	Thu Sep 29 16:52:48 2016 -0700
     4.2 +++ b/src/video/SDL_sysvideo.h	Thu Sep 29 22:52:41 2016 -0400
     4.3 @@ -219,6 +219,7 @@
     4.4      void (*MinimizeWindow) (_THIS, SDL_Window * window);
     4.5      void (*RestoreWindow) (_THIS, SDL_Window * window);
     4.6      void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
     4.7 +    void (*SetWindowResizable) (_THIS, SDL_Window * window, SDL_bool resizable);
     4.8      void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
     4.9      int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
    4.10      int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
     5.1 --- a/src/video/SDL_video.c	Thu Sep 29 16:52:48 2016 -0700
     5.2 +++ b/src/video/SDL_video.c	Thu Sep 29 22:52:41 2016 -0400
     5.3 @@ -1842,6 +1842,24 @@
     5.4  }
     5.5  
     5.6  void
     5.7 +SDL_SetWindowResizable(SDL_Window * window, SDL_bool resizable)
     5.8 +{
     5.9 +    CHECK_WINDOW_MAGIC(window,);
    5.10 +    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    5.11 +        const int want = (resizable != SDL_FALSE);  /* normalize the flag. */
    5.12 +        const int have = ((window->flags & SDL_WINDOW_RESIZABLE) != 0);
    5.13 +        if ((want != have) && (_this->SetWindowResizable)) {
    5.14 +            if (want) {
    5.15 +                window->flags |= SDL_WINDOW_RESIZABLE;
    5.16 +            } else {
    5.17 +                window->flags &= ~SDL_WINDOW_RESIZABLE;
    5.18 +            }
    5.19 +            _this->SetWindowResizable(_this, window, (SDL_bool) want);
    5.20 +        }
    5.21 +    }
    5.22 +}
    5.23 +
    5.24 +void
    5.25  SDL_SetWindowSize(SDL_Window * window, int w, int h)
    5.26  {
    5.27      CHECK_WINDOW_MAGIC(window,);
     6.1 --- a/src/video/cocoa/SDL_cocoavideo.m	Thu Sep 29 16:52:48 2016 -0700
     6.2 +++ b/src/video/cocoa/SDL_cocoavideo.m	Thu Sep 29 22:52:41 2016 -0400
     6.3 @@ -96,6 +96,7 @@
     6.4      device->MinimizeWindow = Cocoa_MinimizeWindow;
     6.5      device->RestoreWindow = Cocoa_RestoreWindow;
     6.6      device->SetWindowBordered = Cocoa_SetWindowBordered;
     6.7 +    device->SetWindowResizable = Cocoa_SetWindowResizable;
     6.8      device->SetWindowFullscreen = Cocoa_SetWindowFullscreen;
     6.9      device->SetWindowGammaRamp = Cocoa_SetWindowGammaRamp;
    6.10      device->GetWindowGammaRamp = Cocoa_GetWindowGammaRamp;
     7.1 --- a/src/video/cocoa/SDL_cocoawindow.h	Thu Sep 29 16:52:48 2016 -0700
     7.2 +++ b/src/video/cocoa/SDL_cocoawindow.h	Thu Sep 29 22:52:41 2016 -0400
     7.3 @@ -133,6 +133,7 @@
     7.4  extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window);
     7.5  extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window);
     7.6  extern void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
     7.7 +extern void Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
     7.8  extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
     7.9  extern int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
    7.10  extern int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
     8.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Thu Sep 29 16:52:48 2016 -0700
     8.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Thu Sep 29 22:52:41 2016 -0400
     8.3 @@ -1492,6 +1492,20 @@
     8.4      }
     8.5  }}
     8.6  
     8.7 +void
     8.8 +Cocoa_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
     8.9 +{ @autoreleasepool
    8.10 +{
    8.11 +    /* Don't set this if we're in a space!
    8.12 +     * The window will get permanently stuck if resizable is false.
    8.13 +     * -flibit
    8.14 +     */
    8.15 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    8.16 +    Cocoa_WindowListener *listener = data->listener;
    8.17 +    if (![listener isInFullscreenSpace]) {
    8.18 +        SetWindowStyle(window, GetWindowStyle(window));
    8.19 +    }
    8.20 +}}
    8.21  
    8.22  void
    8.23  Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
     9.1 --- a/src/video/haiku/SDL_BWin.h	Thu Sep 29 16:52:48 2016 -0700
     9.2 +++ b/src/video/haiku/SDL_BWin.h	Thu Sep 29 22:52:41 2016 -0400
     9.3 @@ -56,6 +56,7 @@
     9.4      BWIN_RESTORE_WINDOW,
     9.5      BWIN_SET_TITLE,
     9.6      BWIN_SET_BORDERED,
     9.7 +    BWIN_SET_RESIZABLE,
     9.8      BWIN_FULLSCREEN
     9.9  };
    9.10  
    9.11 @@ -378,6 +379,9 @@
    9.12              case BWIN_SET_BORDERED:
    9.13                  _SetBordered(message);
    9.14                  break;
    9.15 +            case BWIN_SET_RESIZABLE:
    9.16 +                _SetResizable(message);
    9.17 +                break;
    9.18              case BWIN_SHOW_WINDOW:
    9.19                  Show();
    9.20                  break;
    9.21 @@ -568,6 +572,18 @@
    9.22          SetLook(bEnabled ? B_BORDERED_WINDOW_LOOK : B_NO_BORDER_WINDOW_LOOK);
    9.23      }
    9.24  
    9.25 +    void _SetResizable(BMessage *msg) {
    9.26 +        bool bEnabled;
    9.27 +        if(msg->FindBool("window-resizable", &bEnabled) != B_OK) {
    9.28 +            return;
    9.29 +        }
    9.30 +        if (bEnabled) {
    9.31 +            SetFlags(GetFlags() & ~(B_NOT_RESIZABLE | B_NOT_ZOOMABLE));
    9.32 +        } else {
    9.33 +            SetFlags(GetFlags() | (B_NOT_RESIZABLE | B_NOT_ZOOMABLE));
    9.34 +        }
    9.35 +    }
    9.36 +
    9.37      void _Restore() {
    9.38          if(IsMinimized()) {
    9.39              Minimize(false);
    10.1 --- a/src/video/haiku/SDL_bvideo.cc	Thu Sep 29 16:52:48 2016 -0700
    10.2 +++ b/src/video/haiku/SDL_bvideo.cc	Thu Sep 29 22:52:41 2016 -0400
    10.3 @@ -81,6 +81,7 @@
    10.4      device->MinimizeWindow = BE_MinimizeWindow;
    10.5      device->RestoreWindow = BE_RestoreWindow;
    10.6      device->SetWindowBordered = BE_SetWindowBordered;
    10.7 +    device->SetWindowResizable = BE_SetWindowResizable;
    10.8      device->SetWindowFullscreen = BE_SetWindowFullscreen;
    10.9      device->SetWindowGammaRamp = BE_SetWindowGammaRamp;
   10.10      device->GetWindowGammaRamp = BE_GetWindowGammaRamp;
    11.1 --- a/src/video/haiku/SDL_bwindow.cc	Thu Sep 29 16:52:48 2016 -0700
    11.2 +++ b/src/video/haiku/SDL_bwindow.cc	Thu Sep 29 22:52:41 2016 -0400
    11.3 @@ -145,6 +145,12 @@
    11.4  	_ToBeWin(window)->PostMessage(&msg);
    11.5  }
    11.6  
    11.7 +void BE_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable) {
    11.8 +	BMessage msg(BWIN_SET_RESIZABLE);
    11.9 +	msg.AddBool("window-resizable", resizable != SDL_FALSE);
   11.10 +	_ToBeWin(window)->PostMessage(&msg);
   11.11 +}
   11.12 +
   11.13  void BE_ShowWindow(_THIS, SDL_Window * window) {
   11.14  	BMessage msg(BWIN_SHOW_WINDOW);
   11.15  	_ToBeWin(window)->PostMessage(&msg);
    12.1 --- a/src/video/haiku/SDL_bwindow.h	Thu Sep 29 16:52:48 2016 -0700
    12.2 +++ b/src/video/haiku/SDL_bwindow.h	Thu Sep 29 22:52:41 2016 -0400
    12.3 @@ -39,6 +39,7 @@
    12.4  extern void BE_MinimizeWindow(_THIS, SDL_Window * window);
    12.5  extern void BE_RestoreWindow(_THIS, SDL_Window * window);
    12.6  extern void BE_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
    12.7 +extern void BE_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
    12.8  extern void BE_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
    12.9  extern int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
   12.10  extern int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
    13.1 --- a/src/video/mir/SDL_mirvideo.c	Thu Sep 29 16:52:48 2016 -0700
    13.2 +++ b/src/video/mir/SDL_mirvideo.c	Thu Sep 29 22:52:41 2016 -0400
    13.3 @@ -186,6 +186,7 @@
    13.4      device->SetWindowIcon        = NULL;
    13.5      device->RaiseWindow          = NULL;
    13.6      device->SetWindowBordered    = NULL;
    13.7 +    device->SetWindowResizable   = NULL;
    13.8      device->OnWindowEnter        = NULL;
    13.9      device->SetWindowPosition    = NULL;
   13.10  
    14.1 --- a/src/video/windows/SDL_windowsvideo.c	Thu Sep 29 16:52:48 2016 -0700
    14.2 +++ b/src/video/windows/SDL_windowsvideo.c	Thu Sep 29 22:52:41 2016 -0400
    14.3 @@ -145,6 +145,7 @@
    14.4      device->MinimizeWindow = WIN_MinimizeWindow;
    14.5      device->RestoreWindow = WIN_RestoreWindow;
    14.6      device->SetWindowBordered = WIN_SetWindowBordered;
    14.7 +    device->SetWindowResizable = WIN_SetWindowResizable;
    14.8      device->SetWindowFullscreen = WIN_SetWindowFullscreen;
    14.9      device->SetWindowGammaRamp = WIN_SetWindowGammaRamp;
   14.10      device->GetWindowGammaRamp = WIN_GetWindowGammaRamp;
    15.1 --- a/src/video/windows/SDL_windowswindow.c	Thu Sep 29 16:52:48 2016 -0700
    15.2 +++ b/src/video/windows/SDL_windowswindow.c	Thu Sep 29 22:52:41 2016 -0400
    15.3 @@ -520,6 +520,22 @@
    15.4  }
    15.5  
    15.6  void
    15.7 +WIN_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
    15.8 +{
    15.9 +    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
   15.10 +    HWND hwnd = data->hwnd;
   15.11 +    DWORD style = GetWindowLong(hwnd, GWL_STYLE);
   15.12 +
   15.13 +    if (resizable) {
   15.14 +        style |= STYLE_RESIZABLE;
   15.15 +    } else {
   15.16 +        style &= ~STYLE_RESIZABLE;
   15.17 +    }
   15.18 +
   15.19 +    SetWindowLong(hwnd, GWL_STYLE, style);
   15.20 +}
   15.21 +
   15.22 +void
   15.23  WIN_RestoreWindow(_THIS, SDL_Window * window)
   15.24  {
   15.25      SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    16.1 --- a/src/video/windows/SDL_windowswindow.h	Thu Sep 29 16:52:48 2016 -0700
    16.2 +++ b/src/video/windows/SDL_windowswindow.h	Thu Sep 29 22:52:41 2016 -0400
    16.3 @@ -64,6 +64,7 @@
    16.4  extern void WIN_MinimizeWindow(_THIS, SDL_Window * window);
    16.5  extern void WIN_RestoreWindow(_THIS, SDL_Window * window);
    16.6  extern void WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
    16.7 +extern void WIN_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
    16.8  extern void WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
    16.9  extern int WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
   16.10  extern int WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
    17.1 --- a/src/video/x11/SDL_x11video.c	Thu Sep 29 16:52:48 2016 -0700
    17.2 +++ b/src/video/x11/SDL_x11video.c	Thu Sep 29 22:52:41 2016 -0400
    17.3 @@ -243,6 +243,7 @@
    17.4      device->MinimizeWindow = X11_MinimizeWindow;
    17.5      device->RestoreWindow = X11_RestoreWindow;
    17.6      device->SetWindowBordered = X11_SetWindowBordered;
    17.7 +    device->SetWindowResizable = X11_SetWindowResizable;
    17.8      device->SetWindowFullscreen = X11_SetWindowFullscreen;
    17.9      device->SetWindowGammaRamp = X11_SetWindowGammaRamp;
   17.10      device->SetWindowGrab = X11_SetWindowGrab;
    18.1 --- a/src/video/x11/SDL_x11window.c	Thu Sep 29 16:52:48 2016 -0700
    18.2 +++ b/src/video/x11/SDL_x11window.c	Thu Sep 29 22:52:41 2016 -0400
    18.3 @@ -982,6 +982,44 @@
    18.4  }
    18.5  
    18.6  void
    18.7 +X11_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable)
    18.8 +{
    18.9 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   18.10 +    Display *display = data->videodata->display;
   18.11 +
   18.12 +    XSizeHints *sizehints = X11_XAllocSizeHints();
   18.13 +    long userhints;
   18.14 +
   18.15 +    X11_XGetWMNormalHints(display, data->xwindow, sizehints, &userhints);
   18.16 +
   18.17 +    if (resizable) {
   18.18 +        /* FIXME: Is there a better way to get max window size from X? -flibit */
   18.19 +        const int maxsize = 0x7FFFFFFF;
   18.20 +        sizehints->min_width = window->min_w;
   18.21 +        sizehints->min_height = window->min_h;
   18.22 +        sizehints->max_width = (window->max_w == 0) ? maxsize : window->max_w;
   18.23 +        sizehints->max_height = (window->max_h == 0) ? maxsize : window->max_h;
   18.24 +    } else {
   18.25 +        sizehints->min_width = window->w;
   18.26 +        sizehints->min_height = window->h;
   18.27 +        sizehints->max_width = window->w;
   18.28 +        sizehints->max_height = window->h;
   18.29 +    }
   18.30 +    sizehints->flags |= PMinSize | PMaxSize;
   18.31 +
   18.32 +    X11_XSetWMNormalHints(display, data->xwindow, sizehints);
   18.33 +
   18.34 +    X11_XFree(sizehints);
   18.35 +
   18.36 +    /* See comment in X11_SetWindowSize. */
   18.37 +    X11_XResizeWindow(display, data->xwindow, window->w, window->h);
   18.38 +    X11_XMoveWindow(display, data->xwindow, window->x - data->border_left, window->y - data->border_top);
   18.39 +    X11_XRaiseWindow(display, data->xwindow);
   18.40 +
   18.41 +    X11_XFlush(display);
   18.42 +}
   18.43 +
   18.44 +void
   18.45  X11_ShowWindow(_THIS, SDL_Window * window)
   18.46  {
   18.47      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    19.1 --- a/src/video/x11/SDL_x11window.h	Thu Sep 29 16:52:48 2016 -0700
    19.2 +++ b/src/video/x11/SDL_x11window.h	Thu Sep 29 22:52:41 2016 -0400
    19.3 @@ -96,6 +96,7 @@
    19.4  extern void X11_MinimizeWindow(_THIS, SDL_Window * window);
    19.5  extern void X11_RestoreWindow(_THIS, SDL_Window * window);
    19.6  extern void X11_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
    19.7 +extern void X11_SetWindowResizable(_THIS, SDL_Window * window, SDL_bool resizable);
    19.8  extern void X11_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
    19.9  extern int X11_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
   19.10  extern void X11_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);