33 #include "CEGUI/UDim.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 Size& s)
const
107 return Size(d_width - s.d_width, d_height - s.d_height);
110 inline void clamp(
const Size& min,
const Size& max)
112 assert(min.d_width <= max.d_width);
113 assert(min.d_height <= max.d_height);
115 if (d_width < min.d_width)
116 d_width = min.d_width;
117 else if (d_width > max.d_width)
118 d_width = max.d_width;
120 if (d_height < min.d_height)
121 d_height = min.d_height;
122 else if (d_height > max.d_height)
123 d_height = max.d_height;
126 inline void scaleToAspect(
AspectMode mode, T ratio)
131 if(d_width <= 0 && d_height <= 0)
136 const T expectedWidth = d_height * ratio;
137 const bool keepHeight = (mode ==
AM_SHRINK) ?
138 expectedWidth <= d_width : expectedWidth >= d_width;
142 d_width = expectedWidth;
146 d_height = d_width / ratio;
155 s <<
"CEGUI::Size<" <<
typeid(T).name() <<
">(" << v.d_width <<
", " << v.d_height <<
")";
162 return Size(side, side);
168 return square(TypeSensitiveZero<T>());
174 return square(TypeSensitiveOne<T>());
180 return Size(TypeSensitiveOne<T>(), TypeSensitiveZero<T>());
186 return Size(TypeSensitiveOne<T>(), TypeSensitiveZero<T>());
194 typedef Size<float> Sizef;
195 typedef Size<UDim> USize;
197 inline USize operator*(
const USize& i,
float x)
199 return i * UDim(x,x);
204 #endif // end of guard _CEGUISize_h_