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 #elif defined MAC
00027
00028 #define CornerOffset 1
00029 typedef Rect OsRect;
00030
00031 #else
00032
00033
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 int Near(int x, int y);
00144 int Near(GRect &r);
00145
00147 operator OsRect()
00148 {
00149 OsRect r;
00150
00151 r.left = x1;
00152 r.top = y1;
00153 r.right = x2+CornerOffset;
00154 r.bottom = y2+CornerOffset;
00155
00156 return r;
00157 }
00158
00159 bool operator ==(const GRect &r)
00160 {
00161 return x1 == r.x1 &&
00162 y1 == r.y1 &&
00163 x2 == r.x2 &&
00164 y2 == r.y2;
00165 }
00166
00167 GRect &operator =(const GRect &r);
00168
00169 GRect &operator =(OsRect &r)
00170 {
00171 x1 = (int) r.left;
00172 y1 = (int) r.top;
00173 x2 = (int) r.right - CornerOffset;
00174 y2 = (int) r.bottom - CornerOffset;
00175 return *this;
00176 }
00177
00178 GRect(OsRect r)
00179 {
00180 x1 = (int) r.left;
00181 y1 = (int) r.top;
00182 x2 = (int) r.right - CornerOffset;
00183 y2 = (int) r.bottom - CornerOffset;
00184 }
00185
00186 #ifdef MAC
00187 GRect &operator =(HIRect &r)
00188 {
00189 x1 = (int)r.origin.x;
00190 y1 = (int)r.origin.y;
00191 x2 = x1 + (int)r.size.width - 1;
00192 y2 = y1 + (int)r.size.height - 1;
00193 return *this;
00194 }
00195
00196 operator CGRect()
00197 {
00198 CGRect r;
00199 r.origin.x = x1;
00200 r.origin.y = y2;
00201 r.size.width = x2 - x1;
00202 r.size.height = y2 - y1;
00203 return r;
00204 }
00205 #endif
00206
00207 #ifdef __GTK_H__
00208 operator Gtk::GdkRectangle()
00209 {
00210 Gtk::GdkRectangle r;
00211 r.x = x1;
00212 r.y = y1;
00213 r.width = X();
00214 r.height = Y();
00215 return r;
00216 }
00217 #endif
00218 };
00219
00220 LgiClass bool operator ==(GRect &a, GRect &b);
00221 LgiClass bool operator !=(GRect &a, GRect &b);
00222
00224 class LgiClass GRegion : public GRect
00225 {
00226 int Size;
00227 int Alloc;
00228 int Current;
00229 GRect *a;
00230
00231 bool SetSize(int s);
00232 GRect *NewOne() { return (SetSize(Size+1)) ? a+(Size-1) : 0; }
00233 bool Delete(int i);
00234
00235 public:
00236 GRegion();
00237 GRegion(int X1, int Y1, int X2, int Y2);
00238 GRegion(GRect &r);
00239 GRegion(OsRect &r);
00240 GRegion(GRegion &c);
00241 ~GRegion();
00242
00243 int X() { return x2 - x1 + 1; }
00244 int Y() { return y2 - y1 + 1; }
00245 int Length() { return Size; }
00246 GRect *operator [](int i) { return (i >= 0 AND i < Size) ? a+i : 0; }
00247 GRegion &operator =(const GRect &r);
00248 GRect *First();
00249 GRect *Last();
00250 GRect *Next();
00251 GRect *Prev();
00252
00253 void Empty();
00254 void ZOff(int x, int y);
00255 void Normal();
00256 bool Valid();
00257 void Offset(int x, int y);
00258 void Bound(GRect *b);
00259 GRect Bound();
00260 bool Overlap(GRect *b);
00261 bool Overlap(int x, int y);
00262
00263 void Union(GRect *a);
00264 void Intersect(GRect *a);
00265 void Subtract(GRect *a);
00266
00267 friend bool operator ==(GRegion &a, GRegion &b);
00268 friend bool operator !=(GRegion &a, GRegion &b);
00269 };
00270
00271 #endif
00272
00273