/*---------------------------------------------------------------------------* Project: Horizon File: util_Rect.h Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 46347 $ *---------------------------------------------------------------------------*/ #ifndef NN_UTIL_UTIL_RECT_H_ #define NN_UTIL_UTIL_RECT_H_ #ifdef __cplusplus namespace nn { namespace util { //-------------------------------------------------------------------------- // //--------------------------------------------------------------------------- struct Rect { public: /* ------------------------------------------------------------------------ Variables ------------------------------------------------------------------------ */ f32 left; // f32 top; // f32 right; // f32 bottom; // /* ------------------------------------------------------------------------ Functions ------------------------------------------------------------------------ */ //---------------------------------------- // // //-------------------------------------------------------------------------- // //--------------------------------------------------------------------------- Rect() : left(0), top(0), right(0), bottom(0) { } //-------------------------------------------------------------------------- // // // // // // //--------------------------------------------------------------------------- Rect(f32 l, f32 t, f32 r, f32 b) : left(l), top(t), right(r), bottom(b) { } //-------------------------------------------------------------------------- // //--------------------------------------------------------------------------- Rect(const Rect& v) : left(v.left), top(v.top), right(v.right), bottom(v.bottom) { } //-------------------------------------------------------------------------- // //--------------------------------------------------------------------------- ~Rect() {} // //---------------------------------------- // // //-------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- f32 GetWidth() const { return right - left; } //-------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- f32 GetHeight() const { return bottom - top; } //-------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- f32 GetX() const { return left; } //-------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- f32 GetY() const { return top; } //-------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- void SetWidth(f32 width) { right = left + width; } //-------------------------------------------------------------------------- // // // //--------------------------------------------------------------------------- void SetHeight(f32 height) { bottom = top + height; } //-------------------------------------------------------------------------- // // // // //--------------------------------------------------------------------------- void MoveTo(f32 x, f32 y) { right = x + GetWidth(); left = x; bottom = y + GetHeight(); top = y; } //-------------------------------------------------------------------------- // // // // //--------------------------------------------------------------------------- void Move(f32 dx, f32 dy) { left += dx; right += dx; top += dy; bottom += dy; } //-------------------------------------------------------------------------- // // // // // // //--------------------------------------------------------------------------- void SetOriginAndSize(f32 x, f32 y, f32 width, f32 height ) { left = x; right = x + width; top = y; bottom = y + height; } // //-------------------------------------------------------------------------- // //--------------------------------------------------------------------------- void Normalize() { const f32 l = left; const f32 t = top; const f32 r = right; const f32 b = bottom; left = (r - l) >= 0 ? l : r; right = (r - l) >= 0 ? r : l; top = (b - t) >= 0 ? t : b; bottom = (b - t) >= 0 ? b : t; } }; }} /* namespace nn::util */ #endif // __cplusplus #endif // NN_UTIL_UTIL_RECT_H_