Fixed compatibility of output.
[AROS.git] / test / layers / CRList.c
blob3f1bdfd5a25148007c2e59e65f3a5a7430eab89d
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/asmcall.h>
7 #include <exec/exec.h>
8 #include <dos/dos.h>
9 #include <intuition/intuition.h>
10 #include <intuition/intuitionbase.h>
11 #include <intuition/screens.h>
12 #include <graphics/clip.h>
13 #include <graphics/layers.h>
14 #include <graphics/rastport.h>
15 #include <utility/hooks.h>
16 #include <proto/arossupport.h>
17 #include <proto/exec.h>
18 #include <proto/dos.h>
19 #include <proto/graphics.h>
20 #include <proto/layers.h>
21 #include <proto/alib.h>
23 #include <string.h>
24 #include <setjmp.h>
26 #define ARG_TEMPLATE "FAST=F/S,NUMBERS=N/S,EXTRA/S,HOOK/S"
28 #define ARG_FAST 0
29 #define ARG_NUMBERS 1
30 #define ARG_EXTRA 2
31 #define ARG_HOOK 3
32 #define NUM_ARGS 4
34 static struct Screen *scr;
35 static struct Window *win;
36 static struct Layer *lay;
37 static struct RDArgs *MyArgs;
38 static IPTR Args[NUM_ARGS];
39 static char s[256];
40 static jmp_buf exit_buf;
42 static void Cleanup(char *msg)
44 WORD rc;
46 if (msg)
48 Printf("crlist: %s\n",msg);
49 rc = RETURN_WARN;
50 } else {
51 rc = RETURN_OK;
54 if (MyArgs) FreeArgs(MyArgs);
56 if (rc != RETURN_OK)
57 longjmp(exit_buf, rc);
60 static void GetArguments(void)
62 if (!(MyArgs = ReadArgs(ARG_TEMPLATE,Args,0)))
64 Fault(IoErr(),0,s,255);
65 Cleanup(s);
69 static void Show(struct RastPort *rp, struct ClipRect *cr)
71 WORD x, y, i, count = 0;
73 while(cr)
75 Printf("#%04ld (%4ld,%4ld) - (%4ld, %4ld) Size: %4ld x %4ld %s%s\n",
76 ++count,
77 cr->bounds.MinX,
78 cr->bounds.MinY,
79 cr->bounds.MaxX,
80 cr->bounds.MaxY,
81 cr->bounds.MaxX - cr->bounds.MinX + 1,
82 cr->bounds.MaxY - cr->bounds.MinY + 1,
83 (cr->lobs ? "HIDDEN " : ""),
84 (cr->BitMap ? "BITMAP ": ""));
86 if (cr->BitMap && Args[ARG_EXTRA])
88 ULONG w = GetBitMapAttr(cr->BitMap, BMA_WIDTH);
89 ULONG h = GetBitMapAttr(cr->BitMap, BMA_HEIGHT);
91 Printf(" -> BitMap 0x%p, size %ld x %ld\n", cr->BitMap, w, h);
94 for(i = 0; i < (Args[ARG_FAST] ? 1 : 8);i++)
96 SetAPen(rp,1 + (i & 1));
97 RectFill(rp,cr->bounds.MinX,cr->bounds.MinY,cr->bounds.MaxX,cr->bounds.MinY);
98 RectFill(rp,cr->bounds.MaxX,cr->bounds.MinY,cr->bounds.MaxX,cr->bounds.MaxY);
99 RectFill(rp,cr->bounds.MinX,cr->bounds.MaxY,cr->bounds.MaxX,cr->bounds.MaxY);
100 RectFill(rp,cr->bounds.MinX,cr->bounds.MinY,cr->bounds.MinX,cr->bounds.MaxY);
102 if (!Args[ARG_FAST]) Delay(10);
105 if (Args[ARG_NUMBERS])
107 __sprintf(s,"%d",count);
108 i = TextLength(rp,s,strlen(s));
110 x = (cr->bounds.MinX + cr->bounds.MaxX - i) / 2;
111 y = (cr->bounds.MinY + cr->bounds.MaxY - rp->TxHeight) / 2;
113 if (x < 0)
115 x = 0;
116 } else if (x >= scr->Width - i)
118 x = scr->Width - i - 1;
121 if (y < 0)
123 y = 0;
124 } else if (y >= scr->Height - rp->TxHeight)
126 y = scr->Height - rp->TxHeight - 1;
129 i = strlen(s);
131 SetAPen(rp,1);
132 Move(rp,x + 1, y + 1 + rp->TxBaseline);
133 Text(rp,s,i);
135 SetAPen(rp,2);
136 Move(rp,x, y + rp->TxBaseline);
137 Text(rp,s,i);
139 cr = cr->Next;
143 AROS_UFH3(static void, ClipRectHook,
144 AROS_UFHA(struct Hook *, h, A0),
145 AROS_UFHA(struct RastPort *, rp, A2),
146 AROS_UFHA(struct BackFillMessage *, msg, A1))
148 AROS_USERFUNC_INIT
150 Printf("# RastPort 0x%p, BitMap 0x%p, Layer 0x%p\n", rp, rp->BitMap, msg->Layer);
151 Printf(" -> (%4ld,%4ld) - (%4ld, %4ld), Offset (%4ld, %4ld)\n", msg->Bounds.MinX, msg->Bounds.MinY, msg->Bounds.MaxX, msg->Bounds.MaxY, msg->OffsetX, msg->OffsetY);
153 AROS_USERFUNC_EXIT
156 static struct Hook crHook =
158 .h_Entry = (HOOKFUNC)ClipRectHook
161 static void Action(void)
163 extern struct IntuitionBase *IntuitionBase;
164 struct RastPort *rp;
166 PutStr("Activate the window whose cliprects you want to see.\n");
167 PutStr("You have 3 seconds of time!\n\n");
169 Delay(3*50);
171 win = IntuitionBase->ActiveWindow;
173 if (!win) Cleanup("No active window!");
175 scr = win->WScreen;
177 if (!(rp = CloneRastPort(&scr->RastPort)))
179 Cleanup("Can´t clone screen rastport!");
181 SetDrMd(rp,JAM1);
183 lay = win->WLayer;
185 Show(rp, lay->ClipRect);
186 if (lay->_cliprects)
188 PutStr("This window has ClipRegion installed. Listing hidden cliprects...\n");
189 Show(rp, lay->_cliprects);
192 if (Args[ARG_HOOK])
194 struct Rectangle rect = {20, 20, win->Width - 40 + 1, win->Height - 40 + 1};
196 Printf("Running ClipRectHook on Window's RastPort 0x%p, BitMap 0x%p, Layer 0x%p...\n", win->RPort, win->RPort->BitMap, lay);
197 DoHookClipRects(&crHook, win->RPort, &rect);
200 FreeRastPort(rp);
203 int main(void)
205 int rc;
207 if ((rc = setjmp(exit_buf)) != 0)
208 return rc;
210 GetArguments();
211 Action();
212 Cleanup(0);
214 return 0;