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

Return-To-The-Roots / s25client / 24137503625

08 Apr 2026 01:18PM UTC coverage: 50.373%. First build
24137503625

Pull #1899

github

web-flow
Merge 3d3b4a9ad into e4146df45
Pull Request #1899: GUI: limit the scaling of ctrlTextButtons

83 of 92 new or added lines in 14 files covered. (90.22%)

23090 of 45838 relevant lines covered (50.37%)

43272.08 hits per line

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

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

5
#include "Window.h"
6
#include "CollisionDetection.h"
7
#include "Loader.h"
8
#include "RescaleWindowProp.h"
9
#include "commonDefines.h"
10
#include "controls/controls.h"
11
#include "driver/MouseCoords.h"
12
#include "drivers/ScreenResizeEvent.h"
13
#include "drivers/VideoDriverWrapper.h"
14
#include "helpers/containerUtils.h"
15
#include "ogl/IRenderer.h"
16
#include <boost/range/adaptor/map.hpp>
17
#include <boost/range/adaptor/reversed.hpp>
18
#include <cstdarg>
19

20
Window::Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size,
1,249✔
21
               const ScaleLimPercent& scalePercentage)
1,249✔
22
    : parent_(parent), id_(id), pos_(pos), size_(size), scalePercentage_(scalePercentage), active_(false),
23
      visible_(true), scale_(false), limit_(false), isInMouseRelay(false), animations_(this)
1,249✔
24
{
25
    SetScalePercentage(scalePercentage);
1,249✔
26
    if(parent != nullptr && parent->GetScale())
1,249✔
27
    {
28
        scale_ = parent->GetScale();
109✔
29
        limit_ = parent->GetLimit();
109✔
30
        Scale();
109✔
31
    }
32
}
1,249✔
33

34
Window::~Window()
1,249✔
35
{
36
    RTTR_Assert(!isInMouseRelay);
1,249✔
37
    // Steuerelemente aufräumen
38
    for(Window* ctrl : childIdToWnd_ | boost::adaptors::map_values)
2,336✔
39
        delete ctrl;
1,087✔
40
}
1,249✔
41

42
/**
43
 *  zeichnet das Fenster.
44
 */
45
void Window::Draw()
356✔
46
{
47
    if(visible_)
356✔
48
        Draw_();
349✔
49
}
356✔
50

51
DrawPoint Window::GetPos() const
1,123✔
52
{
53
    return pos_;
1,123✔
54
}
55

56
DrawPoint Window::GetDrawPos() const
1,049✔
57
{
58
    DrawPoint result = pos_;
1,049✔
59
    const Window* temp = this;
1,049✔
60

61
    // Relative Koordinaten in absolute umrechnen
62
    // ( d.h. Koordinaten von allen Eltern zusammenaddieren )
63
    while(temp->parent_)
2,286✔
64
    {
65
        temp = temp->parent_;
1,237✔
66
        result += temp->pos_;
1,237✔
67
    }
68

69
    return result;
1,049✔
70
}
71

72
Extent Window::GetSize() const
5,934✔
73
{
74
    return size_;
5,934✔
75
}
76

77
ScaleLimPercent Window::GetScalePercentage() const
10✔
78
{
79
    return scalePercentage_;
10✔
80
}
81

82
void Window::SetScalePercentage(ScaleLimPercent scalePercentage)
1,249✔
83
{
84
    if(scalePercentage.x > 100)
1,249✔
NEW
85
        scalePercentage.x = 100;
×
86

87
    if(scalePercentage.y > 100)
1,249✔
NEW
88
        scalePercentage.y = 100;
×
89

90
    scalePercentage_ = scalePercentage;
1,249✔
91
}
1,249✔
92

93
Rect Window::GetDrawRect() const
660✔
94
{
95
    return Rect(GetDrawPos(), GetSize());
660✔
96
}
97

98
Rect Window::GetBoundaryRect() const
482✔
99
{
100
    // Default to draw rect
101
    return GetDrawRect();
482✔
102
}
103

104
/**
105
 *  Sendet eine Fensternachricht an die Steuerelemente.
106
 *
107
 *  @param[in] msg   Die Nachricht.
108
 *  @param[in] id    Die ID des Quellsteuerelements.
109
 *  @param[in] param Ein nachrichtenspezifischer Parameter.
110
 */
111
bool Window::RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent& ke)
2✔
112
{
113
    // Abgeleitete Klassen fragen, ob das Weiterleiten von Nachrichten erlaubt ist
114
    // (IngameFenster könnten ja z.B. minimiert sein)
115
    if(!IsMessageRelayAllowed())
2✔
116
        return false;
×
117

118
    // Alle Controls durchgehen
119
    // Falls das Fenster dann plötzlich nich mehr aktiv ist (z.b. neues Fenster geöffnet, sofort abbrechen!)
120
    for(Window* wnd : childIdToWnd_ | boost::adaptors::map_values)
14✔
121
    {
122
        if(wnd->visible_ && wnd->active_ && CALL_MEMBER_FN(*wnd, msg)(ke))
12✔
123
            return true;
×
124
    }
125

126
    return false;
2✔
127
}
128

129
bool Window::RelayMouseMessage(MouseMsgHandler msg, const MouseCoords& mc)
113✔
130
{
131
    // Abgeleitete Klassen fragen, ob das Weiterleiten von Mausnachrichten erlaubt ist
132
    // (IngameFenster könnten ja z.B. minimiert sein)
133
    if(!IsMessageRelayAllowed())
113✔
134
        return false;
×
135

136
    bool processed = false;
113✔
137
    isInMouseRelay = true;
113✔
138

139
    // Alle Controls durchgehen
140
    // Use reverse iterator because the topmost (=last elements) should receive the messages first!
141
    for(Window* wnd : childIdToWnd_ | boost::adaptors::map_values | boost::adaptors::reversed)
448✔
142
    {
143
        if(!lockedAreas_.empty() && IsInLockedRegion(mc.pos, wnd))
335✔
144
            continue;
×
145

146
        if(wnd->visible_ && wnd->active_ && CALL_MEMBER_FN(*wnd, msg)(mc))
335✔
147
            processed = true;
1✔
148
    }
149

150
    for(auto* tofreeArea : tofreeAreas_)
113✔
151
        lockedAreas_.erase(tofreeArea);
×
152
    tofreeAreas_.clear();
113✔
153
    isInMouseRelay = false;
113✔
154

155
    return processed;
113✔
156
}
157

158
/**
159
 *  aktiviert das Fenster.
160
 *
161
 *  @param[in] activate Fenster aktivieren?
162
 */
163
void Window::SetActive(bool activate)
2,378✔
164
{
165
    this->active_ = activate;
2,378✔
166
    ActivateControls(activate);
2,378✔
167
}
2,378✔
168

169
/**
170
 *  aktiviert die Steuerelemente des Fensters.
171
 *
172
 *  @param[in] activate Steuerelemente aktivieren?
173
 */
174
void Window::ActivateControls(bool activate)
2,378✔
175
{
176
    for(auto& it : childIdToWnd_)
3,444✔
177
        it.second->SetActive(activate);
1,066✔
178
}
2,378✔
179

180
/**
181
 *  sperrt eine Region eines Fensters.
182
 *
183
 *  @param[in] window das Fenster, welches die Region sperrt.
184
 *  @param[in] rect   das Rechteck, welches die Region beschreibt.
185
 */
186
void Window::LockRegion(Window* window, const Rect& rect)
×
187
{
188
    lockedAreas_[window] = rect;
×
189
    auto it = helpers::find(tofreeAreas_, window);
×
190
    if(it != tofreeAreas_.end())
×
191
        tofreeAreas_.erase(it);
×
192

193
    // Also lock the region for all parents
194
    if(GetParent())
×
195
        GetParent()->LockRegion(this, rect);
×
196
}
×
197

198
/**
199
 *  Gibt eine gesperrte Region wieder frei.
200
 *
201
 *  @param[in] window das Fenster, welches die Region sperrt.
202
 */
203
void Window::FreeRegion(Window* window)
×
204
{
205
    // We need to keep all locked areas otherwise a closed dropdown will enable "click-through" to below control
206
    if(isInMouseRelay)
×
207
        tofreeAreas_.push_back(window);
×
208
    else
209
        lockedAreas_.erase(window);
×
210

211
    // Also free the locked region for all parents
212
    if(GetParent())
×
213
        GetParent()->FreeRegion(this);
×
214
}
×
215

216
void Window::SetPos(const DrawPoint& newPos)
1,342✔
217
{
218
    pos_ = newPos;
1,342✔
219
}
1,342✔
220

221
/// Weiterleitung von Nachrichten von abgeleiteten Klassen erlaubt oder nicht?
222
bool Window::IsMessageRelayAllowed() const
110✔
223
{
224
    return true;
110✔
225
}
226

227
void Window::DeleteCtrl(unsigned id)
2✔
228
{
229
    auto it = childIdToWnd_.find(id);
2✔
230

231
    if(it == childIdToWnd_.end())
2✔
232
        return;
2✔
233

234
    delete it->second;
×
235

236
    childIdToWnd_.erase(it);
×
237
}
238

239
ctrlBuildingIcon* Window::AddBuildingIcon(unsigned id, const DrawPoint& pos, BuildingType type, const Nation nation,
26✔
240
                                          unsigned short size, const std::string& tooltip)
241
{
242
    return AddCtrl(new ctrlBuildingIcon(this, id, pos, type, nation, Extent(size, 0).x, tooltip));
26✔
243
}
244

245
ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc,
86✔
246
                                  const std::string& text, const glFont* font, const std::string& tooltip)
247
{
248
    return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, ScaleLimPercent(30, 50)));
86✔
249
}
250

251
ctrlButton* Window::AddColorButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc,
1✔
252
                                   const unsigned fillColor, const std::string& tooltip)
253
{
254
    return AddCtrl(new ctrlColorButton(this, id, pos, size, tc, fillColor, tooltip));
1✔
255
}
256

257
ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc,
351✔
258
                                   ITexture* const image, const std::string& tooltip)
259
{
260
    return AddCtrl(new ctrlImageButton(this, id, pos, size, tc, image, tooltip));
351✔
261
}
262

263
ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc,
351✔
264
                                   glArchivItem_Bitmap* const image, const std::string& tooltip)
265
{
266
    return AddImageButton(id, pos, size, tc, static_cast<ITexture*>(image), tooltip);
351✔
267
}
268

269
ctrlChat* Window::AddChatCtrl(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
2✔
270
                              const glFont* font)
271
{
272
    return AddCtrl(new ctrlChat(this, id, pos, size, tc, font));
2✔
273
}
274

275
ctrlCheck* Window::AddCheckBox(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
49✔
276
                               const std::string& text, const glFont* font, bool readonly)
277
{
278
    return AddCtrl(new ctrlCheck(this, id, pos, size, tc, text, font, readonly));
49✔
279
}
280

281
ctrlComboBox* Window::AddComboBox(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
55✔
282
                                  const glFont* font, unsigned short max_list_height, bool readonly)
283
{
284
    return AddCtrl(new ctrlComboBox(this, id, pos, size, tc, font, max_list_height, readonly));
55✔
285
}
286

287
ctrlDeepening* Window::AddTextDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
9✔
288
                                        const std::string& text, const glFont* font, unsigned color, FontStyle style)
289
{
290
    return AddCtrl(new ctrlTextDeepening(this, id, pos, size, tc, text, font, color, style));
9✔
291
}
292

293
ctrlDeepening* Window::AddColorDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
×
294
                                         unsigned fillColor)
295
{
NEW
296
    return AddCtrl(new ctrlColorDeepening(this, id, pos, size, tc, fillColor));
×
297
}
298

299
ctrlDeepening* Window::AddImageDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
×
300
                                         ITexture* image)
301
{
NEW
302
    return AddCtrl(new ctrlImageDeepening(this, id, pos, size, tc, image));
×
303
}
304

305
ctrlDeepening* Window::AddImageDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
×
306
                                         glArchivItem_Bitmap* image)
307
{
308
    return AddImageDeepening(id, pos, size, tc, static_cast<ITexture*>(image));
×
309
}
310

311
ctrlEdit* Window::AddEdit(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font,
6✔
312
                          unsigned short maxlength, bool password, bool disabled, bool notify)
313
{
314
    return AddCtrl(new ctrlEdit(this, id, pos, size, tc, font, maxlength, password, disabled, notify));
6✔
315
}
316

317
ctrlGroup* Window::AddGroup(unsigned id)
101✔
318
{
319
    return AddCtrl(new ctrlGroup(this, id));
101✔
320
}
321

322
ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, ITexture* image, const std::string& tooltip)
54✔
323
{
324
    return AddCtrl(new ctrlImage(this, id, pos, image, tooltip));
54✔
325
}
326

327
ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, glArchivItem_Bitmap* image, const std::string& tooltip)
54✔
328
{
329
    return AddImage(id, pos, static_cast<ITexture*>(image), tooltip);
54✔
330
}
331

332
ctrlList* Window::AddList(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font)
57✔
333
{
334
    return AddCtrl(new ctrlList(this, id, pos, size, tc, font));
57✔
335
}
336

337
ctrlMultiline* Window::AddMultiline(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
13✔
338
                                    const glFont* font, FontStyle format)
339
{
340
    return AddCtrl(new ctrlMultiline(this, id, pos, size, tc, font, format));
13✔
341
}
342

343
/**
344
 *  fügt ein OptionenGruppe hinzu.
345
 *
346
 *  @param[in] id          ID des Steuerelements
347
 *  @param[in] select_type Typ der Auswahl
348
 *
349
 *  @return Instanz das Steuerelement.
350
 */
351
ctrlOptionGroup* Window::AddOptionGroup(unsigned id, GroupSelectType select_type)
4✔
352
{
353
    return AddCtrl(new ctrlOptionGroup(this, id, select_type));
4✔
354
}
355

356
/**
357
 *  fügt ein MultiSelectGruppe hinzu.
358
 *
359
 *  @param[in] id          ID des Steuerelements
360
 *  @param[in] select_type Typ der Auswahl
361
 *
362
 *  @return Instanz das Steuerelement.
363
 */
364
ctrlMultiSelectGroup* Window::AddMultiSelectGroup(unsigned id, GroupSelectType select_type)
×
365
{
366
    return AddCtrl(new ctrlMultiSelectGroup(this, id, select_type));
×
367
}
368

369
ctrlPercent* Window::AddPercent(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
3✔
370
                                unsigned text_color, const glFont* font, const unsigned short* percentage)
371
{
372
    return AddCtrl(new ctrlPercent(this, id, pos, size, tc, text_color, font, percentage));
3✔
373
}
374

375
ctrlProgress* Window::AddProgress(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
7✔
376
                                  unsigned short button_minus, unsigned short button_plus, unsigned short maximum,
377
                                  const std::string& tooltip, const Extent& padding, unsigned force_color,
378
                                  const std::string& button_minus_tooltip, const std::string& button_plus_tooltip)
379
{
380
    return AddCtrl(new ctrlProgress(this, id, pos, size, tc, button_minus, button_plus, maximum, padding, force_color,
7✔
381
                                    tooltip, button_minus_tooltip, button_plus_tooltip));
14✔
382
}
383

384
ctrlScrollBar* Window::AddScrollBar(unsigned id, const DrawPoint& pos, const Extent& size, unsigned short button_height,
76✔
385
                                    TextureColor tc, unsigned short page_size)
386
{
387
    button_height = Extent(0, button_height).y;
76✔
388

389
    return AddCtrl(new ctrlScrollBar(this, id, pos, size, button_height, tc, page_size));
76✔
390
}
391

392
ctrlTab* Window::AddTabCtrl(unsigned id, const DrawPoint& pos, unsigned short width)
3✔
393
{
394
    return AddCtrl(new ctrlTab(this, id, pos, Extent(width, 0).x));
3✔
395
}
396

397
/**
398
 *  fügt eine Tabelle hinzu.
399
 *  ... sollte eine Menge von const char*, int und SortType sein
400
 */
401
ctrlTable* Window::AddTable(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font,
×
402
                            std::vector<TableColumn> columns)
403
{
NEW
404
    return AddCtrl(new ctrlTable(this, id, pos, size, tc, font, std::move(columns)));
×
405
}
406

407
ctrlTimer* Window::AddTimer(unsigned id, std::chrono::milliseconds timeout)
5✔
408
{
409
    return AddCtrl(new ctrlTimer(this, id, timeout));
5✔
410
}
411

412
/**
413
 *  fügt ein TextCtrl hinzu.
414
 *
415
 *  @param[in] x      X-Koordinate des Steuerelements
416
 *  @param[in] y      Y-Koordinate des Steuerelements
417
 *  @param[in] text   Text
418
 *  @param[in] color  Textfarbe
419
 *  @param[in] format Formatierung des Textes
420
 *                      @p FontStyle::LEFT    - Text links ( standard )
421
 *                      @p FontStyle::CENTER  - Text mittig
422
 *                      @p FontStyle::RIGHT   - Text rechts
423
 *                      @p FontStyle::TOP     - Text oben ( standard )
424
 *                      @p FontStyle::VCENTER - Text vertikal zentriert
425
 *                      @p FontStyle::BOTTOM  - Text unten
426
 *  @param[in] font   Schriftart
427
 */
428
ctrlText* Window::AddText(unsigned id, const DrawPoint& pos, const std::string& text, unsigned color, FontStyle format,
166✔
429
                          const glFont* font)
430
{
431
    return AddCtrl(new ctrlText(this, id, pos, text, color, format, font));
166✔
432
}
433

434
ctrlMapSelection* Window::AddMapSelection(unsigned id, const DrawPoint& pos, const Extent& size,
×
435
                                          const SelectionMapInputData& inputData)
436
{
NEW
437
    return AddCtrl(new ctrlMapSelection(this, id, pos, size, inputData));
×
438
}
439

440
TextFormatSetter Window::AddFormattedText(unsigned id, const DrawPoint& pos, const std::string& text, unsigned color,
×
441
                                          FontStyle format, const glFont* font)
442
{
443
    return AddText(id, pos, text, color, format, font);
×
444
}
445

446
ctrlVarDeepening* Window::AddVarDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
1✔
447
                                          const std::string& formatstr, const glFont* font, unsigned color,
448
                                          unsigned parameters, ...)
449
{
450
    va_list liste;
451
    va_start(liste, parameters);
1✔
452

453
    auto* ctrl = new ctrlVarDeepening(this, id, pos, size, tc, formatstr, font, color, parameters, liste);
1✔
454

455
    va_end(liste);
1✔
456

457
    return AddCtrl(ctrl);
2✔
458
}
459

460
/**
461
 *  fügt ein variables TextCtrl hinzu.
462
 *
463
 *  @param[in] x          X-Koordinate des Steuerelements
464
 *  @param[in] y          Y-Koordinate des Steuerelements
465
 *  @param[in] formatstr  Der Formatstring des Steuerelements
466
 *  @param[in] color      Textfarbe
467
 *  @param[in] format     Formatierung des Textes
468
 *                          @p FontStyle::LEFT    - Text links ( standard )
469
 *                          @p FontStyle::CENTER  - Text mittig
470
 *                          @p FontStyle::RIGHT   - Text rechts
471
 *                          @p FontStyle::TOP     - Text oben ( standard )
472
 *                          @p FontStyle::VCENTER - Text vertikal zentriert
473
 *                          @p FontStyle::BOTTOM  - Text unten
474
 *  @param[in] font       Schriftart
475
 *  @param[in] parameters Anzahl der nachfolgenden Parameter
476
 *  @param[in] ...        die variablen Parameter
477
 */
478
ctrlVarText* Window::AddVarText(unsigned id, const DrawPoint& pos, const std::string& formatstr, unsigned color,
×
479
                                FontStyle format, const glFont* font, unsigned parameters, ...)
480
{
481
    va_list liste;
482
    va_start(liste, parameters);
×
483

NEW
484
    auto* ctrl = new ctrlVarText(this, id, pos, formatstr, color, format, font, parameters, liste);
×
485

486
    va_end(liste);
×
487

488
    return AddCtrl(ctrl);
×
489
}
490

491
ctrlPreviewMinimap* Window::AddPreviewMinimap(const unsigned id, const DrawPoint& pos, const Extent& size,
×
492
                                              libsiedler2::ArchivItem_Map* const map)
493
{
NEW
494
    return AddCtrl(new ctrlPreviewMinimap(this, id, pos, size, map));
×
495
}
496

497
void Window::Draw3D(const Rect& rect, TextureColor tc, bool elevated, bool highlighted, bool illuminated,
36✔
498
                    unsigned contentColor)
499
{
500
    const Extent rectSize = rect.getSize();
36✔
501
    if(rectSize.x < 4 || rectSize.y < 4)
36✔
502
        return;
×
503
    Draw3DBorder(rect, tc, elevated);
36✔
504
    // Move content inside border
505
    Rect contentRect(rect.getOrigin() + Position(2, 2), rectSize - Extent(4, 4));
36✔
506
    Draw3DContent(contentRect, tc, elevated, highlighted, illuminated, contentColor);
36✔
507
}
508

509
void Window::Draw3DBorder(const Rect& rect, TextureColor tc, bool elevated)
36✔
510
{
511
    if(tc == TextureColor::Invisible)
36✔
512
        return;
×
513
    glArchivItem_Bitmap* borderImg = LOADER.GetImageN("io", 12 + rttr::enum_cast(tc));
72✔
514
    VIDEODRIVER.GetRenderer()->Draw3DBorder(rect, elevated, *borderImg);
36✔
515
}
516

517
void Window::Draw3DContent(const Rect& rect, TextureColor tc, bool elevated, bool highlighted, bool illuminated,
68✔
518
                           unsigned contentColor)
519
{
520
    if(tc == TextureColor::Invisible)
68✔
521
        return;
×
522
    glArchivItem_Bitmap* contentImg = LOADER.GetImageN("io", rttr::enum_cast(tc) * 2 + (highlighted ? 0 : 1));
136✔
523
    VIDEODRIVER.GetRenderer()->Draw3DContent(rect, elevated, *contentImg, illuminated, contentColor);
68✔
524
}
525

526
void Window::DrawRectangle(const Rect& rect, unsigned color)
266✔
527
{
528
    VIDEODRIVER.GetRenderer()->DrawRect(rect, color);
266✔
529
}
266✔
530

531
void Window::DrawLine(DrawPoint pt1, DrawPoint pt2, unsigned short width, unsigned color)
×
532
{
533
    VIDEODRIVER.GetRenderer()->DrawLine(pt1, pt2, width, color);
×
534
}
×
535

536
void Window::Msg_PaintBefore()
305✔
537
{
538
    animations_.update(VIDEODRIVER.GetTickCount());
305✔
539
    for(Window* control : childIdToWnd_ | boost::adaptors::map_values)
479✔
540
        control->Msg_PaintBefore();
174✔
541
}
305✔
542

543
void Window::Msg_PaintAfter()
351✔
544
{
545
    for(Window* control : childIdToWnd_ | boost::adaptors::map_values)
544✔
546
        control->Msg_PaintAfter();
193✔
547
}
351✔
548

549
void Window::Draw_()
157✔
550
{
551
    for(Window* control : childIdToWnd_ | boost::adaptors::map_values)
340✔
552
        control->Draw();
183✔
553
}
157✔
554

555
void Window::Msg_ScreenResize(const ScreenResizeEvent& sr)
18✔
556
{
557
    // If the window elements don't get scaled there is nothing to do
558
    if(!scale_)
18✔
559
        return;
×
560
    ScaleWindowProp rescale(sr.oldSize, sr.newSize);
18✔
561
    for(Window* ctrl : childIdToWnd_ | boost::adaptors::map_values)
28✔
562
    {
563
        if(!ctrl)
10✔
564
            continue;
×
565
        // Save new size (could otherwise be changed(?) in Msg_ScreenResize)
566
        ScaleLimPercent limits(100, 100);
10✔
567
        if(limit_)
10✔
568
            limits = ctrl->GetScalePercentage();
10✔
569
        Extent newSize = rescale(ctrl->GetSize(), limits);
10✔
570
        ctrl->SetPos(rescale(ctrl->GetPos()));
10✔
571
        ctrl->Msg_ScreenResize(sr);
10✔
572
        ctrl->Resize(newSize);
10✔
573
    }
574
    animations_.onRescale(sr);
18✔
575
}
576

577
template<class T_Pt>
578
T_Pt Window::Scale(const T_Pt& pt, const ScaleLimPercent& scalePercentage)
80✔
579
{
580
    return ScaleWindowProp::scale(pt, VIDEODRIVER.GetRenderSize(), scalePercentage);
80✔
581
}
582

583
void Window::Scale()
109✔
584
{
585
    pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize());
109✔
586
    size_ =
587
      ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), limit_ ? scalePercentage_ : ScaleLimPercent(100, 100));
109✔
588
}
109✔
589

590
template<class T_Pt>
591
T_Pt Window::ScaleIf(const T_Pt& pt) const
877✔
592
{
593
    return scale_ ? Scale(pt) : pt;
1,754✔
594
}
595

596
// Inlining removes those. so add it here
597
template DrawPoint Window::ScaleIf(const DrawPoint&) const;
598
template Extent Window::ScaleIf(const Extent&) const;
599

600
bool Window::IsInLockedRegion(const Position& pos, const Window* exception) const
×
601
{
602
    for(const auto& lockEntry : lockedAreas_)
×
603
    {
604
        // Ignore exception
605
        if(lockEntry.first == exception)
×
606
            continue;
×
607
        if(IsPointInRect(pos, lockEntry.second))
×
608
            return true;
×
609
    }
610
    return false;
×
611
}
612

613
bool Window::IsMouseOver() const
138✔
614
{
615
    return IsMouseOver(VIDEODRIVER.GetMousePos());
138✔
616
}
617

618
bool Window::IsMouseOver(const MouseCoords& mousePos) const
465✔
619
{
620
    return IsPointInRect(mousePos.pos, GetBoundaryRect());
465✔
621
}
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