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
23 Contains defines, includes, types etc that the whole
24 GUI should have included.
32 #ifndef INCLUDED_GUIBASE
33 #define INCLUDED_GUIBASE
36 //--------------------------------------------------------
37 // Includes / Compiler directives
38 //--------------------------------------------------------
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"
48 #include "ps/Errors.h"
50 //--------------------------------------------------------
51 // Forward declarations
52 //--------------------------------------------------------
55 //--------------------------------------------------------
57 //--------------------------------------------------------
59 // Object settings setups
61 // Setup an object's ConstructObject function
62 #define GUI_OBJECT(obj) \
64 static IGUIObject *ConstructObject() { return new obj(); }
67 //--------------------------------------------------------
69 //--------------------------------------------------------
80 GUIM_MOUSE_PRESS_LEFT
,
81 GUIM_MOUSE_PRESS_RIGHT
,
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
,
89 GUIM_MOUSE_WHEEL_DOWN
,
90 GUIM_SETTINGS_UPDATED
, // SGUIMessage.m_Value = name of setting
94 GUIM_LOAD
, // Called when an object is added to the GUI.
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().
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
;
130 * Flag that specifies if object skipped handling the event
136 * Recurse restrictions, when we recurse, if an object
137 * is hidden for instance, you might want it to skip
139 * Notice these are flags! and we don't really need one
140 * for no restrictions, because then you'll just enter 0
144 GUIRR_HIDDEN
= 0x00000001,
145 GUIRR_DISABLED
= 0x00000010,
146 GUIRR_GHOST
= 0x00000100
150 enum EAlign
{ EAlign_Left
, EAlign_Right
, EAlign_Center
};
151 enum EVAlign
{ EVAlign_Top
, EVAlign_Bottom
, EVAlign_Center
};
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.
161 SGUIIcon() : m_CellID(0) {}
163 // Sprite name of icon
169 // Cell of texture to use; ignored unless the texture has specified cell-size
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.
183 CClientArea(const CStr
& Value
);
184 CClientArea(const CRect
& pixel
, const CRect
& percent
);
189 /// Percent modifiers
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:
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
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 //--------------------------------------------------------
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
);