![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * R e c t a n g l e C l a s s * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1994,2002 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXRectangle.h,v 1.5 2002/01/18 22:42:54 jeroen Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXRECTANGLE_H 00025 #define FXRECTANGLE_H 00026 00027 00028 /// Rectangle 00029 class FXAPI FXRectangle { 00030 public: 00031 FXshort x; 00032 FXshort y; 00033 FXshort w; 00034 FXshort h; 00035 public: 00036 00037 /// Constructors 00038 FXRectangle(){ } 00039 FXRectangle(FXshort xx,FXshort yy,FXshort ww,FXshort hh):x(xx),y(yy),w(ww),h(hh){ } 00040 FXRectangle(const FXPoint& p,const FXSize& s):x(p.x),y(p.y),w(s.w),h(s.h){ } 00041 FXRectangle(const FXPoint& topleft,const FXPoint& bottomright):x(topleft.x),y(topleft.y),w(bottomright.x-topleft.x+1),h(bottomright.y-topleft.y+1){ } 00042 00043 /// Equality 00044 friend FXAPI FXbool operator==(const FXRectangle& p,const FXRectangle& q){ return p.x==q.x && p.y==q.y && p.w==q.w && p.h==q.h; } 00045 friend FXAPI FXbool operator!=(const FXRectangle& p,const FXRectangle& q){ return p.x!=q.x || p.y!=q.y || p.w!=q.w || p.h!=q.h; } 00046 00047 /// Point in rectangle 00048 FXbool contains(const FXPoint& p) const { return x<=p.x && y<=p.y && p.x<x+w && p.y<y+h; } 00049 FXbool contains(FXshort xx,FXshort yy) const { return x<=xx && y<=yy && xx<x+w && yy<y+h; } 00050 00051 /// Rectangle properly contained in rectangle 00052 FXbool contains(const FXRectangle& r) const { return x<=r.x && y<=r.y && r.x+r.w<=x+w && r.y+r.h<=y+h; } 00053 00054 /// Rectangles overlap 00055 friend FXAPI FXbool overlap(const FXRectangle& a,const FXRectangle& b){ return b.x<a.x+a.w && b.y<a.y+a.h && a.x<b.x+b.w && a.y<b.y+b.h; } 00056 00057 /// Return moved rectangle 00058 FXRectangle& move(FXshort dx,FXshort dy){ x+=dx; y+=dy; return *this; } 00059 00060 /// Grow by amount 00061 FXRectangle& grow(FXshort margin); 00062 FXRectangle& grow(FXshort hormargin,FXshort vermargin); 00063 FXRectangle& grow(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin); 00064 00065 /// Shrink by amount 00066 FXRectangle& shrink(FXshort margin); 00067 FXRectangle& shrink(FXshort hormargin,FXshort vermargin); 00068 FXRectangle& shrink(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin); 00069 00070 /// Corners 00071 FXPoint tl() const { return FXPoint(x,y); } 00072 FXPoint tr() const { return FXPoint(x+w-1,y); } 00073 FXPoint bl() const { return FXPoint(x,y+h-1); } 00074 FXPoint br() const { return FXPoint(x+w-1,y+h-1); } 00075 00076 /// Union and intersection with rectangle 00077 FXRectangle& operator+=(const FXRectangle &r); 00078 FXRectangle& operator*=(const FXRectangle &r); 00079 00080 /// Union and intersection between rectangles 00081 friend FXAPI FXRectangle operator+(const FXRectangle& p,const FXRectangle& q); 00082 friend FXAPI FXRectangle operator*(const FXRectangle& p,const FXRectangle& q); 00083 00084 /// Save object to a stream 00085 friend FXAPI FXStream& operator<<(FXStream& store,const FXRectangle& r); 00086 00087 /// Load object from a stream 00088 friend FXAPI FXStream& operator>>(FXStream& store,FXRectangle& r); 00089 }; 00090 00091 00092 #endif