00001
00002
00003
00004
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 #else
00027
00028
00029 #define CornerOffset 0
00030 struct OsRect
00031 {
00032 int left, right, top, bottom;
00033 };
00034
00035 #endif
00036
00038 class LgiClass GRect
00039 {
00040 friend LgiClass bool operator ==(GRect &a, GRect &b);
00041 friend LgiClass bool operator !=(GRect &a, GRect &b);
00042
00043 public:
00044 int x1, y1, x2, y2;
00045
00046 GRect() {}
00047 GRect(int X1, int Y1, int X2, int Y2)
00048 {
00049 x1 = X1;
00050 x2 = X2;
00051 y1 = Y1;
00052 y2 = Y2;
00053 }
00054
00055 GRect(GRect *r)
00056 {
00057 x1 = r->x1;
00058 x2 = r->x2;
00059 y1 = r->y1;
00060 y2 = r->y2;
00061 }
00062
00064 int X() { return x2 - x1 + 1; }
00065
00067 int Y() { return y2 - y1 + 1; }
00068
00070 void Set(int X1, int Y1, int X2, int Y2)
00071 {
00072 x1 = X1;
00073 x2 = X2;
00074 y1 = Y1;
00075 y2 = Y2;
00076 }
00077
00079 void ZOff(int x, int y);
00080
00082 void Normal();
00083
00085 bool Valid();
00086
00088 void Offset(int x, int y);
00089
00091 void Offset(GRect *a);
00092
00094 void Size(int x, int y);
00095
00097 void Size(GRect *a);
00098
00100 void Dimension(int x, int y);
00101
00103 void Dimension(GRect *a);
00104
00106 void Bound(GRect *b);
00107
00109 bool Overlap(int x, int y);
00110
00112 bool Overlap(GRect *b);
00113
00115 void Union(int x, int y);
00116
00118 void Union(GRect *a);
00119
00121 void Union(GRect *a, GRect *b);
00122
00124 void Intersection(GRect *a);
00125
00127 void Intersection(GRect *a, GRect *b);
00128
00130 char *GetStr();
00131 char *Describe() { return GetStr(); }
00132
00134 bool SetStr(char *s);
00135
00137 operator OsRect()
00138 {
00139 OsRect r;
00140
00141 r.left = x1;
00142 r.top = y1;
00143 r.right = x2+CornerOffset;
00144 r.bottom = y2+CornerOffset;
00145
00146 return r;
00147 }
00148
00149 GRect &operator =(const GRect &r);
00150
00151 GRect &operator =(OsRect &r)
00152 {
00153 x1 = (int) r.left;
00154 y1 = (int) r.top;
00155 x2 = (int) r.right - CornerOffset;
00156 y2 = (int) r.bottom - CornerOffset;
00157 return *this;
00158 }
00159
00160 GRect(OsRect r)
00161 {
00162 x1 = (int) r.left;
00163 y1 = (int) r.top;
00164 x2 = (int) r.right - CornerOffset;
00165 y2 = (int) r.bottom - CornerOffset;
00166 }
00167 };
00168
00169 LgiClass bool operator ==(GRect &a, GRect &b);
00170 LgiClass bool operator !=(GRect &a, GRect &b);
00171
00173 class LgiClass GRegion : public GRect
00174 {
00175 int Size;
00176 int Alloc;
00177 int Current;
00178 GRect *a;
00179
00180 bool SetSize(int s);
00181 GRect *NewOne() { return (SetSize(Size+1)) ? a+(Size-1) : 0; }
00182 bool Delete(int i);
00183
00184 public:
00185 GRegion();
00186 GRegion(int X1, int Y1, int X2, int Y2);
00187 GRegion(GRect &r);
00188 GRegion(OsRect &r);
00189 GRegion(GRegion &c);
00190 ~GRegion();
00191
00192 int X() { return x2 - x1 + 1; }
00193 int Y() { return y2 - y1 + 1; }
00194 int Length() { return Size; }
00195 GRect *operator [](int i) { return (i >= 0 AND i < Size) ? a+i : 0; }
00196 GRect *First();
00197 GRect *Last();
00198 GRect *Next();
00199 GRect *Prev();
00200
00201 void Empty();
00202 void ZOff(int x, int y);
00203 void Normal();
00204 bool Valid();
00205 void Offset(int x, int y);
00206 void Bound(GRect *b);
00207 GRect Bound();
00208 bool Overlap(GRect *b);
00209 bool Overlap(int x, int y);
00210
00211 void Union(GRect *a);
00212 void Intersect(GRect *a);
00213 void Subtract(GRect *a);
00214
00215 friend bool operator ==(GRegion &a, GRegion &b);
00216 friend bool operator !=(GRegion &a, GRegion &b);
00217 };
00218
00219 #endif
00220
00221