3 * ***** BEGIN GPL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): none yet.
26 * ***** END GPL LICENSE BLOCK *****
30 * Declaration of GHOST_Rect rectangle class.
36 #include "GHOST_Types.h"
40 * Implements rectangle functionality.
41 * The four extreme coordinates are stored as left, top, right and bottom.
42 * To be valid, a rectangle should have a left coordinate smaller than or equal to right.
43 * To be valid, a rectangle should have a top coordinate smaller than or equal to bottom.
44 * @author Maarten Gribnau
52 * Constructs a rectangle with the given values.
53 * @param l requested left coordinate of the rectangle
54 * @param t requested top coordinate of the rectangle
55 * @param r requested right coordinate of the rectangle
56 * @param b requested bottom coordinate of the rectangle
58 GHOST_Rect(GHOST_TInt32 l=0, GHOST_TInt32 t=0, GHOST_TInt32 r=0, GHOST_TInt32 b=0)
59 : m_l(l), m_t(t), m_r(r), m_b(b) {}
63 * @param r rectangle to copy
65 GHOST_Rect(const GHOST_Rect& r)
66 : m_l(r.m_l), m_t(r.m_t), m_r(r.m_r), m_b(r.m_b) {}
71 virtual ~GHOST_Rect() {};
74 * Access to rectangle width.
75 * @return width of the rectangle
77 virtual inline GHOST_TInt32 getWidth() const;
80 * Access to rectangle height.
81 * @return height of the rectangle
83 virtual inline GHOST_TInt32 getHeight() const;
86 * Sets all members of the rectangle.
87 * @param l requested left coordinate of the rectangle
88 * @param t requested top coordinate of the rectangle
89 * @param r requested right coordinate of the rectangle
90 * @param b requested bottom coordinate of the rectangle
92 virtual inline void set(GHOST_TInt32 l, GHOST_TInt32 t, GHOST_TInt32 r, GHOST_TInt32 b);
95 * Returns whether this rectangle is empty.
96 * Empty rectangles are rectangles that have width==0 and/or height==0.
97 * @return boolean value (true==empty rectangle)
99 virtual inline bool isEmpty() const;
102 * Returns whether this rectangle is valid.
103 * Valid rectangles are rectangles that have m_l <= m_r and m_t <= m_b. Thus, emapty rectangles are valid.
104 * @return boolean value (true==valid rectangle)
106 virtual inline bool isValid() const;
109 * Grows (or shrinks the rectangle).
110 * The method avoids negative insets making the rectangle invalid
111 * @param i The amount of offset given to each extreme (negative values shrink the rectangle).
113 virtual void inset(GHOST_TInt32 i);
116 * Does a union of the rectangle given and this rectangle.
117 * The result is stored in this rectangle.
118 * @param r The rectangle that is input for the union operation.
120 virtual inline void unionRect(const GHOST_Rect& r);
123 * Grows the rectangle to included a point.
124 * @param x The x-coordinate of the point.
125 * @param y The y-coordinate of the point.
127 virtual inline void unionPoint(GHOST_TInt32 x, GHOST_TInt32 y);
130 * Returns whether the point is inside this rectangle.
131 * Point on the boundary is considered inside.
132 * @param x x-coordinate of point to test.
133 * @param y y-coordinate of point to test.
134 * @return boolean value (true if point is inside).
136 virtual inline bool isInside(GHOST_TInt32 x, GHOST_TInt32 y) const;
139 * Returns whether the rectangle is inside this rectangle.
140 * @param r rectangle to test.
141 * @return visibility (not, partially or fully visible).
143 virtual GHOST_TVisibility getVisibility(GHOST_Rect& r) const;
146 * Sets rectangle members.
147 * Sets rectangle members such that it is centered at the given location.
148 * @param cx requested center x-coordinate of the rectangle
149 * @param cy requested center y-coordinate of the rectangle
151 virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy);
154 * Sets rectangle members.
155 * Sets rectangle members such that it is centered at the given location,
156 * with the width requested.
157 * @param cx requested center x-coordinate of the rectangle
158 * @param cy requested center y-coordinate of the rectangle
159 * @param w requested width of the rectangle
160 * @param h requested height of the rectangle
162 virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy, GHOST_TInt32 w, GHOST_TInt32 h);
166 * Updates the rectangle given such that it will fit within this one.
167 * This can result in an empty rectangle.
168 * @param r the rectangle to clip
169 * @return whether clipping has occurred
171 virtual bool clip(GHOST_Rect& r) const;
173 /** Left coordinate of the rectangle */
175 /** Top coordinate of the rectangle */
177 /** Right coordinate of the rectangle */
179 /** Bottom coordinate of the rectangle */
184 inline GHOST_TInt32 GHOST_Rect::getWidth() const
189 inline GHOST_TInt32 GHOST_Rect::getHeight() const
194 inline void GHOST_Rect::set(GHOST_TInt32 l, GHOST_TInt32 t, GHOST_TInt32 r, GHOST_TInt32 b)
196 m_l = l; m_t = t; m_r = r; m_b = b;
199 inline bool GHOST_Rect::isEmpty() const
201 return (getWidth() == 0) || (getHeight() == 0);
204 inline bool GHOST_Rect::isValid() const
206 return (m_l <= m_r) && (m_t <= m_b);
209 inline void GHOST_Rect::unionRect(const GHOST_Rect& r)
211 if (r.m_l < m_l) m_l = r.m_l;
212 if (r.m_r > m_r) m_r = r.m_r;
213 if (r.m_t < m_t) m_t = r.m_t;
214 if (r.m_b > m_b) m_b = r.m_b;
217 inline void GHOST_Rect::unionPoint(GHOST_TInt32 x, GHOST_TInt32 y)
219 if (x < m_l) m_l = x;
220 if (x > m_r) m_r = x;
221 if (y < m_t) m_t = y;
222 if (y > m_b) m_b = y;
225 inline bool GHOST_Rect::isInside(GHOST_TInt32 x, GHOST_TInt32 y) const
227 return (x >= m_l) && (x <= m_r) && (y >= m_t) && (y <= m_b);
230 #endif // _H_GHOST_Rect