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

Return-To-The-Roots / s25client / 23405568674

22 Mar 2026 02:51PM UTC coverage: 50.383%. First build
23405568674

Pull #1899

github

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

89 of 96 new or added lines in 14 files covered. (92.71%)

23096 of 45841 relevant lines covered (50.38%)

43008.34 hits per line

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

75.53
/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, const LimitFactors& factors)
1,249✔
21
    : parent_(parent), id_(id), pos_(pos), size_(size), limitFactors_(factors), active_(false),
22
      visible_(true), scale_(false), limit_(false), isInMouseRelay(false), animations_(this)
1,249✔
23
{
24
    if(parent != nullptr && parent->GetScale())
1,249✔
25
    {
26
        scale_ = parent->GetScale();
109✔
27
        limit_ = parent->GetLimit();
109✔
28
        ScaleByFactor();
109✔
29
    }
30
}
1,249✔
31

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

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

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

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

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

67
    return result;
1,049✔
68
}
69

70
Extent Window::GetSize() const
5,948✔
71
{
72
    return size_;
5,948✔
73
}
74

75
LimitFactors Window::GetLimitFactors() const
10✔
76
{
77
    return limitFactors_;
10✔
78
}
79

80
void Window::SetLimitFactors(LimitFactors limitFactors)
88✔
81
{
82
    limitFactors_ = limitFactors;
88✔
83
}
88✔
84

85
Rect Window::GetDrawRect() const
660✔
86
{
87
    return Rect(GetDrawPos(), GetSize());
660✔
88
}
89

90
Rect Window::GetBoundaryRect() const
482✔
91
{
92
    // Default to draw rect
93
    return GetDrawRect();
482✔
94
}
95

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

110
    // Alle Controls durchgehen
111
    // Falls das Fenster dann plötzlich nich mehr aktiv ist (z.b. neues Fenster geöffnet, sofort abbrechen!)
112
    for(Window* wnd : childIdToWnd_ | boost::adaptors::map_values)
14✔
113
    {
114
        if(wnd->visible_ && wnd->active_ && CALL_MEMBER_FN(*wnd, msg)(ke))
12✔
115
            return true;
×
116
    }
117

118
    return false;
2✔
119
}
120

121
bool Window::RelayMouseMessage(MouseMsgHandler msg, const MouseCoords& mc)
113✔
122
{
123
    // Abgeleitete Klassen fragen, ob das Weiterleiten von Mausnachrichten erlaubt ist
124
    // (IngameFenster könnten ja z.B. minimiert sein)
125
    if(!IsMessageRelayAllowed())
113✔
126
        return false;
×
127

128
    bool processed = false;
113✔
129
    isInMouseRelay = true;
113✔
130

131
    // Alle Controls durchgehen
132
    // Use reverse iterator because the topmost (=last elements) should receive the messages first!
133
    for(Window* wnd : childIdToWnd_ | boost::adaptors::map_values | boost::adaptors::reversed)
448✔
134
    {
135
        if(!lockedAreas_.empty() && IsInLockedRegion(mc.pos, wnd))
335✔
136
            continue;
×
137

138
        if(wnd->visible_ && wnd->active_ && CALL_MEMBER_FN(*wnd, msg)(mc))
335✔
139
            processed = true;
1✔
140
    }
141

142
    for(auto* tofreeArea : tofreeAreas_)
113✔
143
        lockedAreas_.erase(tofreeArea);
×
144
    tofreeAreas_.clear();
113✔
145
    isInMouseRelay = false;
113✔
146

147
    return processed;
113✔
148
}
149

150
/**
151
 *  aktiviert das Fenster.
152
 *
153
 *  @param[in] activate Fenster aktivieren?
154
 */
155
void Window::SetActive(bool activate)
2,378✔
156
{
157
    this->active_ = activate;
2,378✔
158
    ActivateControls(activate);
2,378✔
159
}
2,378✔
160

161
/**
162
 *  aktiviert die Steuerelemente des Fensters.
163
 *
164
 *  @param[in] activate Steuerelemente aktivieren?
165
 */
166
void Window::ActivateControls(bool activate)
2,378✔
167
{
168
    for(auto& it : childIdToWnd_)
3,444✔
169
        it.second->SetActive(activate);
1,066✔
170
}
2,378✔
171

172
/**
173
 *  sperrt eine Region eines Fensters.
174
 *
175
 *  @param[in] window das Fenster, welches die Region sperrt.
176
 *  @param[in] rect   das Rechteck, welches die Region beschreibt.
177
 */
178
void Window::LockRegion(Window* window, const Rect& rect)
×
179
{
180
    lockedAreas_[window] = rect;
×
181
    auto it = helpers::find(tofreeAreas_, window);
×
182
    if(it != tofreeAreas_.end())
×
183
        tofreeAreas_.erase(it);
×
184

185
    // Also lock the region for all parents
186
    if(GetParent())
×
187
        GetParent()->LockRegion(this, rect);
×
188
}
×
189

190
/**
191
 *  Gibt eine gesperrte Region wieder frei.
192
 *
193
 *  @param[in] window das Fenster, welches die Region sperrt.
194
 */
195
void Window::FreeRegion(Window* window)
×
196
{
197
    // We need to keep all locked areas otherwise a closed dropdown will enable "click-through" to below control
198
    if(isInMouseRelay)
×
199
        tofreeAreas_.push_back(window);
×
200
    else
201
        lockedAreas_.erase(window);
×
202

203
    // Also free the locked region for all parents
204
    if(GetParent())
×
205
        GetParent()->FreeRegion(this);
×
206
}
×
207

208
void Window::SetPos(const DrawPoint& newPos)
1,342✔
209
{
210
    pos_ = newPos;
1,342✔
211
}
1,342✔
212

213
/// Weiterleitung von Nachrichten von abgeleiteten Klassen erlaubt oder nicht?
214
bool Window::IsMessageRelayAllowed() const
110✔
215
{
216
    return true;
110✔
217
}
218

219
void Window::DeleteCtrl(unsigned id)
2✔
220
{
221
    auto it = childIdToWnd_.find(id);
2✔
222

223
    if(it == childIdToWnd_.end())
2✔
224
        return;
2✔
225

226
    delete it->second;
×
227

228
    childIdToWnd_.erase(it);
×
229
}
230

231
ctrlBuildingIcon* Window::AddBuildingIcon(unsigned id, const DrawPoint& pos, BuildingType type, const Nation nation,
26✔
232
                                          unsigned short size, const std::string& tooltip)
233
{
234
    return AddCtrl(new ctrlBuildingIcon(this, id, pos, type, nation, Extent(size, 0).x, tooltip));
26✔
235
}
236

237
ctrlButton* Window::AddTextButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc,
86✔
238
                                  const std::string& text, const glFont* font, const std::string& tooltip)
239
{
240
    return AddCtrl(new ctrlTextButton(this, id, pos, size, tc, text, font, tooltip, LimitFactors(7, 5)));
86✔
241
}
242

243
ctrlButton* Window::AddColorButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc,
1✔
244
                                   const unsigned fillColor, const std::string& tooltip)
245
{
246
    return AddCtrl(new ctrlColorButton(this, id, pos, size, tc, fillColor, tooltip));
1✔
247
}
248

249
ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc,
351✔
250
                                   ITexture* const image, const std::string& tooltip)
251
{
252
    return AddCtrl(new ctrlImageButton(this, id, pos, size, tc, image, tooltip));
351✔
253
}
254

255
ctrlButton* Window::AddImageButton(unsigned id, const DrawPoint& pos, const Extent& size, const TextureColor tc,
351✔
256
                                   glArchivItem_Bitmap* const image, const std::string& tooltip)
257
{
258
    return AddImageButton(id, pos, size, tc, static_cast<ITexture*>(image), tooltip);
351✔
259
}
260

261
ctrlChat* Window::AddChatCtrl(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
2✔
262
                              const glFont* font)
263
{
264
    return AddCtrl(new ctrlChat(this, id, pos, size, tc, font));
2✔
265
}
266

267
ctrlCheck* Window::AddCheckBox(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
49✔
268
                               const std::string& text, const glFont* font, bool readonly)
269
{
270
    return AddCtrl(new ctrlCheck(this, id, pos, size, tc, text, font, readonly));
49✔
271
}
272

273
ctrlComboBox* Window::AddComboBox(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
55✔
274
                                  const glFont* font, unsigned short max_list_height, bool readonly)
275
{
276
    return AddCtrl(new ctrlComboBox(this, id, pos, size, tc, font, max_list_height, readonly));
55✔
277
}
278

279
ctrlDeepening* Window::AddTextDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
9✔
280
                                        const std::string& text, const glFont* font, unsigned color, FontStyle style)
281
{
282
    return AddCtrl(new ctrlTextDeepening(this, id, pos, size, tc, text, font, color, style));
9✔
283
}
284

285
ctrlDeepening* Window::AddColorDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
×
286
                                         unsigned fillColor)
287
{
NEW
288
    return AddCtrl(new ctrlColorDeepening(this, id, pos, size, tc, fillColor));
×
289
}
290

291
ctrlDeepening* Window::AddImageDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
×
292
                                         ITexture* image)
293
{
NEW
294
    return AddCtrl(new ctrlImageDeepening(this, id, pos, size, tc, image));
×
295
}
296

297
ctrlDeepening* Window::AddImageDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
×
298
                                         glArchivItem_Bitmap* image)
299
{
300
    return AddImageDeepening(id, pos, size, tc, static_cast<ITexture*>(image));
×
301
}
302

303
ctrlEdit* Window::AddEdit(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font,
6✔
304
                          unsigned short maxlength, bool password, bool disabled, bool notify)
305
{
306
    return AddCtrl(
6✔
307
      new ctrlEdit(this, id, pos, size, tc, font, maxlength, password, disabled, notify));
12✔
308
}
309

310
ctrlGroup* Window::AddGroup(unsigned id)
101✔
311
{
312
    return AddCtrl(new ctrlGroup(this, id));
101✔
313
}
314

315
ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, ITexture* image, const std::string& tooltip)
54✔
316
{
317
    return AddCtrl(new ctrlImage(this, id, pos, image, tooltip));
54✔
318
}
319

320
ctrlImage* Window::AddImage(unsigned id, const DrawPoint& pos, glArchivItem_Bitmap* image, const std::string& tooltip)
54✔
321
{
322
    return AddImage(id, pos, static_cast<ITexture*>(image), tooltip);
54✔
323
}
324

325
ctrlList* Window::AddList(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font)
57✔
326
{
327
    return AddCtrl(new ctrlList(this, id, pos, size, tc, font));
57✔
328
}
329

330
ctrlMultiline* Window::AddMultiline(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
13✔
331
                                    const glFont* font, FontStyle format)
332
{
333
    return AddCtrl(new ctrlMultiline(this, id, pos, size, tc, font, format));
13✔
334
}
335

336
/**
337
 *  fügt ein OptionenGruppe hinzu.
338
 *
339
 *  @param[in] id          ID des Steuerelements
340
 *  @param[in] select_type Typ der Auswahl
341
 *
342
 *  @return Instanz das Steuerelement.
343
 */
344
ctrlOptionGroup* Window::AddOptionGroup(unsigned id, GroupSelectType select_type)
4✔
345
{
346
    return AddCtrl(new ctrlOptionGroup(this, id, select_type));
4✔
347
}
348

349
/**
350
 *  fügt ein MultiSelectGruppe hinzu.
351
 *
352
 *  @param[in] id          ID des Steuerelements
353
 *  @param[in] select_type Typ der Auswahl
354
 *
355
 *  @return Instanz das Steuerelement.
356
 */
357
ctrlMultiSelectGroup* Window::AddMultiSelectGroup(unsigned id, GroupSelectType select_type)
×
358
{
359
    return AddCtrl(new ctrlMultiSelectGroup(this, id, select_type));
×
360
}
361

362
ctrlPercent* Window::AddPercent(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
3✔
363
                                unsigned text_color, const glFont* font, const unsigned short* percentage)
364
{
365
    return AddCtrl(new ctrlPercent(this, id, pos, size, tc, text_color, font, percentage));
3✔
366
}
367

368
ctrlProgress* Window::AddProgress(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
7✔
369
                                  unsigned short button_minus, unsigned short button_plus, unsigned short maximum,
370
                                  const std::string& tooltip, const Extent& padding, unsigned force_color,
371
                                  const std::string& button_minus_tooltip, const std::string& button_plus_tooltip)
372
{
373
    return AddCtrl(new ctrlProgress(this, id, pos, size, tc, button_minus, button_plus, maximum,
7✔
374
                                    padding, force_color, tooltip, button_minus_tooltip, button_plus_tooltip));
14✔
375
}
376

377
ctrlScrollBar* Window::AddScrollBar(unsigned id, const DrawPoint& pos, const Extent& size, unsigned short button_height,
76✔
378
                                    TextureColor tc, unsigned short page_size)
379
{
380
    button_height = Extent(0, button_height).y;
76✔
381

382
    return AddCtrl(new ctrlScrollBar(this, id, pos, size, button_height, tc, page_size));
76✔
383
}
384

385
ctrlTab* Window::AddTabCtrl(unsigned id, const DrawPoint& pos, unsigned short width)
3✔
386
{
387
    return AddCtrl(new ctrlTab(this, id, pos, Extent(width, 0).x));
3✔
388
}
389

390
/**
391
 *  fügt eine Tabelle hinzu.
392
 *  ... sollte eine Menge von const char*, int und SortType sein
393
 */
394
ctrlTable* Window::AddTable(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font,
×
395
                            std::vector<TableColumn> columns)
396
{
NEW
397
    return AddCtrl(new ctrlTable(this, id, pos, size, tc, font, std::move(columns)));
×
398
}
399

400
ctrlTimer* Window::AddTimer(unsigned id, std::chrono::milliseconds timeout)
5✔
401
{
402
    return AddCtrl(new ctrlTimer(this, id, timeout));
5✔
403
}
404

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

427
ctrlMapSelection* Window::AddMapSelection(unsigned id, const DrawPoint& pos, const Extent& size,
×
428
                                          const SelectionMapInputData& inputData)
429
{
NEW
430
    return AddCtrl(new ctrlMapSelection(this, id, pos, size, inputData));
×
431
}
432

433
TextFormatSetter Window::AddFormattedText(unsigned id, const DrawPoint& pos, const std::string& text, unsigned color,
×
434
                                          FontStyle format, const glFont* font)
435
{
436
    return AddText(id, pos, text, color, format, font);
×
437
}
438

439
ctrlVarDeepening* Window::AddVarDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
1✔
440
                                          const std::string& formatstr, const glFont* font, unsigned color,
441
                                          unsigned parameters, ...)
442
{
443
    va_list liste;
444
    va_start(liste, parameters);
1✔
445

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

449
    va_end(liste);
1✔
450

451
    return AddCtrl(ctrl);
2✔
452
}
453

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

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

480
    va_end(liste);
×
481

482
    return AddCtrl(ctrl);
×
483
}
484

485
ctrlPreviewMinimap* Window::AddPreviewMinimap(const unsigned id, const DrawPoint& pos, const Extent& size,
×
486
                                              libsiedler2::ArchivItem_Map* const map)
487
{
NEW
488
    return AddCtrl(new ctrlPreviewMinimap(this, id, pos, size, map));
×
489
}
490

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

503
void Window::Draw3DBorder(const Rect& rect, TextureColor tc, bool elevated)
36✔
504
{
505
    if(tc == TextureColor::Invisible)
36✔
506
        return;
×
507
    glArchivItem_Bitmap* borderImg = LOADER.GetImageN("io", 12 + rttr::enum_cast(tc));
72✔
508
    VIDEODRIVER.GetRenderer()->Draw3DBorder(rect, elevated, *borderImg);
36✔
509
}
510

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

520
void Window::DrawRectangle(const Rect& rect, unsigned color)
266✔
521
{
522
    VIDEODRIVER.GetRenderer()->DrawRect(rect, color);
266✔
523
}
266✔
524

525
void Window::DrawLine(DrawPoint pt1, DrawPoint pt2, unsigned short width, unsigned color)
×
526
{
527
    VIDEODRIVER.GetRenderer()->DrawLine(pt1, pt2, width, color);
×
528
}
×
529

530
void Window::Msg_PaintBefore()
305✔
531
{
532
    animations_.update(VIDEODRIVER.GetTickCount());
305✔
533
    for(Window* control : childIdToWnd_ | boost::adaptors::map_values)
479✔
534
        control->Msg_PaintBefore();
174✔
535
}
305✔
536

537
void Window::Msg_PaintAfter()
351✔
538
{
539
    for(Window* control : childIdToWnd_ | boost::adaptors::map_values)
544✔
540
        control->Msg_PaintAfter();
193✔
541
}
351✔
542

543
void Window::Draw_()
157✔
544
{
545
    for(Window* control : childIdToWnd_ | boost::adaptors::map_values)
340✔
546
        control->Draw();
183✔
547
}
157✔
548

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

571
template<class T_Pt>
572
T_Pt Window::Scale(const T_Pt& pt, const LimitFactors& limfactors)
80✔
573
{
574
    return ScaleWindowProp::scale(pt, VIDEODRIVER.GetRenderSize(), limfactors);
80✔
575
}
576

577
void Window::ScaleByFactor()
109✔
578
{
579
    pos_ = ScaleWindowProp::scale(pos_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0));
109✔
580
    if(limit_)
109✔
581
        size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), limitFactors_);
48✔
582
    else
583
        size_ = ScaleWindowProp::scale(size_, VIDEODRIVER.GetRenderSize(), LimitFactors(0, 0));
61✔
584
}
109✔
585

586
template<class T_Pt>
587
T_Pt Window::ScaleIf(const T_Pt& pt) const
877✔
588
{
589
    return scale_ ? Scale(pt, LimitFactors(0, 0)) : pt;
1,754✔
590
}
591

592
// Inlining removes those. so add it here
593
template DrawPoint Window::ScaleIf(const DrawPoint&) const;
594
template Extent Window::ScaleIf(const Extent&) const;
595

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

609
bool Window::IsMouseOver() const
138✔
610
{
611
    return IsMouseOver(VIDEODRIVER.GetMousePos());
138✔
612
}
613

614
bool Window::IsMouseOver(const MouseCoords& mousePos) const
465✔
615
{
616
    return IsPointInRect(mousePos.pos, GetBoundaryRect());
465✔
617
}
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