Crazy Eddie's GUI System 0.8.7
Loading...
Searching...
No Matches
UDim.h
1/***********************************************************************
2 created: Tue May 31 2005
3 author: Paul D Turner <paul@cegui.org.uk>
4*************************************************************************/
5/***************************************************************************
6 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 ***************************************************************************/
27#ifndef _CEGUIUDim_h_
28#define _CEGUIUDim_h_
29
30#include "CEGUI/Base.h"
31#include <ostream>
32
33#if defined(_MSC_VER)
34# pragma warning(push)
35# pragma warning(disable : 4251)
36#endif
37
38// some macros to aid in the creation of UDims
39#define cegui_absdim(x) CEGUI::UDim(0,(x))
40#define cegui_reldim(x) CEGUI::UDim((x),0)
41
42
43// Start of CEGUI namespace section
44namespace CEGUI
45{
92class CEGUIEXPORT UDim :
93 public AllocatedObject<UDim>
94{
95public:
96 inline UDim() :
97 d_scale(0),
98 d_offset(0)
99 {}
100
101 inline UDim(float scale, float offset):
102 d_scale(scale),
103 d_offset(offset)
104 {}
105
106 inline UDim(const UDim& v):
107 d_scale(v.d_scale),
108 d_offset(v.d_offset)
109 {}
110
111 inline UDim operator+(const UDim& other) const
112 {
113 return UDim(d_scale + other.d_scale, d_offset + other.d_offset);
114 }
115
116 inline UDim operator-(const UDim& other) const
117 {
118 return UDim(d_scale - other.d_scale, d_offset - other.d_offset);
119 }
120
121 inline UDim operator*(const float val) const
122 {
123 return UDim(d_scale * val, d_offset * val);
124 }
125
126 inline friend UDim operator*(const float val, const UDim& u)
127 {
128 return UDim(val * u.d_scale, val * u.d_offset);
129 }
130
131 inline UDim operator*(const UDim& other) const
132 {
133 return UDim(d_scale * other.d_scale, d_offset * other.d_offset);
134 }
135
136 inline UDim operator/(const UDim& other) const
137 {
138 // division by zero sets component to zero. Not technically correct
139 // but probably better than exceptions and/or NaN values.
140 return UDim(other.d_scale == 0.0f ? 0.0f : d_scale / other.d_scale,
141 other.d_offset == 0.0f ? 0.0f : d_offset / other.d_offset);
142 }
143
144 inline const UDim& operator+=(const UDim& other)
145 {
146 d_scale += other.d_scale;
147 d_offset += other.d_offset;
148 return *this;
149 }
150
151 inline const UDim& operator-=(const UDim& other)
152 {
153 d_scale -= other.d_scale;
154 d_offset -= other.d_offset;
155 return *this;
156 }
157
158 inline const UDim& operator*=(const UDim& other)
159 {
160 d_scale *= other.d_scale;
161 d_offset *= other.d_offset;
162 return *this;
163 }
164
165 inline const UDim& operator/=(const UDim& other)
166 {
167 // division by zero sets component to zero. Not technically correct
168 // but probably better than exceptions and/or NaN values.
169 d_scale = (other.d_scale == 0.0f ? 0.0f : d_scale / other.d_scale);
170 d_offset = (other.d_offset == 0.0f ? 0.0f : d_offset / other.d_offset);
171 return *this;
172 }
173
174 inline bool operator==(const UDim& other) const
175 {
176 return d_scale == other.d_scale && d_offset == other.d_offset;
177 }
178
179 inline bool operator!=(const UDim& other) const
180 {
181 return !operator==(other);
182 }
183
187 inline friend std::ostream& operator << (std::ostream& s, const UDim& v)
188 {
189 s << "CEGUI::UDim(" << v.d_scale << ", " << v.d_offset << ")";
190 return s;
191 }
192
196 inline static UDim zero()
197 {
198 return UDim(0.0f, 0.0f);
199 }
200
207 inline static UDim relative()
208 {
209 return UDim(1.0f, 0.0f);
210 }
211
218 inline static UDim percent()
219 {
220 return UDim(0.01f, 0.0f);
221 }
222
230 inline static UDim px()
231 {
232 return UDim(0.0f, 1.0f);
233 }
234
235 float d_scale;
236 float d_offset;
237};
238
249class CEGUIEXPORT UBox :
250 public AllocatedObject<UBox>
251{
252public:
253 UBox():
254 d_top(),
255 d_left(),
256 d_bottom(),
257 d_right()
258 {}
259
260 UBox(const UDim& margin):
261 d_top(margin),
262 d_left(margin),
263 d_bottom(margin),
264 d_right(margin)
265 {}
266
267 UBox(const UDim& top, const UDim& left, const UDim& bottom, const UDim& right):
268 d_top(top),
269 d_left(left),
270 d_bottom(bottom),
271 d_right(right)
272 {}
273
274 UBox(const UBox& b):
275 d_top(b.d_top),
276 d_left(b.d_left),
277 d_bottom(b.d_bottom),
278 d_right(b.d_right)
279 {}
280
281 /*************************************************************************
282 Operators
283 *************************************************************************/
284 bool operator==(const UBox& rhs) const
285 {
286 return ((d_top == rhs.d_top) &&
287 (d_left == rhs.d_left) &&
288 (d_bottom == rhs.d_bottom) &&
289 (d_right == rhs.d_right));
290 }
291
292 bool operator!=(const UBox& rhs) const
293 {
294 return !operator==(rhs);
295 }
296
297 UBox& operator=(const UBox& rhs)
298 {
299 d_top = rhs.d_top;
300 d_left = rhs.d_left;
301 d_bottom = rhs.d_bottom;
302 d_right = rhs.d_right;
303
304 return *this;
305 }
306
307 UBox operator*(const float val) const
308 {
309 return UBox(
310 d_top * val, d_left * val,
311 d_bottom * val, d_right * val);
312 }
313
314 UBox operator*(const UDim& dim) const
315 {
316 return UBox(
317 d_top * dim, d_left * dim,
318 d_bottom * dim, d_right * dim);
319 }
320
321 UBox operator+(const UBox& b) const
322 {
323 return UBox(
324 d_top + b.d_top, d_left + b.d_left,
325 d_bottom + b.d_bottom, d_right + b.d_right);
326 }
327
328 /*************************************************************************
329 Data Fields
330 *************************************************************************/
331 UDim d_top;
332 UDim d_left;
333 UDim d_bottom;
334 UDim d_right;
335};
336
342template<typename T>
344{
345 return T(0);
346}
347
348template<>
349inline UDim TypeSensitiveZero<UDim>()
350{
351 return UDim(0, 0);
352}
353
359template<typename T>
361{
362 return T(1);
363}
364
365template<>
366inline UDim TypeSensitiveOne<UDim>()
367{
368 return UDim::relative();
369}
370
371} // End of CEGUI namespace section
372
373
374#if defined(_MSC_VER)
375# pragma warning(pop)
376#endif
377
378#endif // end of guard _CEGUIUDim_h_
379
Definition MemoryAllocatedObject.h:110
base class for properties able to do native set/get
Definition TypedProperty.h:50
Class encapsulating the 'Unified Box' - this is usually used for margin.
Definition UDim.h:251
Dimension that has both a relative 'scale' portion and and absolute 'offset' portion.
Definition UDim.h:94
static UDim px()
finger saving convenience method returning UDim(0, 1)
Definition UDim.h:230
static UDim relative()
finger saving convenience method returning UDim(1, 0)
Definition UDim.h:207
static UDim zero()
finger saving convenience method returning UDim(0, 0)
Definition UDim.h:196
static UDim percent()
finger saving convenience method returning UDim(0.01, 0)
Definition UDim.h:218
Main namespace for Crazy Eddie's GUI Library.
Definition arch_overview.dox:1
T TypeSensitiveZero()
allows you to get UDim(0, 0) if you pass UDim or just 0 if you pass anything else
Definition UDim.h:343
T TypeSensitiveOne()
allows you to get UDim::relative() if you pass UDim or just 1 if you pass anything else
Definition UDim.h:360
String CEGUIEXPORT operator+(const String &str1, const String &str2)
Return String object that is the concatenation of the given inputs.
bool CEGUIEXPORT operator!=(const String &str1, const String &str2)
Return true if String str1 is not equal to String str2.
bool CEGUIEXPORT operator==(const String &str1, const String &str2)
Return true if String str1 is equal to String str2.