Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgrect.h

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka
00004  
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009  
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014  
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021  
00022     Last Update:      $Author: mbickel $
00023     Update Date:      $Date: 2007-04-13 16:15:57 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/include/pgrect.h,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00033 #ifndef PG_RECT_H
00034 #define PG_RECT_H
00035 
00036 #include "pgpoint.h"
00037 
00038 class PG_Widget;
00039 
00045 class DECLSPEC PG_Rect : public SDL_Rect {
00046 public:
00047 
00057         PG_Rect(Sint16 x = 0, Sint16 y = 0, Uint16 w = 0, Uint16 h = 0);
00058 
00065         PG_Rect(const PG_Rect& src);
00066 
00073         PG_Rect(const SDL_Rect& src);
00074 
00075         virtual ~PG_Rect();
00076 
00085         inline void SetRect(Sint16 nx, Sint16 ny, Uint16 nw, Uint16 nh) {
00086                 x = nx;
00087                 y = ny;
00088                 w = nw;
00089                 h = nh;
00090         }
00091 
00094         PG_Rect& operator =(const SDL_Rect& src);
00095 
00096         PG_Rect& operator =(const PG_Rect& src);
00097 
00100         PG_Rect operator / ( const PG_Rect& b) const ;
00101 
00102         inline bool operator ==(const PG_Rect& r) const {
00103                 return (x == r.x) && (y == r.y) && (r.w == w) && (r.h == h);
00104         }
00105 
00106         inline bool operator !=(const PG_Rect& r) const {
00107                 return !((x == r.x) && (y == r.y) && (r.w == w) && (r.h == h));
00108         }
00116         inline static bool IsInside(const PG_Point& p, PG_Rect& r) {
00117                 return r.IsInside(p);
00118         }
00119 
00126         inline bool IsInside(const PG_Point& p) const {
00127                 return ( (x <= p.x) && (p.x <= x + w) && (y <= p.y) && (p.y <= y + h) );
00128         }
00129 
00136         static PG_Rect IntersectRect(const PG_Rect& p, const PG_Rect& c);
00137 
00143         PG_Rect IntersectRect(const PG_Rect& p) const;
00144 
00149         inline Uint16 Width() const {
00150                 return w;
00151         }
00152 
00157         inline Uint16 Height() const {
00158                 return h;
00159         }
00160 
00161         inline bool IsNull() const {
00162                 return (!Width() && !Height());
00163         }
00164 
00166 
00170         inline bool OverlapRect(const PG_Rect& p, const PG_Rect& c) const {
00171                 return !( (p.x + p.w < c.x) || (p.x > c.x + c.w) || (p.y + p.h < c.y) || (p.y > c.y + c.h)  || (p.IntersectRect(c).IsNull()) );
00172         }
00173 
00175 
00179         inline bool OverlapRect(const PG_Rect& p) const {
00180                 return OverlapRect(p, *this);
00181         }
00182 
00184 
00188         inline bool OverlapRect(PG_Rect* p) {
00189                 return OverlapRect(*p, *this);
00190         }
00191 
00196         inline PG_Widget* next() {
00197                 return my_next;
00198         }
00199 
00204         inline PG_Widget* prev() {
00205                 return my_prev;
00206         }
00207 
00208         Sint16& my_xpos;
00209 
00210         Sint16& my_ypos;
00211 
00212         Uint16& my_width;
00213 
00214         Uint16& my_height;
00215 
00216         Uint32 index;
00217 
00218         static PG_Rect null;
00219 
00220 protected:
00221 
00222         PG_Widget* my_next;
00223 
00224         PG_Widget* my_prev;
00225 
00226         friend class PG_RectList;
00227 };
00228 
00229 #endif  // PG_RECT_H

Generated on Tue Jun 24 01:27:49 2008 for Advanced Strategic Command by  doxygen 1.4.2