Added very useful and convenient macro for parsing attribute IDs
[AROS.git] / test / showvisshape.c
blob19297ed2aebcfa38cac1f62f9c7c710dfe4b3de2
1 #include <exec/exec.h>
2 #include <dos/dos.h>
3 #include <intuition/intuition.h>
4 #include <intuition/intuitionbase.h>
5 #include <intuition/screens.h>
6 #include <graphics/clip.h>
7 #include <graphics/rastport.h>
8 #include <proto/exec.h>
9 #include <proto/dos.h>
10 #include <proto/graphics.h>
11 #include <proto/layers.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
17 #ifndef CreateLayerTagList
19 int main(void)
21 printf("showvisregion only works with hyperlayers.library!\n");
22 return 0;
25 #else
27 #define ARG_TEMPLATE "FAST=F/S,NUMBERS=N/S"
29 #define ARG_FAST 0
30 #define ARG_NUMBERS 1
31 #define NUM_ARGS 2
33 struct IntuitionBase *IntuitionBase = NULL;
34 struct GfxBase *GfxBase = NULL;
36 static struct Screen *scr;
37 static struct Window *win;
38 static struct Layer *lay;
39 static struct RDArgs *MyArgs;
40 static IPTR Args[NUM_ARGS];
41 static char s[256];
43 static void Cleanup(char *msg)
45 WORD rc;
47 if (msg)
49 printf("crlist: %s\n",msg);
50 rc = RETURN_WARN;
51 } else {
52 rc = RETURN_OK;
55 if (MyArgs) FreeArgs(MyArgs);
57 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
58 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
60 exit(rc);
63 static void OpenLibs(void)
65 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
67 Cleanup("Can´t open intuition.library!");
70 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)))
72 Cleanup("Can´t open graphics.library!");
76 static void GetArguments(void)
78 if (!(MyArgs = ReadArgs(ARG_TEMPLATE,Args,0)))
80 Fault(IoErr(),0,s,255);
81 Cleanup(s);
85 static void Action(void)
87 struct RastPort *rp;
88 struct Region *reg;
89 struct RegionRectangle *rr;
90 WORD x, y, i, count = 0;
92 puts("Activate the window whose visible region you want to see.\n");
93 puts("You have 3 seconds of time!\n\n");
95 Delay(3*50);
97 win = IntuitionBase->ActiveWindow;
98 scr = win->WScreen;
100 if (!win) Cleanup("No active window!");
102 if (!(rp = CloneRastPort(&win->WScreen->RastPort)))
104 Cleanup("Can´t clone screen rastport!");
106 SetDrMd(rp,JAM1);
108 lay = win->WLayer;
110 reg = lay->visibleshape;
111 rr = reg->RegionRectangle;
112 while(rr)
114 WORD x1 = reg->bounds.MinX + rr->bounds.MinX;
115 WORD y1 = reg->bounds.MinY + rr->bounds.MinY;
116 WORD x2 = reg->bounds.MinX + rr->bounds.MaxX;
117 WORD y2 = reg->bounds.MinY + rr->bounds.MaxY;
119 printf("#%04d (%4d,%4d) - (%4d, %4d) Size: %4d x %4d\n",
120 ++count,
125 x2 - x1 + 1,
126 y2 - y1 + 1);
128 for(i = 0; i < (Args[ARG_FAST] ? 1 : 8);i++)
130 SetAPen(rp,1 + (i & 1));
131 RectFill(rp,x1,y1,x2,y1);
132 RectFill(rp,x2,y1,x2,y2);
133 RectFill(rp,x1,y2,x2,y2);
134 RectFill(rp,x1,y1,x1,y2);
136 if (!Args[ARG_FAST]) Delay(10);
139 if (Args[ARG_NUMBERS])
141 sprintf(s,"%d",count);
142 i = TextLength(rp,s,strlen(s));
144 x = (x1 + x2 - i) / 2;
145 y = (y1 + y2 - rp->TxHeight) / 2;
147 if (x < 0)
149 x = 0;
150 } else if (x >= scr->Width - i)
152 x = scr->Width - i - 1;
155 if (y < 0)
157 y = 0;
158 } else if (y >= scr->Height - rp->TxHeight)
160 y = scr->Height - rp->TxHeight - 1;
163 i = strlen(s);
165 SetAPen(rp,1);
166 Move(rp,x + 1, y + 1 + rp->TxBaseline);
167 Text(rp,s,i);
169 SetAPen(rp,2);
170 Move(rp,x, y + rp->TxBaseline);
171 Text(rp,s,i);
173 rr = rr->Next;
176 FreeRastPort(rp);
179 int main(void)
181 OpenLibs();
182 GetArguments();
183 Action();
184 Cleanup(0);
186 return 0;
189 #endif