Skip to content

Commit 5ca0801

Browse files
committed
Translate and update docstrings of Window class
1 parent a6698d1 commit 5ca0801

4 files changed

Lines changed: 68 additions & 73 deletions

File tree

libs/s25main/Window.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ Window::~Window()
3030
delete ctrl;
3131
}
3232

33-
/**
34-
* zeichnet das Fenster.
35-
*/
3633
void Window::Draw()
3734
{
3835
if(visible_)
@@ -49,8 +46,7 @@ DrawPoint Window::GetDrawPos() const
4946
DrawPoint result = pos_;
5047
const Window* temp = this;
5148

52-
// Relative Koordinaten in absolute umrechnen
53-
// ( d.h. Koordinaten von allen Eltern zusammenaddieren )
49+
// Convert relative to absolute coordinates, i.e. sum positions of parents
5450
while(temp->parent_)
5551
{
5652
temp = temp->parent_;
@@ -76,17 +72,10 @@ Rect Window::GetBoundaryRect() const
7672
return GetDrawRect();
7773
}
7874

79-
/**
80-
* Sendet eine Fensternachricht an die Steuerelemente.
81-
*
82-
* @param[in] msg Die Nachricht.
83-
* @param[in] id Die ID des Quellsteuerelements.
84-
* @param[in] param Ein nachrichtenspezifischer Parameter.
85-
*/
8675
bool Window::RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent& ke)
8776
{
88-
// Abgeleitete Klassen fragen, ob das Weiterleiten von Nachrichten erlaubt ist
89-
// (IngameFenster könnten ja z.B. minimiert sein)
77+
// Ask derived classes whether relaying messages is allowed
78+
// (For example, ingame windows might not want to receive keyboard messages when they are minimized)
9079
if(!IsMessageRelayAllowed())
9180
return false;
9281

@@ -103,19 +92,17 @@ bool Window::RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent& ke)
10392

10493
bool Window::RelayMouseMessage(MouseMsgHandler msg, const MouseCoords& mc)
10594
{
106-
// Abgeleitete Klassen fragen, ob das Weiterleiten von Mausnachrichten erlaubt ist
107-
// (IngameFenster könnten ja z.B. minimiert sein)
95+
// Ask derived classes whether relaying messages is allowed
10896
if(!IsMessageRelayAllowed())
10997
return false;
11098

11199
bool processed = false;
112100
isInMouseRelay = true;
113101

114-
// Alle Controls durchgehen
115102
// Use reverse iterator because the topmost (=last elements) should receive the messages first!
116103
for(Window* wnd : childIdToWnd_ | boost::adaptors::map_values | boost::adaptors::reversed)
117104
{
118-
if(!lockedAreas_.empty() && IsInLockedRegion(mc.pos, wnd))
105+
if(!lockedAreas_.empty() && IsInLockedRegion(mc.pos, wnd.get()))
119106
continue;
120107

121108
if(wnd->visible_ && wnd->active_ && CALL_MEMBER_FN(*wnd, msg)(mc))
@@ -137,7 +124,7 @@ bool Window::RelayMouseMessage(MouseMsgHandler msg, const MouseCoords& mc)
137124
*/
138125
void Window::SetActive(bool activate)
139126
{
140-
this->active_ = activate;
127+
active_ = activate;
141128
ActivateControls(activate);
142129
}
143130

@@ -193,7 +180,6 @@ void Window::SetPos(const DrawPoint& newPos)
193180
pos_ = newPos;
194181
}
195182

196-
/// Weiterleitung von Nachrichten von abgeleiteten Klassen erlaubt oder nicht?
197183
bool Window::IsMessageRelayAllowed() const
198184
{
199185
return true;

libs/s25main/Window.h

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2005 - 2025 Settlers Freaks (sf-team at siedler25.org)
1+
// Copyright (C) 2005 - 2026 Settlers Freaks (sf-team at siedler25.org)
22
//
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

@@ -58,7 +58,7 @@ namespace libsiedler2 {
5858
class ArchivItem_Map;
5959
}
6060

61-
/// Die Basisklasse der Fenster.
61+
/// Base class for windows and controls
6262
class Window
6363
{
6464
public:
@@ -67,36 +67,37 @@ class Window
6767

6868
Window(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size = Extent(0, 0));
6969
virtual ~Window();
70-
/// zeichnet das Fenster.
70+
/// Draw all contained controls if the window is visible
7171
void Draw();
72-
/// Get the current position
72+
/// Get the current position relative to the parent window
7373
DrawPoint GetPos() const;
74-
/// Get the absolute (X,Y) position as when calling GetX/GetY for drawing
74+
/// Get the absolute position for drawing
7575
DrawPoint GetDrawPos() const;
7676
/// Get the size of the window
7777
Extent GetSize() const;
78-
/// gets the extent of the window in absolute coordinates
78+
/// Get the extent of the window in absolute coordinates
7979
Rect GetDrawRect() const;
80-
/// Get the actual extents of the rect (might be different to the draw rect if the window resizes according to
81-
/// content)
80+
/// Get the actual extents of the rect
81+
/// (might be different to the draw rect if the window resizes according to content)
8282
virtual Rect GetBoundaryRect() const;
83-
/// setzt die Größe des Fensters
83+
/// Change the size
8484
virtual void Resize(const Extent& newSize) { size_ = newSize; }
85-
/// setzt die Breite des Fensters
85+
/// Change only the width
8686
void SetWidth(unsigned width) { Resize(Extent(width, size_.y)); }
87-
/// setzt die Höhe des Fensters
87+
/// Change only the height
8888
void SetHeight(unsigned height) { Resize(Extent(size_.x, height)); }
89-
/// Sendet eine Tastaturnachricht an die Steuerelemente.
89+
/// Send a keyboard message to all controls, return true if handled
9090
bool RelayKeyboardMessage(KeyboardMsgHandler msg, const KeyEvent& ke);
91-
/// Sendet eine Mausnachricht weiter an alle Steuerelemente
91+
/// Send a mouse message to all controls, return true if handled
9292
bool RelayMouseMessage(MouseMsgHandler msg, const MouseCoords& mc);
93-
/// aktiviert das Fenster.
93+
/// Make the window active or inactive. Inactive controls e.g. don't react to events
9494
virtual void SetActive(bool activate = true);
95-
/// aktiviert die Steuerelemente des Fensters.
95+
/// Activate/deactivate only the elements of the window
9696
void ActivateControls(bool activate = true);
97-
/// Sperrt eine bestimmte Region für Mausereignisse.
97+
/// Lock a region which won't react to mouse events anymore except for the given window/control.
98+
/// Only a single region can be locked per window.
9899
void LockRegion(Window* window, const Rect& rect);
99-
/// Gibt eine gesperrte Region wieder frei.
100+
/// Release the region locked for the given window/control.
100101
void FreeRegion(Window* window);
101102
/// Check if the given point is in a region locked by any window other than exception
102103
bool IsInLockedRegion(const Position& pos, const Window* exception = nullptr) const;
@@ -108,13 +109,11 @@ class Window
108109
/// Set the position for the window
109110
void SetPos(const DrawPoint& newPos);
110111

111-
// macht das Fenster sichtbar oder blendet es aus
112-
virtual void SetVisible(bool visible) { this->visible_ = visible; }
113-
/// Ist das Fenster sichtbar?
112+
// Make the window visible or hide it
113+
virtual void SetVisible(bool visible) { visible_ = visible; }
114114
bool IsVisible() const { return visible_; }
115-
/// Ist das Fenster aktiv?
116115
bool IsActive() const { return active_; }
117-
/// liefert das übergeordnete Fenster
116+
/// Get the parent window (containing this) or nullptr if this is a top-level window
118117
Window* GetParent() const { return parent_; }
119118
unsigned GetID() const { return id_; }
120119
/// Get control with given ID of given type or nullptr if not found or other type
@@ -185,20 +184,25 @@ class Window
185184
ctrlTab* AddTabCtrl(unsigned id, const DrawPoint& pos, unsigned short width);
186185
ctrlTable* AddTable(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc, const glFont* font,
187186
std::vector<TableColumn> columns);
187+
/// Add text
188+
/// @param color Text color (ARGB)
189+
/// @param format can be a combination of FontStyle::LEFT/CENTER/RIGHT and FontStyle::TOP/VCENTER/BOTTOM and
190+
/// FontStyle::OUTLINE/NO_OUTLINE
191+
/// Alignment specifies how the position is treated, i.e. where relative to the text it will be.
188192
ctrlText* AddText(unsigned id, const DrawPoint& pos, const std::string& text, unsigned color, FontStyle format,
189193
const glFont* font);
190194
ctrlMapSelection* AddMapSelection(unsigned id, const DrawPoint& pos, const Extent& size,
191195
const SelectionMapInputData& inputData);
192196
TextFormatSetter AddFormattedText(unsigned id, const DrawPoint& pos, const std::string& text, unsigned color,
193197
FontStyle format, const glFont* font);
194198
ctrlTimer* AddTimer(unsigned id, std::chrono::milliseconds timeout);
195-
/// fügt ein vertieftes variables TextCtrl hinzu.
196-
/// var parameters are pointers to int, unsigned or const char and must be valid for the lifetime of the var text!
199+
/// Add a 3D text control with a variable text. The text is formatted like printf but with pointers
200+
/// to int (%d), unsigned (%u) or const char (%s) which must be valid for the lifetime of the var text!
197201
ctrlVarDeepening* AddVarDeepening(unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
198202
const std::string& formatstr, const glFont* font, unsigned color,
199203
unsigned parameters, ...);
200-
/// fügt ein variables TextCtrl hinzu.
201-
/// var parameters are pointers to int, unsigned or const char and must be valid for the lifetime of the var text!
204+
/// Add a text control with a variable text. The text is formatted like printf but with pointers
205+
/// to int (%d), unsigned (%u) or const char (%s) which must be valid for the lifetime of the var text!
202206
ctrlVarText* AddVarText(unsigned id, const DrawPoint& pos, const std::string& formatstr, unsigned color,
203207
FontStyle format, const glFont* font, unsigned parameters, ...);
204208
ctrlPreviewMinimap* AddPreviewMinimap(unsigned id, const DrawPoint& pos, const Extent& size,
@@ -210,14 +214,13 @@ class Window
210214
static void Draw3DBorder(const Rect& rect, TextureColor tc, bool elevated);
211215
static void Draw3DContent(const Rect& rect, TextureColor tc, bool elevated, bool highlighted = false,
212216
bool illuminated = false, unsigned contentColor = COLOR_WHITE);
213-
/// Zeichnet ein Rechteck
214217
static void DrawRectangle(const Rect& rect, unsigned color);
215-
/// Zeichnet eine Linie
216218
static void DrawLine(DrawPoint pt1, DrawPoint pt2, unsigned short width, unsigned color);
217219

218220
// GUI-Notify-Messages
219221

220-
// Nachrichten, die von oben (WindowManager) nach unten (zu Controls) gereicht werden
222+
// These messages get passed downwards (WindowManager to controls)
223+
// Return true if the message was handled
221224
virtual void Msg_PaintBefore();
222225
virtual void Msg_PaintAfter();
223226
virtual bool Msg_LeftDown(const MouseCoords&) { return false; }
@@ -232,7 +235,7 @@ class Window
232235
virtual bool Msg_KeyDown(const KeyEvent&) { return false; }
233236
virtual void Msg_ScreenResize(const ScreenResizeEvent& sr);
234237

235-
// Nachrichten, die von unten (Controls) nach oben (Fenster) gereicht werden
238+
// Callback messages that are passed upwards (from controls to window)
236239
virtual void Msg_ButtonClick(unsigned /*ctrl_id*/) {}
237240
virtual void Msg_EditEnter(unsigned /*ctrl_id*/) {}
238241
virtual void Msg_EditChange(unsigned /*ctrl_id*/) {}
@@ -251,10 +254,10 @@ class Window
251254
virtual void Msg_TableRightButton(unsigned /*ctrl_id*/, const boost::optional<unsigned>& /*selection*/) {}
252255
virtual void Msg_TableLeftButton(unsigned /*ctrl_id*/, const boost::optional<unsigned>& /*selection*/) {}
253256

254-
// Sonstiges
257+
/// Callback of a message box when closed
255258
virtual void Msg_MsgBoxResult(unsigned /*msgbox_id*/, MsgboxResult /*mbr*/) {}
256259

257-
// Nachrichten, die von Controls von ctrlGroup weitergeleitet werden
260+
// Callbacks triggered by controls of ctrlGroup
258261
virtual void Msg_Group_ButtonClick(unsigned /*group_id*/, unsigned /*ctrl_id*/) {}
259262
virtual void Msg_Group_EditEnter(unsigned /*group_id*/, unsigned /*ctrl_id*/) {}
260263
virtual void Msg_Group_EditChange(unsigned /*group_id*/, unsigned /*ctrl_id*/) {}
@@ -286,32 +289,36 @@ class Window
286289
friend constexpr auto maxEnumValue(ButtonState) { return ButtonState::Pressed; }
287290
using ControlMap = std::map<unsigned, Window*>;
288291

289-
/// scales X- und Y values to fit the screen
292+
/// Scale the value from the reference coordinates to current render size
290293
template<class T_Pt>
291294
static T_Pt Scale(const T_Pt& pt);
292-
/// Scales the value when scale_ is true, else returns the value
295+
/// Scales the value when scale_ is true, else returns the value unchanged
293296
template<class T_Pt>
294297
T_Pt ScaleIf(const T_Pt& pt) const;
295-
/// setzt Scale-Wert, ob neue Controls skaliert werden sollen oder nicht.
296-
void SetScale(bool scale = true) { this->scale_ = scale; }
297-
/// zeichnet das Fenster.
298+
/// Set whether controls of this window shall be scaled
299+
void SetScale(bool scale = true) { scale_ = scale; }
300+
/// Implementation of drawing the window, derived classes can override this to draw custom backgrounds or similar
298301
virtual void Draw_();
299-
/// Weiterleitung von Nachrichten von abgeleiteten Klassen erlaubt oder nicht?
302+
/// Shall messages be relayed to the controls of this window?
300303
virtual bool IsMessageRelayAllowed() const;
301304

302305
private:
303-
Window* const parent_; /// Handle auf das Parentfenster.
304-
unsigned id_; /// ID des Fensters.
305-
DrawPoint pos_; /// Position des Fensters.
306-
Extent size_; /// Höhe des Fensters.
307-
bool active_; /// Fenster aktiv?
308-
bool visible_; /// Fenster sichtbar?
309-
bool scale_; /// Sollen Controls an Fenstergröße angepasst werden?
310-
311-
std::map<Window*, Rect> lockedAreas_; /// gesperrte Regionen des Fensters.
306+
Window* const parent_; /// Handle to parent window
307+
unsigned id_; /// ID of the window, must be unique among siblings
308+
DrawPoint pos_; /// Position relative to parent window.
309+
Extent size_; /// Size of the window
310+
bool active_; /// Window active?
311+
bool visible_; /// Window visible?
312+
bool scale_; /// Shall the controls of this window be scaled according to the render size?
313+
314+
/// Locked areas for mouse events.
315+
/// The key is the window/control for which the area is locked, i.e. which control is the only one getting mouse
316+
/// events from this region, the value is the locked area relative to this window. Only a single area can be locked
317+
/// per window/control.
318+
std::map<Window*, Rect> lockedAreas_;
312319
std::vector<Window*> tofreeAreas_;
313320
bool isInMouseRelay;
314-
ControlMap childIdToWnd_; /// Die Steuerelemente des Fensters.
321+
ControlMap childIdToWnd_; /// Controls contained in this window, mapped by their ID
315322
AnimationManager animations_;
316323
};
317324

libs/s25main/controls/ctrlBaseVarText.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
1+
// Copyright (C) 2005 - 2026 Settlers Freaks (sf-team at siedler25.org)
22
//
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

@@ -11,11 +11,12 @@
1111

1212
class glFont;
1313

14-
/// Base class for controls containing a text
14+
/// Base class for controls containing a text with format specifies
1515
class ctrlBaseVarText : public ctrlBaseText
1616
{
1717
public:
18-
/// fmtArgs contains pointers to int, unsigned or const char and must be valid for the lifetime of the var text!
18+
/// fmtArgs contains pointers to int (%d), unsigned (%u) or const char (%s)
19+
/// which must be valid for the lifetime of the var text!
1920
ctrlBaseVarText(const std::string& fmtString, unsigned color, const glFont* font, unsigned count, va_list fmtArgs);
2021

2122
protected:

libs/s25main/controls/ctrlVarDeepening.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
1+
// Copyright (C) 2005 - 2026 Settlers Freaks (sf-team at siedler25.org)
22
//
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

@@ -13,7 +13,8 @@ class glFont;
1313
class ctrlVarDeepening : public ctrlDeepening, public ctrlBaseVarText
1414
{
1515
public:
16-
/// fmtArgs contains pointers to int, unsigned or const char and must be valid for the lifetime of the var text!
16+
/// fmtArgs contains pointers to int (%d), unsigned (%u) or const char (%s)
17+
/// which must be valid for the lifetime of the var text!
1718
ctrlVarDeepening(Window* parent, unsigned id, const DrawPoint& pos, const Extent& size, TextureColor tc,
1819
const std::string& fmtString, const glFont* font, unsigned color, unsigned count, va_list fmtArgs);
1920

0 commit comments

Comments
 (0)