Pyrogenesis  trunk
IGUITextOwner.h
Go to the documentation of this file.
1 /* Copyright (C) 2021 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 /*
19 GUI 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"
35 #include "maths/Rect.h"
36 #include "ps/CStrForward.h"
37 
38 #include <vector>
39 
40 class CCanvas2D;
41 struct CGUIColor;
42 struct SGUIMessage;
43 class CGUIText;
44 class CGUIString;
45 class IGUIObject;
46 
47 class CVector2D;
48 
49 /**
50  * Framework for handling Output text.
51  */
53 {
55 
56 public:
57  IGUITextOwner(IGUIObject& pObject);
58  virtual ~IGUITextOwner();
59 
60  /**
61  * Adds a text object.
62  */
63  CGUIText& AddText();
64 
65  /**
66  * Adds a text generated by the given arguments.
67  */
68  CGUIText& AddText(const CGUIString& Text, const CStrW& Font, const float& Width, const float& BufferZone);
69 
70  /**
71  * @see IGUIObject#HandleMessage()
72  */
73  virtual void HandleMessage(SGUIMessage& Message);
74 
75  /**
76  * @see IGUIObject#UpdateCachedSize()
77  */
78  virtual void UpdateCachedSize();
79 
80  /**
81  * Draws the Text.
82  *
83  * @param canvas Canvas to draw on.
84  * @param index Index value of text. Mostly this will be 0
85  * @param color
86  * @param pos Position
87  * @param clipping Clipping rectangle, don't even add a parameter
88  * to get no clipping.
89  */
90  virtual void DrawText(CCanvas2D& canvas, size_t index, const CGUIColor& color, const CVector2D& pos, const CRect& clipping = CRect());
91 
92 protected:
93  /**
94  * Setup texts. Functions that sets up all texts when changes have been made.
95  */
96  virtual void SetupText() = 0;
97 
98  /**
99  * Regenerate the text in case it is invalid. Should only be called when inevitable.
100  */
101  virtual void UpdateText();
102 
103  /**
104  * Whether the cached text is currently valid (if not then SetupText will be called by Draw)
105  */
107 
108  /**
109  * Texts that are generated and ready to be rendered.
110  */
111  std::vector<CGUIText> m_GeneratedTexts;
112 
113  /**
114  * Calculate the position for the text, based on the alignment.
115  */
116  void CalculateTextPosition(CRect& ObjSize, CVector2D& TextPos, CGUIText& Text);
117 
120 
121 private:
122  /**
123  * Reference to the IGUIObject.
124  * Private, because we don't want to inherit it in multiple classes.
125  */
127 };
128 
129 #endif // INCLUDED_IGUITEXTOWNER
virtual void SetupText()=0
Setup texts.
CGUISimpleSetting< EVAlign > m_TextVAlign
Definition: IGUITextOwner.h:119
virtual ~IGUITextOwner()
Definition: IGUITextOwner.cpp:38
virtual void UpdateCachedSize()
Definition: IGUITextOwner.cpp:79
NONCOPYABLE(IGUITextOwner)
Same as the CColor class, but this one can also parse colors predefined in the GUI page (such as "yel...
Definition: CGUIColor.h:29
virtual void UpdateText()
Regenerate the text in case it is invalid.
Definition: IGUITextOwner.cpp:85
GUI object such as a button or an input-box.
Definition: IGUIObject.h:59
IGUITextOwner(IGUIObject &pObject)
Definition: IGUITextOwner.cpp:30
CGUISimpleSetting< EAlign > m_TextAlign
Definition: IGUITextOwner.h:118
virtual void DrawText(CCanvas2D &canvas, size_t index, const CGUIColor &color, const CVector2D &pos, const CRect &clipping=CRect())
Draws the Text.
Definition: IGUITextOwner.cpp:94
IGUIObject & m_pObject
Reference to the IGUIObject.
Definition: IGUITextOwner.h:126
std::vector< CGUIText > m_GeneratedTexts
Texts that are generated and ready to be rendered.
Definition: IGUITextOwner.h:111
Framework for handling Output text.
Definition: IGUITextOwner.h:52
virtual void HandleMessage(SGUIMessage &Message)
Definition: IGUITextOwner.cpp:55
Definition: Canvas2D.h:35
Definition: Vector2D.h:31
CGUIText & AddText()
Adds a text object.
Definition: IGUITextOwner.cpp:42
void CalculateTextPosition(CRect &ObjSize, CVector2D &TextPos, CGUIText &Text)
Calculate the position for the text, based on the alignment.
Definition: IGUITextOwner.cpp:103
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: SGUIMessage.h:67
An CGUIText object is a parsed string, divided into text-rendering components.
Definition: CGUIText.h:56
String class, substitute for CStr, but that parses the tags and builds up a list of all text that wil...
Definition: CGUIString.h:41
bool m_GeneratedTextsValid
Whether the cached text is currently valid (if not then SetupText will be called by Draw) ...
Definition: IGUITextOwner.h:106
Rectangle class used for screen rectangles.
Definition: Rect.h:30