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

Return-To-The-Roots / s25client / 44076625557

17 Nov 2026 11:43AM UTC coverage: 51.803% (-0.002%) from 51.805%
44076625557

push

github

web-flow
Merge pull request #2018 from Return-To-The-Roots/refactor/lowerCamelCase-methods

Rename Msg_* handlers to lowerCamelCase

8121 of 16693 new or added lines in 565 files covered. (48.65%)

323 existing lines in 133 files now uncovered.

24236 of 46785 relevant lines covered (51.8%)

49647.74 hits per line

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

16.16
/libs/s25main/controls/ctrlProgress.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 "ctrlProgress.h"
6
#include "CollisionDetection.h"
7
#include "Loader.h"
8
#include "WindowManager.h"
9
#include "helpers/mathFuncs.h"
10
#include "ogl/FontStyle.h"
11
#include "ogl/glFont.h"
12

13
ctrlProgress::ctrlProgress(Window* parent, const unsigned id, const DrawPoint& pos, const Extent& size,
7 ✔
14
                           const TextureColor tc, unsigned short button_minus, unsigned short button_plus,
15
                           const unsigned short maximum, const Extent& padding, const unsigned force_color,
16
                           const std::string& tooltip, const std::string& button_minus_tooltip,
17
                           const std::string& button_plus_tooltip, unsigned short* const /*write_val*/)
7 ✔
18
    : Window(parent, id, pos, size), ctrlBaseTooltip(tooltip), tc(tc), position(0), maximum(maximum), padding_(padding),
19
      force_color(force_color)
7 ✔
20
{
21
    ResourceId btMinusRes = "io", btPlusRes = "io";
7 ✔
22
    if(button_minus >= 1000)
7 ✔
23
    {
24
        btMinusRes = "io_new";
×
25
        button_minus -= 1000;
×
26
    }
27
    if(button_plus >= 1000)
7 ✔
28
    {
29
        btPlusRes = "io_new";
×
30
        button_plus -= 1000;
×
31
    }
32

33
    Extent btSize = Extent::all(size.y);
7 ✔
34
    addImageButton(0, DrawPoint(0, 0), btSize, tc, LOADER.getImageN(btMinusRes, button_minus),
7 ✔
35
                   (!button_minus_tooltip.empty() ? button_minus_tooltip : _("Less")));
14 ✔
36
    addImageButton(1, DrawPoint(size.x - btSize.x, 0), btSize, tc, LOADER.getImageN(btPlusRes, button_plus),
7 ✔
37
                   (!button_plus_tooltip.empty() ? button_plus_tooltip : _("More")));
14 ✔
38

39
    // Hide left and right 3D border by making the buttons overlap the bar
40
    padding_.x -= 2;
7 ✔
41
}
7 ✔
42

43
/**
44
 *  setzt die Position an den angegebenen Wert.
45
 */
46
void ctrlProgress::setPosition(unsigned short position)
14 ✔
47
{
48
    this->position = std::min(position, maximum);
14 ✔
49
}
14 ✔
50

51
/**
52
 *  Zeichenmethode.
53
 *
54
 *  @return @p true bei Erfolg, @p false bei Fehler
55
 */
NEW
56
void ctrlProgress::drawImpl()
×
57
{
NEW
58
    DrawPoint barPos = getDrawPos() + DrawPoint(padding_);
×
59
    // Offset by button size
NEW
60
    barPos.x += getSize().y;
×
NEW
61
    Extent barSize(calcBarWidth(), getSize().y - 2 * padding_.y);
×
NEW
62
    draw3D(Rect(barPos, barSize), tc, false);
×
63

64
    // Buttons
NEW
65
    Window::drawImpl();
×
66

67
    const DrawPoint innerPadding(4, 4);
×
68
    unsigned percentage = position * 100 / maximum;
×
NEW
69
    unsigned progress = (calcBarWidth() - innerPadding.x * 2) * position / maximum;
×
70

71
    // Farbe herausfinden
72
    unsigned color = 0xFFD70000;
×
73

74
    // Feste Farbe?
75
    if(force_color)
×
76
        color = force_color;
×
77
    else
78
    {
79
        // Farbe wählen je nachdem wie viel Prozent
80
        if(percentage >= 60)
×
81
            color = 0xFF71B63C;
×
82
        else if(percentage >= 30)
×
83
            color = 0xFFFFBF33;
×
84
        else if(percentage >= 20)
×
85
            color = 0xFFDB7428;
×
86
    }
87

88
    // Leiste
NEW
89
    drawRectangle(Rect(barPos + innerPadding, progress, getSize().y - 2 * (innerPadding.y + padding_.y)), color);
×
90

91
    // Prozentzahlen zeichnen
NEW
92
    SmallFont->draw(getDrawPos() + DrawPoint(getSize()) / 2, std::to_string(percentage) + "%",
×
93
                    FontStyle::CENTER | FontStyle::VCENTER, COLOR_YELLOW);
94
}
×
95

NEW
96
void ctrlProgress::resize(const Extent& newSize)
×
97
{
NEW
98
    Window::resize(newSize);
×
99

NEW
100
    auto* lessBt = getCtrl<Window>(0);
×
NEW
101
    auto* moreBt = getCtrl<Window>(1);
×
102
    Extent btSize(newSize.y, newSize.y);
×
NEW
103
    lessBt->resize(btSize);
×
NEW
104
    moreBt->resize(btSize);
×
NEW
105
    moreBt->setPos(DrawPoint(newSize.x - btSize.x, 0));
×
UNCOV
106
}
×
107

NEW
108
unsigned ctrlProgress::calcBarWidth() const
×
109
{
NEW
110
    return getSize().x - 2 * (padding_.x + getSize().y);
×
111
}
112

NEW
113
void ctrlProgress::msgButtonClick(const unsigned ctrl_id)
×
114
{
115
    switch(ctrl_id)
×
116
    {
117
        case 0: // Minus
×
118
        {
119
            if(position)
×
120
                --position;
×
NEW
121
            if(getParent())
×
NEW
122
                getParent()->msgProgressChange(getID(), position);
×
123
        }
124
        break;
×
125
        case 1: // Plus
×
126
        {
127
            if(position < maximum)
×
128
                ++position;
×
NEW
129
            if(getParent())
×
NEW
130
                getParent()->msgProgressChange(getID(), position);
×
131
        }
132
        break;
×
133
    }
134
}
×
135

NEW
136
bool ctrlProgress::msgLeftDown(const MouseCoords& mc)
×
137
{
138
    // Test if clicked on progress bar
NEW
139
    DrawPoint progressOrigin = getDrawPos() + DrawPoint(padding_) + DrawPoint(getSize().y + 2, 4);
×
NEW
140
    Extent progressSize = getSize() - Extent((getSize().y + 1) * 2, 8) - padding_ * 2u;
×
UNCOV
141
    if(IsPointInRect(mc.pos, Rect(progressOrigin, progressSize)))
×
142
    {
143
        position =
×
144
          helpers::iround<uint16_t>(static_cast<double>((mc.pos.x - progressOrigin.x) * maximum) / progressSize.x);
×
145

NEW
146
        if(getParent())
×
NEW
147
            getParent()->msgProgressChange(getID(), position);
×
UNCOV
148
        return true;
×
149
    } else
NEW
150
        return relayMouseMessage(&Window::msgLeftDown, mc);
×
151
}
152

NEW
153
bool ctrlProgress::msgLeftUp(const MouseCoords& mc)
×
154
{
NEW
155
    return relayMouseMessage(&Window::msgLeftUp, mc);
×
156
}
157

NEW
158
bool ctrlProgress::msgWheelUp(const MouseCoords& mc)
×
159
{
160
    // If mouse is over the controls, simulate button click
NEW
161
    if(IsPointInRect(mc.pos, getDrawRect()))
×
162
    {
NEW
163
        msgButtonClick(1);
×
164
        return true;
×
165
    }
166
    return false;
×
167
}
168

NEW
169
bool ctrlProgress::msgWheelDown(const MouseCoords& mc)
×
170
{
171
    // If mouse is over the controls, simulate button click
NEW
172
    if(IsPointInRect(mc.pos, getDrawRect()))
×
173
    {
NEW
174
        msgButtonClick(0);
×
175
        return true;
×
176
    }
177
    return false;
×
178
}
179

NEW
180
bool ctrlProgress::msgMouseMove(const MouseCoords& mc)
×
181
{
182
    // an Buttons weiterleiten
NEW
183
    relayMouseMessage(&Window::msgMouseMove, mc);
×
184

NEW
185
    Extent offset(getSize().y + padding_.x, 0);
×
NEW
186
    DrawPoint rectOrig = getDrawPos() + DrawPoint(offset);
×
NEW
187
    Extent rectSize = getSize() - offset * 2u;
×
UNCOV
188
    if(IsPointInRect(mc.pos, Rect(rectOrig, rectSize)))
×
189
    {
NEW
190
        WINDOWMANAGER.setToolTip(this, tooltip_);
×
191
        return true;
×
192
    } else
193
    {
NEW
194
        WINDOWMANAGER.setToolTip(this, "");
×
195
        return false;
×
196
    }
197
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc