Pyrogenesis  trunk
IGUITextOwner.h
Go to the documentation of this file.
1 /* Copyright (C) 2015 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 --More info--
30 
31  Check GUI.h
32 
33 */
34 
35 #ifndef INCLUDED_IGUITEXTOWNER
36 #define INCLUDED_IGUITEXTOWNER
37 
38 #include "GUI.h"
39 
40 /**
41  * Framework for handling Output text.
42  *
43  * @see IGUIObject
44  */
45 class IGUITextOwner : virtual public IGUIObject
46 {
47 public:
48  IGUITextOwner();
49  virtual ~IGUITextOwner();
50 
51  /**
52  * Adds a text object.
53  */
54  void AddText(SGUIText* text);
55 
56  /**
57  * @see IGUIObject#HandleMessage()
58  */
59  virtual void HandleMessage(SGUIMessage& Message);
60 
61  /**
62  * @see IGUIObject#UpdateCachedSize()
63  */
64  virtual void UpdateCachedSize();
65 
66  /**
67  * Draws the Text.
68  *
69  * @param index Index value of text. Mostly this will be 0
70  * @param color
71  * @param pos Position
72  * @param z Z value
73  * @param clipping Clipping rectangle, don't even add a parameter
74  * to get no clipping.
75  */
76  virtual void DrawText(size_t index, const CColor& color, const CPos& pos, float z, const CRect& clipping = CRect());
77 
78  /**
79  * Test if mouse position is over an icon
80  */
81  virtual bool MouseOverIcon();
82 
83 protected:
84 
85  /**
86  * Setup texts. Functions that sets up all texts when changes have been made.
87  */
88  virtual void SetupText() = 0;
89 
90  /**
91  * Whether the cached text is currently valid (if not then SetupText will be called by Draw)
92  */
94 
95  /**
96  * Texts that are generated and ready to be rendered.
97  */
98  std::vector<SGUIText*> m_GeneratedTexts;
99 
100  /**
101  * Calculate the position for the text, based on the alignment.
102  */
103  void CalculateTextPosition(CRect& ObjSize, CPos& TextPos, SGUIText& Text);
104 };
105 
106 #endif // INCLUDED_IGUITEXTOWNER
virtual void SetupText()=0
Setup texts.
IGUITextOwner()
Definition: IGUITextOwner.cpp:22
virtual void DrawText(size_t index, const CColor &color, const CPos &pos, float z, const CRect &clipping=CRect())
Draws the Text.
Definition: IGUITextOwner.cpp:70
virtual ~IGUITextOwner()
Definition: IGUITextOwner.cpp:26
virtual void UpdateCachedSize()
Definition: IGUITextOwner.cpp:61
Definition: Shapes.h:36
virtual bool MouseOverIcon()
Test if mouse position is over an icon.
Definition: IGUITextOwner.cpp:111
Base settings, all objects possess these settings in their m_BaseSettings Instructions can be found i...
Definition: IGUIObject.h:117
void CalculateTextPosition(CRect &ObjSize, CPos &TextPos, SGUIText &Text)
Calculate the position for the text, based on the alignment.
Definition: IGUITextOwner.cpp:84
Framework for handling Output text.
Definition: IGUITextOwner.h:45
virtual void HandleMessage(SGUIMessage &Message)
Definition: IGUITextOwner.cpp:37
Made to represent screen positions and delta values.
Definition: Shapes.h:169
std::vector< SGUIText * > m_GeneratedTexts
Texts that are generated and ready to be rendered.
Definition: IGUITextOwner.h:98
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: GUIbase.h:91
void AddText(SGUIText *text)
Adds a text object.
Definition: IGUITextOwner.cpp:32
bool m_GeneratedTextsValid
Whether the cached text is currently valid (if not then SetupText will be called by Draw) ...
Definition: IGUITextOwner.h:93
An SGUIText object is a parsed string, divided into text-rendering components.
Definition: GUItext.h:55
Rectangle class used for screen rectangles.
Definition: Shapes.h:73