typo in debug statement.
[AROS.git] / workbench / demos / regiontest.c
blobafd04072d60aa0c49b6c9fa388a9acc13e32b89b
1 /* tab = 3 */
2 #include <stdio.h>
3 #include <string.h>
4 #include <exec/types.h>
5 #include <graphics/rastport.h>
6 #include <graphics/regions.h>
7 #include <intuition/intuition.h>
8 #include <proto/dos.h>
9 #include <proto/exec.h>
10 #include <proto/graphics.h>
11 #include <proto/intuition.h>
13 struct IntuitionBase *IntuitionBase;
14 struct GfxBase *GfxBase;
15 struct Window *win;
17 static const char version[] __attribute__((used)) = "$VER: regiontest 41.1 (14.3.1997)\n";
19 void doall(void);
21 int main(int argc, char **argv)
23 if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0))) {
24 if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0))) {
25 if ((win = OpenWindowTags(NULL,
26 WA_IDCMP, IDCMP_RAWKEY,
27 WA_Height, 400,
28 WA_Width, 800,
29 TAG_END))) {
30 doall();
31 CloseWindow(win);
33 CloseLibrary((struct Library *)GfxBase);
35 CloseLibrary((struct Library *) IntuitionBase);
37 return 0;
42 struct Region *regions[10];
44 void freeregions(void)
46 int i;
47 for (i = 0; i < 10; i++) {
48 if (regions[i])
49 DisposeRegion(regions[i]);
53 void newregion(void)
55 int i;
56 for (i = 0; i < 10; i++)
57 if (regions[i] == NULL)
58 break;
59 if (i < 10) {
60 if ((regions[i] = NewRegion())) {
61 printf("New Region created, id: %d\n", i);
62 } else {
63 printf("Sorry, not enough mem\n");
65 } else {
66 printf("Sorry, no more regions possible\n");
70 void disposeregion(void)
72 int i;
73 printf("Enter Region id: ");
74 fflush (stdout);
75 scanf("%d", &i);
76 if (i >= 0 && i < 10)
77 if (regions[i]) {
78 DisposeRegion(regions[i]);
79 regions[i] = NULL;
80 return;
82 printf("Region with id %d does not exist\n", i);
85 void DrawRectangle(struct Rectangle *r, int offsetx, int offsety)
87 Move(win->RPort, r->MinX + offsetx, r->MinY + offsety);
88 Draw(win->RPort, r->MaxX + offsetx, r->MinY + offsety);
89 Delay(10);
90 Draw(win->RPort, r->MaxX + offsetx, r->MaxY + offsety);
91 Delay(10);
92 Draw(win->RPort, r->MinX + offsetx, r->MaxY + offsety);
93 Delay(10);
94 Draw(win->RPort, r->MinX + offsetx, r->MinY + offsety);
95 Delay(10);
98 void FillRectangle(struct Rectangle *r, int offsetx, int offsety)
100 RectFill(win->RPort, r->MinX + 1 + offsetx, r->MinY + 1 + offsety,
101 r->MaxX - 1 + offsetx, r->MaxY - 1 + offsety);
104 void showregions(void)
106 int i;
107 printf("The following Region id's are currently in use:\n");
108 for (i = 0; i < 10; i++)
109 if (regions[i]) {
110 printf("\t%d - bounds: (%d,%d) - (%d,%d)\n", i,
111 regions[i]->bounds.MinX, regions[i]->bounds.MinY,
112 regions[i]->bounds.MaxX, regions[i]->bounds.MaxY);
113 SetAPen(win->RPort, 3);
114 DrawRectangle(&regions[i]->bounds, 0, 0);
118 void showrects(void)
120 int i;
121 printf("Enter Region id: ");
122 fflush(stdout);
123 scanf("%d", &i);
124 if (i >= 0 && i < 10)
125 if (regions[i]) {
126 struct RegionRectangle *current;
127 for (current = regions[i]->RegionRectangle; current; current = current->Next) {
128 printf("\tbounds: (%d,%d) - (%d,%d)\n", current->bounds.MinX,
129 current->bounds.MinY, current->bounds.MaxX, current->bounds.MaxY);
130 SetAPen(win->RPort, 1);
131 DrawRectangle(&current->bounds, regions[i]->bounds.MinX, regions[i]->bounds.MinY);
132 SetAPen(win->RPort, 2);
133 FillRectangle(&current->bounds, regions[i]->bounds.MinX, regions[i]->bounds.MinY);
134 printf("press a key\n");
135 //Wait(1L << win->UserPort->mp_SigBit);
137 return;
139 printf("Region with id %d does not exist\n", i);
142 void getrectangle(struct Rectangle *rect)
144 int val;
145 printf("Rectangle left edge: ");
146 scanf("%d", &val);
147 rect->MinX = val;
148 printf("Rectangle top edge: ");
149 scanf("%d", &val);
150 rect->MinY = val;
151 printf("Rectangle right edge: ");
152 scanf("%d", &val);
153 rect->MaxX = val;
154 printf("Rectangle lower edge: ");
155 scanf("%d", &val);
156 rect->MaxY = val;
159 void orrectregion(void)
161 int i;
162 printf("Enter Region id: ");
163 fflush(stdout);
164 scanf("%d", &i);
165 if (i >= 0 && i < 10)
166 if (regions[i]) {
167 struct Rectangle rect;
168 getrectangle(&rect);
169 if (OrRectRegion(regions[i], &rect))
170 printf("Done.\n");
171 else
172 printf("Out of memory\n");
173 return;
175 printf("Region with id %d does not exist\n", i);
178 void andrectregion(void)
180 int i;
181 printf("Enter Region id: ");
182 fflush(stdout);
183 scanf("%d", &i);
184 if (i >= 0 && i < 10)
185 if (regions[i]) {
186 struct Rectangle rect;
187 getrectangle(&rect);
188 AndRectRegion(regions[i], &rect);
189 printf("Done.\n");
190 return;
192 printf("Region with id %d does not exist\n", i);
195 void clearrectregion(void)
197 int i;
198 printf("Enter Region id: ");
199 fflush(stdout);
200 scanf("%d", &i);
201 if (i >= 0 && i < 10)
202 if (regions[i]) {
203 struct Rectangle rect;
204 getrectangle(&rect);
205 if (ClearRectRegion(regions[i], &rect))
206 printf("Done.\n");
207 else
208 printf("Out of memory\n");
209 return;
211 printf("Region with id %d does not exist\n", i);
214 void xorrectregion(void)
216 int i;
217 printf("Enter Region id: ");
218 fflush(stdout);
219 scanf("%d", &i);
220 if (i >= 0 && i < 10)
221 if (regions[i]) {
222 struct Rectangle rect;
223 getrectangle(&rect);
224 if (XorRectRegion(regions[i], &rect))
225 printf("Done.\n");
226 else
227 printf("Out of memory\n");
228 return;
230 printf("Region with id %d does not exist\n", i);
233 void clearregion(void)
235 int i;
236 printf("Enter Region id: ");
237 fflush(stdout);
238 scanf("%d", &i);
239 if (i >= 0 && i < 10)
240 if (regions[i]) {
241 ClearRegion(regions[i]);
242 printf("Done.\n");
243 return;
245 printf("Region with id %d does not exist\n", i);
248 void xorregionregion(void)
250 int i1,i2;
251 printf("Enter Region1 id: ");
252 fflush(stdout);
253 scanf("%d", &i1);
254 printf("Enter Region2 (destination) id: ");
255 fflush(stdout);
256 scanf("%d", &i2);
257 if (i1 >= 0 && i1 <= 10 && i2 >= 0 && i2 <= 10)
258 if (regions[i1] && regions[i2]) {
259 XorRegionRegion(regions[i1],regions[i2]);
260 printf("Done.\n");
261 return;
263 printf("Region with id %d or %d does not exist\n",i1,i2);
266 void andregionregion(void)
268 int i1,i2;
269 printf("Enter Region1 id: ");
270 fflush(stdout);
271 scanf("%d", &i1);
272 printf("Enter Region2 (destination) id: ");
273 fflush(stdout);
274 scanf("%d", &i2);
275 if (i1 >= 0 && i1 <= 10 && i2 >= 0 && i2 <= 10)
276 if (regions[i1] && regions[i2]) {
277 AndRegionRegion(regions[i1],regions[i2]);
278 printf("Done.\n");
279 return;
281 printf("Region with id %d or %d does not exist\n",i1,i2);
283 void orregionregion(void)
285 int i1,i2;
286 printf("Enter Region1 id: ");
287 fflush(stdout);
288 scanf("%d", &i1);
289 printf("Enter Region2 (destination) id: ");
290 fflush(stdout);
291 scanf("%d", &i2);
292 if (i1 >= 0 && i1 <= 10 && i2 >= 0 && i2 <= 10)
293 if (regions[i1] && regions[i2]) {
294 OrRegionRegion(regions[i1],regions[i2]);
295 printf("Done.\n");
296 return;
298 printf("Region with id %d or %d does not exist\n",i1,i2);
301 void doall(void)
303 char buf[80];
305 for (;;) {
306 printf("> ");
307 fflush(stdout);
308 scanf("%s", buf);
310 if (!strcmp(buf, "quit")) {
311 freeregions();
312 return;
313 } else if (!strcmp(buf, "help")) {
314 printf("quit help newregion disposeregion clearregion\n");
315 printf("andrectregion orrectregion xorrectregion clearrectregion\n");
316 printf("andregionregion orregionregion xorregionregion\n");
317 printf("showregions showrects clear\n");
318 } else if (!strcmp(buf, "newregion")) {
319 newregion();
320 } else if (!strcmp(buf, "disposeregion")) {
321 disposeregion();
322 } else if (!strcmp(buf, "clearregion")) {
323 clearregion();
324 } else if (!strcmp(buf, "showregions")) {
325 showregions();
326 } else if (!strcmp(buf, "showrects")) {
327 showrects();
328 } else if (!strcmp(buf, "orrectregion")) {
329 orrectregion();
330 } else if (!strcmp(buf, "andrectregion")) {
331 andrectregion();
332 } else if (!strcmp(buf, "clearrectregion")) {
333 clearrectregion();
334 } else if (!strcmp(buf, "xorrectregion")) {
335 xorrectregion();
336 } else if (!strcmp(buf, "xorregionregion")) {
337 xorregionregion();
338 } else if (!strcmp(buf, "orregionregion")) {
339 orregionregion();
340 } else if (!strcmp(buf, "andregionregion")) {
341 andregionregion();
342 } else if (!strcmp(buf, "clear")) {
343 SetRast(win->RPort, 0);
344 } else
345 printf("Unknown command. Try 'help'.\n");