4 #include <exec/types.h>
5 #include <graphics/rastport.h>
6 #include <graphics/regions.h>
7 #include <intuition/intuition.h>
9 #include <proto/exec.h>
10 #include <proto/graphics.h>
11 #include <proto/intuition.h>
13 struct IntuitionBase
*IntuitionBase
;
14 struct GfxBase
*GfxBase
;
17 static const char version
[] __attribute__((used
)) = "$VER: regiontest 41.1 (14.3.1997)\n";
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
,
33 CloseLibrary((struct Library
*)GfxBase
);
35 CloseLibrary((struct Library
*) IntuitionBase
);
42 struct Region
*regions
[10];
44 void freeregions(void)
47 for (i
= 0; i
< 10; i
++) {
49 DisposeRegion(regions
[i
]);
56 for (i
= 0; i
< 10; i
++)
57 if (regions
[i
] == NULL
)
60 if ((regions
[i
] = NewRegion())) {
61 printf("New Region created, id: %d\n", i
);
63 printf("Sorry, not enough mem\n");
66 printf("Sorry, no more regions possible\n");
70 void disposeregion(void)
73 printf("Enter Region id: ");
78 DisposeRegion(regions
[i
]);
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
);
90 Draw(win
->RPort
, r
->MaxX
+ offsetx
, r
->MaxY
+ offsety
);
92 Draw(win
->RPort
, r
->MinX
+ offsetx
, r
->MaxY
+ offsety
);
94 Draw(win
->RPort
, r
->MinX
+ offsetx
, r
->MinY
+ offsety
);
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)
107 printf("The following Region id's are currently in use:\n");
108 for (i
= 0; i
< 10; 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(®ions
[i
]->bounds
, 0, 0);
121 printf("Enter Region id: ");
124 if (i
>= 0 && i
< 10)
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(¤t
->bounds
, regions
[i
]->bounds
.MinX
, regions
[i
]->bounds
.MinY
);
132 SetAPen(win
->RPort
, 2);
133 FillRectangle(¤t
->bounds
, regions
[i
]->bounds
.MinX
, regions
[i
]->bounds
.MinY
);
134 printf("press a key\n");
135 //Wait(1L << win->UserPort->mp_SigBit);
139 printf("Region with id %d does not exist\n", i
);
142 void getrectangle(struct Rectangle
*rect
)
145 printf("Rectangle left edge: ");
148 printf("Rectangle top edge: ");
151 printf("Rectangle right edge: ");
154 printf("Rectangle lower edge: ");
159 void orrectregion(void)
162 printf("Enter Region id: ");
165 if (i
>= 0 && i
< 10)
167 struct Rectangle rect
;
169 if (OrRectRegion(regions
[i
], &rect
))
172 printf("Out of memory\n");
175 printf("Region with id %d does not exist\n", i
);
178 void andrectregion(void)
181 printf("Enter Region id: ");
184 if (i
>= 0 && i
< 10)
186 struct Rectangle rect
;
188 AndRectRegion(regions
[i
], &rect
);
192 printf("Region with id %d does not exist\n", i
);
195 void clearrectregion(void)
198 printf("Enter Region id: ");
201 if (i
>= 0 && i
< 10)
203 struct Rectangle rect
;
205 if (ClearRectRegion(regions
[i
], &rect
))
208 printf("Out of memory\n");
211 printf("Region with id %d does not exist\n", i
);
214 void xorrectregion(void)
217 printf("Enter Region id: ");
220 if (i
>= 0 && i
< 10)
222 struct Rectangle rect
;
224 if (XorRectRegion(regions
[i
], &rect
))
227 printf("Out of memory\n");
230 printf("Region with id %d does not exist\n", i
);
233 void clearregion(void)
236 printf("Enter Region id: ");
239 if (i
>= 0 && i
< 10)
241 ClearRegion(regions
[i
]);
245 printf("Region with id %d does not exist\n", i
);
248 void xorregionregion(void)
251 printf("Enter Region1 id: ");
254 printf("Enter Region2 (destination) id: ");
257 if (i1
>= 0 && i1
<= 10 && i2
>= 0 && i2
<= 10)
258 if (regions
[i1
] && regions
[i2
]) {
259 XorRegionRegion(regions
[i1
],regions
[i2
]);
263 printf("Region with id %d or %d does not exist\n",i1
,i2
);
266 void andregionregion(void)
269 printf("Enter Region1 id: ");
272 printf("Enter Region2 (destination) id: ");
275 if (i1
>= 0 && i1
<= 10 && i2
>= 0 && i2
<= 10)
276 if (regions
[i1
] && regions
[i2
]) {
277 AndRegionRegion(regions
[i1
],regions
[i2
]);
281 printf("Region with id %d or %d does not exist\n",i1
,i2
);
283 void orregionregion(void)
286 printf("Enter Region1 id: ");
289 printf("Enter Region2 (destination) id: ");
292 if (i1
>= 0 && i1
<= 10 && i2
>= 0 && i2
<= 10)
293 if (regions
[i1
] && regions
[i2
]) {
294 OrRegionRegion(regions
[i1
],regions
[i2
]);
298 printf("Region with id %d or %d does not exist\n",i1
,i2
);
310 if (!strcmp(buf
, "quit")) {
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")) {
320 } else if (!strcmp(buf
, "disposeregion")) {
322 } else if (!strcmp(buf
, "clearregion")) {
324 } else if (!strcmp(buf
, "showregions")) {
326 } else if (!strcmp(buf
, "showrects")) {
328 } else if (!strcmp(buf
, "orrectregion")) {
330 } else if (!strcmp(buf
, "andrectregion")) {
332 } else if (!strcmp(buf
, "clearrectregion")) {
334 } else if (!strcmp(buf
, "xorrectregion")) {
336 } else if (!strcmp(buf
, "xorregionregion")) {
338 } else if (!strcmp(buf
, "orregionregion")) {
340 } else if (!strcmp(buf
, "andregionregion")) {
342 } else if (!strcmp(buf
, "clear")) {
343 SetRast(win
->RPort
, 0);
345 printf("Unknown command. Try 'help'.\n");