grub2: bring back build of aros-side grub2 tools
[AROS.git] / test / layers / clippingtest.c
blob11f66198dfd1a32f4d73ac618aacd35b52fc02d1
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <intuition/intuition.h>
7 #include <intuition/intuitionbase.h>
8 #include <graphics/gfx.h>
9 #include <graphics/gfxbase.h>
10 #include <proto/exec.h>
11 #include <proto/dos.h>
12 #include <proto/intuition.h>
13 #include <proto/graphics.h>
14 #include <proto/layers.h>
16 #include <stdio.h>
17 #include <stdlib.h>
19 #define ARG_TEMPLATE "SIMPLE/S"
21 #define ARG_SIMPLE 0
22 #define NUM_ARGS 1
24 struct IntuitionBase *IntuitionBase;
25 struct GfxBase *GfxBase;
26 struct Library *LayersBase;
28 static struct Window *win;
29 static struct RastPort *rp;
30 static struct Layer *lay;
32 static struct RDArgs *myargs;
33 static IPTR args[NUM_ARGS];
34 static char s[256];
36 static void Cleanup(char *msg)
38 if (msg)
40 printf("clippingtest: %s\n",msg);
43 if (win) CloseWindow(win);
45 if (myargs) FreeArgs(myargs);
47 if (LayersBase) CloseLibrary(LayersBase);
48 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
49 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
51 exit(0);
54 static void DosError(void)
56 Fault(IoErr(),0,s,255);
57 Cleanup(s);
60 static void OpenLibs(void)
62 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",39)))
64 Cleanup("Can't open intuition.library V39!");
67 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",39)))
69 Cleanup("Can't open graphics.library V39!");
72 if (!(LayersBase = OpenLibrary("layers.library",39)))
74 Cleanup("Can't open layers.library V39!");
78 static void GetArguments(void)
80 if (!(myargs = ReadArgs(ARG_TEMPLATE, args, 0)))
82 DosError();
86 static void MakeWin(void)
88 win = OpenWindowTags(0,WA_Left,10,
89 WA_Top,20,
90 WA_Width,200,
91 WA_Height,200,
92 WA_Title,(IPTR)"Press key to flip color!",
93 WA_CloseGadget,TRUE,
94 WA_DepthGadget,TRUE,
95 WA_DragBar,TRUE,
96 WA_Activate,TRUE,
97 args[ARG_SIMPLE] ? WA_SimpleRefresh : TAG_IGNORE, TRUE,
98 WA_IDCMP,IDCMP_CLOSEWINDOW |
99 IDCMP_VANILLAKEY |
100 IDCMP_REFRESHWINDOW,
101 TAG_DONE);
103 if (!win) Cleanup("Can't open window!");
105 rp = win->RPort;
106 lay = win->WLayer;
109 static void Action(void)
111 struct Region *clip, *oldclip;
112 struct Rectangle rect1;
113 struct Rectangle rect2;
114 struct IntuiMessage *msg;
115 WORD col = 1;
116 BOOL installed = TRUE;
117 BOOL quitme = FALSE;
119 rect1.MinX = 20;rect1.MinY = 80;
120 rect1.MaxX = 180;rect1.MaxY = 120;
121 rect2.MinX = 80;rect2.MinY = 20;
122 rect2.MaxX = 120;rect2.MaxY = 180;
124 Move(rp, 20, 20);
125 Draw(rp, 180, 180);
127 clip = NewRegion();
128 if (!clip) Cleanup("Can't create clip region!");
130 OrRectRegion(clip, &rect1);
131 OrRectRegion(clip, &rect2);
133 oldclip = InstallClipRegion(lay, clip);
135 SetAPen(rp,col);
136 RectFill(rp,0,0,1000,1000);
138 while(!quitme)
140 WaitPort(win->UserPort);
141 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
143 switch(msg->Class)
145 case IDCMP_CLOSEWINDOW:
146 quitme = TRUE;
147 break;
149 case IDCMP_VANILLAKEY:
150 switch (msg->Code)
152 case 'c':
153 case 'C':
154 if (installed)
156 InstallClipRegion(lay, oldclip);
157 installed = FALSE;
159 else
161 oldclip = InstallClipRegion(lay, clip);
162 installed = TRUE;
164 /* Fallthrough */
166 default:
167 col = 3 - col;
168 SetAPen(rp,col);
169 RectFill(rp,0,0,1000,1000);
170 break;
173 case IDCMP_REFRESHWINDOW:
174 BeginRefresh(win);
175 SetAPen(rp,col);
176 RectFill(rp,0,0,1000,1000);
177 EndRefresh(win,TRUE);
178 break;
181 ReplyMsg((struct Message *)msg);
185 if (installed)
186 InstallClipRegion(lay, oldclip);
187 DisposeRegion(clip);
190 int main(void)
192 OpenLibs();
193 GetArguments();
194 MakeWin();
195 Action();
196 Cleanup(0);
197 return 0;