SDL2: fix toggling fullscreen. dunno how well this works on non-linux-OS
authorsheepluva
Wed, 20 Jan 2016 00:57:09 +0100
changeset 11523 02a13be714d2
parent 11522 b3ee79e8e3b9
child 11524 aab4767d9a50
SDL2: fix toggling fullscreen. dunno how well this works on non-linux-OS if it works well, then resizing could be made way more responsive too
hedgewars/SDLh.pas
hedgewars/uStore.pas
--- a/hedgewars/SDLh.pas	Sat Jan 16 19:50:38 2016 +0100
+++ b/hedgewars/SDLh.pas	Wed Jan 20 00:57:09 2016 +0100
@@ -1066,7 +1066,9 @@
 function  SDL_CreateRenderer(window: PSDL_Window; index: LongInt; flags: LongWord): PSDL_Renderer; cdecl; external SDLLibName;
 function  SDL_DestroyWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
 function  SDL_DestroyRenderer(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
+procedure SDL_SetWindowPosition(window: PSDL_Window; w, h: LongInt); cdecl; external SDLLibName;
 procedure SDL_SetWindowSize(window: PSDL_Window; w, h: LongInt); cdecl; external SDLLibName;
+procedure SDL_SetWindowFullscreen(window: PSDL_Window; flags: LongWord); cdecl; external SDLLibName;
 function  SDL_GetCurrentVideoDriver:Pchar; cdecl; external SDLLibName;
 
 function  SDL_GL_CreateContext(window: PSDL_Window): PSDL_GLContext; cdecl; external SDLLibName;
--- a/hedgewars/uStore.pas	Sat Jan 16 19:50:38 2016 +0100
+++ b/hedgewars/uStore.pas	Wed Jan 20 00:57:09 2016 +0100
@@ -1066,25 +1066,47 @@
  *)
     SetupOpenGLAttributes();
 {$ENDIF}
+
     // these values in x and y make the window appear in the center
     x:= SDL_WINDOWPOS_CENTERED_MASK;
     y:= SDL_WINDOWPOS_CENTERED_MASK;
-    // SDL_WINDOW_RESIZABLE makes the window resizable and
-    //  respond to rotation events on mobile devices
-    flags:= SDL_WINDOW_OPENGL or SDL_WINDOW_SHOWN or SDL_WINDOW_RESIZABLE;
-
-    {$IFDEF MOBILE}
-    if isPhone() then
-        SDL_SetHint('SDL_IOS_ORIENTATIONS','LandscapeLeft LandscapeRight');
-    // no need for borders on mobile devices
-    flags:= flags or SDL_WINDOW_BORDERLESS;
-    {$ENDIF}
-
-    if cFullScreen then
-        flags:= flags or SDL_WINDOW_FULLSCREEN;
 
     if SDLwindow = nil then
+        begin
+
+        // SDL_WINDOW_RESIZABLE makes the window resizable and
+        //  respond to rotation events on mobile devices
+        flags:= SDL_WINDOW_OPENGL or SDL_WINDOW_SHOWN or SDL_WINDOW_RESIZABLE;
+
+        {$IFDEF MOBILE}
+        if isPhone() then
+            SDL_SetHint('SDL_IOS_ORIENTATIONS','LandscapeLeft LandscapeRight');
+        // no need for borders on mobile devices
+        flags:= flags or SDL_WINDOW_BORDERLESS;
+        {$ENDIF}
+
+        if cFullScreen then
+            flags:= flags or SDL_WINDOW_FULLSCREEN;
+
         SDLwindow:= SDL_CreateWindow(PChar('Hedgewars'), x, y, cScreenWidth, cScreenHeight, flags);
+        end
+    // we're toggling
+    else if Length(s) = 0 then
+        begin
+        if cFullScreen then
+            begin
+            SDL_SetWindowSize(SDLwindow, cScreenWidth, cScreenHeight);
+            SDL_SetWindowFullscreen(SDLwindow, SDL_WINDOW_FULLSCREEN);
+            end
+        else
+            begin
+            SDL_SetWindowFullscreen(SDLwindow, 0);
+            SDL_SetWindowSize(SDLwindow, cScreenWidth, cScreenHeight);
+            SDL_SetWindowPosition(SDLwindow, x, y);
+            end;
+        updateViewLimits();
+        end;
+
     if SDLCheck(SDLwindow <> nil, 'SDL_CreateWindow', true) then exit;
 
     // load engine ico