x11.hid: Use the AROS_UFIx() macros
[AROS.git] / test / gfxtest.c
blob8b5d26d2d82d35d5f6f9eca557e0346c3dbb2c31
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Demo showing gfx hidd
6 */
8 #include <stdio.h>
9 #include <string.h>
10 #include <exec/types.h>
11 #include <graphics/rastport.h>
12 #include <graphics/gfxmacros.h>
13 #include <intuition/intuition.h>
14 #include <proto/dos.h>
15 #include <proto/exec.h>
16 #include <proto/graphics.h>
17 #include <proto/intuition.h>
19 #define SDEBUG 1
20 #define DEBUG 1
22 #include <aros/debug.h>
24 #define USE_TWO_WINDOWS
26 struct IntuitionBase *IntuitionBase;
27 struct GfxBase *GfxBase;
28 struct Library *LayersBase;
29 struct DosLibrary *DOSBase;
31 struct Screen * openscreen(void);
32 struct Window *openwindow(struct Screen *screen, const char *title, LONG x, LONG y, LONG w, LONG h);
34 VOID test_blttemplate( struct Window *w);
35 VOID test_bltpattern(struct Window *w);
36 VOID test_bltmask(struct Window *w);
37 VOID test_flood(struct Window *w);
38 VOID test_readpixel(struct Window *w);
39 VOID test_linedrawing(struct Window *w1, struct Window *w2);
41 ULONG handleevents(struct Window *win, ULONG idcmp);
43 #define W1_LEFT 100
44 #define W1_TOP 100
45 #define W1_WIDTH 200
46 #define W1_HEIGHT 200
48 #define W2_LEFT 150
49 #define W2_TOP 150
50 #define W2_WIDTH 250
51 #define W2_HEIGHT 250
54 int main(int argc, char **argv)
56 /* Intialize debugging */
57 SDInit();
59 if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0)))
61 if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0)))
63 if ((DOSBase = (struct DosLibrary *) OpenLibrary("dos.library",0)))
65 struct Screen *screen;
66 struct Window *w1;
69 if ((screen = openscreen()))
71 w1 = openwindow(screen, "Window 1", W1_LEFT, W1_TOP, W1_WIDTH, W1_HEIGHT);
72 if (w1)
75 #ifdef USE_TWO_WINDOWS
76 struct Window *w2;
78 w2 = openwindow(screen, "Window 2", W2_LEFT, W2_TOP, W2_WIDTH, W2_HEIGHT);
79 if (w2)
82 #endif
83 /* Wait forever */
84 // test_readpixel(w1);
85 /* SetAPen(w1->RPort, 3);
86 SetBPen(w1->RPort, 4);
87 test_blttemplate(w1);
89 test_linedrawing(w1, w2);
90 handleevents(w1, 0);
92 #ifdef USE_TWO_WINDOWS
93 CloseWindow(w2);
95 #endif
96 CloseWindow(w1);
98 CloseScreen(screen);
100 CloseLibrary((struct Library *)DOSBase);
102 CloseLibrary((struct Library *)GfxBase);
104 CloseLibrary((struct Library *) IntuitionBase);
106 return 0;
107 } /* main */
111 struct Window *openwindow(struct Screen *screen, const char *title, LONG x, LONG y, LONG w, LONG h)
114 struct Window *window;
115 printf("Opening window, screen=%p\n", screen);
117 window = OpenWindowTags(NULL,
118 WA_IDCMP, IDCMP_RAWKEY | IDCMP_CLOSEWINDOW | IDCMP_CHANGEWINDOW,
119 WA_Left, x,
120 WA_Top, y,
121 WA_Width, w,
122 WA_Height, h,
123 WA_CustomScreen, screen,
124 WA_Activate, TRUE,
125 WA_DepthGadget, TRUE,
126 WA_CloseGadget, TRUE,
127 WA_SmartRefresh, TRUE,
128 WA_NotifyDepth, TRUE,
129 WA_Title, title,
131 TAG_END);
133 printf("Window opened\n");
135 return window;
139 struct Screen * openscreen(void)
141 struct Screen * screen;
142 UWORD pens[] = { ~0 };
143 ULONG patterncoltab[] = {
144 (16L << 16) + 0, /* 16 colors, loaded at index 0 */
146 0xB3B3B3B3, 0xB3B3B3B3, 0xB3B3B3B3, /* Grey70 */
147 0x00000000, 0x00000000, 0x00000000, /* Black */
148 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, /* White */
149 0x66666666, 0x88888888, 0xBBBBBBBB, /* AMIGA Blue */
151 0x00000000, 0x00000000, 0xFFFFFFFF, /* Blue */
152 0x00000000, 0xFFFFFFFF, 0x00000000, /* Green */
153 0xFFFFFFFF, 0x00000000, 0x00000000, /* Red */
154 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, /* Cyan */
156 0x33333333, 0x33333333, 0x33333333, /* Pattern Col 1 */
157 0xcdcdcdcd, 0x6c6c6c6c, 0xc7c7c7c7, /* Pattern Col 2 */
158 0x8e8e8e8e, 0x85858585, 0x93939393, /* Pattern Col 3 */
159 0x22222222, 0x22222222, 0x22222222, /* Pattern Col 4 */
161 0x77777777, 0x77777777, 0x77777777, /* Pattern Col 5 */
162 0x66666666, 0x66666666, 0x66666666, /* Pattern Col 6 */
163 0x55555555, 0x55555555, 0x55555555, /* Pattern Col 7 */
164 0x44444444, 0x44444444, 0x44444444, /* Pattern Col 8 */
166 0L /* Termination */
169 printf("Opening screen\n");
170 if ((screen = OpenScreenTags(NULL,
171 SA_Width, 640,
172 SA_Height, 480,
173 SA_Depth, 24,
174 SA_Title, "gfx hidd demo",
175 SA_Pens, pens,
176 TAG_END))) {
177 } else {
178 screen = OpenScreenTags(NULL,
179 SA_Width, 640,
180 SA_Height, 480,
181 SA_Title, "gfx hidd demo",
182 TAG_END);
185 if (screen)
186 LoadRGB32(&screen->ViewPort, patterncoltab);
188 /* screen->RastPort.longreserved[0] = window->RPort->longreserved[0];
190 Draw(&screen->RastPort, 100, 100);
192 return screen;
196 VOID test_readpixel(struct Window *w)
198 ULONG i;
200 for (i = 0; i < 16; i ++) {
201 UBYTE pen;
202 SetAPen(w->RPort, i);
203 WritePixel(w->RPort, 70, 70);
205 pen = ReadPixel(w->RPort, 70, 70);
207 printf("Wrote pen %ld, read pen %d\n", (long)i, pen);
212 VOID test_flood(struct Window *w)
215 struct TmpRas tmpras;
216 BYTE *buffer;
218 D(bug("Window layer: %p\n", w->WLayer));
220 buffer = AllocRaster(w->WLayer->Width, w->WLayer->Height);
221 D(bug("buffer: %p\n", buffer));
222 if (!buffer)
223 return;
225 InitTmpRas(&tmpras, buffer, RASSIZE(w->WLayer->Width, w->WLayer->Height));
226 w->RPort->TmpRas = &tmpras;
228 SetOutlinePen(w->RPort, 1);
229 SetAPen(w->RPort, 1);
231 SetDrPt(w->RPort, ~0L);
233 Move(w->RPort, 50, 50);
234 Draw(w->RPort, 100, 100);
235 Draw(w->RPort, 50, 100);
236 Draw(w->RPort, 50, 50);
238 D(bug("Calling Flood()\n"));
239 Flood(w->RPort, 0, 70, 80); /* outline mode */
241 w->RPort->TmpRas = NULL;
245 #define MASK_WIDTH 32
246 #define MASK_HEIGHT 6
248 #define SRC_X 50
249 #define SRC_Y 50
251 #define DEST_X 100
252 #define DEST_Y 50
254 VOID test_bltmask(struct Window *w)
256 /* ULONG mask[] = {
257 0xAAAAAAAA,
258 0xAAAAAAAA,
259 0xFFFFFFFF,
260 0xFFFFFFFF,
261 0xAAAAAAAA,
262 0xAAAAAAAA
265 /* Fill a area to blit from */
267 SetAPen(w->RPort, 1);
269 RectFill(w->RPort, SRC_X, SRC_Y, SRC_X + MASK_WIDTH - 1, SRC_Y + MASK_HEIGHT);
271 /* Blit from source area */
272 /* BltMaskBitMapRastPort(w->RPort
273 , SRC_X, SRC_Y
274 , DEST_X, DEST_Y
275 , MASK_WIDTH, MASK_HEIGHT
276 , 0x00C0
277 , (PLANEPTR) mask
281 return;
284 VOID test_blttemplate(struct Window *w)
286 UBYTE template[] = { 0xAA, 0xAA, 0xAA, 0xAA
287 , 0xAA, 0xAA, 0xAA, 0xAA };
289 BltTemplate((PLANEPTR)template
290 , 0 /* xsrc */
291 , 4 /* modulo */
292 , w->RPort
293 , 50, 50 /* xdest, ydest */
294 , 16 , 2 /* width, height */
297 return;
300 VOID test_bltpattern(struct Window *w)
302 UWORD afpt[] = { 0xAAAA , 0x5555 };
305 SetDrMd(w->RPort, JAM2);
306 SetAPen(w->RPort, 1);
307 SetBPen(w->RPort, 2);
310 SetAfPt(w->RPort, afpt, 1);
312 BltPattern(w->RPort, NULL, 50, 50, 100, 100, 0);
314 return;
318 VOID test_linedrawing(struct Window *w1, struct Window *w2)
320 struct RastPort *rp;
321 struct Window *frontwin, *backwin, *tmp;
322 LONG x;
323 ULONG innerwidth;
325 rp = w1->RPort;
326 frontwin = w2;
327 backwin = w1;
329 SetAPen(rp, 3);
330 SetDrMd(rp, COMPLEMENT);
332 innerwidth = W1_WIDTH - w1->BorderLeft - w1->BorderRight;
334 for (x = 0; x < innerwidth; x ++) {
335 Move(rp, x + w1->BorderLeft, w1->BorderTop);
336 Draw(rp, w1->BorderLeft + innerwidth - x - 1, W1_HEIGHT - w1->BorderBottom - 1);
339 Delay(25);
340 WindowToFront(backwin);
341 Delay(25);
342 /* Wait for IDCMP_CHANGEWINDOW */
343 kprintf("WAITING FOR TOFRONT ON %s\n", backwin->Title);
344 handleevents(backwin, IDCMP_CHANGEWINDOW);
346 tmp = backwin;
347 backwin = frontwin;
348 frontwin = tmp;
350 Move(rp, x + w1->BorderLeft, w1->BorderTop);
351 Draw(rp, w1->BorderLeft + innerwidth - x - 1, W1_HEIGHT - w1->BorderBottom - 1);
353 Delay(25);
356 WindowToFront(backwin);
357 Delay(25);
358 /* Wait for IDCMP_CHANGEWINDOW */
359 kprintf("WAITING FOR TOFRONT ON %s\n", backwin->Title);
360 handleevents(backwin, IDCMP_CHANGEWINDOW);
362 tmp = backwin;
363 backwin = frontwin;
364 frontwin = tmp;
371 ULONG handleevents(struct Window *win, ULONG idcmp)
373 struct IntuiMessage *imsg;
374 struct MsgPort *port = win->UserPort;
375 BOOL terminated = FALSE;
376 ULONG retidcmp = 0;
378 while (!terminated)
380 if ((imsg = (struct IntuiMessage *)GetMsg(port)) != NULL)
383 switch (imsg->Class)
385 case IDCMP_REFRESHWINDOW:
386 BeginRefresh(win);
387 EndRefresh(win, TRUE);
388 break;
390 case IDCMP_CLOSEWINDOW:
391 terminated = TRUE;
392 break;
394 default:
395 if ((idcmp & imsg->Class) == imsg->Class) {
396 retidcmp = imsg->Class;
397 terminated = TRUE;
399 break;
401 } /* switch (imsg->Class) */
402 ReplyMsg((struct Message *)imsg);
405 } /* if ((imsg = GetMsg(port)) != NULL) */
406 else
408 Wait(1L << port->mp_SigBit);
410 } /* while (!terminated) */
412 return retidcmp;
414 } /* HandleEvents() */