Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

GRect.h

00001 /*
00002     \file
00003     \author Matthew Allen
00004     \date 22/8/1997
00005 */
00006 
00007 #ifndef __GDCREGION_H
00008 #define __GDCREGION_H
00009 
00010 #if defined WIN32
00011 
00012     #define CornerOffset 1
00013     typedef RECT OsRect;
00014 
00015 #elif defined BEOS
00016 
00017     #define CornerOffset 0
00018     typedef BRect OsRect;
00019 
00020 #elif defined ATHEOS
00021 
00022     #include <gui/rect.h>
00023     #define CornerOffset 0
00024     typedef os::Rect OsRect;
00025 
00026 #elif defined MAC
00027 
00028     #define CornerOffset 0
00029     typedef Rect OsRect;
00030 
00031 #else
00032 
00033     // Implement as required
00034     #define CornerOffset 0
00035     struct OsRect
00036     {
00037         int left, right, top, bottom;
00038     };
00039 
00040 #endif
00041 
00043 class LgiClass GRect
00044 {
00045     friend LgiClass bool operator ==(GRect &a, GRect &b);
00046     friend LgiClass bool operator !=(GRect &a, GRect &b);
00047 
00048 public:
00049     int x1, y1, x2, y2;
00050 
00051     GRect() {}
00052     GRect(int X1, int Y1, int X2, int Y2)
00053     {
00054         x1 = X1;
00055         x2 = X2;
00056         y1 = Y1;
00057         y2 = Y2;
00058     }
00059 
00060     GRect(GRect *r)
00061     {
00062         x1 = r->x1;
00063         x2 = r->x2;
00064         y1 = r->y1;
00065         y2 = r->y2;
00066     }
00067 
00069     int X() { return x2 - x1 + 1; }
00070     
00072     int Y() { return y2 - y1 + 1; }
00073     
00075     void Set(int X1, int Y1, int X2, int Y2)
00076     {
00077         x1 = X1;
00078         x2 = X2;
00079         y1 = Y1;
00080         y2 = Y2;
00081     }
00082 
00084     void ZOff(int x, int y);
00085     
00087     void Normal();
00088     
00090     bool Valid();
00091     
00093     void Offset(int x, int y);
00094     
00096     void Offset(GRect *a);
00097     
00099     void Size(int x, int y);
00100 
00102     void Size(GRect *a);
00103 
00105     void Dimension(int x, int y);
00106 
00108     void Dimension(GRect *a);
00109 
00111     void Bound(GRect *b);
00112 
00114     bool Overlap(int x, int y);
00115 
00117     bool Overlap(GRect *b);
00118     
00120     void Union(int x, int y);
00121 
00123     void Union(GRect *a);
00124 
00126     void Union(GRect *a, GRect *b);
00127 
00129     void Intersection(GRect *a);
00130 
00132     void Intersection(GRect *a, GRect *b);
00133 
00135     char *GetStr();
00136     char *Describe() { return GetStr(); }
00137 
00139     bool SetStr(char *s);
00140 
00142     operator OsRect()
00143     {
00144         OsRect r;
00145 
00146         r.left = x1;
00147         r.top = y1;
00148         r.right = x2+CornerOffset;
00149         r.bottom = y2+CornerOffset;
00150 
00151         return r;
00152     }
00153 
00154     GRect &operator =(const GRect &r);  
00155     
00156     GRect &operator =(OsRect &r)
00157     {
00158         x1 = (int) r.left;
00159         y1 = (int) r.top;
00160         x2 = (int) r.right - CornerOffset;
00161         y2 = (int) r.bottom - CornerOffset;
00162         return *this;
00163     }
00164 
00165     GRect(OsRect r)
00166     {
00167         x1 = (int) r.left;
00168         y1 = (int) r.top;
00169         x2 = (int) r.right - CornerOffset;
00170         y2 = (int) r.bottom - CornerOffset;
00171     }
00172     
00173     #ifdef MAC
00174     GRect &operator =(HIRect &r)
00175     {
00176         x1 = (int)r.origin.x;
00177         y1 = (int)r.origin.y;
00178         x2 = x1 + (int)r.size.width - 1;
00179         y2 = y1 + (int)r.size.height - 1;
00180         return *this;
00181     }
00182     #endif
00183 };
00184 
00185 LgiClass bool operator ==(GRect &a, GRect &b);
00186 LgiClass bool operator !=(GRect &a, GRect &b);
00187 
00189 class LgiClass GRegion : public GRect
00190 {
00191     int Size;
00192     int Alloc;
00193     int Current;
00194     GRect *a;
00195 
00196     bool SetSize(int s);
00197     GRect *NewOne() { return (SetSize(Size+1)) ? a+(Size-1) : 0; }
00198     bool Delete(int i);
00199 
00200 public:
00201     GRegion();
00202     GRegion(int X1, int Y1, int X2, int Y2);
00203     GRegion(GRect &r);
00204     GRegion(OsRect &r);
00205     GRegion(GRegion &c);
00206     ~GRegion();
00207 
00208     int X() { return x2 - x1 + 1; }
00209     int Y() { return y2 - y1 + 1; }
00210     int Length() { return Size; }
00211     GRect *operator [](int i) { return (i >= 0 AND i < Size) ? a+i : 0; }
00212     GRect *First();
00213     GRect *Last();
00214     GRect *Next();
00215     GRect *Prev();
00216 
00217     void Empty();
00218     void ZOff(int x, int y);
00219     void Normal();
00220     bool Valid();
00221     void Offset(int x, int y);
00222     void Bound(GRect *b);
00223     GRect Bound();
00224     bool Overlap(GRect *b);
00225     bool Overlap(int x, int y);
00226     
00227     void Union(GRect *a);
00228     void Intersect(GRect *a);
00229     void Subtract(GRect *a);
00230 
00231     friend bool operator ==(GRegion &a, GRegion &b);
00232     friend bool operator !=(GRegion &a, GRegion &b);
00233 };
00234 
00235 #endif
00236 
00237 

Generated on Tue May 2 10:24:42 2006 for Lgi by  doxygen 1.4.1