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) {}
54 float asAbsolute(
float base)
const {
return PixelAligned(base * d_scale) + d_offset; }
55 float asRelative(
float base)
const {
return (base != 0.0f) ? d_offset / base + d_scale : 0.0f; }
57 UDim operator+(
const UDim& other)
const {
return UDim(d_scale + other.d_scale, d_offset + other.d_offset); }
58 UDim operator-(
const UDim& other)
const {
return UDim(d_scale - other.d_scale, d_offset - other.d_offset); }
59 UDim operator*(
const UDim& other)
const {
return UDim(d_scale * other.d_scale, d_offset * other.d_offset); }
60 UDim operator/(
const UDim& other)
const
64 return UDim(other.d_scale == 0.0f ? 0.0f : d_scale / other.d_scale,
65 other.d_offset == 0.0f ? 0.0f : d_offset / other.d_offset);
68 const UDim& operator+=(
const UDim& other) { d_scale += other.d_scale; d_offset += other.d_offset;
return *
this; }
69 const UDim& operator-=(
const UDim& other) { d_scale -= other.d_scale; d_offset -= other.d_offset;
return *
this; }
70 const UDim& operator*=(
const UDim& other) { d_scale *= other.d_scale; d_offset *= other.d_offset;
return *
this; }
71 const UDim& operator/=(
const UDim& other)
75 d_scale = (other.d_scale == 0.0f ? 0.0f : d_scale / other.d_scale);
76 d_offset = (other.d_offset == 0.0f ? 0.0f : d_offset / other.d_offset);
80 bool operator==(
const UDim& other)
const {
return d_scale == other.d_scale && d_offset == other.d_offset; }
83 float d_scale, d_offset;
98 Vector2 asAbsolute(
const Size& base)
const {
return Vector2(d_x.asAbsolute(base.d_width), d_y.asAbsolute(base.d_height)); }
99 Vector2 asRelative(
const Size& base)
const {
return Vector2(d_x.asRelative(base.d_width), d_y.asRelative(base.d_height)); }
106 const UVector2& operator+=(
const UVector2& other) { d_x += other.d_x; d_y += other.d_y;
return *
this; }
107 const UVector2& operator-=(
const UVector2& other) { d_x -= other.d_x; d_y -= other.d_y;
return *
this; }
108 const UVector2& operator/=(
const UVector2& other) { d_x /= other.d_x; d_y /= other.d_y;
return *
this; }
109 const UVector2& operator*=(
const UVector2& other) { d_x *= other.d_x; d_y *= other.d_y;
return *
this; }
116 const UVector2& operator+=(
const UDim& dim) { d_x += dim; d_y += dim;
return *
this; }
117 const UVector2& operator-=(
const UDim& dim) { d_x -= dim; d_y -= dim;
return *
this; }
118 const UVector2& operator/=(
const UDim& dim) { d_x /= dim; d_y /= dim;
return *
this; }
119 const UVector2& operator*=(
const UDim& dim) { d_x *= dim; d_y *= dim;
return *
this; }
121 bool operator==(
const UVector2& other)
const {
return d_x == other.d_x && d_y == other.d_y; }
148 Rect asAbsolute(
const Size& base)
const
151 d_min.d_x.asAbsolute(base.d_width),
152 d_min.d_y.asAbsolute(base.d_height),
153 d_max.d_x.asAbsolute(base.d_width),
154 d_max.d_y.asAbsolute(base.d_height)
158 Rect asRelative(
const Size& base)
const
161 d_min.d_x.asRelative(base.d_width),
162 d_min.d_y.asRelative(base.d_height),
163 d_max.d_x.asRelative(base.d_width),
164 d_max.d_y.asRelative(base.d_height)
168 const UVector2& getPosition()
const {
return d_min; }
169 UVector2 getSize()
const {
return d_max - d_min; }
170 UDim getWidth()
const {
return d_max.d_x - d_min.d_x; }
171 UDim getHeight()
const {
return d_max.d_y - d_min.d_y; }
173 void setPosition(
const UVector2& pos)
185 void setWidth(
const UDim& w) { d_max.d_x = d_min.d_x + w; }
186 void setHeight(
const UDim& h) { d_max.d_y = d_min.d_y + h; }
200 #endif // end of guard _CEGUIUDim_h_