00001
00002
00003
00004
00005
00006
00007
00009
00010 #ifndef _GOBJECT_H
00011 #define _GOBJECT_H
00012
00013 #include "magic/mobject.h"
00014 #include "magic/mcoord.h"
00015
00016
00017
00018
00019
00020
00022
00023
00024
00025
00026
00027
00028 class Rect {
00029 protected:
00030 Coord2D mCorner1;
00031 Coord2D mCorner2;
00032 public:
00033
00034 Rect () : mCorner1(0,0), mCorner2(0,0) {;}
00035 Rect (float x0, float y0, float x1, float y1) {
00036 mCorner1.moveTo (x0, y0);
00037 mCorner2.moveTo (x1, y1);
00038 }
00039 Rect (const Coord2D& s, const Coord2D& e) : mCorner1(s), mCorner2(e) {
00040 }
00041
00042 void operator= (const Rect& other);
00043
00044
00045
00046
00047 void set (float x0, float y0, float x1, float y1) {
00048 mCorner1.moveTo (x0, y0);
00049 mCorner2.moveTo (x1, y1);
00050 }
00051 void set (const Coord2D& s, const Coord2D& e) {
00052 mCorner1.copy (s);
00053 mCorner2.copy (e);
00054 }
00055
00056
00057 void get (float& x0, float& y0, float& x1, float& y1) const;
00058
00059 const Coord2D& lowerLeft () const {return mCorner1;}
00060 Coord2D& lowerLeft () {return mCorner1;}
00061 const Coord2D& upperRight () const {return mCorner2;}
00062 Coord2D& upperRight () {return mCorner2;}
00063
00064
00065 void setPos (float x, float y);
00066
00067
00068 void setSize (float xsize, float ysize);
00069
00070
00071 void getSize (float& xsize, float& ysize) const;
00072
00073 float width () const {return fabs(mCorner2.x-mCorner1.x);}
00074 float height () const {return fabs(mCorner2.y-mCorner1.y);}
00075
00076
00077
00078
00079 void moveTo (const Coord2D& pos);
00080
00081
00082 void moveBy (const Coord2D& offset);
00083
00084
00085
00086
00087 bool isInside (const Coord2D& pos) const {
00088 return (pos.x>=mCorner1.x && pos.x<=mCorner2.x &&
00089 pos.y>=mCorner1.y && pos.y<=mCorner2.y);
00090 }
00091
00092
00093 bool touches (const Rect& other) const;
00094 };
00095
00096 #endif