32 #include "CEGUI/UDim.h"
33 #include "CEGUI/Vector.h"
67 public AllocatedObject<Size<T> >
75 inline Size(
const T width,
const T height):
80 inline Size(
const Size& v):
85 inline bool operator==(
const Size& other)
const
87 return d_width == other.d_width && d_height == other.d_height;
90 inline bool operator!=(
const Size& other)
const
92 return !operator==(other);
95 inline Size operator*(
const T c)
const
97 return Size(d_width * c, d_height * c);
100 inline Size operator*(
const Size& s)
const
102 return Size(d_width * s.d_width, d_height * s.d_height);
105 inline Size operator*(
const Vector2f& vec)
const
107 return Size(d_width * vec.d_x, d_height * vec.d_y);
110 inline Size operator+(
const Size& s)
const
112 return Size(d_width + s.d_width, d_height + s.d_height);
115 inline Size operator-(
const Size& s)
const
117 return Size(d_width - s.d_width, d_height - s.d_height);
120 inline void clamp(
const Size& min,
const Size& max)
122 assert(min.d_width <= max.d_width);
123 assert(min.d_height <= max.d_height);
125 if (d_width < min.d_width)
126 d_width = min.d_width;
127 else if (d_width > max.d_width)
128 d_width = max.d_width;
130 if (d_height < min.d_height)
131 d_height = min.d_height;
132 else if (d_height > max.d_height)
133 d_height = max.d_height;
136 inline void scaleToAspect(
AspectMode mode, T ratio)
141 if(d_width <= 0 && d_height <= 0)
146 const T expectedWidth = d_height * ratio;
147 const bool keepHeight = (mode ==
AM_SHRINK) ?
148 expectedWidth <= d_width : expectedWidth >= d_width;
152 d_width = expectedWidth;
156 d_height = d_width / ratio;
165 s <<
"CEGUI::Size<" <<
typeid(T).name() <<
">(" << v.d_width <<
", " << v.d_height <<
")";
172 return Size(side, side);
178 return square(TypeSensitiveZero<T>());
184 return square(TypeSensitiveOne<T>());
190 return Size(TypeSensitiveOne<T>(), TypeSensitiveZero<T>());
196 return Size(TypeSensitiveOne<T>(), TypeSensitiveZero<T>());
204 typedef Size<float> Sizef;
205 typedef Size<UDim> USize;
207 inline USize operator*(
const USize& i,
float x)
209 return i * UDim(x,x);
214 #endif // end of guard _CEGUISize_h_