MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_Align.h
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_ALIGN_H__
23 #define __MYGUI_ALIGN_H__
24
25 #include "MyGUI_Prerequest.h"
26 #include "MyGUI_Macros.h"
27 #include "MyGUI_Diagnostic.h"
28 #include "MyGUI_StringUtility.h"
29 #include <map>
30
31 namespace MyGUI
32 {
33
34 struct MYGUI_EXPORT Align
35 {
36 enum Enum
37 {
38 HCenter = MYGUI_FLAG_NONE,
39 VCenter = MYGUI_FLAG_NONE,
40 Center = HCenter | VCenter,
42 Left = MYGUI_FLAG(1),
43 Right = MYGUI_FLAG(2),
44 HStretch = Left | Right,
46 Top = MYGUI_FLAG(3),
47 Bottom = MYGUI_FLAG(4),
48 VStretch = Top | Bottom,
50 Stretch = HStretch | VStretch,
51 Default = Left | Top
52 };
53
54 Align(Enum _value = Default) :
55 value(_value)
56 {
57 }
58
59 bool isHCenter() const
60 {
61 return HCenter == (value & ((int)HStretch));
62 }
63
64 bool isVCenter() const
65 {
66 return VCenter == (value & ((int)VStretch));
67 }
68
69 bool isCenter() const
70 {
71 return Center == (value & ((int)Stretch));
72 }
73
74 bool isLeft() const
75 {
76 return Left == (value & ((int)HStretch));
77 }
78
79 bool isRight() const
80 {
81 return Right == (value & ((int)HStretch));
82 }
83
84 bool isHStretch() const
85 {
86 return HStretch == (value & ((int)HStretch));
87 }
88
89 bool isTop() const
90 {
91 return Top == (value & ((int)VStretch));
92 }
93
94 bool isBottom() const
95 {
96 return (Bottom == (value & ((int)VStretch)));
97 }
98
99 bool isVStretch() const
100 {
101 return (VStretch == (value & ((int)VStretch)));
102 }
103
104 bool isStretch() const
105 {
106 return (Stretch == (value & ((int)Stretch)));
107 }
108
109 bool isDefault() const
110 {
111 return (Default == (value & ((int)Stretch)));
112 }
113
114 Align& operator |= (Align const& _other)
115 {
116 value = Enum(int(value) | int(_other.value));
117 return *this;
118 }
119
120 friend Align operator | (Enum const& a, Enum const& b)
121 {
122 return Align(Enum(int(a) | int(b)));
123 }
124
125 friend Align operator | (Align const& a, Align const& b)
126 {
127 return Align(Enum(int(a.value) | int(b.value)));
128 }
129
130 friend bool operator == (Align const& a, Align const& b)
131 {
132 return a.value == b.value;
133 }
134
135 friend bool operator != (Align const& a, Align const& b)
136 {
137 return a.value != b.value;
138 }
139
140 typedef std::map<std::string, int> MapAlign;
141
142 static Align parse(const std::string& _value)
143 {
144 Align result(Enum(0));
145 const MapAlign& map_names = result.getValueNames();
146 const std::vector<std::string>& vec = utility::split(_value);
147 for (size_t pos = 0; pos < vec.size(); pos++)
148 {
149 MapAlign::const_iterator iter = map_names.find(vec[pos]);
150 if (iter != map_names.end())
151 {
152 result.value = Enum(int(result.value) | int(iter->second));
153 }
154 }
155 return result;
156 }
157
158 std::string print() const
159 {
160 std::string result;
161
162 if (value & Left)
163 {
164 if (value & Right)
165 result = "HStretch";
166 else
167 result = "Left";
168 }
169 else if (value & Right)
170 result = "Right";
171 else
172 result = "HCenter";
173
174 if (value & Top)
175 {
176 if (value & Bottom)
177 result += " VStretch";
178 else
179 result += " Top";
180 }
181 else if (value & Bottom)
182 result += " Bottom";
183 else
184 result += " VCenter";
185
186 return result;
187 }
188
189 friend std::ostream& operator << ( std::ostream& _stream, const Align& _value )
190 {
191 _stream << _value.print();
192 return _stream;
193 }
194
195 friend std::istream& operator >> ( std::istream& _stream, Align& _value )
196 {
197 _value.value = Enum(0);
198 std::string value;
199 _stream >> value;
200
201 const MapAlign& map_names = _value.getValueNames();
202 MapAlign::const_iterator iter = map_names.find(value);
203 if (iter != map_names.end())
204 _value.value = Enum(int(_value.value) | int(iter->second));
205
206 if (!_stream.eof())
207 {
208 std::string value2;
209 _stream >> value2;
210 iter = map_names.find(value2);
211 if (iter != map_names.end())
212 _value.value = Enum(int(_value.value) | int(iter->second));
213 }
214
215 return _stream;
216 }
217
218 private:
219 const MapAlign& getValueNames() const
220 {
221 static MapAlign map_names;
222
223 if (map_names.empty())
224 {
225 // OBSOLETE
226 map_names["ALIGN_HCENTER"] = HCenter;
227 map_names["ALIGN_VCENTER"] = VCenter;
228 map_names["ALIGN_CENTER"] = Center;
229 map_names["ALIGN_LEFT"] = Left;
230 map_names["ALIGN_RIGHT"] = Right;
231 map_names["ALIGN_HSTRETCH"] = HStretch;
232 map_names["ALIGN_TOP"] = Top;
233 map_names["ALIGN_BOTTOM"] = Bottom;
234 map_names["ALIGN_VSTRETCH"] = VStretch;
235 map_names["ALIGN_STRETCH"] = Stretch;
236 map_names["ALIGN_DEFAULT"] = Default;
237
238 MYGUI_REGISTER_VALUE(map_names, HCenter);
239 MYGUI_REGISTER_VALUE(map_names, VCenter);
240 MYGUI_REGISTER_VALUE(map_names, Center);
241 MYGUI_REGISTER_VALUE(map_names, Left);
242 MYGUI_REGISTER_VALUE(map_names, Right);
243 MYGUI_REGISTER_VALUE(map_names, HStretch);
244 MYGUI_REGISTER_VALUE(map_names, Top);
245 MYGUI_REGISTER_VALUE(map_names, Bottom);
246 MYGUI_REGISTER_VALUE(map_names, VStretch);
247 MYGUI_REGISTER_VALUE(map_names, Stretch);
248 MYGUI_REGISTER_VALUE(map_names, Default);
249 }
250
251 return map_names;
252 }
253
254 private:
255 Enum value;
256 };
257
258 } // namespace MyGUI
259
260 #endif // __MYGUI_ALIGN_H__
MyGUI::FontCodeType::Enum
Enum
Definition: MyGUI_FontData.h:33
MyGUI::geometry_utility::Left
Definition: MyGUI_GeometryUtility.h:36
MyGUI_Diagnostic.h
MyGUI::Align::isVStretch
bool isVStretch() const
Definition: MyGUI_Align.h:99
MyGUI_Prerequest.h
MyGUI::Align::isBottom
bool isBottom() const
Definition: MyGUI_Align.h:94
MyGUI::operator!=
bool operator!=(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1049
MyGUI::geometry_utility::Bottom
Definition: MyGUI_GeometryUtility.h:36
MyGUI_Macros.h
MyGUI::Align::isVCenter
bool isVCenter() const
Definition: MyGUI_Align.h:64
MyGUI::Align::print
std::string print() const
Definition: MyGUI_Align.h:158
MyGUI_StringUtility.h
MyGUI::Align::Align
Align(Enum _value=Default)
Definition: MyGUI_Align.h:54
MyGUI::operator==
bool operator==(const UString::_const_fwd_iterator &left, const UString::_const_fwd_iterator &right)
Definition: MyGUI_UString.h:1046
MYGUI_FLAG
#define MYGUI_FLAG(num)
Definition: MyGUI_Macros.h:39
MyGUI::Align::parse
static Align parse(const std::string &_value)
Definition: MyGUI_Align.h:142
MyGUI::Align::Enum
Enum
Definition: MyGUI_Align.h:36
MyGUI::Align::isHCenter
bool isHCenter() const
Definition: MyGUI_Align.h:59
MyGUI::geometry_utility::Right
Definition: MyGUI_GeometryUtility.h:36
MYGUI_REGISTER_VALUE
#define MYGUI_REGISTER_VALUE(map, value)
Definition: MyGUI_Diagnostic.h:82
MyGUI::Align::isStretch
bool isStretch() const
Definition: MyGUI_Align.h:104
MyGUI::Align::isLeft
bool isLeft() const
Definition: MyGUI_Align.h:74
MyGUI::utility::split
std::vector< std::string > split(const std::string &_source, const std::string &_delims="\t\n ")
Definition: MyGUI_StringUtility.h:306
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:120
MyGUI::Align::isRight
bool isRight() const
Definition: MyGUI_Align.h:79
MyGUI::Align::isTop
bool isTop() const
Definition: MyGUI_Align.h:89
MYGUI_FLAG_NONE
#define MYGUI_FLAG_NONE
Definition: MyGUI_Macros.h:38
MyGUI::Align
Definition: MyGUI_Align.h:34
MyGUI::geometry_utility::Top
Definition: MyGUI_GeometryUtility.h:36
MyGUI::Align::MapAlign
std::map< std::string, int > MapAlign
Definition: MyGUI_Align.h:140
MyGUI::Align::isHStretch
bool isHStretch() const
Definition: MyGUI_Align.h:84
MyGUI::Align::isDefault
bool isDefault() const
Definition: MyGUI_Align.h:109
MyGUI::Align::isCenter
bool isCenter() const
Definition: MyGUI_Align.h:69