Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
IGUITextOwner.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/*
19GUI Object Base - Text Owner
20
21--Overview--
22
23 Interface class that enhance the IGUIObject with
24 cached CGUIStrings. This class is not at all needed,
25 and many controls that will use CGUIStrings might
26 not use this, but does help for regular usage such
27 as a text-box, a button, a radio button etc.
28*/
29
30#ifndef INCLUDED_IGUITEXTOWNER
31#define INCLUDED_IGUITEXTOWNER
32
33#include "gui/CGUISetting.h"
34#include "lib/code_annotation.h"
35#include "maths/Rect.h"
36
37#include <cstddef>
38#include <vector>
39
40class CCanvas2D;
41class CGUIString;
42class CGUIText;
43class CStrW;
44class CVector2D;
45class IGUIObject;
46enum class EAlign;
47enum class EVAlign;
48struct CGUIColor;
49struct SGUIMessage;
50
51/**
52 * Framework for handling Output text.
53 */
55{
57
58public:
59 IGUITextOwner(IGUIObject& pObject);
60 virtual ~IGUITextOwner();
61
62 /**
63 * Adds a text object.
64 */
66
67 /**
68 * Adds a text generated by the given arguments.
69 */
70 CGUIText& AddText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone);
71
72 /**
73 * @see IGUIObject#HandleMessage()
74 */
75 virtual void HandleMessage(SGUIMessage& Message);
76
77 /**
78 * @see IGUIObject#HandleSizeChanged()
79 */
80 virtual void HandleSizeChanged();
81
82 /**
83 * Draws the Text.
84 *
85 * @param canvas Canvas to draw on.
86 * @param index Index value of text. Mostly this will be 0
87 * @param color
88 * @param pos Position
89 * @param clipping Clipping rectangle, don't even add a parameter
90 * to get no clipping.
91 */
92 virtual void DrawText(CCanvas2D& canvas, size_t index, const CGUIColor& color, const CVector2D& pos, const CRect& clipping = CRect());
93
94protected:
95 /**
96 * Setup texts. Functions that sets up all texts when changes have been made.
97 */
98 virtual void SetupText() = 0;
99
100 /**
101 * Regenerate the text in case it is invalid. Should only be called when inevitable.
102 */
103 virtual void UpdateText();
104
105 /**
106 * Whether the cached text is currently valid (if not then SetupText will be called by Draw)
107 */
109
110 /**
111 * Texts that are generated and ready to be rendered.
112 */
113 std::vector<CGUIText> m_GeneratedTexts;
114
115 /**
116 * Calculate the position for the text, based on the alignment.
117 */
118 void CalculateTextPosition(const CRect& ObjSize, CVector2D& TextPos, CGUIText& Text);
119
122
123private:
124 /**
125 * Reference to the IGUIObject.
126 * Private, because we don't want to inherit it in multiple classes.
127 */
129};
130
131#endif // INCLUDED_IGUITEXTOWNER
EVAlign
Definition: EAlign.h:29
EAlign
Definition: EAlign.h:22
Definition: Canvas2D.h:36
String class, substitute for CStr, but that parses the tags and builds up a list of all text that wil...
Definition: CGUIString.h:47
An CGUIText object is a parsed string, divided into text-rendering components.
Definition: CGUIText.h:59
Rectangle class used for screen rectangles.
Definition: Rect.h:31
Definition: Vector2D.h:32
GUI object such as a button or an input-box.
Definition: IGUIObject.h:63
Framework for handling Output text.
Definition: IGUITextOwner.h:55
virtual void SetupText()=0
Setup texts.
std::vector< CGUIText > m_GeneratedTexts
Texts that are generated and ready to be rendered.
Definition: IGUITextOwner.h:113
CGUISimpleSetting< EAlign > m_TextAlign
Definition: IGUITextOwner.h:120
virtual void UpdateText()
Regenerate the text in case it is invalid.
Definition: IGUITextOwner.cpp:88
NONCOPYABLE(IGUITextOwner)
virtual ~IGUITextOwner()
Definition: IGUITextOwner.cpp:41
CGUISimpleSetting< EVAlign > m_TextVAlign
Definition: IGUITextOwner.h:121
virtual void HandleMessage(SGUIMessage &Message)
Definition: IGUITextOwner.cpp:58
void CalculateTextPosition(const CRect &ObjSize, CVector2D &TextPos, CGUIText &Text)
Calculate the position for the text, based on the alignment.
Definition: IGUITextOwner.cpp:106
virtual void DrawText(CCanvas2D &canvas, size_t index, const CGUIColor &color, const CVector2D &pos, const CRect &clipping=CRect())
Draws the Text.
Definition: IGUITextOwner.cpp:97
IGUITextOwner(IGUIObject &pObject)
Definition: IGUITextOwner.cpp:33
virtual void HandleSizeChanged()
Definition: IGUITextOwner.cpp:82
IGUIObject & m_pObject
Reference to the IGUIObject.
Definition: IGUITextOwner.h:128
bool m_GeneratedTextsValid
Whether the cached text is currently valid (if not then SetupText will be called by Draw)
Definition: IGUITextOwner.h:108
CGUIText & AddText()
Adds a text object.
Definition: IGUITextOwner.cpp:45
Same as the CColor class, but this one can also parse colors predefined in the GUI page (such as "yel...
Definition: CGUIColor.h:31
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: SGUIMessage.h:73