source: OGRE/trunk/ogrenew/Dependencies/include/CEGUI/CEGUIRect.h @ 657

Revision 657, 5.2 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

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
53        /*!
54        \brief
55                Return top-left postion of Rect as a Point
56        */
57        Point   getPosition(void) const         {return Point(d_left, d_top);}
58
59        /*!
60        \brief
61                return width of Rect area
62        */
63        float   getWidth(void) const            {return d_right - d_left;}
64
65
66        /*!
67        \brief
68                return height of Rect area
69        */
70        float   getHeight(void) const           {return d_bottom - d_top;}
71
72
73        /*!
74        \brief
75                return the size of the Rect area
76        */
77        Size    getSize(void) const                     {return Size(getWidth(), getHeight());}
78
79
80        /*!
81        \brief
82                set the position of the Rect (leaves size in tact)
83        */
84        void    setPosition(const Point& pt);
85
86
87        /*!
88        \brief
89                set the width of the Rect object
90        */
91        void    setWidth(float width)           {d_right = d_left + width;}
92
93        /*!
94        \brief
95                set the height of the Rect object
96        */
97        void    setHeight(float height)         {d_bottom = d_top + height;}
98
99
100        /*!
101        \brief
102                set the size of the Rect area
103        */
104        void    setSize(const Size& sze)        {setWidth(sze.d_width); setHeight(sze.d_height);}
105
106
107        /*!
108        \brief
109                return a Rect that is the intersection of 'this' Rect with the Rect 'rect'
110
111        \note
112                It can be assumed that if d_left == d_right, or d_top == d_bottom, or getWidth() == 0, or getHeight() == 0, then
113                'this' rect was totally outside 'rect'.
114        */
115        Rect    getIntersection(const Rect& rect) const;
116
117
118        /*!
119        \brief
120                Applies an offset the Rect object
121
122        \param pt
123                Point object containing the offsets to be applied to the Rect.
124
125        \return
126                this Rect after the offset is performed
127        */
128        Rect&   offset(const Point& pt);
129
130
131        /*!
132        \brief
133                Return true if the given Point falls within this Rect
134
135        \param pt
136                Point object describing the position to test.
137
138        \return
139                true if position \a pt is within this Rect's area, else false
140        */
141        bool    isPointInRect(const Point& pt) const;
142
143
144        /*!
145        \brief
146                check the size of the Rect object and if it is bigger than \a sz, resize it so it isn't.
147
148        \param sz
149                Size object that describes the maximum dimensions that this Rect should be limited to.
150
151        \return
152                'this' Rect object after the constrain operation
153        */
154        Rect&   constrainSizeMax(const Size& sz);
155
156
157        /*!
158        \brief
159                check the size of the Rect object and if it is smaller than \a sz, resize it so it isn't.
160
161        \param sz
162                Size object that describes the minimum dimensions that this Rect should be limited to.
163
164        \return
165                'this' Rect object after the constrain operation
166        */
167        Rect&   constrainSizeMin(const Size& sz);
168
169
170        /*!
171        \brief
172                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.
173
174        \param max_sz
175                Size object that describes the maximum dimensions that this Rect should be limited to.
176
177        \param min_sz
178                Size object that describes the minimum dimensions that this Rect should be limited to.
179
180        \return
181                'this' Rect object after the constrain operation
182        */
183        Rect&   constrainSize(const Size& max_sz, const Size& min_sz);
184
185
186        /*************************************************************************
187                Operators
188        *************************************************************************/
189        bool    operator==(const Rect& rhs) const
190        {
191                return ((d_left == rhs.d_left) && (d_right == rhs.d_right) && (d_top == rhs.d_top) && (d_bottom == rhs.d_bottom));
192        }
193
194        bool    operator!=(const Rect& rhs) const               {return !operator==(rhs);}
195
196        Rect&   operator=(const Rect& rhs);
197
198
199        /*************************************************************************
200                Data Fields
201        *************************************************************************/
202        float   d_top, d_bottom, d_left, d_right;
203};
204
205} // End of  CEGUI namespace section
206
207
208#endif  // end of guard _CEGUIRect_h_
Note: See TracBrowser for help on using the repository browser.