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

Return-To-The-Roots / s25client / 24905699225

24 Apr 2026 06:33PM UTC coverage: 50.223% (-0.2%) from 50.384%
24905699225

push

github

web-flow
Merge pull request #1890 from Flamefire/lock-window-size

167 of 641 new or added lines in 44 files covered. (26.05%)

25 existing lines in 8 files now uncovered.

23077 of 45949 relevant lines covered (50.22%)

43291.23 hits per line

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

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

5
#include "dskTest.h"
6
#include "CollisionDetection.h"
7
#include "Loader.h"
8
#include "WindowManager.h"
9
#include "animation/BlinkButtonAnim.h"
10
#include "animation/MoveAnimation.h"
11
#include "controls/ctrlButton.h"
12
#include "controls/ctrlComboBox.h"
13
#include "controls/ctrlEdit.h"
14
#include "controls/ctrlText.h"
15
#include "desktops/dskMainMenu.h"
16
#include "desktops/dskTextureTest.h"
17
#include "dskBenchmark.h"
18
#include "files.h"
19
#include "ogl/FontStyle.h"
20
#include "s25util/colors.h"
21

22
namespace {
23
enum
24
{
25
    ID_txtTitle = dskMenuBase::ID_FIRST_FREE,
26
    ID_grpBtStart,
27
    ID_grpBtEnd = ID_grpBtStart + 5 * 4,
28
    ID_btDisable,
29
    ID_btAniBg,
30
    ID_btAni,
31
    ID_btAnimate,
32
    ID_btAnimateRepeat,
33
    ID_btAnimateOscillate,
34
    ID_btTextureTest,
35
    ID_edtTest,
36
    ID_txtTest,
37
    ID_cbTxtSize,
38
    ID_btHideCtrls,
39
    ID_btShowBenchmark
40
};
41
}
42

43
dskTest::dskTest() : curBGIdx(LOAD_SCREENS.size())
×
44
{
45
    AddText(ID_txtTitle, DrawPoint(300, 20), _("Internal test screen for developers"), COLOR_ORANGE, FontStyle::CENTER,
×
46
            LargeFont);
×
47
    std::array<TextureColor, 4> textures = {
×
48
      {TextureColor::Green1, TextureColor::Green2, TextureColor::Red1, TextureColor::Grey}};
49
    std::array<std::string, 4> labels = {{"Green1", "Green2", "Red1", "Grey"}};
×
50
    unsigned yPos = 50;
×
51
    unsigned curId = ID_grpBtStart;
×
52
    for(unsigned i = 0; i < textures.size(); i++)
×
53
    {
54
        AddText(curId, DrawPoint(10, yPos + 3), labels.at(i), COLOR_YELLOW, FontStyle::LEFT, NormalFont);
×
55
        ctrlButton* bt;
56
        bt = AddTextButton(curId + 1, DrawPoint(120, yPos), Extent(95, 22), textures[i], "Nothing", NormalFont);
×
57
        bt->SetIlluminated(false);
×
58
        bt->SetBorder(false);
×
59
        bt = AddTextButton(curId + 2, DrawPoint(220, yPos), Extent(95, 22), textures[i], "Illuminated", NormalFont);
×
60
        bt->SetIlluminated(true);
×
61
        bt->SetBorder(false);
×
62
        bt = AddTextButton(curId + 3, DrawPoint(320, yPos), Extent(95, 22), textures[i], "Border", NormalFont);
×
63
        bt->SetIlluminated(false);
×
64
        bt->SetBorder(true);
×
65
        bt = AddTextButton(curId + 4, DrawPoint(420, yPos), Extent(95, 22), textures[i], "Both", NormalFont);
×
66
        bt->SetIlluminated(true);
×
67
        bt->SetBorder(true);
×
68
        curId += 5;
×
69
        yPos += 30;
×
70
    }
71
    RTTR_Assert(curId == ID_grpBtEnd);
×
72

73
    DrawPoint btPos(10, yPos);
×
74
    ctrlButton* bt = AddTextButton(ID_btAniBg, btPos, Extent(700, 40), TextureColor::Green2, "", NormalFont);
×
75
    bt->SetBorder(false);
×
76
    bt->SetEnabled(false);
×
77
    bt = AddTextButton(ID_btAni, btPos + DrawPoint(0, 5), Extent(30, 30), TextureColor::Red1, "", NormalFont);
×
78
    bt->SetBorder(false);
×
79
    bt->SetEnabled(false);
×
80
    bt->SetIlluminated(true);
×
81

82
    btPos.y += 45;
×
83
    AddEdit(ID_edtTest, btPos, Extent(150, 22), TextureColor::Green2, NormalFont, 0, false, false, true);
×
84
    btPos.x += 170;
×
85
    ctrlComboBox* cb = AddComboBox(ID_cbTxtSize, btPos, Extent(100, 22), TextureColor::Green2, NormalFont, 100);
×
NEW
86
    cb->AddItem("Small Font");
×
NEW
87
    cb->AddItem("Medium Font");
×
NEW
88
    cb->AddItem("Large Font");
×
89
    cb->SetSelection(0);
×
90
    btPos.x += 110;
×
91
    btPos.y += 11;
×
92
    AddText(ID_txtTest, btPos, "Enter something", COLOR_YELLOW, FontStyle::VCENTER, SmallFont);
×
93

94
    AddTextButton(ID_btDisable, DrawPoint(10, 540), Extent(150, 22), TextureColor::Green1, "Enable/Disable buttons",
×
95
                  NormalFont);
×
96
    AddTextButton(ID_btAnimate, DrawPoint(165, 540), Extent(80, 22), TextureColor::Green1, "Animate", NormalFont);
×
97
    AddTextButton(ID_btAnimateRepeat, DrawPoint(250, 540), Extent(110, 22), TextureColor::Green1, "Animate-Repeat",
×
98
                  NormalFont);
×
99
    AddTextButton(ID_btAnimateOscillate, DrawPoint(365, 540), Extent(110, 22), TextureColor::Green1,
×
100
                  "Animate-Oscillate", NormalFont);
×
101
    AddTextButton(ID_btHideCtrls, DrawPoint(480, 540), Extent(140, 22), TextureColor::Green1, "Hide all elements (H)",
×
102
                  NormalFont);
×
103
    AddTextButton(ID_btTextureTest, DrawPoint(625, 540), Extent(90, 22), TextureColor::Green1, "Texture test",
×
104
                  NormalFont);
×
105
    AddTextButton(ID_btShowBenchmark, DrawPoint(720, 540), Extent(80, 22), TextureColor::Green1, "Benchmark",
×
106
                  NormalFont);
×
107
}
×
108

109
void dskTest::Msg_EditChange(const unsigned ctrl_id)
×
110
{
111
    if(ctrl_id == ID_edtTest)
×
112
        GetCtrl<ctrlText>(ID_txtTest)->SetText(GetCtrl<ctrlEdit>(ID_edtTest)->GetText());
×
113
}
×
114

115
void dskTest::Msg_ComboSelectItem(const unsigned ctrl_id, const unsigned selection)
×
116
{
117
    if(ctrl_id == ID_cbTxtSize)
×
118
    {
119
        if(selection == 0)
×
120
            GetCtrl<ctrlText>(ID_txtTest)->SetFont(SmallFont);
×
121
        else if(selection == 1)
×
122
            GetCtrl<ctrlText>(ID_txtTest)->SetFont(NormalFont);
×
123
        else
124
            GetCtrl<ctrlText>(ID_txtTest)->SetFont(LargeFont);
×
125
    }
126
}
×
127

128
void dskTest::Msg_ButtonClick(const unsigned ctrl_id)
×
129
{
130
    switch(ctrl_id)
×
131
    {
132
        case ID_btTextureTest: WINDOWMANAGER.Switch(std::make_unique<dskTextureTest>()); break;
×
133
        case ID_btShowBenchmark: WINDOWMANAGER.Switch(std::make_unique<dskBenchmark>()); break;
×
134
        case ID_btDisable:
×
135
            for(unsigned i = ID_grpBtStart; i < ID_grpBtEnd; i++)
×
136
            {
137
                auto* bt = GetCtrl<ctrlButton>(i);
×
138
                if(bt)
×
139
                    bt->SetEnabled(!bt->GetEnabled());
×
140
            }
141
            break;
×
142
        case ID_btAnimate:
×
143
        case ID_btAnimateOscillate:
144
        case ID_btAnimateRepeat:
145
        {
146
            auto* btAniBg = GetCtrl<ctrlButton>(ID_btAniBg);
×
147
            auto* btAni = GetCtrl<ctrlButton>(ID_btAni);
×
148
            // Stop all
149
            GetAnimationManager().removeElementAnimations(btAni->GetID());
×
150
            GetAnimationManager().finishElementAnimations(ID_btAnimate, false);
×
151
            GetAnimationManager().finishElementAnimations(ID_btAnimateOscillate, false);
×
152
            GetAnimationManager().finishElementAnimations(ID_btAnimateRepeat, false);
×
153
            DrawPoint startPos(btAniBg->GetPos());
×
154
            startPos.y += 5;
×
155
            btAni->SetPos(startPos);
×
156
            DrawPoint endPos(startPos);
×
157
            endPos.x += btAniBg->GetSize().x - btAni->GetSize().x;
×
158
            Animation::RepeatType repeat = Animation::RepeatType::None;
×
159
            if(ctrl_id == ID_btAnimateOscillate)
×
160
                repeat = Animation::RepeatType::Oscillate;
×
161
            else if(ctrl_id == ID_btAnimateRepeat)
×
162
                repeat = Animation::RepeatType::Repeat;
×
163
            GetAnimationManager().addAnimation(new MoveAnimation(btAni, endPos, 4000, repeat));
×
164
            GetAnimationManager().addAnimation(new BlinkButtonAnim(GetCtrl<ctrlButton>(ctrl_id)));
×
165
            break;
×
166
        }
167
        case ID_btHideCtrls: ToggleCtrlVisibility();
×
168
    }
169
}
×
170

171
bool dskTest::Msg_RightUp(const MouseCoords& mc)
×
172
{
173
    std::vector<ctrlButton*> bts = GetCtrls<ctrlButton>();
×
174
    for(ctrlButton* bt : bts)
×
175
    {
176
        if(IsPointInRect(mc.pos, bt->GetDrawRect()))
×
177
        {
178
            bt->SetChecked(!bt->GetCheck());
×
179
            return true;
×
180
        }
181
    }
182
    return dskMenuBase::Msg_RightUp(mc);
×
183
}
184

185
void dskTest::ToggleCtrlVisibility()
×
186
{
187
    for(int i = ID_txtTitle; i <= ID_btHideCtrls; i++)
×
188
    {
189
        auto* ctrl = GetCtrl<Window>(i);
×
190
        if(ctrl)
×
191
            ctrl->SetVisible(!ctrl->IsVisible());
×
192
    }
193
}
×
194

195
bool dskTest::Msg_KeyDown(const KeyEvent& ke)
×
196
{
197
    if(ke.kt == KeyType::Char && ke.c == 'h')
×
198
        ToggleCtrlVisibility();
×
199
    else if(ke.kt == KeyType::Left)
×
200
    {
201
        curBGIdx = (curBGIdx > 0) ? curBGIdx - 1 : LOAD_SCREENS.size() - 1;
×
202
        background = LOADER.GetImageN(ResourceId(LOAD_SCREENS[curBGIdx]), 0);
×
203
    } else if(ke.kt == KeyType::Right)
×
204
    {
205
        curBGIdx = (curBGIdx < LOAD_SCREENS.size() - 1) ? curBGIdx + 1 : 0;
×
206
        background = LOADER.GetImageN(ResourceId(LOAD_SCREENS[curBGIdx]), 0);
×
207
    } else if(ke.kt == KeyType::Escape)
×
208
        WINDOWMANAGER.Switch(std::make_unique<dskMainMenu>());
×
209
    else
210
        return false;
×
211
    return true;
×
212
}
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