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

Return-To-The-Roots / s25client / 22797872430

07 Mar 2026 11:05AM UTC coverage: 50.156% (-0.2%) from 50.327%
22797872430

Pull #1890

github

web-flow
Merge 4597ccbf9 into d2a3730c9
Pull Request #1890: Add support for borderless Windows

155 of 626 new or added lines in 44 files covered. (24.76%)

26 existing lines in 9 files now uncovered.

23041 of 45939 relevant lines covered (50.16%)

44513.07 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,
57✔
16
                           const glFont* font, unsigned short max_list_height, bool readonly)
57✔
17
    : Window(parent, id, pos, size), tc(tc), font(font), max_list_height(max_list_height), readonly(readonly),
18
      suppressSelectEvent(false)
57✔
19
{
20
    AddList(0, DrawPoint(0, size.y), Extent(size.x, 4), tc, font)->SetVisible(false);
57✔
21

22
    if(!readonly)
57✔
23
        AddImageButton(1, DrawPoint(size.x - size.y, 0), Extent(size.y, size.y), tc, LOADER.GetImageN("io", 34));
70✔
24

25
    Resize(size);
57✔
26
}
57✔
27

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

32
    auto* button = GetCtrl<ctrlButton>(1);
330✔
33
    if(button)
330✔
34
    {
35
        button->SetPos(DrawPoint(newSize.x - newSize.y, 0));
210✔
36
        button->Resize(Extent(newSize.y, newSize.y));
210✔
37
    }
38

39
    auto* list = GetCtrl<ctrlList>(0);
330✔
40

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

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

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

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

62
    list->SetPos(DrawPoint(0, newSize.y));
330✔
63
    list->Resize(listSize);
330✔
64
}
65

66
boost::optional<std::string> ctrlComboBox::GetSelectedText() const
4✔
67
{
68
    const boost::optional<unsigned>& selection = GetSelection();
4✔
69
    if(selection)
4✔
70
        return GetText(*selection);
4✔
71
    else
72
        return boost::none;
×
73
}
74

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

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

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

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

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

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

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

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

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

124
    return ret;
×
125
}
126

127
bool ctrlComboBox::Msg_WheelUp(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✔
134
        return RelayMouseMessage(&Window::Msg_WheelUp, 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::Msg_WheelDown(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 ->
157
        return RelayMouseMessage(&Window::Msg_WheelDown, 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);
8✔
164
        return true;
4✔
165
    }
166

167
    return false;
×
168
}
169

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

177
void ctrlComboBox::Msg_ListSelectItem(unsigned, const int selection)
74✔
178
{
179
    // Liste wieder ausblenden
180
    ShowList(false);
74✔
181

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

190
void ctrlComboBox::AddItem(const std::string& text)
272✔
191
{
192
    GetCtrl<ctrlList>(0)->AddItem(text);
272✔
193
    Resize(GetSize());
272✔
194
}
272✔
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)
75✔
203
{
204
    // Avoid sending the change method when this is invoked intentionally
205
    suppressSelectEvent = true;
75✔
206
    GetCtrl<ctrlList>(0)->SetSelection(selection);
75✔
207
    suppressSelectEvent = false;
75✔
208
}
75✔
209

210
void ctrlComboBox::Draw_()
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::Msg_PaintAfter()
4✔
230
{
231
    // Draw list now so it is on top of everything
232
    GetCtrl<ctrlList>(0)->Draw();
4✔
233
    Window::Msg_PaintAfter();
4✔
234
}
4✔
235

236
void ctrlComboBox::ShowList(bool show)
74✔
237
{
238
    auto* list = GetCtrl<ctrlList>(0);
74✔
239
    if(list->IsVisible() == show)
74✔
240
        return;
74✔
241

242
    // list field
NEW
243
    list->SetVisible(show);
×
244
    // Arrow button
UNCOV
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
251
        GetParent()->FreeRegion(this);
×
252

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