• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Return-To-The-Roots / s25client / 14284294327

05 Apr 2025 05:41PM UTC coverage: 50.311% (+0.02%) from 50.288%
14284294327

Pull #1750

github

web-flow
Merge 6b1072a28 into c8cf430f2
Pull Request #1750: Fix size of Settings window

8 of 26 new or added lines in 15 files covered. (30.77%)

7 existing lines in 2 files now uncovered.

22370 of 44463 relevant lines covered (50.31%)

35678.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/s25main/ingameWindows/iwSettings.cpp
1
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "iwSettings.h"
6
#include "Loader.h"
7
#include "Settings.h"
8
#include "WindowManager.h"
9
#include "controls/ctrlCheck.h"
10
#include "controls/ctrlComboBox.h"
11
#include "controls/ctrlOptionGroup.h"
12
#include "drivers/VideoDriverWrapper.h"
13
#include "helpers/format.hpp"
14
#include "iwMsgbox.h"
15
#include "gameData/const_gui_ids.h"
16
#include "s25util/colors.h"
17

18
namespace {
19
enum
20
{
21
    ID_txtResolution,
22
    ID_txtFullScreen,
23
    ID_grpFullscreen,
24
    ID_cbResolution,
25
    ID_cbInvertMouse,
26
    ID_cbStatisticScale,
27
};
28
constexpr auto ID_btOn = 1;
29
constexpr auto ID_btOff = 0;
30
} // namespace
31

32
iwSettings::iwSettings()
×
NEW
33
    : IngameWindow(CGI_SETTINGS, IngameWindow::posLastOrCenter, Extent(370, 199), _("Settings"),
×
34
                   LOADER.GetImageN("resource", 41))
×
35
{
36
    // Controls are in 2 columns, the left might be the label for the control on the right
37
    constexpr auto leftColOffset = 15u;   // X-position of the left column
×
38
    constexpr auto rightColOffset = 200u; // X-position of the right column
×
39
    constexpr Extent ctrlSize(150, 22);
×
40
    constexpr auto rowWidth = rightColOffset + ctrlSize.x;
×
41

42
    AddText(ID_txtResolution, DrawPoint(leftColOffset, 40), _("Fullscreen resolution:"), COLOR_YELLOW, FontStyle{},
×
43
            NormalFont);
×
44
    auto* cbResolution =
45
      AddComboBox(ID_cbResolution, DrawPoint(rightColOffset, 35), ctrlSize, TextureColor::Grey, NormalFont, 110);
×
46

47
    VIDEODRIVER.ListVideoModes(video_modes);
×
48
    for(unsigned i = 0; i < video_modes.size(); ++i)
×
49
    {
50
        // >=800x600, alles andere macht keinen Sinn
51
        if(video_modes[i].width >= 800 && video_modes[i].height >= 600)
×
52
        {
53
            cbResolution->AddString(helpers::format("%ux%u", video_modes[i].width, video_modes[i].height));
×
54
            if(video_modes[i] == SETTINGS.video.fullscreenSize)
×
55
                cbResolution->SetSelection(i);
×
56
        } else
57
        {
58
            video_modes.erase(video_modes.begin() + i);
×
59
            --i;
×
60
        }
61
    }
62
    AddText(ID_txtFullScreen, DrawPoint(leftColOffset, 85), _("Mode:"), COLOR_YELLOW, FontStyle{}, NormalFont);
×
63
    ctrlOptionGroup* optiongroup = AddOptionGroup(ID_grpFullscreen, GroupSelectType::Check);
×
64
    DrawPoint curPos(rightColOffset, 70);
×
65
    optiongroup->AddTextButton(ID_btOn, curPos, ctrlSize, TextureColor::Grey, _("Fullscreen"), NormalFont);
×
66
    curPos.y += ctrlSize.y + 3;
×
67
    optiongroup->AddTextButton(ID_btOff, curPos, ctrlSize, TextureColor::Grey, _("Windowed"), NormalFont);
×
68
    optiongroup->SetSelection(SETTINGS.video.fullscreen); //-V807
×
69

70
    curPos = DrawPoint(leftColOffset, curPos.y + ctrlSize.y + 5);
×
NEW
71
    const auto cbSize = Extent(rowWidth - curPos.x, 26);
×
72
    AddCheckBox(ID_cbInvertMouse, curPos, cbSize, TextureColor::Grey, _("Invert Mouse Pan"), NormalFont, false)
×
73
      ->setChecked(SETTINGS.interface.invertMouse);
×
74
    curPos.y += cbSize.y + 3;
×
75
    AddCheckBox(ID_cbStatisticScale, curPos, cbSize, TextureColor::Grey, _("Statistics Scale"), NormalFont, false)
×
76
      ->setChecked(SETTINGS.ingame.scale_statistics);
×
77
}
×
78

79
iwSettings::~iwSettings()
×
80
{
81
    try
82
    {
83
        auto* SizeCombo = GetCtrl<ctrlComboBox>(ID_cbResolution);
×
84
        SETTINGS.video.fullscreenSize = video_modes[SizeCombo->GetSelection().get()];
×
85

86
        if((SETTINGS.video.fullscreen && SETTINGS.video.fullscreenSize != VIDEODRIVER.GetWindowSize())
×
87
           || SETTINGS.video.fullscreen != VIDEODRIVER.IsFullscreen())
×
88
        {
89
            const auto screenSize =
90
              SETTINGS.video.fullscreen ? SETTINGS.video.fullscreenSize : SETTINGS.video.windowedSize;
×
91
            if(!VIDEODRIVER.ResizeScreen(screenSize, SETTINGS.video.fullscreen))
×
92
            {
93
                WINDOWMANAGER.Show(std::make_unique<iwMsgbox>(
×
94
                  _("Sorry!"), _("You need to restart your game to change the screen resolution!"), this,
×
95
                  MsgboxButton::Ok, MsgboxIcon::ExclamationGreen, 1));
×
96
            }
97
        }
98
    } catch(...)
×
99
    {
100
        // ignored
101
    }
102
}
×
103

104
void iwSettings::Msg_OptionGroupChange(const unsigned ctrl_id, const unsigned selection)
×
105
{
106
    switch(ctrl_id)
×
107
    {
108
        case ID_grpFullscreen: SETTINGS.video.fullscreen = selection == ID_btOn; break;
×
109
    }
110
}
×
111

112
void iwSettings::Msg_CheckboxChange(const unsigned ctrl_id, const bool checked)
×
113
{
114
    switch(ctrl_id)
×
115
    {
116
        case ID_cbInvertMouse: SETTINGS.interface.invertMouse = checked; break;
×
117
        case ID_cbStatisticScale: SETTINGS.ingame.scale_statistics = checked; break;
×
118
    }
119
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc