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