3 * ***** BEGIN GPL/BL DUAL 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. The Blender
9 * Foundation also sells licenses for use in proprietary software under
10 * the Blender License. See http://www.blender.org/BL/ for information
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23 * All rights reserved.
25 * The Original Code is: all of this file.
27 * Contributor(s): none yet.
29 * ***** END GPL/BL DUAL LICENSE BLOCK *****
33 * Declaration of GHOST_Rect rectangle class.
39 #include "GHOST_Types.h"
43 * Implements rectangle functionality.
44 * The four extreme coordinates are stored as left, top, right and bottom.
45 * To be valid, a rectangle should have a left coordinate smaller than or equal to right.
46 * To be valid, a rectangle should have a top coordinate smaller than or equal to bottom.
47 * @author Maarten Gribnau
55 * Constructs a rectangle with the given values.
56 * @param l requested left coordinate of the rectangle
57 * @param t requested top coordinate of the rectangle
58 * @param r requested right coordinate of the rectangle
59 * @param b requested bottom coordinate of the rectangle
61 GHOST_Rect(GHOST_TInt32 l=0, GHOST_TInt32 t=0, GHOST_TInt32 r=0, GHOST_TInt32 b=0)
62 : m_l(l), m_t(t), m_r(r), m_b(b) {}
66 * @param r rectangle to copy
68 GHOST_Rect(const GHOST_Rect& r)
69 : m_l(r.m_l), m_t(r.m_t), m_r(r.m_r), m_b(r.m_b) {}
74 virtual ~GHOST_Rect() {};
77 * Access to rectangle width.
78 * @return width of the rectangle
80 virtual inline GHOST_TInt32 getWidth() const;
83 * Access to rectangle height.
84 * @return height of the rectangle
86 virtual inline GHOST_TInt32 getHeight() const;
89 * Sets all members of the rectangle.
90 * @param l requested left coordinate of the rectangle
91 * @param t requested top coordinate of the rectangle
92 * @param r requested right coordinate of the rectangle
93 * @param b requested bottom coordinate of the rectangle
95 virtual inline void set(GHOST_TInt32 l, GHOST_TInt32 t, GHOST_TInt32 r, GHOST_TInt32 b);
98 * Returns whether this rectangle is empty.
99 * Empty rectangles are rectangles that have width==0 and/or height==0.
100 * @return boolean value (true==empty rectangle)
102 virtual inline bool isEmpty() const;
105 * Returns whether this rectangle is valid.
106 * Valid rectangles are rectangles that have m_l <= m_r and m_t <= m_b. Thus, emapty rectangles are valid.
107 * @return boolean value (true==valid rectangle)
109 virtual inline bool isValid() const;
112 * Grows (or shrinks the rectangle).
113 * The method avoids negative insets making the rectangle invalid
114 * @param i The amount of offset given to each extreme (negative values shrink the rectangle).
116 virtual void inset(GHOST_TInt32 i);
119 * Does a union of the rectangle given and this rectangle.
120 * The result is stored in this rectangle.
121 * @param r The rectangle that is input for the union operation.
123 virtual inline void unionRect(const GHOST_Rect& r);
126 * Grows the rectangle to included a point.
127 * @param x The x-coordinate of the point.
128 * @param y The y-coordinate of the point.
130 virtual inline void unionPoint(GHOST_TInt32 x, GHOST_TInt32 y);
133 * Returns whether the point is inside this rectangle.
134 * Point on the boundary is considered inside.
135 * @param x x-coordinate of point to test.
136 * @param y y-coordinate of point to test.
137 * @return boolean value (true if point is inside).
139 virtual inline bool isInside(GHOST_TInt32 x, GHOST_TInt32 y) const;
142 * Returns whether the rectangle is inside this rectangle.
143 * @param r rectangle to test.
144 * @return visibility (not, partially or fully visible).
146 virtual GHOST_TVisibility getVisibility(GHOST_Rect& r) const;
149 * Sets rectangle members.
150 * Sets rectangle members such that it is centered at the given location.
151 * @param cx requested center x-coordinate of the rectangle
152 * @param cy requested center y-coordinate of the rectangle
154 virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy);
157 * Sets rectangle members.
158 * Sets rectangle members such that it is centered at the given location,
159 * with the width requested.
160 * @param cx requested center x-coordinate of the rectangle
161 * @param cy requested center y-coordinate of the rectangle
162 * @param w requested width of the rectangle
163 * @param h requested height of the rectangle
165 virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy, GHOST_TInt32 w, GHOST_TInt32 h);
169 * Updates the rectangle given such that it will fit within this one.
170 * This can result in an empty rectangle.
171 * @param r the rectangle to clip
172 * @return whether clipping has occurred
174 virtual bool clip(GHOST_Rect& r) const;
176 /** Left coordinate of the rectangle */
178 /** Top coordinate of the rectangle */
180 /** Right coordinate of the rectangle */
182 /** Bottom coordinate of the rectangle */
187 inline GHOST_TInt32 GHOST_Rect::getWidth() const
192 inline GHOST_TInt32 GHOST_Rect::getHeight() const
197 inline void GHOST_Rect::set(GHOST_TInt32 l, GHOST_TInt32 t, GHOST_TInt32 r, GHOST_TInt32 b)
199 m_l = l; m_t = t; m_r = r; m_b = b;
202 inline bool GHOST_Rect::isEmpty() const
204 return (getWidth() == 0) || (getHeight() == 0);
207 inline bool GHOST_Rect::isValid() const
209 return (m_l <= m_r) && (m_t <= m_b);
212 inline void GHOST_Rect::unionRect(const GHOST_Rect& r)
214 if (r.m_l < m_l) m_l = r.m_l;
215 if (r.m_r > m_r) m_r = r.m_r;
216 if (r.m_t < m_t) m_t = r.m_t;
217 if (r.m_b > m_b) m_b = r.m_b;
220 inline void GHOST_Rect::unionPoint(GHOST_TInt32 x, GHOST_TInt32 y)
222 if (x < m_l) m_l = x;
223 if (x > m_r) m_r = x;
224 if (y < m_t) m_t = y;
225 if (y > m_b) m_b = y;
228 inline bool GHOST_Rect::isInside(GHOST_TInt32 x, GHOST_TInt32 y) const
230 return (x >= m_l) && (x <= m_r) && (y >= m_t) && (y <= m_b);
233 #endif // _H_GHOST_Rect