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