• 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

68.38
/libs/s25main/controls/ctrlComboBox.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 "ctrlComboBox.h"
6
#include "CollisionDetection.h"
7
#include "Loader.h"
8
#include "ctrlButton.h"
9
#include "ctrlList.h"
10
#include "driver/MouseCoords.h"
11
#include "ogl/FontStyle.h"
12
#include "ogl/SoundEffectItem.h"
13
#include "ogl/glFont.h"
14

15
ctrlComboBox::ctrlComboBox(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
75 ✔
16
                           const glFont* font, unsigned short max_list_height, bool readonly)
75 ✔
17
    : Window(parent, id, pos, size), tc(tc), font(font), max_list_height(max_list_height), readonly(readonly),
18
      suppressSelectEvent(false)
75 ✔
19
{
20
    addList(0, DrawPoint(0, size.y), Extent(size.x, 4), tc, font)->setVisible(false);
75 ✔
21

22
    if(!readonly)
75 ✔
23
        addImageButton(1, DrawPoint(size.x - size.y, 0), Extent(size.y, size.y), tc, LOADER.getImageN("io", 34));
88 ✔
24

25
    resize(size);
75 ✔
26
}
75 ✔
27

28
void ctrlComboBox::resize(const Extent& newSize)
436 ✔
29
{
30
    Window::resize(newSize);
436 ✔
31

32
    auto* button = getCtrl<ctrlButton>(1);
436 ✔
33
    if(button)
436 ✔
34
    {
35
        button->setPos(DrawPoint(newSize.x - newSize.y, 0));
263 ✔
36
        button->resize(Extent(newSize.y, newSize.y));
263 ✔
37
    }
38

39
    auto* list = getCtrl<ctrlList>(0);
436 ✔
40

41
    Extent listSize(newSize.x, 4);
436 ✔
42

43
    // Langsam die Höhe der maximalen annähern
44
    for(unsigned i = 0; i < list->getNumLines(); ++i)
1,555 ✔
45
    {
46
        // zu große geworden?
47
        listSize.y += font->getHeight();
1,147 ✔
48
        unsigned short scaledMaxHeight = scaleIf(Extent(0, max_list_height)).y;
1,147 ✔
49

50
        if(listSize.y > scaledMaxHeight)
1,147 ✔
51
        {
52
            // kann nicht mal ein Item aufnehmen, dann raus
53
            if(i == 0)
28 ✔
54
                return;
×
55

56
            // Höhe um eins erniedrigen, damits wieder kleiner ist als die maximale
57
            listSize.y -= font->getHeight();
28 ✔
58
            break;
28 ✔
59
        }
60
    }
61

62
    list->setPos(DrawPoint(0, newSize.y));
436 ✔
63
    list->resize(listSize);
436 ✔
64
}
65

66
std::optional<std::string> ctrlComboBox::getSelectedText() const
4 ✔
67
{
68
    const std::optional<unsigned>& selection = getSelection();
4 ✔
69
    if(selection)
4 ✔
70
        return getText(*selection);
4 ✔
71
    else
72
        return std::nullopt;
×
73
}
74

NEW
75
bool ctrlComboBox::msgMouseMove(const MouseCoords& mc)
×
76
{
77
    // Für Button und Liste weiterleiten
NEW
78
    return relayMouseMessage(&Window::msgMouseMove, mc);
×
79
}
80

NEW
81
bool ctrlComboBox::msgLeftDown(const MouseCoords& mc)
×
82
{
NEW
83
    auto* list = getCtrl<ctrlList>(0);
×
84

85
    // Irgendwo anders hingeklickt --> Liste ausblenden
NEW
86
    if(!readonly && !IsPointInRect(mc.pos, getFullDrawRect(list)))
×
87
    {
88
        // Liste wieder ausblenden
NEW
89
        showList(false);
×
90
        return false;
×
91
    }
92

NEW
93
    if(!readonly && IsPointInRect(mc.pos, getDrawRect()))
×
94
    {
95
        // Liste wieder ein/ausblenden
NEW
96
        showList(!list->isVisible());
×
97
        return true;
×
98
    }
99

100
    // Für Button und Liste weiterleiten
NEW
101
    return relayMouseMessage(&Window::msgLeftDown, mc);
×
102
}
103

NEW
104
bool ctrlComboBox::msgLeftUp(const MouseCoords& mc)
×
105
{
106
    // Für Button und Liste weiterleiten
NEW
107
    return relayMouseMessage(&Window::msgLeftUp, mc);
×
108
}
109

NEW
110
bool ctrlComboBox::msgRightDown(const MouseCoords& mc)
×
111
{
NEW
112
    auto* list = getCtrl<ctrlList>(0);
×
113

114
    // Für Button und Liste weiterleiten (und danach erst schließen)
NEW
115
    bool ret = relayMouseMessage(&Window::msgRightDown, mc);
×
116

117
    // Clicked on list -> close it
NEW
118
    if(!readonly && IsPointInRect(mc.pos, list->getDrawRect()))
×
119
    {
120
        // Liste wieder ausblenden
NEW
121
        showList(false);
×
122
    }
123

124
    return ret;
×
125
}
126

127
bool ctrlComboBox::msgWheelUp(const MouseCoords& mc)
3 ✔
128
{
129
    if(readonly)
3 ✔
130
        return false;
×
131

132
    auto* list = getCtrl<ctrlList>(0);
3 ✔
133
    if(list->isVisible() && IsPointInRect(mc.pos, list->getDrawRect()))
3 ✔
NEW
134
        return relayMouseMessage(&Window::msgWheelUp, mc);
×
135

136
    if(IsPointInRect(mc.pos, getDrawRect()))
3 ✔
137
    {
138
        // Don't scroll too far down
139
        if(list->getSelection().value_or(0u) > 0u)
3 ✔
140
            list->setSelection(*list->getSelection() - 1u);
2 ✔
141
        return true;
3 ✔
142
    }
143

144
    return false;
×
145
}
146

147
bool ctrlComboBox::msgWheelDown(const MouseCoords& mc)
4 ✔
148
{
149
    if(readonly)
4 ✔
150
        return false;
×
151

152
    auto* list = getCtrl<ctrlList>(0);
4 ✔
153

154
    if(list->isVisible() && IsPointInRect(mc.pos, list->getDrawRect()))
4 ✔
155
    {
156
        // Scrolled in opened list ->
NEW
157
        return relayMouseMessage(&Window::msgWheelDown, mc);
×
158
    }
159

160
    if(IsPointInRect(mc.pos, getDrawRect()))
4 ✔
161
    {
162
        // Will be ignored by the list if to high
163
        list->setSelection(list->getSelection() ? *list->getSelection() + 1u : 0u);
4 ✔
164
        return true;
4 ✔
165
    }
166

167
    return false;
×
168
}
169

NEW
170
Rect ctrlComboBox::getFullDrawRect(const ctrlList* list)
×
171
{
NEW
172
    Rect myRect = getDrawRect();
×
NEW
173
    myRect.bottom = list->getDrawRect().bottom;
×
UNCOV
174
    return myRect;
×
175
}
176

177
void ctrlComboBox::msgListSelectItem(unsigned, const int selection)
95 ✔
178
{
179
    // Liste wieder ausblenden
180
    showList(false);
95 ✔
181

182
    // ist in der Liste überhaupt was drin?
183
    if(selection >= 0 && !suppressSelectEvent)
95 ✔
184
    {
185
        // Nachricht an übergeordnetes Fenster verschicken
186
        getParent()->msgComboSelectItem(getID(), selection);
5 ✔
187
    }
188
}
95 ✔
189

190
void ctrlComboBox::addItem(const std::string& text)
360 ✔
191
{
192
    getCtrl<ctrlList>(0)->addItem(text);
360 ✔
193
    resize(getSize());
360 ✔
194
}
360 ✔
195

196
void ctrlComboBox::deleteAllItems()
1 ✔
197
{
198
    getCtrl<ctrlList>(0)->deleteAllItems();
1 ✔
199
    resize(getSize());
1 ✔
200
}
1 ✔
201

202
void ctrlComboBox::setSelection(unsigned selection)
93 ✔
203
{
204
    // Avoid sending the change method when this is invoked intentionally
205
    suppressSelectEvent = true;
93 ✔
206
    getCtrl<ctrlList>(0)->setSelection(selection);
93 ✔
207
    suppressSelectEvent = false;
93 ✔
208
}
93 ✔
209

210
void ctrlComboBox::drawImpl()
4 ✔
211
{
212
    auto* liste = getCtrl<ctrlList>(0);
4 ✔
213

214
    draw3D(Rect(getDrawPos(), getSize()), tc, false);
4 ✔
215

216
    // Show selected item in the box
217
    if(liste->getNumLines() > 0)
4 ✔
218
    {
219
        font->draw(getDrawPos() + DrawPoint(2, getSize().y / 2), liste->getSelItemText(), FontStyle::VCENTER,
8 ✔
220
                   COLOR_YELLOW, getSize().x - 2 - getSize().y, "");
4 ✔
221
    }
222

223
    // Draw button manually as we can't use DrawControls which would draw the list we do in Msg_PaintAfter
224
    auto* button = getCtrl<ctrlButton>(1);
4 ✔
225
    if(button)
4 ✔
226
        button->draw();
4 ✔
227
}
4 ✔
228

229
void ctrlComboBox::msgPaintAfter()
4 ✔
230
{
231
    // Draw list now so it is on top of everything
232
    getCtrl<ctrlList>(0)->draw();
4 ✔
233
    Window::msgPaintAfter();
4 ✔
234
}
4 ✔
235

236
void ctrlComboBox::showList(bool show)
95 ✔
237
{
238
    auto* list = getCtrl<ctrlList>(0);
95 ✔
239
    if(list->isVisible() == show)
95 ✔
240
        return;
95 ✔
241

242
    // list field
NEW
243
    list->setVisible(show);
×
244
    // Arrow button
NEW
245
    getCtrl<ctrlButton>(1)->setChecked(show);
×
246

247
    // Lock/unlock region of extended list
248
    if(show)
×
NEW
249
        getParent()->lockRegion(this, list->getDrawRect());
×
250
    else
NEW
251
        getParent()->freeRegion(this);
×
252

NEW
253
    LOADER.getSoundN("sound", 113)->play(255, false);
×
254
}
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