Skip to content

Commit 133ba88

Browse files
committed
Add option for window pinning to settings screen
Also make layout more adaptive
1 parent 2933031 commit 133ba88

1 file changed

Lines changed: 55 additions & 29 deletions

File tree

libs/s25main/desktops/dskOptions.cpp

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include <sstream>
3737

3838
namespace {
39+
using Offset = DrawPoint;
40+
3941
enum
4042
{
4143
ID_btBack = dskMenuBase::ID_FIRST_FREE,
@@ -71,6 +73,8 @@ enum
7173
ID_grpInvertScroll,
7274
ID_txtSmartCursor,
7375
ID_grpSmartCursor,
76+
ID_txtWindowPinning,
77+
ID_grpWindowPinning,
7478
ID_txtGFInfo,
7579
ID_grpGFInfo,
7680
ID_txtResolution,
@@ -112,8 +116,13 @@ constexpr auto ID_btSubmitDebugAsk = 2;
112116
constexpr auto rowHeight = 30;
113117
constexpr auto sectionSpacing = 20;
114118
constexpr auto sectionSpacingCommon = 10;
115-
constexpr auto tabButtonsStartPosition = DrawPoint(80, 510);
116-
constexpr auto optionRowsStartPosition = DrawPoint(80, 80);
119+
constexpr auto optionRowsStartPosition = DrawPoint(80, 75);
120+
constexpr auto tabButtonsStartPosition = optionRowsStartPosition + Offset(0, static_cast<int>(rowHeight * 15.5));
121+
122+
constexpr Offset ctrlOffset(200, -5); // Offset of control to its description text
123+
constexpr Offset ctrlOffset2 = ctrlOffset + Offset(200, 0); // Offset of 2nd control to its description text
124+
constexpr Extent ctrlSize(190, 22);
125+
constexpr Extent ctrlSizeLarge = ctrlSize + Extent(ctrlOffset2 - ctrlOffset);
117126
} // namespace
118127

119128
static VideoMode getAspectRatio(const VideoMode& vm)
@@ -149,7 +158,7 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
149158
_("Graphics"), NormalFont);
150159
mainGroup->AddTextButton(ID_btSound, DrawPoint(curPos.x + 440, curPos.y), Extent(200, 22), TextureColor::Green2,
151160
_("Sound/Music"), NormalFont);
152-
curPos.y += rowHeight + sectionSpacingCommon;
161+
curPos.y += rowHeight;
153162

154163
AddTextButton(ID_btBack, DrawPoint(curPos.x + 220, curPos.y), Extent(200, 22), TextureColor::Red1, _("Back"),
155164
NormalFont);
@@ -165,34 +174,27 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
165174
// {
166175

167176
curPos = optionRowsStartPosition;
168-
using Offset = DrawPoint;
169-
constexpr Offset ctrlOffset(200, -5); // Offset of control to its description text
170-
constexpr Offset ctrlOffset2 = ctrlOffset + Offset(200, 0); // Offset of 2nd control to its description text
171-
constexpr Extent ctrlSize(190, 22);
172-
constexpr Extent ctrlSizeLarge = ctrlSize + Extent(ctrlOffset2 - ctrlOffset);
173177

174178
groupCommon->AddText(ID_txtName, curPos, _("Name in Game:"), COLOR_YELLOW, FontStyle{}, NormalFont);
175179
ctrlEdit* name =
176180
groupCommon->AddEdit(ID_edtName, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 15);
177181
name->SetText(SETTINGS.lobby.name);
178182

179183
const auto& currentPortrait = Portraits[SETTINGS.lobby.portraitIndex];
180-
groupCommon->AddImageButton(ID_btCommonPortrait, DrawPoint(500, curPos.y - 5), Extent(40, 54), TextureColor::Grey,
184+
groupCommon->AddImageButton(ID_btCommonPortrait, DrawPoint(500, curPos.y + ctrlOffset.y), Extent(40, rowHeight * 2),
185+
TextureColor::Grey,
181186
LOADER.GetImageN(currentPortrait.resourceId, currentPortrait.resourceIndex));
182187
curPos.y += rowHeight;
183188

184-
groupCommon->AddText(ID_txtCommonPortrait, DrawPoint(80, curPos.y), _("Portrait:"), COLOR_YELLOW, FontStyle{},
185-
NormalFont);
186-
combo = groupCommon->AddComboBox(ID_cbCommonPortrait, DrawPoint(280, curPos.y - 5), Extent(190, 20),
187-
TextureColor::Grey, NormalFont, 100);
189+
groupCommon->AddText(ID_txtCommonPortrait, curPos, _("Portrait:"), COLOR_YELLOW, FontStyle{}, NormalFont);
190+
combo =
191+
groupCommon->AddComboBox(ID_cbCommonPortrait, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 100);
188192

189193
for(unsigned i = 0; i < Portraits.size(); ++i)
190194
{
191195
combo->AddString(_(Portraits[i].name));
192196
if(SETTINGS.lobby.portraitIndex == i)
193-
{
194197
combo->SetSelection(i);
195-
}
196198
}
197199
curPos.y += rowHeight;
198200

@@ -217,8 +219,9 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
217219

218220
groupCommon->AddTextButton(ID_btKeyboardLayout, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey,
219221
_("Keyboard layout"), NormalFont);
220-
curPos.y += rowHeight + sectionSpacingCommon;
222+
curPos.y += rowHeight;
221223

224+
curPos.y += sectionSpacingCommon;
222225
groupCommon->AddText(ID_txtPort, curPos, _("Local Port:"), COLOR_YELLOW, FontStyle{}, NormalFont);
223226
ctrlEdit* edtPort =
224227
groupCommon->AddEdit(ID_edtPort, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 15);
@@ -235,8 +238,9 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
235238
ipv6->SetSelection(SETTINGS.server.ipv6);
236239
// Enable/disable the IPv6 field if necessary
237240
ipv6->GetCtrl<ctrlButton>(1)->SetEnabled(SETTINGS.proxy.type != ProxyType::Socks5); //-V807
238-
curPos.y += rowHeight + sectionSpacingCommon;
241+
curPos.y += rowHeight;
239242

243+
curPos.y += sectionSpacingCommon;
240244
// Proxy server
241245
groupCommon->AddText(ID_txtProxy, curPos, _("Proxyserver:"), COLOR_YELLOW, FontStyle{}, NormalFont);
242246
ctrlEdit* proxy = groupCommon->AddEdit(ID_edtProxy, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont);
@@ -269,8 +273,9 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
269273
case ProxyType::Socks4: combo->SetSelection(1); break;
270274
case ProxyType::Socks5: combo->SetSelection(2); break;
271275
}
272-
curPos.y += rowHeight + sectionSpacingCommon;
276+
curPos.y += rowHeight;
273277

278+
curPos.y += sectionSpacingCommon;
274279
groupCommon->AddText(ID_txtInvertScroll, curPos, _("Invert Mouse Pan:"), COLOR_YELLOW, FontStyle{}, NormalFont);
275280
ctrlOptionGroup* invertScroll = groupCommon->AddOptionGroup(ID_grpInvertScroll, GroupSelectType::Check);
276281
invertScroll->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont,
@@ -288,8 +293,18 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
288293
ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont,
289294
_("Don't move cursor automatically\nUseful e.g. for split-screen / dual-mice multiplayer (see wiki)"));
290295
smartCursor->SetSelection(SETTINGS.global.smartCursor);
291-
curPos.y += rowHeight + sectionSpacingCommon;
296+
curPos.y += rowHeight;
297+
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.\nMinimize by double-clicking the title bar."));
303+
windowPinning->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont);
304+
windowPinning->SetSelection(SETTINGS.interface.enableWindowPinning);
305+
curPos.y += rowHeight;
292306

307+
curPos.y += sectionSpacingCommon;
293308
groupCommon->AddText(ID_txtDebugData, curPos, _("Submit debug data:"), COLOR_YELLOW, FontStyle{}, NormalFont);
294309
mainGroup = groupCommon->AddOptionGroup(ID_grpDebugData, GroupSelectType::Check);
295310
mainGroup->AddTextButton(ID_btSubmitDebugOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"),
@@ -312,24 +327,28 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
312327
groupGraphics->AddText(ID_txtResolution, curPos, _("Fullscreen resolution:"), COLOR_YELLOW, FontStyle{},
313328
NormalFont);
314329
groupGraphics->AddComboBox(ID_cbResolution, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 150);
315-
curPos.y += rowHeight + sectionSpacing;
330+
curPos.y += rowHeight;
316331

332+
curPos.y += sectionSpacing;
317333
groupGraphics->AddText(ID_txtFullscreen, curPos, _("Mode:"), COLOR_YELLOW, FontStyle{}, NormalFont);
318334
mainGroup = groupGraphics->AddOptionGroup(ID_grpFullscreen, GroupSelectType::Check);
319335
mainGroup->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("Fullscreen"), NormalFont);
320336
mainGroup->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Windowed"), NormalFont);
321-
curPos.y += rowHeight + sectionSpacing;
337+
curPos.y += rowHeight;
322338

339+
curPos.y += sectionSpacing;
323340
groupGraphics->AddText(ID_txtFramerate, curPos, _("Limit Framerate:"), COLOR_YELLOW, FontStyle{}, NormalFont);
324341
groupGraphics->AddComboBox(ID_cbFramerate, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey, NormalFont, 150);
325-
curPos.y += rowHeight + sectionSpacing;
342+
curPos.y += rowHeight;
326343

344+
curPos.y += sectionSpacing;
327345
groupGraphics->AddText(ID_txtVBO, curPos, _("Vertex Buffer Objects:"), COLOR_YELLOW, FontStyle{}, NormalFont);
328346
mainGroup = groupGraphics->AddOptionGroup(ID_grpVBO, GroupSelectType::Check);
329347
mainGroup->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont);
330348
mainGroup->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont);
331-
curPos.y += rowHeight + sectionSpacing;
349+
curPos.y += rowHeight;
332350

351+
curPos.y += sectionSpacing;
333352
groupGraphics->AddText(ID_txtVideoDriver, curPos, _("Graphics Driver"), COLOR_YELLOW, FontStyle{}, NormalFont);
334353
combo = groupGraphics->AddComboBox(ID_cbVideoDriver, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey,
335354
NormalFont, 100);
@@ -342,15 +361,17 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
342361
if(video_driver.GetName() == SETTINGS.driver.video)
343362
combo->SetSelection(combo->GetNumItems() - 1);
344363
}
345-
curPos.y += rowHeight + sectionSpacing;
364+
curPos.y += rowHeight;
346365

366+
curPos.y += sectionSpacing;
347367
groupGraphics->AddText(ID_txtOptTextures, curPos, _("Optimized Textures:"), COLOR_YELLOW, FontStyle{}, NormalFont);
348368
mainGroup = groupGraphics->AddOptionGroup(ID_grpOptTextures, GroupSelectType::Check);
349369

350370
mainGroup->AddTextButton(ID_btOn, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("On"), NormalFont);
351371
mainGroup->AddTextButton(ID_btOff, curPos + ctrlOffset2, ctrlSize, TextureColor::Grey, _("Off"), NormalFont);
352-
curPos.y += rowHeight + sectionSpacing;
372+
curPos.y += rowHeight;
353373

374+
curPos.y += sectionSpacing;
354375
groupGraphics->AddText(ID_txtGuiScale, curPos, _("GUI Scale:"), COLOR_YELLOW, FontStyle{}, NormalFont);
355376
groupGraphics->AddComboBox(ID_cbGuiScale, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, NormalFont, 100);
356377
updateGuiScale();
@@ -369,14 +390,16 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
369390
ctrlProgress* FXvolume =
370391
groupSound->AddProgress(ID_pgEffectsVol, curPos + volOffset, ctrlSize, TextureColor::Grey, 139, 138, 100);
371392
FXvolume->SetPosition((SETTINGS.sound.effectsVolume * 100) / 255);
372-
curPos.y += rowHeight + sectionSpacing;
393+
curPos.y += rowHeight;
373394

395+
curPos.y += sectionSpacing;
374396
groupSound->AddText(ID_txtBirdSounds, curPos, _("Bird sounds"), COLOR_YELLOW, FontStyle{}, NormalFont);
375397
mainGroup = groupSound->AddOptionGroup(ID_grpBirdSounds, GroupSelectType::Check);
376398
mainGroup->AddTextButton(ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _("On"), NormalFont);
377399
mainGroup->AddTextButton(ID_btOff, curPos + bt2Offset, ctrlSizeSmall, TextureColor::Grey, _("Off"), NormalFont);
378-
curPos.y += rowHeight + sectionSpacing;
400+
curPos.y += rowHeight;
379401

402+
curPos.y += sectionSpacing;
380403
groupSound->AddText(ID_txtMusic, curPos, _("Music"), COLOR_YELLOW, FontStyle{}, NormalFont);
381404
mainGroup = groupSound->AddOptionGroup(ID_grpMusic, GroupSelectType::Check);
382405
mainGroup->AddTextButton(ID_btOn, curPos + bt1Offset, ctrlSizeSmall, TextureColor::Grey, _("On"), NormalFont);
@@ -385,12 +408,14 @@ dskOptions::dskOptions() : Desktop(LOADER.GetImageN("setup013", 0))
385408
ctrlProgress* Mvolume =
386409
groupSound->AddProgress(ID_pgMusicVol, curPos + volOffset, ctrlSize, TextureColor::Grey, 139, 138, 100);
387410
Mvolume->SetPosition((SETTINGS.sound.musicVolume * 100) / 255); //-V807
388-
curPos.y += rowHeight + sectionSpacing;
411+
curPos.y += rowHeight;
389412

413+
curPos.y += sectionSpacing;
390414
groupSound->AddTextButton(ID_btMusicPlayer, curPos + ctrlOffset, ctrlSize, TextureColor::Grey, _("Music player"),
391415
NormalFont);
392-
curPos.y += rowHeight + sectionSpacing;
416+
curPos.y += rowHeight;
393417

418+
curPos.y += sectionSpacing;
394419
groupSound->AddText(ID_txtAudioDriver, curPos, _("Sounddriver"), COLOR_YELLOW, FontStyle{}, NormalFont);
395420
combo = groupSound->AddComboBox(ID_cbAudioDriver, curPos + ctrlOffset, ctrlSizeLarge, TextureColor::Grey,
396421
NormalFont, 100);
@@ -588,6 +613,7 @@ void dskOptions::Msg_Group_OptionGroupChange(const unsigned /*group_id*/, const
588613
SETTINGS.global.smartCursor = enabled;
589614
VIDEODRIVER.SetMouseWarping(enabled);
590615
break;
616+
case ID_grpWindowPinning: SETTINGS.interface.enableWindowPinning = enabled; break;
591617
case ID_grpGFInfo: SETTINGS.global.showGFInfo = enabled; break;
592618
}
593619
}

0 commit comments

Comments
 (0)