Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GUIbase.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 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 Core, stuff that the whole GUI uses
20 
21 --Overview--
22 
23  Contains defines, includes, types etc that the whole
24  GUI should have included.
25 
26 --More info--
27 
28  Check GUI.h
29 
30 */
31 
32 #ifndef INCLUDED_GUIBASE
33 #define INCLUDED_GUIBASE
34 
35 
36 //--------------------------------------------------------
37 // Includes / Compiler directives
38 //--------------------------------------------------------
39 #include <map>
40 #include <vector>
41 
42 // I would like to just forward declare CSize, but it doesn't
43 // seem to be defined anywhere in the predefined header.
44 #include "ps/Overlay.h"
45 
46 #include "ps/CStr.h"
47 
48 #include "ps/Errors.h"
49 
50 //--------------------------------------------------------
51 // Forward declarations
52 //--------------------------------------------------------
53 class IGUIObject;
54 
55 //--------------------------------------------------------
56 // Macros
57 //--------------------------------------------------------
58 
59 // Object settings setups
60 
61 // Setup an object's ConstructObject function
62 #define GUI_OBJECT(obj) \
63 public: \
64  static IGUIObject *ConstructObject() { return new obj(); }
65 
66 
67 //--------------------------------------------------------
68 // Types
69 //--------------------------------------------------------
70 
71 /**
72  * Message types.
73  * @see SGUIMessage
74  */
76 {
90  GUIM_SETTINGS_UPDATED, // SGUIMessage.m_Value = name of setting
94  GUIM_LOAD, // Called when an object is added to the GUI.
99 };
100 
101 /**
102  * Message send to IGUIObject::HandleMessage() in order
103  * to give life to Objects manually with
104  * a derived HandleMessage().
105  */
107 {
108  SGUIMessage(EGUIMessageType _type) : type(_type), skipped(false) {}
109  SGUIMessage(EGUIMessageType _type, const CStr& _value) : type(_type), value(_value), skipped(false) {}
110 
111  /**
112  * This method can be used to allow other event handlers to process this GUI event,
113  * by default an event is not skipped (only the first handler will process it).
114  *
115  * @param skip true to allow further event handling, false to prevent it
116  */
117  void Skip(bool skip = true) { skipped = skip; }
118 
119  /**
120  * Describes what the message regards
121  */
123 
124  /**
125  * Optional data
126  */
127  CStr value;
128 
129  /**
130  * Flag that specifies if object skipped handling the event
131  */
132  bool skipped;
133 };
134 
135 /**
136  * Recurse restrictions, when we recurse, if an object
137  * is hidden for instance, you might want it to skip
138  * the children also
139  * Notice these are flags! and we don't really need one
140  * for no restrictions, because then you'll just enter 0
141  */
142 enum
143 {
144  GUIRR_HIDDEN = 0x00000001,
145  GUIRR_DISABLED = 0x00000010,
146  GUIRR_GHOST = 0x00000100
147 };
148 
149 // Text alignments
152 
153 // Typedefs
154 typedef std::map<CStr, IGUIObject*> map_pObjects;
155 typedef std::vector<IGUIObject*> vector_pObjects;
156 
157 // Icon, you create them in the XML file with root element <setup>
158 // you use them in text owned by different objects... Such as CText.
159 struct SGUIIcon
160 {
161  SGUIIcon() : m_CellID(0) {}
162 
163  // Sprite name of icon
165 
166  // Size
168 
169  // Cell of texture to use; ignored unless the texture has specified cell-size
170  int m_CellID;
171 };
172 
173 /**
174  * Client Area is a rectangle relative to a parent rectangle
175  *
176  * You can input the whole value of the Client Area by
177  * string. Like used in the GUI.
178  */
180 {
181 public:
182  CClientArea();
183  CClientArea(const CStr& Value);
184  CClientArea(const CRect& pixel, const CRect& percent);
185 
186  /// Pixel modifiers
188 
189  /// Percent modifiers
191 
192  /**
193  * Get client area rectangle when the parent is given
194  */
195  CRect GetClientArea(const CRect &parent) const;
196 
197  /**
198  * The ClientArea can be set from a string looking like:
199  *
200  * "0 0 100% 100%"
201  * "50%-10 50%-10 50%+10 50%+10"
202  *
203  * i.e. First percent modifier, then + or - and the pixel modifier.
204  * Although you can use just the percent or the pixel modifier. Notice
205  * though that the percent modifier must always be the first when
206  * both modifiers are inputted.
207  *
208  * @return true if success, false if failure. If false then the client area
209  * will be unchanged.
210  */
211  bool SetClientArea(const CStr& Value);
212 };
213 
214 //--------------------------------------------------------
215 // Error declarations
216 //--------------------------------------------------------
218 
219 ERROR_TYPE(GUI, NullObjectProvided);
220 ERROR_TYPE(GUI, InvalidSetting);
221 ERROR_TYPE(GUI, OperationNeedsGUIObject);
222 ERROR_TYPE(GUI, NameAmbiguity);
223 ERROR_TYPE(GUI, ObjectNeedsName);
224 
225 #endif
static char * skip(char **buf, const char *delimiters)
Definition: mongoose.cpp:748
int m_CellID
Definition: GUIbase.h:170
Made to represent a screen size, should in philosophy be made of unsigned ints, but for the sake of c...
Definition: Overlay.h:205
CStr value
Optional data.
Definition: GUIbase.h:127
SGUIMessage(EGUIMessageType _type, const CStr &_value)
Definition: GUIbase.h:109
CRect pixel
Pixel modifiers.
Definition: GUIbase.h:187
Base settings, all objects possess these settings in their m_BaseSettings Instructions can be found i...
Definition: IGUIObject.h:140
#define ERROR_TYPE(a, b)
Definition: Errors.h:96
#define ERROR_GROUP(a)
Definition: Errors.h:87
CRect percent
Percent modifiers.
Definition: GUIbase.h:190
Includes static functions that needs one template argument.
Definition: GUIutil.h:103
bool SetClientArea(const CStr &Value)
The ClientArea can be set from a string looking like:
Definition: GUIbase.cpp:63
CStr m_SpriteName
Definition: GUIbase.h:164
EGUIMessageType
Message types.
Definition: GUIbase.h:75
SGUIMessage(EGUIMessageType _type)
Definition: GUIbase.h:108
CRect GetClientArea(const CRect &parent) const
Get client area rectangle when the parent is given.
Definition: GUIbase.cpp:46
SGUIIcon()
Definition: GUIbase.h:161
void Skip(bool skip=true)
This method can be used to allow other event handlers to process this GUI event, by default an event ...
Definition: GUIbase.h:117
std::map< CStr, IGUIObject * > map_pObjects
Definition: GUIbase.h:154
bool skipped
Flag that specifies if object skipped handling the event.
Definition: GUIbase.h:132
std::vector< IGUIObject * > vector_pObjects
Definition: GUIbase.h:155
EAlign
Definition: GUIbase.h:150
CSize m_Size
Definition: GUIbase.h:167
EVAlign
Definition: GUIbase.h:151
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: GUIbase.h:106
EGUIMessageType type
Describes what the message regards.
Definition: GUIbase.h:122
Rectangle class used for screen rectangles.
Definition: Overlay.h:71
Client Area is a rectangle relative to a parent rectangle.
Definition: GUIbase.h:179