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

pgrect.cpp

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:16:01 $
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/draw/pgrect.cpp,v $
00025     CVS/RCS Revision: $Revision: 1.2 $
00026     Status:           $State: Exp $
00027 */
00028 
00029 #include "pgrect.h"
00030 
00031 PG_Rect PG_Rect::null;
00032 
00033 PG_Rect::PG_Rect(Sint16 xv, Sint16 yv, Uint16 wv, Uint16 hv) :
00034                 my_xpos(x),
00035                 my_ypos(y),
00036                 my_width(w),
00037                 my_height(h),
00038                 index(0),
00039                 my_next(NULL),
00040 my_prev(NULL) {
00041         SetRect(xv, yv, wv, hv);
00042 }
00043 
00044 PG_Rect::PG_Rect(const PG_Rect& src) :
00045                 my_xpos(x),
00046                 my_ypos(y),
00047                 my_width(w),
00048                 my_height(h),
00049                 my_next(NULL),
00050 my_prev(NULL) {
00051         *this = src;
00052 }
00053 
00054 PG_Rect::PG_Rect(const SDL_Rect& src) :
00055                 my_xpos(x),
00056                 my_ypos(y),
00057                 my_width(w),
00058                 my_height(h),
00059                 my_next(NULL),
00060 my_prev(NULL) {
00061         *this = src;
00062 }
00063 
00064 PG_Rect::~PG_Rect() {}
00065 
00066 PG_Rect PG_Rect::IntersectRect(const PG_Rect& p, const PG_Rect& c) {
00067         static int px0,py0,px1,py1;
00068         static int cx0,cy0,cx1,cy1;
00069         static int rx0,ry0,rx1,ry1;
00070 
00071         // fill in default (NULL) result rectangle
00072         PG_Rect result;
00073 
00074         // get coordinates of the rectangles
00075         px0 = p.my_xpos;
00076         py0 = p.my_ypos;
00077         px1 = p.my_xpos + p.my_width - 1;
00078         py1 = p.my_ypos + p.my_height - 1;
00079 
00080         cx0 = c.my_xpos;
00081         cy0 = c.my_ypos;
00082         cx1 = c.my_xpos + c.my_width - 1;
00083         cy1 = c.my_ypos + c.my_height - 1;
00084 
00085         // check if the rectangles intersect
00086         if((cx1 < px0) || (cx0 > px1) || (cy1 < py0) || (cy0 > py1))
00087                 return result;
00088 
00089         // intersect x
00090         if(cx0 <= px0)
00091                 rx0 = px0;
00092         else
00093                 rx0 = cx0;
00094 
00095         if(cx1 >= px1)
00096                 rx1 = px1;
00097         else
00098                 rx1 = cx1;
00099 
00100         // intersect y
00101         if(cy0 <= py0)
00102                 ry0 = py0;
00103         else
00104                 ry0 = cy0;
00105 
00106         if(cy1 >= py1)
00107                 ry1 = py1;
00108         else
00109                 ry1 = cy1;
00110 
00111         // fill in result rect
00112         result.SetRect(
00113             rx0,
00114             ry0,
00115             (rx1-rx0)+1,
00116             (ry1-ry0)+1);
00117 
00118         return result;
00119 }
00120 
00121 PG_Rect PG_Rect::IntersectRect(const PG_Rect& p) const {
00122         return IntersectRect(p, *this);
00123 }
00124 
00125 PG_Rect& PG_Rect::operator =(const PG_Rect& src) {
00126         SetRect(src.x, src.y, src.w, src.h);
00127         my_next = NULL;
00128         my_prev = NULL;
00129         return *this;
00130 }
00131 
00132 PG_Rect PG_Rect::operator / ( const PG_Rect& b) const {
00133         return IntersectRect(b);
00134 }
00135 
00136 PG_Rect& PG_Rect::operator =(const SDL_Rect& src) {
00137         x = src.x;
00138         y = src.y;
00139         w = src.w;
00140         h = src.h;
00141         return *this;
00142 }

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