Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #ifndef _H_GHOST_Rect 00034 #define _H_GHOST_Rect 00035 00036 #include "GHOST_Types.h" 00037 00038 00048 class GHOST_Rect { 00049 public: 00050 00058 GHOST_Rect(GHOST_TInt32 l=0, GHOST_TInt32 t=0, GHOST_TInt32 r=0, GHOST_TInt32 b=0) 00059 : m_l(l), m_t(t), m_r(r), m_b(b) {} 00060 00065 GHOST_Rect(const GHOST_Rect& r) 00066 : m_l(r.m_l), m_t(r.m_t), m_r(r.m_r), m_b(r.m_b) {} 00067 00071 virtual ~GHOST_Rect() {}; 00072 00077 virtual inline GHOST_TInt32 getWidth() const; 00078 00083 virtual inline GHOST_TInt32 getHeight() const; 00084 00092 virtual inline void set(GHOST_TInt32 l, GHOST_TInt32 t, GHOST_TInt32 r, GHOST_TInt32 b); 00093 00099 virtual inline bool isEmpty() const; 00100 00106 virtual inline bool isValid() const; 00107 00113 virtual void inset(GHOST_TInt32 i); 00114 00120 virtual inline void unionRect(const GHOST_Rect& r); 00121 00127 virtual inline void unionPoint(GHOST_TInt32 x, GHOST_TInt32 y); 00128 00134 virtual inline void wrapPoint(GHOST_TInt32 &x, GHOST_TInt32 &y, GHOST_TInt32 ofs); 00135 00143 virtual inline bool isInside(GHOST_TInt32 x, GHOST_TInt32 y) const; 00144 00150 virtual GHOST_TVisibility getVisibility(GHOST_Rect& r) const; 00151 00158 virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy); 00159 00169 virtual void setCenter(GHOST_TInt32 cx, GHOST_TInt32 cy, GHOST_TInt32 w, GHOST_TInt32 h); 00170 00178 virtual bool clip(GHOST_Rect& r) const; 00179 00181 GHOST_TInt32 m_l; 00183 GHOST_TInt32 m_t; 00185 GHOST_TInt32 m_r; 00187 GHOST_TInt32 m_b; 00188 00189 #ifdef WITH_CXX_GUARDEDALLOC 00190 public: 00191 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GHOST:GHOST_Rect"); } 00192 void operator delete( void *mem ) { MEM_freeN(mem); } 00193 #endif 00194 }; 00195 00196 00197 inline GHOST_TInt32 GHOST_Rect::getWidth() const 00198 { 00199 return m_r - m_l; 00200 } 00201 00202 inline GHOST_TInt32 GHOST_Rect::getHeight() const 00203 { 00204 return m_b - m_t; 00205 } 00206 00207 inline void GHOST_Rect::set(GHOST_TInt32 l, GHOST_TInt32 t, GHOST_TInt32 r, GHOST_TInt32 b) 00208 { 00209 m_l = l; m_t = t; m_r = r; m_b = b; 00210 } 00211 00212 inline bool GHOST_Rect::isEmpty() const 00213 { 00214 return (getWidth() == 0) || (getHeight() == 0); 00215 } 00216 00217 inline bool GHOST_Rect::isValid() const 00218 { 00219 return (m_l <= m_r) && (m_t <= m_b); 00220 } 00221 00222 inline void GHOST_Rect::unionRect(const GHOST_Rect& r) 00223 { 00224 if (r.m_l < m_l) m_l = r.m_l; 00225 if (r.m_r > m_r) m_r = r.m_r; 00226 if (r.m_t < m_t) m_t = r.m_t; 00227 if (r.m_b > m_b) m_b = r.m_b; 00228 } 00229 00230 inline void GHOST_Rect::unionPoint(GHOST_TInt32 x, GHOST_TInt32 y) 00231 { 00232 if (x < m_l) m_l = x; 00233 if (x > m_r) m_r = x; 00234 if (y < m_t) m_t = y; 00235 if (y > m_b) m_b = y; 00236 } 00237 #include <stdio.h> 00238 inline void GHOST_Rect::wrapPoint(GHOST_TInt32 &x, GHOST_TInt32 &y, GHOST_TInt32 ofs) 00239 { 00240 GHOST_TInt32 w= getWidth(); 00241 GHOST_TInt32 h= getHeight(); 00242 00243 /* highly unlikely but avoid eternal loop */ 00244 if(w-ofs*2 <= 0 || h-ofs*2 <= 0) 00245 return; 00246 while(x-ofs < m_l) x+= w-(ofs*2); 00247 while(y-ofs < m_t) y+= h-(ofs*2); 00248 while(x+ofs > m_r) x-= w-(ofs*2); 00249 while(y+ofs > m_b) y-= h-(ofs*2); 00250 } 00251 00252 inline bool GHOST_Rect::isInside(GHOST_TInt32 x, GHOST_TInt32 y) const 00253 { 00254 return (x >= m_l) && (x <= m_r) && (y >= m_t) && (y <= m_b); 00255 } 00256 00257 #endif // _H_GHOST_Rect 00258