Remember maximized state of game window
authorWuzzy <Wuzzy2@mail.ru>
Tue, 06 Aug 2019 19:00:51 +0200
changeset 15320 3bf780084c86
parent 15319 976b3ed9b1fd
child 15321 a3823f0916b8
Remember maximized state of game window
ChangeLog.txt
QTfrontend/game.cpp
QTfrontend/gameuiconfig.cpp
QTfrontend/gameuiconfig.h
QTfrontend/hwform.cpp
hedgewars/ArgParsers.pas
hedgewars/hwengine.pas
hedgewars/uVariables.pas
--- a/ChangeLog.txt	Tue Aug 06 11:41:38 2019 +0200
+++ b/ChangeLog.txt	Tue Aug 06 19:00:51 2019 +0200
@@ -156,6 +156,7 @@
  + Visual notification when someone joins the room online
  + Display recommended max. hedgehog count for Perlin maps
  + Various minor style tweaks
+ + Remember maximized state of frontend/game window
  * Fix broken handling of /watch chat command on official server
  * Fix renaming a video leading to loss of thumbnail after restart
  * Fix controls list failing to display correct key names with regards to keyboard layout
--- a/QTfrontend/game.cpp	Tue Aug 06 11:41:38 2019 +0200
+++ b/QTfrontend/game.cpp	Tue Aug 06 19:00:51 2019 +0200
@@ -507,9 +507,20 @@
             // fetch new window resolution via IPC and save it in the settings
             int size = msg.size();
             QString newResolution = QString().append(msg.mid(2)).left(size - 4);
+            bool windowMaximized;
+            if (newResolution.endsWith('M'))
+            {
+                windowMaximized = true;
+                newResolution.chop(1);
+            }
+            else
+            {
+                windowMaximized = false;
+            }
             QStringList wh = newResolution.split('x');
             config->Form->ui.pageOptions->windowWidthEdit->setValue(wh[0].toInt());
             config->Form->ui.pageOptions->windowHeightEdit->setValue(wh[1].toInt());
+            config->vid_SetMaximized(windowMaximized);
             break;
         }
         case '~':
@@ -609,6 +620,8 @@
     arguments << QString::number(resolutions.second.width());
     arguments << "--height";
     arguments << QString::number(resolutions.second.height());
+    if (config->vid_Maximized())
+        arguments << "--maximized";
     if (config->zoom() != 100) {
         arguments << "--zoom";
         arguments << QString::number(config->zoom());
--- a/QTfrontend/gameuiconfig.cpp	Tue Aug 06 11:41:38 2019 +0200
+++ b/QTfrontend/gameuiconfig.cpp	Tue Aug 06 19:00:51 2019 +0200
@@ -93,6 +93,7 @@
     QString heightStr = QString::number(screenSize.height());
     QString wWidth = value("video/windowedWidth", widthStr).toString();
     QString wHeight = value("video/windowedHeight", heightStr).toString();
+    pIsEngineWindowMaximized = value("video/windowedMaximized", false).toBool();
     // If left blank reset the resolution to the default
     wWidth = (wWidth == "" ? widthStr : wWidth);
     wHeight = (wHeight == "" ? heightStr : wHeight);
@@ -247,6 +248,7 @@
     setValue("video/fullscreenResolution", Form->ui.pageOptions->CBResolution->currentText());
     setValue("video/windowedWidth", Form->ui.pageOptions->windowWidthEdit->value());
     setValue("video/windowedHeight", Form->ui.pageOptions->windowHeightEdit->value());
+    setValue("video/windowedMaximized", vid_Maximized());
     setValue("video/fullscreen", vid_Fullscreen());
 
     setValue("video/quality", Form->ui.pageOptions->SLQuality->value());
@@ -384,6 +386,16 @@
         return result.second;
 }
 
+bool GameUIConfig::vid_Maximized()
+{
+    return pIsEngineWindowMaximized;
+}
+
+void GameUIConfig::vid_SetMaximized(bool isMaximized)
+{
+    pIsEngineWindowMaximized = isMaximized;
+}
+
 bool GameUIConfig::vid_Fullscreen()
 {
     return Form->ui.pageOptions->CBFullscreen->isChecked();
--- a/QTfrontend/gameuiconfig.h	Tue Aug 06 11:41:38 2019 +0200
+++ b/QTfrontend/gameuiconfig.h	Tue Aug 06 19:00:51 2019 +0200
@@ -40,6 +40,8 @@
         QStringList GetTeamsList();
         QRect vid_Resolution();
         std::pair<QRect, QRect> vid_ResolutionPair();
+        bool vid_Maximized();
+        void vid_SetMaximized(bool isMaximized);
         bool vid_Fullscreen();
         quint32 translateQuality();
         bool isSoundEnabled();
@@ -107,6 +109,7 @@
         QList<BindAction> m_binds;
 
         void applyProxySettings();
+        bool pIsEngineWindowMaximized;
 
         QString cachedRandomNick;
 };
--- a/QTfrontend/hwform.cpp	Tue Aug 06 11:41:38 2019 +0200
+++ b/QTfrontend/hwform.cpp	Tue Aug 06 19:00:51 2019 +0200
@@ -2321,6 +2321,7 @@
                    + " --fullscreen-height " + QString::number(resolutions.first.height())
                    + " --width " + QString::number(resolutions.second.width())
                    + " --height " + QString::number(resolutions.second.height())
+                   + (config->vid_Maximized() ? " --maximized" : "")
                    + (config->zoom() == 100 ? "" : " --zoom " + QString::number(config->zoom()))
                    + " --volume " + QString::number(config->volume())
                    + (config->isMusicEnabled() ? "" : " --nomusic")
--- a/hedgewars/ArgParsers.pas	Tue Aug 06 11:41:38 2019 +0200
+++ b/hedgewars/ArgParsers.pas	Tue Aug 06 19:00:51 2019 +0200
@@ -87,6 +87,7 @@
     WriteLn(stdout, 'Graphics:');
     WriteLn(stdout, '  --width <width in pixels>: Set game window width');
     WriteLn(stdout, '  --height <height in pixels>: Set game window height');
+    WriteLn(stdout, '  --maximized: Start in maximized window');
     WriteLn(stdout, '  --fullscreen: Start in fullscreen');
     WriteLn(stdout, '  --fullscreen-width <width in pixels>: Set fullscreen width');
     WriteLn(stdout, '  --fullscreen-height <height in pixels>: Set fullscreen height');
@@ -252,14 +253,14 @@
 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
 
 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
-const videoarray: array [0..4] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth');
+const videoarray: array [0..5] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--maximized', '--depth');
       audioarray: array [0..2] of string = ('--volume','--nomusic','--nosound');
       otherarray: array [0..2] of string = ('--locale','--fullscreen','--showfps');
-      mediaarray: array [0..9] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
-      allarray: array [0..18] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--depth','--volume','--nomusic','--nosound','--nodampen','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags');
-      reallyAll: array[0..39] of shortstring = (
+      mediaarray: array [0..10] of string = ('--fullscreen-width', '--fullscreen-height', '--width', '--height', '--maximized', '--depth', '--volume','--nomusic','--nosound','--locale','--fullscreen');
+      allarray: array [0..19] of string = ('--fullscreen-width','--fullscreen-height', '--width', '--height', '--maximized', '--depth', '--volume','--nomusic','--nosound','--nodampen','--locale','--fullscreen','--showfps','--altdmg','--frame-interval','--low-quality','--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags');
+      reallyAll: array[0..40] of shortstring = (
                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
-                '--height', '--frame-interval', '--volume','--nomusic', '--nosound', '--nodampen',
+                '--height', '--maximized', '--frame-interval', '--volume','--nomusic', '--nosound', '--nodampen',
                 '--fullscreen', '--showfps', '--altdmg', '--low-quality', '--raw-quality', '--stereo', '--nick',
                 '--zoom',
   {deprecated}  '--depth', '--set-video', '--set-audio', '--set-other', '--set-multimedia', '--set-everything',
@@ -282,42 +283,43 @@
         {--fullscreen-height}    4 : cFullscreenHeight := max(getLongIntParameter(arg, paramIndex, parseParameter), cMinScreenHeight);
         {--width}                5 : cWindowedWidth    := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenWidth);
         {--height}               6 : cWindowedHeight   := max(2 * (getLongIntParameter(arg, paramIndex, parseParameter) div 2), cMinScreenHeight);
-        {--frame-interval}       7 : cTimerInterval    := getLongIntParameter(arg, paramIndex, parseParameter);
-        {--volume}               8 : SetVolume          ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
-        {--nomusic}              9 : SetMusic           ( false );
-        {--nosound}             10 : SetSound           ( false );
-        {--nodampen}            11 : SetAudioDampen     ( false );
-        {--fullscreen}          12 : cFullScreen       := true;
-        {--showfps}             13 : cShowFPS          := true;
-        {--altdmg}              14 : cAltDamage        := true;
-        {--low-quality}         15 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
-        {--raw-quality}         16 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
-        {--stereo}              17 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
-        {--nick}                18 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
-        {--zoom}                19 : setZoom(arg, paramIndex, parseParameter);
+        {--maximized}            7 : cWindowedMaximized:= true;
+        {--frame-interval}       8 : cTimerInterval    := getLongIntParameter(arg, paramIndex, parseParameter);
+        {--volume}               9 : SetVolume          ( max(getLongIntParameter(arg, paramIndex, parseParameter), 0) );
+        {--nomusic}             10 : SetMusic           ( false );
+        {--nosound}             11 : SetSound           ( false );
+        {--nodampen}            12 : SetAudioDampen     ( false );
+        {--fullscreen}          13 : cFullScreen       := true;
+        {--showfps}             14 : cShowFPS          := true;
+        {--altdmg}              15 : cAltDamage        := true;
+        {--low-quality}         16 : cReducedQuality   := $FFFFFFFF xor rqLowRes;
+        {--raw-quality}         17 : cReducedQuality   := getLongIntParameter(arg, paramIndex, parseParameter);
+        {--stereo}              18 : setStereoMode      ( getLongIntParameter(arg, paramIndex, parseParameter) );
+        {--nick}                19 : UserNick          := parseNick( getstringParameter(arg, paramIndex, parseParameter) );
+        {--zoom}                20 : setZoom(arg, paramIndex, parseParameter);
         {deprecated options}
-        {--depth}               20 : setDepth(paramIndex);
-        {--set-video}           21 : parseClassicParameter(videoarray,5,paramIndex);
-        {--set-audio}           22 : parseClassicParameter(audioarray,3,paramIndex);
-        {--set-other}           23 : parseClassicParameter(otherarray,3,paramIndex);
-        {--set-multimedia}      24 : parseClassicParameter(mediaarray,10,paramIndex);
-        {--set-everything}      25 : parseClassicParameter(allarray,14,paramIndex);
+        {--depth}               21 : setDepth(paramIndex);
+        {--set-video}           22 : parseClassicParameter(videoarray,5,paramIndex);
+        {--set-audio}           23 : parseClassicParameter(audioarray,3,paramIndex);
+        {--set-other}           24 : parseClassicParameter(otherarray,3,paramIndex);
+        {--set-multimedia}      25 : parseClassicParameter(mediaarray,10,paramIndex);
+        {--set-everything}      26 : parseClassicParameter(allarray,14,paramIndex);
         {"internal" options}
-        {--internal}            26 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
-        {--port}                27 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
-        {--recorder}            28 : startVideoRecording(paramIndex);
-        {--landpreview}         29 : GameType := gmtLandPreview;
+        {--internal}            27 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
+        {--port}                28 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
+        {--recorder}            29 : startVideoRecording(paramIndex);
+        {--landpreview}         30 : GameType := gmtLandPreview;
         {anything else}
-        {--stats-only}          30 : statsOnlyGame();
-        {--gci}                 31 : GciEasterEgg();
-        {--help}                32 : DisplayUsage();
-        {--protocol}            33 : DisplayProtocol();
-        {--no-teamtag}          34 : cTagsMask := cTagsMask and (not htTeamName);
-        {--no-hogtag}           35 : cTagsMask := cTagsMask and (not htName);
-        {--no-healthtag}        36 : cTagsMask := cTagsMask and (not htHealth);
-        {--translucent-tags}    37 : cTagsMask := cTagsMask or htTransparent;
-        {--lua-test}            38 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
-        {--no-holiday-silliness} 39 : cHolidaySilliness:= false;
+        {--stats-only}          31 : statsOnlyGame();
+        {--gci}                 32 : GciEasterEgg();
+        {--help}                33 : DisplayUsage();
+        {--protocol}            34 : DisplayProtocol();
+        {--no-teamtag}          35 : cTagsMask := cTagsMask and (not htTeamName);
+        {--no-hogtag}           36 : cTagsMask := cTagsMask and (not htName);
+        {--no-healthtag}        37 : cTagsMask := cTagsMask and (not htHealth);
+        {--translucent-tags}    38 : cTagsMask := cTagsMask or htTransparent;
+        {--lua-test}            39 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
+        {--no-holiday-silliness} 40 : cHolidaySilliness:= false;
     else
         begin
         //Assume the first "non parameter" is the demo file, anything else is invalid
@@ -353,7 +355,7 @@
         isValid:= (cmd<>'--depth');
 
         // check if the parameter is a boolean one
-        isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--nodampen') or (cmd = '--fullscreen') or (cmd = '--showfps') or (cmd = '--altdmg') or (cmd = '--no-teamtag') or (cmd = '--no-hogtag') or (cmd = '--no-healthtag') or (cmd = '--translucent-tags');
+        isBool:= (cmd = '--nomusic') or (cmd = '--nosound') or (cmd = '--nodampen') or (cmd = '--maximized') or (cmd = '--fullscreen') or (cmd = '--showfps') or (cmd = '--altdmg') or (cmd = '--no-teamtag') or (cmd = '--no-hogtag') or (cmd = '--no-healthtag') or (cmd = '--translucent-tags');
         if isBool and (arg='0') then
             isValid:= false;
         if (cmd='--nomusic') or (cmd='--nosound') or (cmd='--nodampen') then
--- a/hedgewars/hwengine.pas	Tue Aug 06 11:41:38 2019 +0200
+++ b/hedgewars/hwengine.pas	Tue Aug 06 19:00:51 2019 +0200
@@ -230,11 +230,14 @@
                                 begin
                                 if GameState = gsSuspend then
                                     GameState:= previousGameState;
+                                cWindowedMaximized:= false;
 {$IFDEF ANDROID}
                                 //This call is used to reinitialize the glcontext and reload the textures
                                 ParseCommand('fullscr '+intToStr(LongInt(cFullScreen)), true);
 {$ENDIF}
                                 end;
+                        SDL_WINDOWEVENT_MAXIMIZED:
+                                cWindowedMaximized:= true;
                         SDL_WINDOWEVENT_RESIZED:
                                 begin
                                 cNewScreenWidth:= max(2 * (event.window.data1 div 2), cMinScreenWidth);
@@ -302,12 +305,18 @@
             cScreenHeight:= cWindowedHeight;
 
             ParseCommand('fullscr '+intToStr(LongInt(cFullScreen)), true);
-            WriteLnToConsole('window resize: ' + IntToStr(cScreenWidth) + ' x ' + IntToStr(cScreenHeight));
+            if cWindowedMaximized then
+                WriteLnToConsole('window resize: ' + IntToStr(cScreenWidth) + ' x ' + IntToStr(cScreenHeight) + ' (maximized)')
+            else
+                WriteLnToConsole('window resize: ' + IntToStr(cScreenWidth) + ' x ' + IntToStr(cScreenHeight));
             ScriptOnScreenResize();
             InitCameraBorders();
             InitTouchInterface();
             InitZoom(zoomValue);
-            SendIPC('W' + IntToStr(cScreenWidth) + 'x' + IntToStr(cScreenHeight));
+            if cWindowedMaximized then
+                SendIPC('W' + IntToStr(cScreenWidth) + 'x' + IntToStr(cScreenHeight) + 'M')
+            else
+                SendIPC('W' + IntToStr(cScreenWidth) + 'x' + IntToStr(cScreenHeight));
         end;
 
         CurrTime:= SDL_GetTicks();
--- a/hedgewars/uVariables.pas	Tue Aug 06 11:41:38 2019 +0200
+++ b/hedgewars/uVariables.pas	Tue Aug 06 19:00:51 2019 +0200
@@ -33,6 +33,7 @@
     cFullscreenHeight  : LongInt;
     cWindowedWidth     : LongInt;
     cWindowedHeight    : LongInt;
+    cWindowedMaximized : boolean;
     cScreenWidth       : LongInt;
     cScreenHeight      : LongInt;
     cNewScreenWidth    : LongInt;
@@ -2664,6 +2665,7 @@
     cFullscreenHeight := 0;
     cWindowedWidth    := 1024;
     cWindowedHeight   := 768;
+    cWindowedMaximized:= false;
     cScreenWidth      := cWindowedWidth;
     cScreenHeight     := cWindowedHeight;