Fixed bug #1117
authorSam Lantinga <slouken@libsdl.org>
Sat, 12 Feb 2011 19:02:14 -0800
changeset 52768e421890cdb8
parent 5275 bad04e4710f6
child 5283 a3bfe8657cde
Fixed bug #1117

There's a new event that's always sent when the window changes size, and that event is what the renderers listen for to determine if they need to rebind their context.
include/SDL_video.h
src/events/SDL_windowevents.c
src/render/opengl/SDL_render_gl.c
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
src/render/software/SDL_render_sw.c
src/video/SDL_video.c
src/video/directfb/SDL_DirectFB_render.c
     1.1 --- a/include/SDL_video.h	Sat Feb 12 17:51:47 2011 -0800
     1.2 +++ b/include/SDL_video.h	Sat Feb 12 19:02:14 2011 -0800
     1.3 @@ -140,7 +140,8 @@
     1.4                                           redrawn */
     1.5      SDL_WINDOWEVENT_MOVED,          /**< Window has been moved to data1, data2 
     1.6                                       */
     1.7 -    SDL_WINDOWEVENT_RESIZED,        /**< Window size changed to data1xdata2 */
     1.8 +    SDL_WINDOWEVENT_RESIZED,        /**< Window has been resized to data1xdata2 */
     1.9 +    SDL_WINDOWEVENT_SIZE_CHANGED,   /**< The window size has changed, either as a result of an API call or through the system or user changing the window size. */
    1.10      SDL_WINDOWEVENT_MINIMIZED,      /**< Window has been minimized */
    1.11      SDL_WINDOWEVENT_MAXIMIZED,      /**< Window has been maximized */
    1.12      SDL_WINDOWEVENT_RESTORED,       /**< Window has been restored to normal size
     2.1 --- a/src/events/SDL_windowevents.c	Sat Feb 12 17:51:47 2011 -0800
     2.2 +++ b/src/events/SDL_windowevents.c	Sat Feb 12 19:02:14 2011 -0800
     2.3 @@ -35,7 +35,8 @@
     2.4      SDL_Event *new_event = (SDL_Event *)userdata;
     2.5  
     2.6      if (event->type == SDL_WINDOWEVENT &&
     2.7 -        event->window.event == SDL_WINDOWEVENT_RESIZED &&
     2.8 +        (event->window.event == SDL_WINDOWEVENT_RESIZED ||
     2.9 +         event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) &&
    2.10          event->window.windowID == new_event->window.windowID) {
    2.11          /* We're about to post a new size event, drop the old one */
    2.12          return 0;
     3.1 --- a/src/render/opengl/SDL_render_gl.c	Sat Feb 12 17:51:47 2011 -0800
     3.2 +++ b/src/render/opengl/SDL_render_gl.c	Sat Feb 12 19:02:14 2011 -0800
     3.3 @@ -348,7 +348,7 @@
     3.4  {
     3.5      GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
     3.6  
     3.7 -    if (event->event == SDL_WINDOWEVENT_RESIZED) {
     3.8 +    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
     3.9          /* Rebind the context to the window area and update matrices */
    3.10          SDL_CurrentContext = NULL;
    3.11          data->updateSize = SDL_TRUE;
     4.1 --- a/src/render/opengles/SDL_render_gles.c	Sat Feb 12 17:51:47 2011 -0800
     4.2 +++ b/src/render/opengles/SDL_render_gles.c	Sat Feb 12 19:02:14 2011 -0800
     4.3 @@ -261,7 +261,7 @@
     4.4  {
     4.5      GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
     4.6  
     4.7 -    if (event->event == SDL_WINDOWEVENT_RESIZED) {
     4.8 +    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
     4.9          /* Rebind the context to the window area and update matrices */
    4.10          SDL_CurrentContext = NULL;
    4.11          data->updateSize = SDL_TRUE;
     5.1 --- a/src/render/opengles2/SDL_render_gles2.c	Sat Feb 12 17:51:47 2011 -0800
     5.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Sat Feb 12 19:02:14 2011 -0800
     5.3 @@ -170,7 +170,7 @@
     5.4  {
     5.5      GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
     5.6  
     5.7 -    if (event->event == SDL_WINDOWEVENT_RESIZED) {
     5.8 +    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
     5.9          /* Rebind the context to the window area */
    5.10          SDL_CurrentContext = NULL;
    5.11          rdata->updateSize = SDL_TRUE;
     6.1 --- a/src/render/software/SDL_render_sw.c	Sat Feb 12 17:51:47 2011 -0800
     6.2 +++ b/src/render/software/SDL_render_sw.c	Sat Feb 12 19:02:14 2011 -0800
     6.3 @@ -173,7 +173,7 @@
     6.4  {
     6.5      SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
     6.6  
     6.7 -    if (event->event == SDL_WINDOWEVENT_RESIZED) {
     6.8 +    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
     6.9          data->updateSize = SDL_TRUE;
    6.10      }
    6.11  }
     7.1 --- a/src/video/SDL_video.c	Sat Feb 12 17:51:47 2011 -0800
     7.2 +++ b/src/video/SDL_video.c	Sat Feb 12 19:02:14 2011 -0800
     7.3 @@ -1431,10 +1431,15 @@
     7.4  
     7.5      /* FIXME: Should this change fullscreen modes? */
     7.6      if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
     7.7 +        window->w = w;
     7.8 +        window->h = h;
     7.9          if (_this->SetWindowSize) {
    7.10              _this->SetWindowSize(_this, window);
    7.11          }
    7.12 -        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
    7.13 +        if (window->w == w && window->h == h) {
    7.14 +            /* We didn't get a SDL_WINDOWEVENT_RESIZED event (by design) */
    7.15 +            SDL_OnWindowResized(window);
    7.16 +        }
    7.17      }
    7.18  }
    7.19  
    7.20 @@ -1706,6 +1711,7 @@
    7.21  SDL_OnWindowResized(SDL_Window * window)
    7.22  {
    7.23      window->surface_valid = SDL_FALSE;
    7.24 +    SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
    7.25  }
    7.26  
    7.27  void
     8.1 --- a/src/video/directfb/SDL_DirectFB_render.c	Sat Feb 12 17:51:47 2011 -0800
     8.2 +++ b/src/video/directfb/SDL_DirectFB_render.c	Sat Feb 12 19:02:14 2011 -0800
     8.3 @@ -279,7 +279,7 @@
     8.4  {
     8.5      SDL_DFB_RENDERERDATA(renderer);
     8.6  
     8.7 -    if (event->event == SDL_WINDOWEVENT_RESIZED) {
     8.8 +    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
     8.9          /* Rebind the context to the window area and update matrices */
    8.10          //SDL_CurrentContext = NULL;
    8.11          //data->updateSize = SDL_TRUE;