// rect.h ////////////////////////////////////////////////////////////////////////////// #ifndef RECT_H #define RECT_H #ifndef POINTT_H # include "pointt.h" #endif ////////////////////////////////////////////////////////////////////////////// // rect can draw itself, move to new postition (and size) // tell if point is inluded in rect's area. // rect has also a fillcolor, that is white as default. // color can be changed using method setColor ////////////////////////////////////////////////////////////////////////////// class rect { protected: POINTT upper; POINTT lower; color col; public: rect(int ux=0,int uy=0,int lx=0,int ly=0) { upper=POINTT(ux,uy); lower=POINTT(lx,ly); col=white;} rect(POINTT &u, POINTT &l) { upper=u; lower=l; col=white;} void moveTo(int ux,int uy, int lx, int ly) {upper=POINTT(ux,uy); lower=POINTT(lx,ly);} void moveTo(POINTT &u, POINTT &l) { upper=u; lower=l; } int includes(POINTT p) { return ( upper <= p && p <= lower ); } int includes(int x,int y) { return includes(POINTT(x,y)); } void setColor(color c) { col = c; } virtual void draw(window *W) { W->setPen(blue,solidLine,1); W->setBrush(col); W->rectangle(XY(upper),lower.x-upper.x,lower.y-upper.y); // w->line(upper.x,upper.y,lower.x,upper.y); // W->line(lower.x,upper.y,lower.x,lower.y); // W->line(lower.x,lower.y,upper.x,lower.y); // W->line(upper.x,lower.y,upper.x,upper.y); } }; // rect #endif