00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef FXRECTANGLE_H
00025 #define FXRECTANGLE_H
00026
00027
00028 #ifndef FXPOINT_H
00029 #include "FXPoint.h"
00030 #endif
00031
00032
00033 namespace FX {
00034
00035
00037 class FXAPI FXRectangle {
00038 public:
00039 FXshort x;
00040 FXshort y;
00041 FXshort w;
00042 FXshort h;
00043 public:
00044
00046 FXRectangle(){ }
00047 FXRectangle(FXshort xx,FXshort yy,FXshort ww,FXshort hh):x(xx),y(yy),w(ww),h(hh){ }
00048 FXRectangle(const FXPoint& p,const FXSize& s):x(p.x),y(p.y),w(s.w),h(s.h){ }
00049 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){ }
00050
00052 bool empty() const { return w<=0 || h<=0; }
00053
00055 bool operator!() const { return x==0 && y==0 && w==0 && h==0; }
00056
00058 bool operator==(const FXRectangle& r) const { return x==r.x && y==r.y && w==r.w && h==r.h; }
00059 bool operator!=(const FXRectangle& r) const { return x!=r.x || y!=r.y || w!=r.w || h!=r.h; }
00060
00062 bool operator<(const FXRectangle& r) const { return w*h<r.w*r.h; }
00063 bool operator>(const FXRectangle& r) const { return w*h>r.w*r.h; }
00064
00066 bool contains(const FXPoint& p) const { return x<=p.x && y<=p.y && p.x<x+w && p.y<y+h; }
00067 bool contains(FXshort xx,FXshort yy) const { return x<=xx && y<=yy && xx<x+w && yy<y+h; }
00068
00070 bool contains(const FXRectangle& r) const { return x<=r.x && y<=r.y && r.x+r.w<=x+w && r.y+r.h<=y+h; }
00071
00073 friend inline bool overlap(const FXRectangle& a,const FXRectangle& b);
00074
00076 FXRectangle& move(const FXPoint& p){ x+=p.x; y+=p.y; return *this; }
00077 FXRectangle& move(FXshort dx,FXshort dy){ x+=dx; y+=dy; return *this; }
00078
00080 FXRectangle& grow(FXshort margin);
00081 FXRectangle& grow(FXshort hormargin,FXshort vermargin);
00082 FXRectangle& grow(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin);
00083
00085 FXRectangle& shrink(FXshort margin);
00086 FXRectangle& shrink(FXshort hormargin,FXshort vermargin);
00087 FXRectangle& shrink(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin);
00088
00090 FXPoint tl() const { return FXPoint(x,y); }
00091 FXPoint tr() const { return FXPoint(x+w-1,y); }
00092 FXPoint bl() const { return FXPoint(x,y+h-1); }
00093 FXPoint br() const { return FXPoint(x+w-1,y+h-1); }
00094
00096 FXRectangle& operator=(const FXRectangle& r){ x=r.x; y=r.y; w=r.w; h=r.h; return *this; }
00097
00099 FXRectangle& set(const FXRectangle& r){ x=r.x; y=r.y; w=r.w; h=r.h; return *this; }
00100
00102 FXRectangle& set(const FXPoint& p,const FXSize& s){ x=p.x; y=p.y; w=s.w; h=s.h; return *this; }
00103
00105 FXRectangle& set(const FXPoint& topleft,const FXPoint& bottomright){ x=topleft.x; y=topleft.y; w=bottomright.x-topleft.x+1; h=bottomright.y-topleft.y+1; return *this; }
00106
00108 FXRectangle& set(FXshort xx,FXshort yy,FXshort ww,FXshort hh){ x=xx; y=yy; w=ww; h=hh; return *this; }
00109
00111 FXRectangle& operator+=(const FXRectangle &r);
00112 FXRectangle& operator*=(const FXRectangle &r);
00113
00115 FXRectangle operator+(const FXRectangle& r) const;
00116 FXRectangle operator*(const FXRectangle& r) const;
00117
00119 friend FXAPI FXStream& operator<<(FXStream& store,const FXRectangle& r);
00120
00122 friend FXAPI FXStream& operator>>(FXStream& store,FXRectangle& r);
00123 };
00124
00125
00126 inline bool 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; }
00127
00128 extern FXAPI FXStream& operator<<(FXStream& store,const FXRectangle& r);
00129 extern FXAPI FXStream& operator>>(FXStream& store,FXRectangle& r);
00130
00131 }
00132
00133 #endif