/usr/include/CEGUI/CEGUIUDim.h is in libcegui-mk2-dev 0.7.5-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | /***********************************************************************
filename: CEGUIUDim.h
created: Tue May 31 2005
author: Paul D Turner <paul@cegui.org.uk>
*************************************************************************/
/***************************************************************************
* Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
***************************************************************************/
#ifndef _CEGUIUDim_h_
#define _CEGUIUDim_h_
#include "CEGUIRect.h"
#include "CEGUIVector.h"
// some macros to aid in the creation of UDims
#define cegui_absdim(x) CEGUI::UDim(0,(x))
#define cegui_reldim(x) CEGUI::UDim((x),0)
// Start of CEGUI namespace section
namespace CEGUI
{
/*!
\brief
Class representing a unified dimension; that is a dimension that has both
a relative 'scale' portion and and absolute 'offset' portion.
*/
class CEGUIEXPORT UDim
{
public:
UDim() {}
UDim(float scale, float offset) : d_scale(scale), d_offset(offset) {}
UDim(const UDim& v): d_scale(v.d_scale), d_offset(v.d_offset) {}
~UDim() {}
float asAbsolute(float base) const
{
return PixelAligned(base * d_scale) + d_offset;
}
float asRelative(float base) const
{
return (base != 0.0f) ? d_offset / base + d_scale : 0.0f;
}
UDim operator+(const UDim& other) const
{
return UDim(d_scale + other.d_scale, d_offset + other.d_offset);
}
UDim operator-(const UDim& other) const
{
return UDim(d_scale - other.d_scale, d_offset - other.d_offset);
}
UDim operator*(const UDim& other) const
{
return UDim(d_scale * other.d_scale, d_offset * other.d_offset);
}
UDim operator/(const UDim& other) const
{
// division by zero sets component to zero. Not technically correct
// but probably better than exceptions and/or NaN values.
return UDim(other.d_scale == 0.0f ? 0.0f : d_scale / other.d_scale,
other.d_offset == 0.0f ? 0.0f : d_offset / other.d_offset);
}
const UDim& operator+=(const UDim& other)
{
d_scale += other.d_scale;
d_offset += other.d_offset;
return *this;
}
const UDim& operator-=(const UDim& other)
{
d_scale -= other.d_scale;
d_offset -= other.d_offset;
return *this;
}
const UDim& operator*=(const UDim& other)
{
d_scale *= other.d_scale;
d_offset *= other.d_offset;
return *this;
}
const UDim& operator/=(const UDim& other)
{
// division by zero sets component to zero. Not technically correct
// but probably better than exceptions and/or NaN values.
d_scale = (other.d_scale == 0.0f ? 0.0f : d_scale / other.d_scale);
d_offset = (other.d_offset == 0.0f ? 0.0f : d_offset / other.d_offset);
return *this;
}
bool operator==(const UDim& other) const
{
return d_scale == other.d_scale && d_offset == other.d_offset;
}
bool operator!=(const UDim& other) const
{
return !operator==(other);
}
float d_scale, d_offset;
};
/*!
\brief
Two dimensional vector class built using unified dimensions (UDims).
The UVector2 class is used for representing both positions and sizes.
*/
class CEGUIEXPORT UVector2
{
public:
UVector2() {}
UVector2(const UDim& x, const UDim& y) : d_x(x), d_y(y) {}
UVector2(const UVector2& v): d_x(v.d_x), d_y(v.d_y) {}
~UVector2() {}
Vector2 asAbsolute(const Size& base) const
{
return Vector2(d_x.asAbsolute(base.d_width), d_y.asAbsolute(base.d_height));
}
Vector2 asRelative(const Size& base) const
{
return Vector2(d_x.asRelative(base.d_width), d_y.asRelative(base.d_height));
}
UVector2 operator+(const UVector2& other) const
{
return UVector2(d_x + other.d_x, d_y + other.d_y);
}
UVector2 operator-(const UVector2& other) const
{
return UVector2(d_x - other.d_x, d_y - other.d_y);
}
UVector2 operator/(const UVector2& other) const
{
return UVector2(d_x / other.d_x, d_y / other.d_y);
}
UVector2 operator*(const UVector2& other) const
{
return UVector2(d_x * other.d_x, d_y * other.d_y);
}
const UVector2& operator+=(const UVector2& other)
{
d_x += other.d_x;
d_y += other.d_y;
return *this;
}
const UVector2& operator-=(const UVector2& other)
{
d_x -= other.d_x;
d_y -= other.d_y;
return *this;
}
const UVector2& operator/=(const UVector2& other)
{
d_x /= other.d_x;
d_y /= other.d_y;
return *this;
}
const UVector2& operator*=(const UVector2& other)
{
d_x *= other.d_x;
d_y *= other.d_y;
return *this;
}
UVector2 operator+(const UDim& dim) const
{
return UVector2(d_x + dim, d_y + dim);
}
UVector2 operator-(const UDim& dim) const
{
return UVector2(d_x - dim, d_y - dim);
}
UVector2 operator/(const UDim& dim) const
{
return UVector2(d_x / dim, d_y / dim);
}
UVector2 operator*(const UDim& dim) const
{
return UVector2(d_x * dim, d_y * dim);
}
const UVector2& operator+=(const UDim& dim)
{
d_x += dim;
d_y += dim;
return *this;
}
const UVector2& operator-=(const UDim& dim)
{
d_x -= dim;
d_y -= dim;
return *this;
}
const UVector2& operator/=(const UDim& dim)
{
d_x /= dim;
d_y /= dim;
return *this;
}
const UVector2& operator*=(const UDim& dim)
{
d_x *= dim;
d_y *= dim;
return *this;
}
bool operator==(const UVector2& other) const
{
return d_x == other.d_x && d_y == other.d_y;
}
bool operator!=(const UVector2& other) const
{
return !operator==(other);
}
UDim d_x, d_y;
};
/*!
\brief
Area rectangle class built using unified dimensions (UDims).
*/
class CEGUIEXPORT URect
{
public:
URect() {}
URect(const UVector2& min, const UVector2& max) : d_min(min), d_max(max) {}
URect(const UDim& left, const UDim& top, const UDim& right, const UDim& bottom)
{
d_min.d_x = left;
d_min.d_y = top;
d_max.d_x = right;
d_max.d_y = bottom;
}
URect(const URect& v): d_min(v.d_min), d_max(v.d_max) {}
~URect() {}
Rect asAbsolute(const Size& base) const
{
return Rect(
d_min.d_x.asAbsolute(base.d_width),
d_min.d_y.asAbsolute(base.d_height),
d_max.d_x.asAbsolute(base.d_width),
d_max.d_y.asAbsolute(base.d_height)
);
}
Rect asRelative(const Size& base) const
{
return Rect(
d_min.d_x.asRelative(base.d_width),
d_min.d_y.asRelative(base.d_height),
d_max.d_x.asRelative(base.d_width),
d_max.d_y.asRelative(base.d_height)
);
}
const UVector2& getPosition() const
{
return d_min;
}
UVector2 getSize() const
{
return d_max - d_min;
}
UDim getWidth() const
{
return d_max.d_x - d_min.d_x;
}
UDim getHeight() const
{
return d_max.d_y - d_min.d_y;
}
void setPosition(const UVector2& pos)
{
UVector2 sz(d_max - d_min);
d_min = pos;
d_max = d_min + sz;
}
void setSize(const UVector2& sz)
{
d_max = d_min + sz;
}
void setWidth(const UDim& w)
{
d_max.d_x = d_min.d_x + w;
}
void setHeight(const UDim& h)
{
d_max.d_y = d_min.d_y + h;
}
void offset(const UVector2& sz)
{
d_min += sz;
d_max += sz;
}
URect operator*(const UDim& dim) const
{
return URect(d_min * dim, d_max * dim);
}
URect operator+(const URect& r) const
{
return URect(d_min + r.d_min, d_max + r.d_max);
}
UVector2 d_min, d_max;
};
/*!
\brief
Class encapsulating the 'Unified Box' - this is usually used for margin
\par
top, left, right and bottom represent offsets on each edge
\note
Name taken from W3 'box model'
*/
class CEGUIEXPORT UBox
{
public:
UBox():
d_top(),
d_left(),
d_bottom(),
d_right()
{}
UBox(const UDim& margin):
d_top(margin),
d_left(margin),
d_bottom(margin),
d_right(margin)
{}
UBox(const UDim& top, const UDim& left, const UDim& bottom, const UDim& right):
d_top(top),
d_left(left),
d_bottom(bottom),
d_right(right)
{}
UBox(const UBox& b):
d_top(b.d_top),
d_left(b.d_left),
d_bottom(b.d_bottom),
d_right(b.d_right)
{}
/*************************************************************************
Operators
*************************************************************************/
bool operator==(const UBox& rhs) const
{
return ((d_top == rhs.d_top) &&
(d_left == rhs.d_left) &&
(d_bottom == rhs.d_bottom) &&
(d_right == rhs.d_right));
}
bool operator!=(const UBox& rhs) const
{
return !operator==(rhs);
}
UBox& operator=(const UBox& rhs)
{
d_top = rhs.d_top;
d_left = rhs.d_left;
d_bottom = rhs.d_bottom;
d_right = rhs.d_right;
return *this;
}
UBox operator*(const UDim& dim) const
{
return UBox(
d_top * dim, d_left * dim,
d_bottom * dim, d_right * dim);
}
UBox operator+(const UBox& b) const
{
return UBox(
d_top + b.d_top, d_left + b.d_left,
d_bottom + b.d_bottom, d_right + b.d_right);
}
/*************************************************************************
Data Fields
*************************************************************************/
UDim d_top;
UDim d_left;
UDim d_bottom;
UDim d_right;
};
} // End of CEGUI namespace section
#endif // end of guard _CEGUIUDim_h_
|