start fleshing out the headers a little
[AROS.git] / test / graphics / gfxtest.c
blob0a64b95c158c7361f9b695820302781070e1df0e
1 /*
2 Copyright © 1995-2014, 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 static BOOL quit = FALSE;
33 struct Screen * openscreen(void);
34 struct Window *openwindow(struct Screen *screen, const char *title, LONG x, LONG y, LONG w, LONG h);
36 VOID test_blttemplate( struct Window *w);
37 VOID test_bltpattern(struct Window *w);
38 VOID test_bltmask(struct Window *w);
39 VOID test_flood(struct Window *w);
40 VOID test_readpixel(struct Window *w);
41 VOID test_linedrawing(struct Window *w1, struct Window *w2);
43 ULONG handleevents(struct Window *win, ULONG idcmp);
45 #define W1_LEFT 100
46 #define W1_TOP 100
47 #define W1_WIDTH 200
48 #define W1_HEIGHT 200
50 #define W2_LEFT 150
51 #define W2_TOP 150
52 #define W2_WIDTH 250
53 #define W2_HEIGHT 250
56 int main(int argc, char **argv)
58 /* Intialize debugging */
59 SDInit();
61 if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0)))
63 if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0)))
65 if ((DOSBase = (struct DosLibrary *) OpenLibrary("dos.library",0)))
67 struct Screen *screen;
68 struct Window *w1;
71 if ((screen = openscreen()))
73 w1 = openwindow(screen, "Window 1", W1_LEFT, W1_TOP, W1_WIDTH, W1_HEIGHT);
74 if (w1)
77 #ifdef USE_TWO_WINDOWS
78 struct Window *w2;
80 w2 = openwindow(screen, "Window 2", W2_LEFT, W2_TOP, W2_WIDTH, W2_HEIGHT);
81 if (w2)
84 #endif
85 /* Wait forever */
86 // test_readpixel(w1);
87 /* SetAPen(w1->RPort, 3);
88 SetBPen(w1->RPort, 4);
89 test_blttemplate(w1);
91 test_linedrawing(w1, w2);
92 /* handleevents(w1, 0);*/
94 #ifdef USE_TWO_WINDOWS
95 CloseWindow(w2);
97 #endif
98 CloseWindow(w1);
100 CloseScreen(screen);
102 CloseLibrary((struct Library *)DOSBase);
104 CloseLibrary((struct Library *)GfxBase);
106 CloseLibrary((struct Library *) IntuitionBase);
108 return 0;
109 } /* main */
113 struct Window *openwindow(struct Screen *screen, const char *title, LONG x, LONG y, LONG w, LONG h)
116 struct Window *window;
117 printf("Opening window, screen=%p\n", screen);
119 window = OpenWindowTags(NULL,
120 WA_IDCMP, IDCMP_RAWKEY | IDCMP_CLOSEWINDOW | IDCMP_CHANGEWINDOW,
121 WA_Left, x,
122 WA_Top, y,
123 WA_Width, w,
124 WA_Height, h,
125 WA_CustomScreen, screen,
126 WA_Activate, TRUE,
127 WA_DepthGadget, TRUE,
128 WA_CloseGadget, TRUE,
129 WA_SmartRefresh, TRUE,
130 WA_NotifyDepth, TRUE,
131 WA_Title, title,
133 TAG_END);
135 printf("Window opened\n");
137 return window;
141 struct Screen * openscreen(void)
143 struct Screen * screen;
144 UWORD pens[] = { ~0 };
145 ULONG patterncoltab[] = {
146 (16L << 16) + 0, /* 16 colors, loaded at index 0 */
148 0xB3B3B3B3, 0xB3B3B3B3, 0xB3B3B3B3, /* Grey70 */
149 0x00000000, 0x00000000, 0x00000000, /* Black */
150 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, /* White */
151 0x66666666, 0x88888888, 0xBBBBBBBB, /* AMIGA Blue */
153 0x00000000, 0x00000000, 0xFFFFFFFF, /* Blue */
154 0x00000000, 0xFFFFFFFF, 0x00000000, /* Green */
155 0xFFFFFFFF, 0x00000000, 0x00000000, /* Red */
156 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, /* Cyan */
158 0x33333333, 0x33333333, 0x33333333, /* Pattern Col 1 */
159 0xcdcdcdcd, 0x6c6c6c6c, 0xc7c7c7c7, /* Pattern Col 2 */
160 0x8e8e8e8e, 0x85858585, 0x93939393, /* Pattern Col 3 */
161 0x22222222, 0x22222222, 0x22222222, /* Pattern Col 4 */
163 0x77777777, 0x77777777, 0x77777777, /* Pattern Col 5 */
164 0x66666666, 0x66666666, 0x66666666, /* Pattern Col 6 */
165 0x55555555, 0x55555555, 0x55555555, /* Pattern Col 7 */
166 0x44444444, 0x44444444, 0x44444444, /* Pattern Col 8 */
168 0L /* Termination */
171 printf("Opening screen\n");
172 if ((screen = OpenScreenTags(NULL,
173 SA_Width, 640,
174 SA_Height, 480,
175 SA_Depth, 24,
176 SA_Title, "gfx hidd demo",
177 SA_Pens, pens,
178 TAG_END))) {
179 } else {
180 screen = OpenScreenTags(NULL,
181 SA_Width, 640,
182 SA_Height, 480,
183 SA_Title, "gfx hidd demo",
184 TAG_END);
187 if (screen)
188 LoadRGB32(&screen->ViewPort, patterncoltab);
190 /* screen->RastPort.longreserved[0] = window->RPort->longreserved[0];
192 Draw(&screen->RastPort, 100, 100);
194 return screen;
198 VOID test_readpixel(struct Window *w)
200 ULONG i;
202 for (i = 0; i < 16; i ++) {
203 UBYTE pen;
204 SetAPen(w->RPort, i);
205 WritePixel(w->RPort, 70, 70);
207 pen = ReadPixel(w->RPort, 70, 70);
209 printf("Wrote pen %ld, read pen %d\n", (long)i, pen);
214 VOID test_flood(struct Window *w)
217 struct TmpRas tmpras;
218 BYTE *buffer;
220 D(bug("Window layer: %p\n", w->WLayer));
222 buffer = AllocRaster(w->WLayer->Width, w->WLayer->Height);
223 D(bug("buffer: %p\n", buffer));
224 if (!buffer)
225 return;
227 InitTmpRas(&tmpras, buffer, RASSIZE(w->WLayer->Width, w->WLayer->Height));
228 w->RPort->TmpRas = &tmpras;
230 SetOutlinePen(w->RPort, 1);
231 SetAPen(w->RPort, 1);
233 SetDrPt(w->RPort, ~0L);
235 Move(w->RPort, 50, 50);
236 Draw(w->RPort, 100, 100);
237 Draw(w->RPort, 50, 100);
238 Draw(w->RPort, 50, 50);
240 D(bug("Calling Flood()\n"));
241 Flood(w->RPort, 0, 70, 80); /* outline mode */
243 w->RPort->TmpRas = NULL;
247 #define MASK_WIDTH 32
248 #define MASK_HEIGHT 6
250 #define SRC_X 50
251 #define SRC_Y 50
253 #define DEST_X 100
254 #define DEST_Y 50
256 VOID test_bltmask(struct Window *w)
258 /* ULONG mask[] = {
259 0xAAAAAAAA,
260 0xAAAAAAAA,
261 0xFFFFFFFF,
262 0xFFFFFFFF,
263 0xAAAAAAAA,
264 0xAAAAAAAA
267 /* Fill a area to blit from */
269 SetAPen(w->RPort, 1);
271 RectFill(w->RPort, SRC_X, SRC_Y, SRC_X + MASK_WIDTH - 1, SRC_Y + MASK_HEIGHT);
273 /* Blit from source area */
274 /* BltMaskBitMapRastPort(w->RPort
275 , SRC_X, SRC_Y
276 , DEST_X, DEST_Y
277 , MASK_WIDTH, MASK_HEIGHT
278 , 0x00C0
279 , (PLANEPTR) mask
283 return;
286 VOID test_blttemplate(struct Window *w)
288 UBYTE template[] = { 0xAA, 0xAA, 0xAA, 0xAA
289 , 0xAA, 0xAA, 0xAA, 0xAA };
291 BltTemplate((PLANEPTR)template
292 , 0 /* xsrc */
293 , 4 /* modulo */
294 , w->RPort
295 , 50, 50 /* xdest, ydest */
296 , 16 , 2 /* width, height */
299 return;
302 VOID test_bltpattern(struct Window *w)
304 UWORD afpt[] = { 0xAAAA , 0x5555 };
307 SetDrMd(w->RPort, JAM2);
308 SetAPen(w->RPort, 1);
309 SetBPen(w->RPort, 2);
312 SetAfPt(w->RPort, afpt, 1);
314 BltPattern(w->RPort, NULL, 50, 50, 100, 100, 0);
316 return;
320 VOID test_linedrawing(struct Window *w1, struct Window *w2)
322 struct RastPort *rp;
323 struct Window *frontwin, *backwin, *tmp;
324 LONG x;
325 ULONG innerwidth;
327 rp = w1->RPort;
328 frontwin = w2;
329 backwin = w1;
331 SetAPen(rp, 3);
332 SetDrMd(rp, COMPLEMENT);
334 innerwidth = W1_WIDTH - w1->BorderLeft - w1->BorderRight;
336 for (x = 0; x < innerwidth && !quit; x ++) {
337 Move(rp, x + w1->BorderLeft, w1->BorderTop);
338 Draw(rp, w1->BorderLeft + innerwidth - x - 1, W1_HEIGHT - w1->BorderBottom - 1);
341 Delay(25);
342 WindowToFront(backwin);
343 Delay(25);
344 /* Wait for IDCMP_CHANGEWINDOW */
345 kprintf("WAITING FOR TOFRONT ON %s\n", backwin->Title);
346 handleevents(backwin, IDCMP_CHANGEWINDOW);
348 tmp = backwin;
349 backwin = frontwin;
350 frontwin = tmp;
352 Move(rp, x + w1->BorderLeft, w1->BorderTop);
353 Draw(rp, w1->BorderLeft + innerwidth - x - 1, W1_HEIGHT - w1->BorderBottom - 1);
355 Delay(25);
358 WindowToFront(backwin);
359 Delay(25);
360 /* Wait for IDCMP_CHANGEWINDOW */
361 kprintf("WAITING FOR TOFRONT ON %s\n", backwin->Title);
362 handleevents(backwin, IDCMP_CHANGEWINDOW);
364 tmp = backwin;
365 backwin = frontwin;
366 frontwin = tmp;
373 ULONG handleevents(struct Window *win, ULONG idcmp)
375 struct IntuiMessage *imsg;
376 struct MsgPort *port = win->UserPort;
377 BOOL terminated = FALSE;
378 ULONG retidcmp = 0;
380 while (!terminated)
382 if ((imsg = (struct IntuiMessage *)GetMsg(port)) != NULL)
385 switch (imsg->Class)
387 case IDCMP_REFRESHWINDOW:
388 BeginRefresh(win);
389 EndRefresh(win, TRUE);
390 break;
392 case IDCMP_CLOSEWINDOW:
393 quit = terminated = TRUE;
394 break;
396 default:
397 if ((idcmp & imsg->Class) == imsg->Class) {
398 retidcmp = imsg->Class;
399 terminated = TRUE;
401 break;
403 } /* switch (imsg->Class) */
404 ReplyMsg((struct Message *)imsg);
407 } /* if ((imsg = GetMsg(port)) != NULL) */
408 else
410 Wait(1L << port->mp_SigBit);
412 } /* while (!terminated) */
414 return retidcmp;
416 } /* HandleEvents() */