1 /* Copyright (C) 2017 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
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"
46 // Object settings setups
47 // Setup an object's ConstructObject function
48 #define GUI_OBJECT(obj) \
50 static IGUIObject* ConstructObject() { return new obj(); }
62 GUIM_MOUSE_PRESS_LEFT
,
63 GUIM_MOUSE_PRESS_LEFT_ITEM
,
64 GUIM_MOUSE_PRESS_RIGHT
,
66 GUIM_MOUSE_DOWN_RIGHT
,
67 GUIM_MOUSE_DBLCLICK_LEFT
,
68 GUIM_MOUSE_DBLCLICK_LEFT_ITEM
, // Triggered when doubleclicking on a list item
69 GUIM_MOUSE_DBLCLICK_RIGHT
,
70 GUIM_MOUSE_RELEASE_LEFT
,
71 GUIM_MOUSE_RELEASE_RIGHT
,
73 GUIM_MOUSE_WHEEL_DOWN
,
74 GUIM_SETTINGS_UPDATED
, // SGUIMessage.m_Value = name of setting
79 GUIM_LOAD
, // Called when an object is added to the GUI.
82 GUIM_PRESSED_MOUSE_RIGHT
,
83 GUIM_DOUBLE_PRESSED_MOUSE_RIGHT
,
84 GUIM_TAB
, // Used by CInput
89 * Message send to IGUIObject::HandleMessage() in order
90 * to give life to Objects manually with
91 * a derived HandleMessage().
95 SGUIMessage(EGUIMessageType _type
) : type(_type
), skipped(false) {}
96 SGUIMessage(EGUIMessageType _type
, const CStr
& _value
) : type(_type
), value(_value
), skipped(false) {}
99 * This method can be used to allow other event handlers to process this GUI event,
100 * by default an event is not skipped (only the first handler will process it).
102 * @param skip true to allow further event handling, false to prevent it
104 void Skip(bool skip
= true) { skipped
= skip
; }
107 * Describes what the message regards
109 EGUIMessageType type
;
117 * Flag that specifies if object skipped handling the event
123 * Recurse restrictions, when we recurse, if an object
124 * is hidden for instance, you might want it to skip
126 * Notice these are flags! and we don't really need one
127 * for no restrictions, because then you'll just enter 0
131 GUIRR_HIDDEN
= 0x00000001,
132 GUIRR_DISABLED
= 0x00000010,
133 GUIRR_GHOST
= 0x00000100
137 enum EAlign
{ EAlign_Left
, EAlign_Right
, EAlign_Center
};
138 enum EVAlign
{ EVAlign_Top
, EVAlign_Bottom
, EVAlign_Center
};
141 typedef std::map
<CStr
, IGUIObject
*> map_pObjects
;
142 typedef std::vector
<IGUIObject
*> vector_pObjects
;
144 // Icon, you create them in the XML file with root element <setup>
145 // you use them in text owned by different objects... Such as CText.
148 SGUIIcon() : m_CellID(0) {}
150 // Sprite name of icon
156 // Cell of texture to use; ignored unless the texture has specified cell-size
161 * Client Area is a rectangle relative to a parent rectangle
163 * You can input the whole value of the Client Area by
164 * string. Like used in the GUI.
170 CClientArea(const CStr
& Value
);
171 CClientArea(const CRect
& pixel
, const CRect
& percent
);
176 /// Percent modifiers
180 * Get client area rectangle when the parent is given
182 CRect
GetClientArea(const CRect
& parent
) const;
185 * The ClientArea can be set from a string looking like:
188 * "50%-10 50%-10 50%+10 50%+10"
190 * i.e. First percent modifier, then + or - and the pixel modifier.
191 * Although you can use just the percent or the pixel modifier. Notice
192 * though that the percent modifier must always be the first when
193 * both modifiers are inputted.
195 * @return true if success, false if failure. If false then the client area
198 bool SetClientArea(const CStr
& Value
);
200 bool operator==(const CClientArea
& other
) const
202 return pixel
== other
.pixel
&& percent
== other
.percent
;
209 ERROR_TYPE(GUI
, NullObjectProvided
);
210 ERROR_TYPE(GUI
, InvalidSetting
);
211 ERROR_TYPE(GUI
, OperationNeedsGUIObject
);
212 ERROR_TYPE(GUI
, NameAmbiguity
);
213 ERROR_TYPE(GUI
, ObjectNeedsName
);
215 #endif // INCLUDED_GUIBASE