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 {
return UDim(d_scale * other.d_scale, d_offset * other.d_offset); }
62 const UDim& operator+=(
const UDim& other) { d_scale += other.d_scale; d_offset += other.d_offset;
return *
this; }
63 const UDim& operator-=(
const UDim& other) { d_scale -= other.d_scale; d_offset -= other.d_offset;
return *
this; }
64 const UDim& operator/=(
const UDim& other) { d_scale /= other.d_scale; d_offset /= other.d_offset;
return *
this; }
65 const UDim& operator*=(
const UDim& other) { d_scale *= other.d_scale; d_offset *= other.d_offset;
return *
this; }
67 bool operator==(
const UDim& other)
const {
return d_scale == other.d_scale && d_offset == other.d_offset; }
70 float d_scale, d_offset;
85 Vector2 asAbsolute(
const Size& base)
const {
return Vector2(d_x.asAbsolute(base.d_width), d_y.asAbsolute(base.d_height)); }
86 Vector2 asRelative(
const Size& base)
const {
return Vector2(d_x.asRelative(base.d_width), d_y.asRelative(base.d_height)); }
93 const UVector2& operator+=(
const UVector2& other) { d_x += other.d_x; d_y += other.d_y;
return *
this; }
94 const UVector2& operator-=(
const UVector2& other) { d_x -= other.d_x; d_y -= other.d_y;
return *
this; }
95 const UVector2& operator/=(
const UVector2& other) { d_x /= other.d_x; d_y /= other.d_y;
return *
this; }
96 const UVector2& operator*=(
const UVector2& other) { d_x *= other.d_x; d_y *= other.d_y;
return *
this; }
98 bool operator==(
const UVector2& other)
const {
return d_x == other.d_x && d_y == other.d_y; }
125 Rect asAbsolute(
const Size& base)
const
128 d_min.d_x.asAbsolute(base.d_width),
129 d_min.d_y.asAbsolute(base.d_height),
130 d_max.d_x.asAbsolute(base.d_width),
131 d_max.d_y.asAbsolute(base.d_height)
135 Rect asRelative(
const Size& base)
const
138 d_min.d_x.asRelative(base.d_width),
139 d_min.d_y.asRelative(base.d_height),
140 d_max.d_x.asRelative(base.d_width),
141 d_max.d_y.asRelative(base.d_height)
145 const UVector2& getPosition()
const {
return d_min; }
146 UVector2 getSize()
const {
return d_max - d_min; }
147 UDim getWidth()
const {
return d_max.d_x - d_min.d_x; }
148 UDim getHeight()
const {
return d_max.d_y - d_min.d_y; }
150 void setPosition(
const UVector2& pos)
162 void setWidth(
const UDim& w) { d_max.d_x = d_min.d_x + w; }
163 void setHeight(
const UDim& h) { d_max.d_y = d_min.d_y + h; }
177 #endif // end of guard _CEGUIUDim_h_