src/render/SDL_render.c
changeset 6260 fd494c5f305b
parent 6258 fce7ce72677b
child 6320 6077a1310907
--- a/src/render/SDL_render.c	Sun Jan 22 19:47:33 2012 -0500
+++ b/src/render/SDL_render.c	Sun Jan 22 21:46:06 2012 -0500
@@ -100,7 +100,7 @@
                 renderer->WindowEvent(renderer, &event->window);
             }
 
-            if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
+            if (event->window.event == SDL_WINDOWEVENT_RESIZED) {
                 /* Try to keep the previous viewport centered */
                 int w, h;
                 SDL_Rect viewport;
@@ -116,10 +116,40 @@
                     viewport.h = renderer->viewport.h;
                     SDL_RenderSetViewport(renderer, &viewport);
                 }
+                renderer->resized = SDL_TRUE;
+            } else if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
+                int w, h;
+                SDL_Rect viewport;
+
+                if (!renderer->resized) {
+                    /* Window was programmatically resized, reset viewport */
+                    SDL_GetWindowSize(window, &w, &h);
+                    if (renderer->target) {
+                        renderer->viewport_backup.x = 0;
+                        renderer->viewport_backup.y = 0;
+                        renderer->viewport_backup.w = w;
+                        renderer->viewport_backup.h = h;
+                    } else {
+                        viewport.x = 0;
+                        viewport.y = 0;
+                        viewport.w = w;
+                        viewport.h = h;
+                        SDL_RenderSetViewport(renderer, &viewport);
+                    }
+                    renderer->resized = SDL_FALSE;
+                }
+            } else if (event->window.event == SDL_WINDOWEVENT_HIDDEN) {
+                renderer->hidden = SDL_TRUE;
+            } else if (event->window.event == SDL_WINDOWEVENT_SHOWN) {
+                if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)) {
+                    renderer->hidden = SDL_FALSE;
+                }
             } else if (event->window.event == SDL_WINDOWEVENT_MINIMIZED) {
-                renderer->minimized = SDL_TRUE;
+                renderer->hidden = SDL_TRUE;
             } else if (event->window.event == SDL_WINDOWEVENT_RESTORED) {
-                renderer->minimized = SDL_FALSE;
+                if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_HIDDEN)) {
+                    renderer->hidden = SDL_FALSE;
+                }
             }
         }
     }
@@ -218,10 +248,10 @@
         renderer->magic = &renderer_magic;
         renderer->window = window;
 
-        if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) {
-            renderer->minimized = SDL_TRUE;
+        if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED)) {
+            renderer->hidden = SDL_TRUE;
         } else {
-            renderer->minimized = SDL_FALSE;
+            renderer->hidden = SDL_FALSE;
         }
 
         SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
@@ -974,8 +1004,8 @@
 {
     CHECK_RENDERER_MAGIC(renderer, -1);
 
-    /* Don't draw while we're minimized */
-    if (renderer->minimized) {
+    /* Don't draw while we're hidden */
+    if (renderer->hidden) {
         return 0;
     }
     return renderer->RenderClear(renderer);
@@ -1004,8 +1034,8 @@
     if (count < 1) {
         return 0;
     }
-    /* Don't draw while we're minimized */
-    if (renderer->minimized) {
+    /* Don't draw while we're hidden */
+    if (renderer->hidden) {
         return 0;
     }
     return renderer->RenderDrawPoints(renderer, points, count);
@@ -1036,8 +1066,8 @@
     if (count < 2) {
         return 0;
     }
-    /* Don't draw while we're minimized */
-    if (renderer->minimized) {
+    /* Don't draw while we're hidden */
+    if (renderer->hidden) {
         return 0;
     }
     return renderer->RenderDrawLines(renderer, points, count);
@@ -1089,8 +1119,8 @@
         return 0;
     }
 
-    /* Don't draw while we're minimized */
-    if (renderer->minimized) {
+    /* Don't draw while we're hidden */
+    if (renderer->hidden) {
         return 0;
     }
     for (i = 0; i < count; ++i) {
@@ -1132,8 +1162,8 @@
     if (count < 1) {
         return 0;
     }
-    /* Don't draw while we're minimized */
-    if (renderer->minimized) {
+    /* Don't draw while we're hidden */
+    if (renderer->hidden) {
         return 0;
     }
     return renderer->RenderFillRects(renderer, rects, count);
@@ -1193,8 +1223,8 @@
         texture = texture->native;
     }
 
-    /* Don't draw while we're minimized */
-    if (renderer->minimized) {
+    /* Don't draw while we're hidden */
+    if (renderer->hidden) {
         return 0;
     }
     return renderer->RenderCopy(renderer, texture, &real_srcrect,
@@ -1246,8 +1276,8 @@
 {
     CHECK_RENDERER_MAGIC(renderer, );
 
-    /* Don't draw while we're minimized */
-    if (renderer->minimized) {
+    /* Don't draw while we're hidden */
+    if (renderer->hidden) {
         return;
     }
     renderer->RenderPresent(renderer);