Add setting to set default/initial zoom
authorWuzzy <Wuzzy2@mail.ru>
Tue, 05 Feb 2019 02:13:04 +0100
changeset 14677 93429d8f6b3f
parent 14676 9377ee00f1f1
child 14678 c96889bf5796
Add setting to set default/initial zoom
ChangeLog.txt
QTfrontend/game.cpp
QTfrontend/gameuiconfig.cpp
QTfrontend/gameuiconfig.h
QTfrontend/hwform.cpp
QTfrontend/ui/page/pageoptions.cpp
QTfrontend/ui/page/pageoptions.h
hedgewars/ArgParsers.pas
hedgewars/uCommandHandlers.pas
hedgewars/uConsts.pas
hedgewars/uVariables.pas
--- a/ChangeLog.txt	Tue Feb 05 01:40:16 2019 +0300
+++ b/ChangeLog.txt	Tue Feb 05 02:13:04 2019 +0100
@@ -51,6 +51,7 @@
 Graphics:
  + Show contour of flying saucer when in highly opaque water
  + Remove visual clutter in cut scenes
+ + Add setting to set default/initial zoom
  * Fix speech bubbles overlapping in the wrong order
  * Fix wrong ice beam angle if it goes diagonally up out of map through world wrap
  * Fix double water splash when flying saucer drowns
--- a/QTfrontend/game.cpp	Tue Feb 05 01:40:16 2019 +0300
+++ b/QTfrontend/game.cpp	Tue Feb 05 02:13:04 2019 +0100
@@ -438,6 +438,10 @@
     arguments << QString::number(resolutions.second.width());
     arguments << "--height";
     arguments << QString::number(resolutions.second.height());
+    if (config->zoom() != 100) {
+        arguments << "--zoom";
+        arguments << QString::number(config->zoom());
+    }
     arguments << "--raw-quality";
     arguments << QString::number(config->translateQuality());
     arguments << "--stereo";
--- a/QTfrontend/gameuiconfig.cpp	Tue Feb 05 01:40:16 2019 +0300
+++ b/QTfrontend/gameuiconfig.cpp	Tue Feb 05 02:13:04 2019 +0100
@@ -105,6 +105,7 @@
     Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr);
 
     Form->ui.pageOptions->SLQuality->setValue(value("video/quality", 5).toUInt());
+    Form->ui.pageOptions->SLZoom->setValue(value("video/zoom", 100).toUInt());
     Form->ui.pageOptions->CBStereoMode->setCurrentIndex(value("video/stereo", 0).toUInt());
     Form->ui.pageOptions->CBFrontendEffects->setChecked(value("frontend/effects", true).toBool());
     Form->ui.pageOptions->CBSound->setChecked(value("audio/sound", true).toBool());
@@ -245,6 +246,7 @@
     setValue("video/fullscreen", vid_Fullscreen());
 
     setValue("video/quality", Form->ui.pageOptions->SLQuality->value());
+    setValue("video/zoom", Form->ui.pageOptions->SLZoom->value());
     setValue("video/stereo", stereoMode());
 
     setValue("frontend/effects", isFrontendEffects());
@@ -441,6 +443,11 @@
     return Form->ui.pageOptions->CBFrontendFullscreen->isChecked();
 }
 
+quint16 GameUIConfig::zoom()
+{
+    return Form->ui.pageOptions->SLZoom->value();
+}
+
 bool GameUIConfig::isHolidaySillinessEnabled() const
 {
     return value("misc/holidaySilliness", true).toBool();
--- a/QTfrontend/gameuiconfig.h	Tue Feb 05 01:40:16 2019 +0300
+++ b/QTfrontend/gameuiconfig.h	Tue Feb 05 02:13:04 2019 +0100
@@ -66,6 +66,7 @@
         bool isReducedQuality() const;
         bool isFrontendEffects() const;
         bool isFrontendFullscreen() const;
+        quint16 zoom();
         bool isHolidaySillinessEnabled() const;
         void resizeToConfigValues();
         quint32 stereoMode() const;
--- a/QTfrontend/hwform.cpp	Tue Feb 05 01:40:16 2019 +0300
+++ b/QTfrontend/hwform.cpp	Tue Feb 05 02:13:04 2019 +0100
@@ -2253,6 +2253,7 @@
                    + " --fullscreen-height " + QString::number(resolutions.first.height())
                    + " --width " + QString::number(resolutions.second.width())
                    + " --height " + QString::number(resolutions.second.height())
+                   + (config->zoom() == 100 ? "" : " --zoom " + QString::number(config->zoom()))
                    + " --volume " + QString::number(config->volume())
                    + (config->isMusicEnabled() ? "" : " --nomusic")
                    + (config->isSoundEnabled() ? "" : " --nosound")
--- a/QTfrontend/ui/page/pageoptions.cpp	Tue Feb 05 01:40:16 2019 +0300
+++ b/QTfrontend/ui/page/pageoptions.cpp	Tue Feb 05 02:13:04 2019 +0100
@@ -321,11 +321,23 @@
             SLQuality->setFixedWidth(150);
             groupGame->layout()->addWidget(SLQuality, 3, 1, Qt::AlignLeft);
 
+            // Zoom
+            QLabel * lblZoom = new QLabel(groupGame);
+            lblZoom->setText(QLabel::tr("Zoom (%)"));
+            lblZoom->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+            groupGame->layout()->addWidget(lblZoom, 4, 0);
+
+            SLZoom = new QSpinBox(groupGame);
+            SLZoom->setSingleStep(5);
+            SLZoom->setMaximum(150);
+            SLZoom->setMinimum(50);
+            groupGame->layout()->addWidget(SLZoom, 4, 1, Qt::AlignLeft);
+
             // Stereo spacing
 
             QLabel * lblStereo = new QLabel(groupGame);
             lblStereo->setText(QLabel::tr("Stereoscopy"));
-            groupGame->layout()->addWidget(lblStereo, 4, 0);
+            groupGame->layout()->addWidget(lblStereo, 5, 0);
 
             CBStereoMode = new QComboBox(groupGame);
             CBStereoMode->setWhatsThis(QComboBox::tr("Stereoscopy creates an illusion of depth when you wear 3D glasses."));
@@ -346,16 +358,16 @@
             CBStereoMode->addItem(QComboBox::tr("Side-by-side"));
             CBStereoMode->addItem(QComboBox::tr("Top-Bottom"));
             CBStereoMode->setFixedWidth(CBResolution->width());
-            groupGame->layout()->addWidget(CBStereoMode, 4, 1);
+            groupGame->layout()->addWidget(CBStereoMode, 5, 1);
 
             // Divider
 
-            groupGame->addDivider(); // row 5
+            groupGame->addDivider(); // row 6
 
             // FPS limit
 
             QHBoxLayout * fpsLayout = new QHBoxLayout();
-            groupGame->layout()->addLayout(fpsLayout, 6, 0, 1, 2);
+            groupGame->layout()->addLayout(fpsLayout, 7, 0, 1, 2);
             QLabel * maxfps = new QLabel(groupGame);
             maxfps->setText(QLabel::tr("FPS limit"));
             fpsLayout->addWidget(maxfps);
@@ -372,30 +384,30 @@
 
             // Divider
 
-            groupGame->addDivider(); // row 7
+            groupGame->addDivider(); // row 8
 
             // Alternative damage show
 
             CBAltDamage = new QCheckBox(groupGame);
             CBAltDamage->setText(QCheckBox::tr("Alternative damage show"));
-            groupGame->layout()->addWidget(CBAltDamage, 8, 0, 1, 2);
+            groupGame->layout()->addWidget(CBAltDamage, 9, 0, 1, 2);
 
             // Show ammo menu tooltips
 
             WeaponTooltip = new QCheckBox(groupGame);
             WeaponTooltip->setText(QCheckBox::tr("Show ammo menu tooltips"));
-            groupGame->layout()->addWidget(WeaponTooltip, 9, 0, 1, 2);
+            groupGame->layout()->addWidget(WeaponTooltip, 10, 0, 1, 2);
 
             groupGame->addDivider();
 
             lblTags = new QLabel(groupGame);
             lblTags->setText(QLabel::tr("Displayed tags above hogs and translucent tags"));
-            groupGame->layout()->addWidget(lblTags, 11, 0, 1, 2);
+            groupGame->layout()->addWidget(lblTags, 12, 0, 1, 2);
 
             tagsContainer = new QWidget();
             QHBoxLayout * tagsLayout = new QHBoxLayout(tagsContainer);
             tagsLayout->setSpacing(0);
-            groupGame->layout()->addWidget(tagsContainer, 12, 0, 1, 2);
+            groupGame->layout()->addWidget(tagsContainer, 13, 0, 1, 2);
 
             CBTeamTag = new QCheckBox(groupGame);
             CBTeamTag->setText(QCheckBox::tr("Team"));
--- a/QTfrontend/ui/page/pageoptions.h	Tue Feb 05 01:40:16 2019 +0300
+++ b/QTfrontend/ui/page/pageoptions.h	Tue Feb 05 02:13:04 2019 +0100
@@ -110,6 +110,7 @@
         QLineEdit *editNetNick;
         QLineEdit *editNetPassword;
         QSlider *SLQuality;
+        QSpinBox *SLZoom;
         QCheckBox *CBFrontendEffects;
         QComboBox * cbProxyType;
         QSpinBox * sbProxyPort;
--- a/hedgewars/ArgParsers.pas	Tue Feb 05 01:40:16 2019 +0300
+++ b/hedgewars/ArgParsers.pas	Tue Feb 05 02:13:04 2019 +0100
@@ -91,6 +91,7 @@
     WriteLn(stdout, '  --fullscreen-width <width in pixels>: Set fullscreen width');
     WriteLn(stdout, '  --fullscreen-height <height in pixels>: Set fullscreen height');
     WriteLn(stdout, '  --low-quality: Lowers the game quality');
+    WriteLn(stdout, '  --zoom <percent>: Start with custom zoom level');
     WriteLn(stdout, '');
     WriteLn(stdout, 'Audio:');
     WriteLn(stdout, '  --volume <sound level>: Set volume between 0 and 100');
@@ -231,6 +232,23 @@
     getstringParameter:= str;
 end;
 
+procedure setZoom(str:shortstring; var paramIndex:LongInt; var wrongParameter:Boolean);
+var param: LongInt;
+begin
+    param:= getLongIntParameter(str, paramIndex, wrongParameter);
+
+    if param = 100 then
+        exit;
+    UserZoom:= (param/100.0) * cDefaultZoomLevel;
+
+    if UserZoom < cMaxZoomLevel then
+        UserZoom:= cMaxZoomLevel;
+    if UserZoom > cMinZoomLevel then
+        UserZoom:= cMinZoomLevel;
+    zoom:= UserZoom;
+    ZoomValue:= UserZoom;
+end;
+
 procedure parseClassicParameter(cmdarray: array of string; size:LongInt; var paramIndex:LongInt); forward;
 
 function parseParameter(cmd:string; arg:string; var paramIndex:LongInt): Boolean;
@@ -239,10 +257,11 @@
       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..38] of shortstring = (
+      reallyAll: array[0..39] of shortstring = (
                 '--prefix', '--user-prefix', '--locale', '--fullscreen-width', '--fullscreen-height', '--width',
                 '--height', '--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',
   {internal}    '--internal', '--port', '--recorder', '--landpreview',
   {misc}        '--stats-only', '--gci', '--help','--protocol', '--no-teamtag','--no-hogtag','--no-healthtag','--translucent-tags','--lua-test','--no-holiday-silliness');
@@ -275,29 +294,30 @@
         {--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);
         {deprecated options}
-        {--depth}               19 : setDepth(paramIndex);
-        {--set-video}           20 : parseClassicParameter(videoarray,5,paramIndex);
-        {--set-audio}           21 : parseClassicParameter(audioarray,3,paramIndex);
-        {--set-other}           22 : parseClassicParameter(otherarray,3,paramIndex);
-        {--set-multimedia}      23 : parseClassicParameter(mediaarray,10,paramIndex);
-        {--set-everything}      24 : parseClassicParameter(allarray,14,paramIndex);
+        {--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);
         {"internal" options}
-        {--internal}            25 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
-        {--port}                26 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
-        {--recorder}            27 : startVideoRecording(paramIndex);
-        {--landpreview}         28 : GameType := gmtLandPreview;
+        {--internal}            26 : {$IFDEF HWLIBRARY}isInternal:= true{$ENDIF};
+        {--port}                27 : setIpcPort( getLongIntParameter(arg, paramIndex, parseParameter), parseParameter );
+        {--recorder}            28 : startVideoRecording(paramIndex);
+        {--landpreview}         29 : GameType := gmtLandPreview;
         {anything else}
-        {--stats-only}          29 : statsOnlyGame();
-        {--gci}                 30 : GciEasterEgg();
-        {--help}                31 : DisplayUsage();
-        {--protocol}            32 : DisplayProtocol();
-        {--no-teamtag}          33 : cTagsMask := cTagsMask and (not htTeamName);
-        {--no-hogtag}           34 : cTagsMask := cTagsMask and (not htName);
-        {--no-healthtag}        35 : cTagsMask := cTagsMask and (not htHealth);
-        {--translucent-tags}    36 : cTagsMask := cTagsMask or htTransparent;
-        {--lua-test}            37 : begin cTestLua := true; SetSound(false); cScriptName := getstringParameter(arg, paramIndex, parseParameter); WriteLn(stdout, 'Lua test file specified: ' + cScriptName);end;
-        {--no-holiday-silliness} 38 : cHolidaySilliness:= false;
+        {--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;
     else
         begin
         //Assume the first "non parameter" is the demo file, anything else is invalid
--- a/hedgewars/uCommandHandlers.pas	Tue Feb 05 01:40:16 2019 +0300
+++ b/hedgewars/uCommandHandlers.pas	Tue Feb 05 02:13:04 2019 +0100
@@ -732,7 +732,7 @@
 procedure chZoomReset(var s: shortstring);
 begin
     s:= s; // avoid compiler hint
-    ZoomValue:= cDefaultZoomLevel;
+    ZoomValue:= UserZoom;
 end;
 
 procedure chMapGen(var s: shortstring);
--- a/hedgewars/uConsts.pas	Tue Feb 05 01:40:16 2019 +0300
+++ b/hedgewars/uConsts.pas	Tue Feb 05 02:13:04 2019 +0100
@@ -216,7 +216,7 @@
     ExtraTime = 30000; // amount of time (ms) given for using Extra Time
 
     // do not change this value
-    cDefaultZoomLevel = 2.0;
+    cDefaultZoomLevel = 2.0; // 100% zoom
 
     // game flags
     gfAny                = $FFFFFFFF; // mask for all possible gameflags
--- a/hedgewars/uVariables.pas	Tue Feb 05 01:40:16 2019 +0300
+++ b/hedgewars/uVariables.pas	Tue Feb 05 02:13:04 2019 +0100
@@ -133,8 +133,9 @@
 
     cTagsMask        : byte;
     cPrevTagsMask    : byte;
-    zoom             : GLfloat;
-    ZoomValue        : GLfloat;
+    zoom             : GLfloat; // current zoom
+    ZoomValue        : GLfloat; // aimed zoom
+    UserZoom         : GLfloat; // user-chosen initial and default zoom
 
     cWaterLine       : LongInt;
     cGearScrEdgesDist: LongInt;
@@ -168,6 +169,7 @@
 
     cCaseFactor     : Longword;
     cMaxCaseDrops   : Longword; // Max. number of crates which can be in the game when dropping
+
     cLandMines      : Longword;
     cAirMines       : Longword;
     cExplosives     : Longword;
@@ -2624,6 +2626,20 @@
     cScriptParam    := '';
     cTestLua        := False;
 
+    UserZoom        := cDefaultZoomLevel;
+    zoom            := cDefaultZoomLevel;
+    ZoomValue       := cDefaultZoomLevel;
+
+{$IFDEF MOBILE}
+    cMaxZoomLevel:= 0.5;
+    cMinZoomLevel:= 3.5;
+    cZoomDelta:=    0.20;
+{$ELSE}
+    cMaxZoomLevel:= 1.0;
+    cMinZoomLevel:= 3.0;
+    cZoomDelta:=    0.25;
+{$ENDIF}
+
 {$IFDEF USE_VIDEO_RECORDING}
     RecPrefix          := '';
     cAVFormat          := '';
@@ -2777,16 +2793,6 @@
     cDamageModifier         := _1;
     TargetPoint             := cTargetPointRef;
 
-{$IFDEF MOBILE}
-    cMaxZoomLevel:= 0.5;
-    cMinZoomLevel:= 3.5;
-    cZoomDelta:= 0.20;
-{$ELSE}
-    cMaxZoomLevel:= 1.0;
-    cMinZoomLevel:= 3.0;
-    cZoomDelta:= 0.25;
-    {$ENDIF}
-
     aVertex:= 0;
     aTexCoord:= 1;
     aColor:= 2;
@@ -2844,8 +2850,6 @@
     cExplosives     := 2;
 
     GameState       := Low(TGameState);
-    zoom            := cDefaultZoomLevel;
-    ZoomValue       := cDefaultZoomLevel;
     WeaponTooltipTex:= nil;
     cLaserSighting  := false;
     cLaserSightingSniper := false;