Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

sdlmm_srect.h

Go to the documentation of this file.
00001 /*
00002  * SDLmm - a C++ wrapper for SDL and related libraries
00003  * Copyright © 2001 David Hedbor <david@hedbor.org>
00004  * 
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License as
00007  * published by the Free Software Foundation; either version 2 of the
00008  * License, or (at your option) any later version.
00009  * 
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  *
00019  */
00020 
00028 #ifndef SDLMM_SRECT_H
00029 #define SDLMM_SRECT_H
00030 #include  "sdlmm_spoint.h"
00031 
00032 namespace SDLmm {
00043   class DECLSPEC SRect : public SDL_Rect {
00044   public:
00047     SRect();
00048 
00051 
00052     SRect(const SRect& rect);
00053 
00055 
00056     SRect(const SDL_Rect& rect);
00057 
00059 
00063     SRect(const SPoint& point);
00064 
00067 
00071     SRect(const SPoint &upper_left_point,
00072           const SPoint &bottom_right_point);
00073 
00076 
00083     SRect(const SPoint &point, Uint16 nw, Uint16 nh);
00084     
00086 
00090     SRect(Sint16 nx, Sint16 ny, Uint16 nw, Uint16 nh);
00091 
00093 
00097     SRect(Uint16 nw, Uint16 nh);
00098 
00100     SRect& operator=(const SDL_Rect& rect) {
00101       if(this == &rect) return *this;
00102       x = rect.x; y = rect.y;
00103       w = rect.w; h = rect.h;
00104       return *this;
00105     }
00106 
00108 
00111     bool operator==(const SDL_Rect& rect) const {
00112       return ((x == rect.x) && (y == rect.y) &&
00113               (w == rect.w) && (h == rect.h));
00114     }
00115 
00117 
00120     void Move(const SPoint& point) {
00121         x += point.x; y += point.y;
00122     }
00123     
00125     bool Contains(const SPoint& point) const {
00126         return (x <= point.x) && (y <= point.y) &&
00127                ((x+w) > point.x) && ((y+h) > point.y);
00128     }
00129     
00131 
00132     SPoint GetUpperLeft() const { return SPoint(x, y); }    
00134 
00135     SPoint GetUpperRight() const { return SPoint(x+w, y); }    
00137 
00138     SPoint GetBottomLeft() const { return SPoint(x, y+h); }    
00140 
00141     SPoint GetBottomRight() const { return SPoint(x+w, y+h); }    
00142     
00143   };
00144   
00146 
00148   SRect Intersect(const SRect& r1, const SRect& r2);
00149 
00151 
00153   SRect Union(const SRect& r1, const SRect& r2);
00154 }
00155 
00156 #endif // SDLMM_SRECT_H
00157 

Documentation automatically generated by doxygen written by Dimitri van Heesch. Project hosted at
Hosted by SourceForge