1 /* Copyright (C) 2016 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_RIGHT
,
65 GUIM_MOUSE_DOWN_RIGHT
,
66 GUIM_MOUSE_DBLCLICK_LEFT
,
67 GUIM_MOUSE_DBLCLICK_LEFT_ITEM
, // Triggered when doubleclicking on a list item
68 GUIM_MOUSE_DBLCLICK_RIGHT
,
69 GUIM_MOUSE_RELEASE_LEFT
,
70 GUIM_MOUSE_RELEASE_RIGHT
,
72 GUIM_MOUSE_WHEEL_DOWN
,
73 GUIM_SETTINGS_UPDATED
, // SGUIMessage.m_Value = name of setting
78 GUIM_LOAD
, // Called when an object is added to the GUI.
81 GUIM_PRESSED_MOUSE_RIGHT
,
82 GUIM_DOUBLE_PRESSED_MOUSE_RIGHT
,
83 GUIM_TAB
// Used by CInput
87 * Message send to IGUIObject::HandleMessage() in order
88 * to give life to Objects manually with
89 * a derived HandleMessage().
93 SGUIMessage(EGUIMessageType _type
) : type(_type
), skipped(false) {}
94 SGUIMessage(EGUIMessageType _type
, const CStr
& _value
) : type(_type
), value(_value
), skipped(false) {}
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).
100 * @param skip true to allow further event handling, false to prevent it
102 void Skip(bool skip
= true) { skipped
= skip
; }
105 * Describes what the message regards
107 EGUIMessageType type
;
115 * Flag that specifies if object skipped handling the event
121 * Recurse restrictions, when we recurse, if an object
122 * is hidden for instance, you might want it to skip
124 * Notice these are flags! and we don't really need one
125 * for no restrictions, because then you'll just enter 0
129 GUIRR_HIDDEN
= 0x00000001,
130 GUIRR_DISABLED
= 0x00000010,
131 GUIRR_GHOST
= 0x00000100
135 enum EAlign
{ EAlign_Left
, EAlign_Right
, EAlign_Center
};
136 enum EVAlign
{ EVAlign_Top
, EVAlign_Bottom
, EVAlign_Center
};
139 typedef std::map
<CStr
, IGUIObject
*> map_pObjects
;
140 typedef std::vector
<IGUIObject
*> vector_pObjects
;
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.
146 SGUIIcon() : m_CellID(0) {}
148 // Sprite name of icon
154 // Cell of texture to use; ignored unless the texture has specified cell-size
159 * Client Area is a rectangle relative to a parent rectangle
161 * You can input the whole value of the Client Area by
162 * string. Like used in the GUI.
168 CClientArea(const CStr
& Value
);
169 CClientArea(const CRect
& pixel
, const CRect
& percent
);
174 /// Percent modifiers
178 * Get client area rectangle when the parent is given
180 CRect
GetClientArea(const CRect
& parent
) const;
183 * The ClientArea can be set from a string looking like:
186 * "50%-10 50%-10 50%+10 50%+10"
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.
193 * @return true if success, false if failure. If false then the client area
196 bool SetClientArea(const CStr
& Value
);
198 bool operator==(const CClientArea
& other
) const
200 return pixel
== other
.pixel
&& percent
== other
.percent
;
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
);
213 #endif // INCLUDED_GUIBASE