Crazy Eddies GUI System  0.7.9
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
CEGUIRect.h
1 /***********************************************************************
2  filename: CEGUIRect.h
3  created: 8/3/2004
4  author: Paul D Turner
5 
6  purpose: Defines 'Rect' class
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUIRect_h_
31 #define _CEGUIRect_h_
32 
33 #include "CEGUIBase.h"
34 #include "CEGUIVector.h"
35 #include "CEGUISize.h"
36 
37 // Start of CEGUI namespace section
38 namespace CEGUI
39 {
44 class CEGUIEXPORT Rect
45 {
46 public:
47  Rect(void) {}
48 
49 
54  Rect(float left, float top, float right, float bottom);
55 
56  Rect(Point pos, Size sz);
57 
58 
63  Point getPosition(void) const {return Point(d_left, d_top);}
64 
69  float getWidth(void) const {return d_right - d_left;}
70 
71 
76  float getHeight(void) const {return d_bottom - d_top;}
77 
78 
83  Size getSize(void) const {return Size(getWidth(), getHeight());}
84 
85 
90  void setPosition(const Point& pt);
91 
92 
97  void setWidth(float width) {d_right = d_left + width;}
98 
103  void setHeight(float height) {d_bottom = d_top + height;}
104 
105 
110  void setSize(const Size& sze) {setWidth(sze.d_width); setHeight(sze.d_height);}
111 
112 
121  Rect getIntersection(const Rect& rect) const;
122 
123 
134  Rect& offset(const Point& pt);
135 
136 
147  bool isPointInRect(const Point& pt) const;
148 
149 
160  Rect& constrainSizeMax(const Size& sz);
161 
162 
173  Rect& constrainSizeMin(const Size& sz);
174 
175 
189  Rect& constrainSize(const Size& max_sz, const Size& min_sz);
190 
191 
192  /*************************************************************************
193  Operators
194  *************************************************************************/
195  bool operator==(const Rect& rhs) const
196  {
197  return ((d_left == rhs.d_left) && (d_right == rhs.d_right) && (d_top == rhs.d_top) && (d_bottom == rhs.d_bottom));
198  }
199 
200  bool operator!=(const Rect& rhs) const {return !operator==(rhs);}
201 
202  Rect& operator=(const Rect& rhs);
203 
204  Rect operator*(float scalar) const { return Rect(d_left * scalar, d_top * scalar, d_right * scalar, d_bottom * scalar); }
205  const Rect& operator*=(float scalar) { d_left *= scalar; d_top *= scalar; d_right *= scalar; d_bottom *= scalar; return *this; }
206 
207  Rect operator+(const Rect& r) const { return Rect(d_left + r.d_left, d_top + r.d_top, d_right + r.d_right, d_bottom + r.d_bottom); }
208 
209 
210  /*************************************************************************
211  Data Fields
212  *************************************************************************/
213  float d_left, d_top, d_right, d_bottom;
214 };
215 
216 } // End of CEGUI namespace section
217 
218 
219 #endif // end of guard _CEGUIRect_h_
220