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
namespace FX {
00029
00030
00031 class FXAPI FXRectangle {
00032
public:
00033 FXshort x;
00034 FXshort y;
00035 FXshort w;
00036 FXshort h;
00037
public:
00038
00039
00040 FXRectangle(){ }
00041 FXRectangle(FXshort xx,FXshort yy,FXshort ww,FXshort hh):x(xx),y(yy),w(ww),h(hh){ }
00042 FXRectangle(
const FXPoint& p,
const FXSize& s):x(p.x),y(p.y),w(s.w),h(s.h){ }
00043 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){ }
00044
00045
00046 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; }
00047
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; }
00048
00049
00050 FXbool contains(
const FXPoint& p)
const {
return x<=p.
x && y<=p.
y && p.
x<x+w && p.
y<y+h; }
00051 FXbool contains(FXshort xx,FXshort yy)
const {
return x<=xx && y<=yy && xx<x+w && yy<y+h; }
00052
00053
00054 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; }
00055
00056
00057 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; }
00058
00059
00060 FXRectangle& move(FXshort dx,FXshort dy){ x+=dx; y+=dy;
return *
this; }
00061
00062
00063 FXRectangle& grow(FXshort margin);
00064 FXRectangle& grow(FXshort hormargin,FXshort vermargin);
00065 FXRectangle& grow(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin);
00066
00067
00068 FXRectangle& shrink(FXshort margin);
00069 FXRectangle& shrink(FXshort hormargin,FXshort vermargin);
00070 FXRectangle& shrink(FXshort leftmargin,FXshort rightmargin,FXshort topmargin,FXshort bottommargin);
00071
00072
00073 FXPoint tl()
const {
return FXPoint(x,y); }
00074
FXPoint tr()
const {
return FXPoint(x+w-1,y); }
00075 FXPoint bl()
const {
return FXPoint(x,y+h-1); }
00076 FXPoint br()
const {
return FXPoint(x+w-1,y+h-1); }
00077
00078
00079 FXRectangle& operator+=(
const FXRectangle &r);
00080 FXRectangle& operator*=(
const FXRectangle &r);
00081
00082
00083
friend FXAPI FXRectangle operator+(
const FXRectangle& p,
const FXRectangle& q);
00084
friend FXAPI FXRectangle operator*(
const FXRectangle& p,
const FXRectangle& q);
00085
00086
00087
friend FXAPI FXStream& operator<<(FXStream& store,
const FXRectangle& r);
00088
00089
00090
friend FXAPI FXStream& operator>>(FXStream& store,FXRectangle& r);
00091 };
00092
00093 }
00094
00095
#endif