nux-1.14.0
Rect.h
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef RECT_H
00024 #define RECT_H
00025 
00026 #include "Point.h"
00027 #include "Size.h"
00028 
00029 namespace nux
00030 {
00031 
00032   class Rect
00033   {
00034   public:
00035     Rect();
00036     Rect (int x_, int y_, int width_, int height_);
00037     ~Rect();
00038     Rect (const Rect &r);
00039 
00040     Rect &operator = (const Rect &r);
00041     bool operator == (const Rect &p) const;
00042     bool operator != (const Rect &p) const;
00043 
00044     bool IsNull() const
00045     {
00046       return ( (width == 0) || (height == 0) );
00047     }
00048     bool IsInside (const Point &p) const;
00049     Rect Intersect (const Rect &) const;
00050 
00051     // expand the width by factor_x and the height by factor_y
00052     void Expand (int factor_x, int factor_y);
00053 
00054     int GetWidth() const
00055     {
00056       return width;
00057     }
00058     int GetHeight() const
00059     {
00060       return height;
00061     }
00063     Point   GetCenter() const
00064     {
00065       return Point (x + width / 2, y + height / 2);
00066     }
00068     Point GetPosition()
00069     {
00070       return Point (x, y);
00071     }
00072 
00073     void SetWidth (int w)
00074     {
00075       width = w;
00076     }
00077     void SetHeight (int h)
00078     {
00079       height = h;
00080     }
00081     void SetX (int px)
00082     {
00083       x = px;
00084     }
00085     void SetY (int py)
00086     {
00087       y = py;
00088     }
00089 
00090     void Set (int px, int py, int w, int h);
00091     void SetPosition (int px, int py);
00092     void SetSize (int px, int py);
00093 
00094     void OffsetSize (int dw, int dh)
00095     {
00096       width += dw;
00097       height += dh;
00098 
00099       if (width < 0)
00100         width = 0;
00101 
00102       if (height < 0)
00103         height = 0;
00104     }
00105     void OffsetPosition (int dx, int dy)
00106     {
00107       x += dx;
00108       y += dy;
00109     }
00110 
00111     bool IsPointInside (int dx, int dy) const;
00112     Rect GetExpand (int dx, int dy) const;
00113 
00114     int x, y;
00115     int width, height;
00116   };
00117 
00118 }
00119 
00120 #endif // RECT_H
00121 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends