31 #include "CEGUIRect.h"
32 #include "CEGUIVector.h"
35 #define cegui_absdim(x) CEGUI::UDim(0,(x))
36 #define cegui_reldim(x) CEGUI::UDim((x),0)
51 UDim(
float scale,
float offset) : d_scale(scale), d_offset(offset) {}
52 UDim(
const UDim& v): d_scale(v.d_scale), d_offset(v.d_offset) {}
55 float asAbsolute(
float base)
const
57 return PixelAligned(base * d_scale) + d_offset;
59 float asRelative(
float base)
const
61 return (base != 0.0f) ? d_offset / base + d_scale : 0.0f;
66 return UDim(d_scale + other.d_scale, d_offset + other.d_offset);
68 UDim operator-(
const UDim& other)
const
70 return UDim(d_scale - other.d_scale, d_offset - other.d_offset);
72 UDim operator*(
const UDim& other)
const
74 return UDim(d_scale * other.d_scale, d_offset * other.d_offset);
76 UDim operator/(
const UDim& other)
const
80 return UDim(other.d_scale == 0.0f ? 0.0f : d_scale / other.d_scale,
81 other.d_offset == 0.0f ? 0.0f : d_offset / other.d_offset);
84 const UDim& operator+=(
const UDim& other)
86 d_scale += other.d_scale;
87 d_offset += other.d_offset;
90 const UDim& operator-=(
const UDim& other)
92 d_scale -= other.d_scale;
93 d_offset -= other.d_offset;
96 const UDim& operator*=(
const UDim& other)
98 d_scale *= other.d_scale;
99 d_offset *= other.d_offset;
102 const UDim& operator/=(
const UDim& other)
106 d_scale = (other.d_scale == 0.0f ? 0.0f : d_scale / other.d_scale);
107 d_offset = (other.d_offset == 0.0f ? 0.0f : d_offset / other.d_offset);
113 return d_scale == other.d_scale && d_offset == other.d_offset;
120 float d_scale, d_offset;
138 return Vector2(d_x.asAbsolute(base.d_width), d_y.asAbsolute(base.d_height));
142 return Vector2(d_x.asRelative(base.d_width), d_y.asRelative(base.d_height));
147 return UVector2(d_x + other.d_x, d_y + other.d_y);
151 return UVector2(d_x - other.d_x, d_y - other.d_y);
155 return UVector2(d_x / other.d_x, d_y / other.d_y);
159 return UVector2(d_x * other.d_x, d_y * other.d_y);
189 return UVector2(d_x + dim, d_y + dim);
193 return UVector2(d_x - dim, d_y - dim);
197 return UVector2(d_x / dim, d_y / dim);
201 return UVector2(d_x * dim, d_y * dim);
231 return d_x == other.d_x && d_y == other.d_y;
260 URect(
const URect& v): d_min(v.d_min), d_max(v.d_max) {}
264 Rect asAbsolute(
const Size& base)
const
267 d_min.d_x.asAbsolute(base.d_width),
268 d_min.d_y.asAbsolute(base.d_height),
269 d_max.d_x.asAbsolute(base.d_width),
270 d_max.d_y.asAbsolute(base.d_height)
274 Rect asRelative(
const Size& base)
const
277 d_min.d_x.asRelative(base.d_width),
278 d_min.d_y.asRelative(base.d_height),
279 d_max.d_x.asRelative(base.d_width),
280 d_max.d_y.asRelative(base.d_height)
290 return d_max - d_min;
292 UDim getWidth()
const
294 return d_max.d_x - d_min.d_x;
296 UDim getHeight()
const
298 return d_max.d_y - d_min.d_y;
301 void setPosition(
const UVector2& pos)
313 void setWidth(
const UDim& w)
315 d_max.d_x = d_min.d_x + w;
317 void setHeight(
const UDim& h)
319 d_max.d_y = d_min.d_y + h;
330 return URect(d_min * dim, d_max * dim);
335 return URect(d_min + r.d_min, d_max + r.d_max);
378 d_bottom(b.d_bottom),
387 return ((d_top == rhs.d_top) &&
388 (d_left == rhs.d_left) &&
389 (d_bottom == rhs.d_bottom) &&
390 (d_right == rhs.d_right));
402 d_bottom = rhs.d_bottom;
403 d_right = rhs.d_right;
408 UBox operator*(
const UDim& dim)
const
411 d_top * dim, d_left * dim,
412 d_bottom * dim, d_right * dim);
418 d_top + b.d_top, d_left + b.d_left,
419 d_bottom + b.d_bottom, d_right + b.d_right);
434 #endif // end of guard _CEGUIUDim_h_