1414#include " controls/ctrlImageButton.h"
1515#include " controls/ctrlOptionGroup.h"
1616#include " controls/ctrlProgress.h"
17+ #include " controls/ctrlTextButton.h"
1718#include " driver/VideoDriver.h"
1819#include " drivers/AudioDriverWrapper.h"
1920#include " drivers/VideoDriverWrapper.h"
6667 ID_cbProxyType,
6768 ID_txtDebugData,
6869 ID_grpDebugData,
69- ID_txtUPNP,
7070 ID_grpUPNP,
7171 ID_txtMapScrollMode,
7272 ID_cbMapScrollMode,
73- ID_txtSmartCursor,
7473 ID_grpSmartCursor,
75- ID_txtWindowPinning,
7674 ID_grpWindowPinning,
77- ID_txtGFInfo,
7875 ID_grpGFInfo,
7976 ID_txtResolution,
8077 ID_cbResolution,
8178 ID_txtFullscreen,
8279 ID_cbDisplayMode,
8380 ID_txtFramerate,
8481 ID_cbFramerate,
85- ID_txtVBO,
8682 ID_grpVBO,
8783 ID_txtVideoDriver,
8884 ID_cbVideoDriver,
89- ID_txtOptTextures,
9085 ID_grpOptTextures,
9186 ID_txtGuiScale,
9287 ID_cbGuiScale,
9388 ID_txtAudioDriver,
9489 ID_cbAudioDriver,
95- ID_txtMusic,
9690 ID_grpMusic,
9791 ID_pgMusicVol,
98- ID_txtEffects,
9992 ID_grpEffects,
10093 ID_pgEffectsVol,
10194 ID_btMusicPlayer,
10295 ID_txtCommonPortrait,
10396 ID_btCommonPortrait,
10497 ID_cbCommonPortrait,
105- ID_txtBirdSounds,
10698 ID_grpBirdSounds,
99+ ID_txtsStart, // First ID for texts used by options (ID of option is used as offset on top)
107100};
108101// Use these as IDs in dedicated groups
109102constexpr auto ID_btOn = 1 ;
@@ -122,9 +115,8 @@ constexpr Offset ctrlOffset(200, -5); // Offset of control
122115constexpr Offset ctrlOffset2 = ctrlOffset + Offset(200 , 0 ); // Offset of 2nd control to its description text
123116constexpr Extent ctrlSize (190 , 22 );
124117constexpr Extent ctrlSizeLarge = ctrlSize + Extent(ctrlOffset2 - ctrlOffset);
125- } // namespace
126118
127- static VideoMode getAspectRatio (const VideoMode& vm)
119+ VideoMode getAspectRatio (const VideoMode& vm)
128120{
129121 // First some a bit off values where the aspect ratio is defined by convention
130122 if (vm == VideoMode (1360 , 1024 ))
@@ -144,6 +136,32 @@ static VideoMode getAspectRatio(const VideoMode& vm)
144136 return ratio;
145137}
146138
139+ enum class ButtonSize
140+ {
141+ Normal,
142+ Half // / Both buttons take up the same space as a single button
143+ };
144+
145+ ctrlOptionGroup& addOnOffOption (ctrlGroup& parentGroup, DrawPoint pos, unsigned id, const std::string& title,
146+ bool value, ButtonSize btSize = ButtonSize::Normal)
147+ {
148+ constexpr auto spacing = 10 ;
149+ auto size = ctrlSize;
150+ if (btSize == ButtonSize::Half)
151+ size.x = (ctrlSize.x - spacing) / 2 ;
152+
153+ parentGroup.AddText (ID_txtsStart + id, pos, title, COLOR_YELLOW, FontStyle{}, NormalFont);
154+ auto * option = parentGroup.AddOptionGroup (id, GroupSelectType::Check);
155+ pos += ctrlOffset;
156+ option->AddTextButton (ID_btOn, pos, size, TextureColor::Grey, _ (" On" ), NormalFont);
157+ pos.x += size.x + spacing;
158+ option->AddTextButton (ID_btOff, pos, size, TextureColor::Grey, _ (" Off" ), NormalFont);
159+ option->SetSelection (value);
160+ return *option;
161+ }
162+
163+ } // namespace
164+
147165dskOptions::dskOptions () : Desktop(LOADER.GetImageN(" setup013" , 0 ))
148166{
149167 AddText (ID_txtOptions, DrawPoint (400 , 10 ), _ (" Options" ), COLOR_YELLOW, FontStyle::CENTER, LargeFont);
@@ -229,14 +247,11 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
229247 curPos.y += rowHeight;
230248
231249 // IPv4/6
232- groupCommon->AddText (ID_txtIpv6, curPos, _ (" Use IPv6:" ), COLOR_YELLOW, FontStyle{}, NormalFont);
233-
234- ctrlOptionGroup* ipv6 = groupCommon->AddOptionGroup (ID_grpIpv6, GroupSelectType::Check);
235- ipv6->AddTextButton (ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _ (" IPv6" ), NormalFont);
236- ipv6->AddTextButton (ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _ (" IPv4" ), NormalFont);
237- ipv6->SetSelection (SETTINGS.server .ipv6 );
250+ auto & grpIPv6 = addOnOffOption (*groupCommon, curPos, ID_grpIpv6, _ (" Use IPv6:" ), SETTINGS.server .ipv6 );
251+ grpIPv6.GetCtrl <ctrlTextButton>(ID_btOn)->SetText (_ (" IPv6" ));
252+ grpIPv6.GetCtrl <ctrlTextButton>(ID_btOff)->SetText (_ (" IPv4" ));
238253 // Enable/disable the IPv6 field if necessary
239- ipv6-> GetCtrl <ctrlButton>(1 )->SetEnabled (SETTINGS.proxy .type != ProxyType::Socks5); // -V807
254+ grpIPv6. GetCtrl <ctrlButton>(ID_btOn )->SetEnabled (SETTINGS.proxy .type != ProxyType::Socks5); // -V807
240255 curPos.y += rowHeight;
241256
242257 curPos.y += sectionSpacingCommon;
@@ -250,11 +265,7 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
250265 proxy->SetText (SETTINGS.proxy .port );
251266 curPos.y += rowHeight;
252267
253- groupCommon->AddText (ID_txtUPNP, curPos, _ (" Use UPnP" ), COLOR_YELLOW, FontStyle{}, NormalFont);
254- ctrlOptionGroup* upnp = groupCommon->AddOptionGroup (ID_grpUPNP, GroupSelectType::Check);
255- upnp->AddTextButton (ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _ (" On" ), NormalFont);
256- upnp->AddTextButton (ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _ (" Off" ), NormalFont);
257- upnp->SetSelection (SETTINGS.global .useUPNP );
268+ addOnOffOption (*groupCommon, curPos, ID_grpUPNP, _ (" Use UPnP" ), SETTINGS.global .useUPNP );
258269 curPos.y += rowHeight;
259270
260271 // Proxy type
@@ -285,23 +296,19 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
285296 combo->SetSelection (static_cast <int >(SETTINGS.interface .mapScrollMode ));
286297 curPos.y += rowHeight;
287298
288- groupCommon->AddText (ID_txtSmartCursor, curPos, _ (" Smart Cursor" ), COLOR_YELLOW, FontStyle{}, NormalFont);
289- ctrlOptionGroup* smartCursor = groupCommon->AddOptionGroup (ID_grpSmartCursor, GroupSelectType::Check);
290- smartCursor->AddTextButton (ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _ (" On" ), NormalFont,
291- _ (" Place cursor on default button for new dialogs / action windows (default)" ));
292- smartCursor->AddTextButton (
293- ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _ (" Off" ), NormalFont,
299+ auto & grpSmartCursor =
300+ addOnOffOption (*groupCommon, curPos, ID_grpSmartCursor, _ (" Smart Cursor" ), SETTINGS.global .smartCursor );
301+ grpSmartCursor.GetCtrl <ctrlButton>(ID_btOn)->SetTooltip (
302+ _ (" Place cursor on default button for new dialogs / action windows (default)" ));
303+ grpSmartCursor.GetCtrl <ctrlButton>(ID_btOff)->SetTooltip (
294304 _ (" Don't move cursor automatically\n Useful e.g. for split-screen / dual-mice multiplayer (see wiki)" ));
295- smartCursor->SetSelection (SETTINGS.global .smartCursor );
296305 curPos.y += rowHeight;
297306
298- groupCommon->AddText (ID_txtWindowPinning, curPos, _ (" Window pinning" ), COLOR_YELLOW, FontStyle{}, NormalFont);
299- ctrlOptionGroup* windowPinning = groupCommon->AddOptionGroup (ID_grpWindowPinning, GroupSelectType::Check);
300- windowPinning->AddTextButton (ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _ (" On" ), NormalFont,
301- _ (" Replace minimize button on windows by pin button avoiding closing the window with "
302- " ESC.\n Minimize by double-clicking the title bar." ));
303- windowPinning->AddTextButton (ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _ (" Off" ), NormalFont);
304- windowPinning->SetSelection (SETTINGS.interface .enableWindowPinning );
307+ auto & grpWindowPinning = addOnOffOption (*groupCommon, curPos, ID_grpWindowPinning, _ (" Window pinning" ),
308+ SETTINGS.interface .enableWindowPinning );
309+ grpWindowPinning.GetCtrl <ctrlButton>(ID_btOn)->SetTooltip (
310+ _ (" Replace minimize button on windows by pin button avoiding closing the window with "
311+ " ESC.\n Minimize by double-clicking the title bar." ));
305312 curPos.y += rowHeight;
306313
307314 curPos.y += sectionSpacingCommon;
@@ -315,12 +322,7 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
315322 mainGroup->SetSelection ((SETTINGS.global .submitDebugData == 1 ) ? ID_btSubmitDebugOn : ID_btSubmitDebugAsk); // -V807
316323 curPos.y += rowHeight;
317324
318- groupCommon->AddText (ID_txtGFInfo, curPos, _ (" Show GameFrame Info:" ), COLOR_YELLOW, FontStyle{}, NormalFont);
319- mainGroup = groupCommon->AddOptionGroup (ID_grpGFInfo, GroupSelectType::Check);
320- mainGroup->AddTextButton (ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _ (" On" ), NormalFont);
321- mainGroup->AddTextButton (ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _ (" Off" ), NormalFont);
322-
323- mainGroup->SetSelection (SETTINGS.global .showGFInfo );
325+ addOnOffOption (*groupCommon, curPos, ID_grpGFInfo, _ (" Show GameFrame Info:" ), SETTINGS.global .showGFInfo );
324326
325327 curPos = optionRowsStartPosition;
326328 groupGraphics->AddText (ID_txtResolution, curPos, _ (" Fullscreen resolution:" ), COLOR_YELLOW, FontStyle{},
@@ -344,10 +346,7 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
344346 curPos.y += rowHeight;
345347
346348 curPos.y += sectionSpacing;
347- groupGraphics->AddText (ID_txtVBO, curPos, _ (" Vertex Buffer Objects:" ), COLOR_YELLOW, FontStyle{}, NormalFont);
348- mainGroup = groupGraphics->AddOptionGroup (ID_grpVBO, GroupSelectType::Check);
349- mainGroup->AddTextButton (ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _ (" On" ), NormalFont);
350- mainGroup->AddTextButton (ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _ (" Off" ), NormalFont);
349+ addOnOffOption (*groupGraphics, curPos, ID_grpVBO, _ (" Vertex Buffer Objects:" ), SETTINGS.video .vbo );
351350 curPos.y += rowHeight;
352351
353352 curPos.y += sectionSpacing;
@@ -366,11 +365,7 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
366365 curPos.y += rowHeight;
367366
368367 curPos.y += sectionSpacing;
369- groupGraphics->AddText (ID_txtOptTextures, curPos, _ (" Optimized Textures:" ), COLOR_YELLOW, FontStyle{}, NormalFont);
370- mainGroup = groupGraphics->AddOptionGroup (ID_grpOptTextures, GroupSelectType::Check);
371-
372- mainGroup->AddTextButton (ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _ (" On" ), NormalFont);
373- mainGroup->AddTextButton (ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _ (" Off" ), NormalFont);
368+ addOnOffOption (*groupGraphics, curPos, ID_grpOptTextures, _ (" Optimized Textures:" ), SETTINGS.video .sharedTextures );
374369 curPos.y += rowHeight;
375370
376371 curPos.y += sectionSpacing;
@@ -379,36 +374,24 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
379374 updateGuiScale ();
380375
381376 curPos = optionRowsStartPosition;
382- constexpr Offset bt1Offset (200 , -5 );
383- constexpr Offset bt2Offset (300 , -5 );
384- constexpr Offset volOffset (400 , -5 );
385- constexpr Extent ctrlSizeSmall (90 , ctrlSize.y );
386377
387- groupSound->AddText (ID_txtEffects, curPos, _ (" Effects" ), COLOR_YELLOW, FontStyle{}, NormalFont);
388- mainGroup = groupSound->AddOptionGroup (ID_grpEffects, GroupSelectType::Check);
389- mainGroup->AddTextButton (ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _ (" On" ), NormalFont);
390- mainGroup->AddTextButton (ID_btOff, curPos + bt2Offset, ctrlSizeSmall, TextureColor::Grey, _ (" Off" ), NormalFont);
378+ addOnOffOption (*groupSound, curPos, ID_grpEffects, _ (" Effects" ), SETTINGS.sound .effectsEnabled , ButtonSize::Half);
391379
392380 ctrlProgress* FXvolume =
393- groupSound->AddProgress (ID_pgEffectsVol, curPos + volOffset , ctrlSize, TextureColor::Grey, 139 , 138 , 100 );
381+ groupSound->AddProgress (ID_pgEffectsVol, curPos + ctrlOffset2 , ctrlSize, TextureColor::Grey, 139 , 138 , 100 );
394382 FXvolume->SetPosition ((SETTINGS.sound .effectsVolume * 100 ) / 255 );
395383 curPos.y += rowHeight;
396384
397385 curPos.y += sectionSpacing;
398- groupSound->AddText (ID_txtBirdSounds, curPos, _ (" Bird sounds" ), COLOR_YELLOW, FontStyle{}, NormalFont);
399- mainGroup = groupSound->AddOptionGroup (ID_grpBirdSounds, GroupSelectType::Check);
400- mainGroup->AddTextButton (ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _ (" On" ), NormalFont);
401- mainGroup->AddTextButton (ID_btOff, curPos + bt2Offset, ctrlSizeSmall, TextureColor::Grey, _ (" Off" ), NormalFont);
386+ addOnOffOption (*groupSound, curPos, ID_grpBirdSounds, _ (" Bird sounds" ), SETTINGS.sound .birdsEnabled ,
387+ ButtonSize::Half);
402388 curPos.y += rowHeight;
403389
404390 curPos.y += sectionSpacing;
405- groupSound->AddText (ID_txtMusic, curPos, _ (" Music" ), COLOR_YELLOW, FontStyle{}, NormalFont);
406- mainGroup = groupSound->AddOptionGroup (ID_grpMusic, GroupSelectType::Check);
407- mainGroup->AddTextButton (ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _ (" On" ), NormalFont);
408- mainGroup->AddTextButton (ID_btOff, curPos + bt2Offset, ctrlSizeSmall, TextureColor::Grey, _ (" Off" ), NormalFont);
391+ addOnOffOption (*groupSound, curPos, ID_grpMusic, _ (" Music" ), SETTINGS.sound .musicEnabled , ButtonSize::Half);
409392
410393 ctrlProgress* Mvolume =
411- groupSound->AddProgress (ID_pgMusicVol, curPos + volOffset , ctrlSize, TextureColor::Grey, 139 , 138 , 100 );
394+ groupSound->AddProgress (ID_pgMusicVol, curPos + ctrlOffset2 , ctrlSize, TextureColor::Grey, 139 , 138 , 100 );
412395 Mvolume->SetPosition ((SETTINGS.sound .musicVolume * 100 ) / 255 ); // -V807
413396 curPos.y += rowHeight;
414397
@@ -476,9 +459,6 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
476459 if (!cbFrameRate->GetSelection ())
477460 cbFrameRate->SetSelection (0 );
478461
479- groupGraphics->GetCtrl <ctrlOptionGroup>(ID_grpVBO)->SetSelection (SETTINGS.video .vbo );
480-
481- groupGraphics->GetCtrl <ctrlOptionGroup>(ID_grpOptTextures)->SetSelection (SETTINGS.video .sharedTextures );
482462 // }
483463
484464 // Sound
@@ -614,6 +594,7 @@ void dskOptions::Msg_Group_OptionGroupChange(const unsigned /*group_id*/, const
614594 break ;
615595 case ID_grpWindowPinning: SETTINGS.interface .enableWindowPinning = enabled; break ;
616596 case ID_grpGFInfo: SETTINGS.global .showGFInfo = enabled; break ;
597+ default : RTTR_Assert (false );
617598 }
618599}
619600
0 commit comments