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

rect.h

00001 /* 00002 libwftk - Worldforge Toolkit - a widget library 00003 Copyright (C) 2002 Malcolm Walker <malcolm@worldforge.org> 00004 Based on code copyright (C) 1999-2002 Karsten Laux 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the 00018 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, SA. 00020 */ 00021 00022 #ifndef _RECT_H 00023 #define _RECT_H 00024 00025 #include <SDL/SDL.h> 00026 00027 #include <wftk/point.h> 00028 00029 namespace wftk { 00030 00032 class Rect : public SDL_Rect 00033 { 00034 public: 00035 00037 Rect() : valid_(true) {x = y = 0; w = h = 0;} 00039 Rect(int x_, int y_, int w_, int h_); 00041 explicit Rect( const SDL_Rect& r) : SDL_Rect(r), valid_(true) {} 00043 // Rect( const Point& upperLeft, const Point& lowerRight); 00045 ~Rect() {} 00046 00048 static Rect invalid; 00050 static Rect empty; 00052 bool isEmpty() const {return w == 0 && h == 0;} 00054 bool isValid() const {return valid_;} 00056 void setValid(bool val = true) {valid_ = val;} 00058 bool contains( const Point &p ) const; 00060 bool contains( const Rect &r ) const; 00061 00063 void translate( int dx, int dy ); 00065 void translate(const Point& p) {translate(p.x, p.y);} 00067 void warp(const Point &newOrigin); 00069 void resize(int w_, int h_); 00071 Rect unite( const Rect &r ) const; 00073 00076 Rect intersect( const Rect &r) const; 00077 00079 Point upperLeft() const { return origin(); } 00080 00082 Point origin() const {return Point(x, y);} 00084 Uint16 width() const {return w;} 00086 Uint16 height() const {return h;} 00087 00089 friend bool operator==(const Rect &p, const Rect &q) 00090 {return p.x == q.x && p.y == q.y && p.w == q.w && p.h == q.h;} 00091 00093 friend bool operator!=(const Rect &p, const Rect &q) {return !(p == q);} 00094 00096 friend bool operator<(const Rect &p, const Rect &q) 00097 {return p.x < q.x || (p.x == q.x && 00098 (p.y < q.y || (p.y == q.y && 00099 (p.w < q.w || (p.w == q.w && p.h < q.h)))));} 00100 00102 friend std::ostream& operator<<(std::ostream& s, const Rect& p); 00103 00104 private: 00106 bool valid_; 00107 }; 00108 00109 } // namespace wftk 00110 00111 #endif // _RECT_H

Generated Wed Jul 28 17:28:43 2004.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.