foxygit / doom Log in
commit a283f1edd26aca2b93854a1a40d15af4eb929d07
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Fri Nov 28 21:00:04 2014 -0500
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Fri Nov 28 21:00:04 2014 -0500

    Fix window resizing.

    Window resizing is also possible under OS X now, as the handle is no
    longer shown on resizable windows.
---
 src/i_video.c | 64 +++++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 43 insertions(+), 21 deletions(-)

diff --git a/src/i_video.c b/src/i_video.c
index 3599c719..5d51308c 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -688,6 +688,32 @@ static void UpdateShiftStatus(SDL_Event *event)
     }
 }

+static void HandleWindowEvent(SDL_WindowEvent *event)
+{
+    switch (event->event)
+    {
+#if 0 // SDL2-TODO
+        case SDL_ACTIVEEVENT:
+            // need to update our focus state
+            UpdateFocus();
+            break;
+#endif
+        case SDL_WINDOWEVENT_EXPOSED:
+            palette_to_set = true;
+            break;
+
+        case SDL_WINDOWEVENT_RESIZED:
+            need_resize = true;
+            resize_w = event->data1;
+            resize_h = event->data2;
+            last_resize_time = SDL_GetTicks();
+            break;
+
+        default:
+            break;
+    }
+}
+
 void I_GetEvent(void)
 {
     SDL_Event sdlevent;
@@ -782,23 +808,12 @@ void I_GetEvent(void)
                 D_PostEvent(&event);
                 break;

-#if 0 // SDL2-TODO
-            case SDL_ACTIVEEVENT:
-                // need to update our focus state
-                UpdateFocus();
-                break;
-
-            case SDL_VIDEOEXPOSE:
-                palette_to_set = true;
-                break;
-
-            case SDL_RESIZABLE:
-                need_resize = true;
-                resize_w = sdlevent.resize.w;
-                resize_h = sdlevent.resize.h;
-                last_resize_time = SDL_GetTicks();
+            case SDL_WINDOWEVENT:
+                if (sdlevent.window.windowID == SDL_GetWindowID(screen))
+                {
+                    HandleWindowEvent(&sdlevent.window);
+                }
                 break;
-#endif

             default:
                 break;
@@ -1760,6 +1775,15 @@ static void SetVideoMode(screen_mode_t *mode, int w, int h)
     if (screenbuffer != NULL)
     {
         SDL_FreeSurface(screenbuffer);
+        screenbuffer = NULL;
+    }
+
+    // Close the current window.
+
+    if (screen != NULL)
+    {
+        SDL_DestroyWindow(screen);
+        screen = NULL;
     }

     // Generate lookup tables before setting the video mode.
@@ -1783,9 +1807,7 @@ static void SetVideoMode(screen_mode_t *mode, int w, int h)
         // running.  This feature is disabled on OS X, as it adds an ugly
         // scroll handle to the corner of the screen.

-#ifndef __MACOSX__
         flags |= SDL_WINDOW_RESIZABLE;
-#endif
     }

     screen = SDL_CreateWindow(
@@ -1799,6 +1821,9 @@ static void SetVideoMode(screen_mode_t *mode, int w, int h)
                 w, h, SDL_GetError());
     }

+    I_InitWindowTitle();
+    I_InitWindowIcon();
+
     // Blank out the full screen area in case there is any junk in
     // the borders that won't otherwise be overwritten.

@@ -1947,9 +1972,6 @@ void I_InitGraphics(void)
         SetVideoMode(screen_mode, w, h);
     }

-    I_InitWindowTitle();
-    I_InitWindowIcon();
-
     // Start with a clear black screen
     // (screen will be flipped after we set the palette)