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

sdlmm_srect.cpp

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 
00021 // The SDLmm::SRect class
00022 
00023 #include "sdlmm_config.h"
00024 
00025 #include <SDL.h>
00026 #include "sdlmm_srect.h"
00027 #include "sdlmm_misc.h"
00028 
00029 namespace SDLmm {
00030   SRect::SRect() {
00031     x = y = w = h = 0;
00032   }
00033 
00034   SRect::SRect(const SRect& rect) {
00035     x = rect.x; y = rect.y;
00036     w = rect.w; h = rect.h;
00037   }
00038 
00039   SRect::SRect(const SDL_Rect& rect) {
00040     x = rect.x; y = rect.y;
00041     w = rect.w; h = rect.h;
00042   }
00043 
00044   SRect::SRect(Sint16 nx, Sint16 ny, Uint16 nw, Uint16 nh) {
00045     x = nx; y = ny; w = nw; h = nh;
00046   }
00047 
00048   SRect::SRect(Uint16 nw, Uint16 nh) {
00049     x = y = 0;
00050     w = nw; h = nh;
00051   }
00052 
00053   SRect::SRect(const SPoint &point) {
00054     x = point.x; y = point.y;
00055     w = 0;    h = 0;
00056   }
00057   SRect::SRect(const SPoint &point, Uint16 nw, Uint16 nh) {
00058     x = point.x; y = point.y;
00059     w = nw;   h = nh;
00060   }
00061 
00062   SRect::SRect(const SPoint &upper_left_point,
00063                const SPoint &bottom_right_point) {
00064     ASSERT(upper_left_point <= bottom_right_point);
00065     x = upper_left_point.x; y = upper_left_point.y;
00066     w = bottom_right_point.x - upper_left_point.x;
00067     h = bottom_right_point.y - upper_left_point.y;
00068   }
00069   
00070   SRect Intersect(const SRect& r1, const SRect& r2) {
00071     SRect r;
00072     r.x = Max(r1.x, r2.x);
00073     r.y = Max(r1.y, r2.y);
00074     r.w = Min(r1.x + r1.w, r2.x + r2.w) - r.x;
00075     r.h = Min(r1.y + r1.h, r2.y + r2.h) - r.y;
00076     if (r.w < 0) r.w = 0;
00077     if (r.h < 0) r.h = 0;
00078     return r;
00079   }
00080 
00081   SRect Union(const SRect& r1, const SRect& r2) {
00082     SRect r;
00083     r.x = Min(r1.x, r2.x);
00084     r.y = Min(r1.y, r2.y);
00085     r.w = Max(r1.x + r1.w, r2.x + r2.w) - r.x;
00086     r.h = Max(r1.y + r1.h, r2.y + r2.h) - r.y;
00087     ASSERT(r.w >= 0);
00088     ASSERT(r.h >= 0);
00089     return r;
00090   }
00091 }
00092 
00093 

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