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 {
5858class ArchivItem_Map ;
5959}
6060
61- // / Die Basisklasse der Fenster.
61+ // / Base class for windows and controls
6262class Window
6363{
6464public:
@@ -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
302305private:
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
0 commit comments