Added different textures for each ptolemaic camel rank
[0ad.git] / source / gui / GUIbase.h
blob75a9a3f1daeca1480407517c1cdb999b88d9b5c9
1 /* Copyright (C) 2012 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
19 GUI Core, stuff that the whole GUI uses
21 --Overview--
23 Contains defines, includes, types etc that the whole
24 GUI should have included.
26 --More info--
28 Check GUI.h
32 #ifndef INCLUDED_GUIBASE
33 #define INCLUDED_GUIBASE
36 //--------------------------------------------------------
37 // Includes / Compiler directives
38 //--------------------------------------------------------
39 #include <map>
40 #include <vector>
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"
46 #include "ps/CStr.h"
48 #include "ps/Errors.h"
50 //--------------------------------------------------------
51 // Forward declarations
52 //--------------------------------------------------------
53 class IGUIObject;
55 //--------------------------------------------------------
56 // Macros
57 //--------------------------------------------------------
59 // Object settings setups
61 // Setup an object's ConstructObject function
62 #define GUI_OBJECT(obj) \
63 public: \
64 static IGUIObject *ConstructObject() { return new obj(); }
67 //--------------------------------------------------------
68 // Types
69 //--------------------------------------------------------
71 /**
72 * Message types.
73 * @see SGUIMessage
75 enum EGUIMessageType
77 GUIM_MOUSE_OVER,
78 GUIM_MOUSE_ENTER,
79 GUIM_MOUSE_LEAVE,
80 GUIM_MOUSE_PRESS_LEFT,
81 GUIM_MOUSE_PRESS_RIGHT,
82 GUIM_MOUSE_DOWN_LEFT,
83 GUIM_MOUSE_DOWN_RIGHT,
84 GUIM_MOUSE_DBLCLICK_LEFT,
85 GUIM_MOUSE_DBLCLICK_RIGHT,
86 GUIM_MOUSE_RELEASE_LEFT,
87 GUIM_MOUSE_RELEASE_RIGHT,
88 GUIM_MOUSE_WHEEL_UP,
89 GUIM_MOUSE_WHEEL_DOWN,
90 GUIM_SETTINGS_UPDATED, // SGUIMessage.m_Value = name of setting
91 GUIM_PRESSED,
92 GUIM_DOUBLE_PRESSED,
93 GUIM_MOUSE_MOTION,
94 GUIM_LOAD, // Called when an object is added to the GUI.
95 GUIM_GOT_FOCUS,
96 GUIM_LOST_FOCUS,
97 GUIM_PRESSED_MOUSE_RIGHT,
98 GUIM_DOUBLE_PRESSED_MOUSE_RIGHT
102 * Message send to IGUIObject::HandleMessage() in order
103 * to give life to Objects manually with
104 * a derived HandleMessage().
106 struct SGUIMessage
108 SGUIMessage(EGUIMessageType _type) : type(_type), skipped(false) {}
109 SGUIMessage(EGUIMessageType _type, const CStr& _value) : type(_type), value(_value), skipped(false) {}
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).
115 * @param skip true to allow further event handling, false to prevent it
117 void Skip(bool skip = true) { skipped = skip; }
120 * Describes what the message regards
122 EGUIMessageType type;
125 * Optional data
127 CStr value;
130 * Flag that specifies if object skipped handling the event
132 bool skipped;
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
142 enum
144 GUIRR_HIDDEN = 0x00000001,
145 GUIRR_DISABLED = 0x00000010,
146 GUIRR_GHOST = 0x00000100
149 // Text alignments
150 enum EAlign { EAlign_Left, EAlign_Right, EAlign_Center };
151 enum EVAlign { EVAlign_Top, EVAlign_Bottom, EVAlign_Center };
153 // Typedefs
154 typedef std::map<CStr, IGUIObject*> map_pObjects;
155 typedef std::vector<IGUIObject*> vector_pObjects;
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
161 SGUIIcon() : m_CellID(0) {}
163 // Sprite name of icon
164 CStr m_SpriteName;
166 // Size
167 CSize m_Size;
169 // Cell of texture to use; ignored unless the texture has specified cell-size
170 int m_CellID;
174 * Client Area is a rectangle relative to a parent rectangle
176 * You can input the whole value of the Client Area by
177 * string. Like used in the GUI.
179 class CClientArea
181 public:
182 CClientArea();
183 CClientArea(const CStr& Value);
184 CClientArea(const CRect& pixel, const CRect& percent);
186 /// Pixel modifiers
187 CRect pixel;
189 /// Percent modifiers
190 CRect percent;
193 * Get client area rectangle when the parent is given
195 CRect GetClientArea(const CRect &parent) const;
198 * The ClientArea can be set from a string looking like:
200 * "0 0 100% 100%"
201 * "50%-10 50%-10 50%+10 50%+10"
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.
208 * @return true if success, false if failure. If false then the client area
209 * will be unchanged.
211 bool SetClientArea(const CStr& Value);
213 bool operator==(const CClientArea& other) const
215 return pixel == other.pixel && percent == other.percent;
219 //--------------------------------------------------------
220 // Error declarations
221 //--------------------------------------------------------
222 ERROR_GROUP(GUI);
224 ERROR_TYPE(GUI, NullObjectProvided);
225 ERROR_TYPE(GUI, InvalidSetting);
226 ERROR_TYPE(GUI, OperationNeedsGUIObject);
227 ERROR_TYPE(GUI, NameAmbiguity);
228 ERROR_TYPE(GUI, ObjectNeedsName);
230 #endif