source: OGRE/trunk/ogre_dependencies/Dependencies/include/CEGUI/CEGUIRect.h @ 692

Revision 692, 5.5 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/************************************************************************
2        filename:       CEGUIRect.h
3        created:        8/3/2004
4        author:         Paul D Turner
5       
6        purpose:        Defines 'Rect' class
7*************************************************************************/
8/*************************************************************************
9    Crazy Eddie's GUI System (http://www.cegui.org.uk)
10    Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
11
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 2.1 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25*************************************************************************/
26#ifndef _CEGUIRect_h_
27#define _CEGUIRect_h_
28
29#include "CEGUIBase.h"
30#include "CEGUIVector.h"
31#include "CEGUISize.h"
32
33// Start of CEGUI namespace section
34namespace CEGUI
35{
36/*!
37\brief
38        Class encapsulating operations on a Rectangle
39*/
40class CEGUIEXPORT Rect
41{
42public:
43        Rect(void) {}
44
45
46        /*!
47        \brief
48                Constructor for a Rect.
49        */
50        Rect(float left, float top, float right, float bottom);
51
52    Rect(Point pos, Size sz);
53
54
55        /*!
56        \brief
57                Return top-left postion of Rect as a Point
58        */
59        Point   getPosition(void) const         {return Point(d_left, d_top);}
60
61        /*!
62        \brief
63                return width of Rect area
64        */
65        float   getWidth(void) const            {return d_right - d_left;}
66
67
68        /*!
69        \brief
70                return height of Rect area
71        */
72        float   getHeight(void) const           {return d_bottom - d_top;}
73
74
75        /*!
76        \brief
77                return the size of the Rect area
78        */
79        Size    getSize(void) const                     {return Size(getWidth(), getHeight());}
80
81
82        /*!
83        \brief
84                set the position of the Rect (leaves size in tact)
85        */
86        void    setPosition(const Point& pt);
87
88
89        /*!
90        \brief
91                set the width of the Rect object
92        */
93        void    setWidth(float width)           {d_right = d_left + width;}
94
95        /*!
96        \brief
97                set the height of the Rect object
98        */
99        void    setHeight(float height)         {d_bottom = d_top + height;}
100
101
102        /*!
103        \brief
104                set the size of the Rect area
105        */
106        void    setSize(const Size& sze)        {setWidth(sze.d_width); setHeight(sze.d_height);}
107
108
109        /*!
110        \brief
111                return a Rect that is the intersection of 'this' Rect with the Rect 'rect'
112
113        \note
114                It can be assumed that if d_left == d_right, or d_top == d_bottom, or getWidth() == 0, or getHeight() == 0, then
115                'this' rect was totally outside 'rect'.
116        */
117        Rect    getIntersection(const Rect& rect) const;
118
119
120        /*!
121        \brief
122                Applies an offset the Rect object
123
124        \param pt
125                Point object containing the offsets to be applied to the Rect.
126
127        \return
128                this Rect after the offset is performed
129        */
130        Rect&   offset(const Point& pt);
131
132
133        /*!
134        \brief
135                Return true if the given Point falls within this Rect
136
137        \param pt
138                Point object describing the position to test.
139
140        \return
141                true if position \a pt is within this Rect's area, else false
142        */
143        bool    isPointInRect(const Point& pt) const;
144
145
146        /*!
147        \brief
148                check the size of the Rect object and if it is bigger than \a sz, resize it so it isn't.
149
150        \param sz
151                Size object that describes the maximum dimensions that this Rect should be limited to.
152
153        \return
154                'this' Rect object after the constrain operation
155        */
156        Rect&   constrainSizeMax(const Size& sz);
157
158
159        /*!
160        \brief
161                check the size of the Rect object and if it is smaller than \a sz, resize it so it isn't.
162
163        \param sz
164                Size object that describes the minimum dimensions that this Rect should be limited to.
165
166        \return
167                'this' Rect object after the constrain operation
168        */
169        Rect&   constrainSizeMin(const Size& sz);
170
171
172        /*!
173        \brief
174                check the size of the Rect object and if it is bigger than \a max_sz or smaller than \a min_sz, resize it so it isn't.
175
176        \param max_sz
177                Size object that describes the maximum dimensions that this Rect should be limited to.
178
179        \param min_sz
180                Size object that describes the minimum dimensions that this Rect should be limited to.
181
182        \return
183                'this' Rect object after the constrain operation
184        */
185        Rect&   constrainSize(const Size& max_sz, const Size& min_sz);
186
187
188        /*************************************************************************
189                Operators
190        *************************************************************************/
191        bool    operator==(const Rect& rhs) const
192        {
193                return ((d_left == rhs.d_left) && (d_right == rhs.d_right) && (d_top == rhs.d_top) && (d_bottom == rhs.d_bottom));
194        }
195
196        bool    operator!=(const Rect& rhs) const               {return !operator==(rhs);}
197
198        Rect&   operator=(const Rect& rhs);
199
200    Rect operator*(float scalar) const      { return Rect(d_left * scalar, d_top * scalar, d_right * scalar, d_bottom * scalar); }
201    const Rect& operator*=(float scalar)    { d_left *= scalar; d_top *= scalar; d_right *= scalar; d_bottom *= scalar; return *this; }
202
203
204        /*************************************************************************
205                Data Fields
206        *************************************************************************/
207        float   d_top, d_bottom, d_left, d_right;
208};
209
210} // End of  CEGUI namespace section
211
212
213#endif  // end of guard _CEGUIRect_h_
Note: See TracBrowser for help on using the repository browser.