Back to index

nux  3.0.0
Rect.h
Go to the documentation of this file.
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 
00045 
00048     bool IsNull() const;
00049 
00050     bool IsInside(const Point &p) const;
00051     Rect Intersect(const Rect &) const;
00052 
00053     // expand the width by factor_x and the height by factor_y
00054     void Expand (int factor_x, int factor_y);
00055 
00056     int GetWidth() const
00057     {
00058       return width;
00059     }
00060     int GetHeight() const
00061     {
00062       return height;
00063     }
00065     Point   GetCenter() const
00066     {
00067       return Point (x + width / 2, y + height / 2);
00068     }
00070     Point GetPosition()
00071     {
00072       return Point (x, y);
00073     }
00074 
00075     void SetWidth (int w)
00076     {
00077       width = w;
00078     }
00079     void SetHeight (int h)
00080     {
00081       height = h;
00082     }
00083     void SetX (int px)
00084     {
00085       x = px;
00086     }
00087     void SetY (int py)
00088     {
00089       y = py;
00090     }
00091 
00092     void Set (int px, int py, int w, int h);
00093     void SetPosition (int px, int py);
00094     void SetSize (int px, int py);
00095 
00096     void OffsetSize (int dw, int dh)
00097     {
00098       width += dw;
00099       height += dh;
00100 
00101       if (width < 0)
00102         width = 0;
00103 
00104       if (height < 0)
00105         height = 0;
00106     }
00107     void OffsetPosition (int dx, int dy)
00108     {
00109       x += dx;
00110       y += dy;
00111     }
00112 
00113     bool IsPointInside (int dx, int dy) const;
00114     Rect GetExpand (int dx, int dy) const;
00115 
00116     int x, y;
00117     int width, height;
00118   };
00119 
00120 }
00121 
00122 #endif // RECT_H
00123