Added missing property.
[tangerine.git] / test / gfxtest.c
blobbaf5ee8f708ae93b4682c235e82bc814d832be0c
1 /*
2 Copyright © 1995-2002, The AROS Development Team. All rights reserved.
3 $Id$
5 Demo showing x11gfx.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 screen = OpenScreenTags(NULL,
171 SA_Width, 640,
172 SA_Height, 480,
173 SA_Depth, 24,
174 SA_Title, "X11 gfx hidd demo",
175 SA_Pens, pens,
177 TAG_END);
179 LoadRGB32(&screen->ViewPort, patterncoltab);
181 #if 0
182 screen = LockPubScreen(NULL);
183 #endif
185 /* screen->RastPort.longreserved[0] = window->RPort->longreserved[0];
187 Draw(&screen->RastPort, 100, 100);
189 return screen;
193 VOID test_readpixel(struct Window *w)
195 ULONG i;
197 for (i = 0; i < 16; i ++) {
198 UBYTE pen;
199 SetAPen(w->RPort, i);
200 WritePixel(w->RPort, 70, 70);
202 pen = ReadPixel(w->RPort, 70, 70);
204 printf("Wrote pen %ld, read pen %d\n", i, pen);
209 VOID test_flood(struct Window *w)
212 struct TmpRas tmpras;
213 BYTE *buffer;
215 D(bug("Window layer: %p\n", w->WLayer));
217 buffer = AllocRaster(w->WLayer->Width, w->WLayer->Height);
218 D(bug("buffer: %p\n", buffer));
219 if (!buffer)
220 return;
222 InitTmpRas(&tmpras, buffer, RASSIZE(w->WLayer->Width, w->WLayer->Height));
223 w->RPort->TmpRas = &tmpras;
225 SetOutlinePen(w->RPort, 1);
226 SetAPen(w->RPort, 1);
228 SetDrPt(w->RPort, ~0L);
230 Move(w->RPort, 50, 50);
231 Draw(w->RPort, 100, 100);
232 Draw(w->RPort, 50, 100);
233 Draw(w->RPort, 50, 50);
235 D(bug("Calling Flood()\n"));
236 Flood(w->RPort, 0, 70, 80); /* outline mode */
238 w->RPort->TmpRas = NULL;
242 #define MASK_WIDTH 32
243 #define MASK_HEIGHT 6
245 #define SRC_X 50
246 #define SRC_Y 50
248 #define DEST_X 100
249 #define DEST_Y 50
251 VOID test_bltmask(struct Window *w)
253 /* ULONG mask[] = {
254 0xAAAAAAAA,
255 0xAAAAAAAA,
256 0xFFFFFFFF,
257 0xFFFFFFFF,
258 0xAAAAAAAA,
259 0xAAAAAAAA
262 /* Fill a area to blit from */
264 SetAPen(w->RPort, 1);
266 RectFill(w->RPort, SRC_X, SRC_Y, SRC_X + MASK_WIDTH - 1, SRC_Y + MASK_HEIGHT);
268 /* Blit from source area */
269 /* BltMaskBitMapRastPort(w->RPort
270 , SRC_X, SRC_Y
271 , DEST_X, DEST_Y
272 , MASK_WIDTH, MASK_HEIGHT
273 , 0x00C0
274 , (PLANEPTR) mask
278 return;
281 VOID test_blttemplate(struct Window *w)
283 UBYTE template[] = { 0xAA, 0xAA, 0xAA, 0xAA
284 , 0xAA, 0xAA, 0xAA, 0xAA };
286 BltTemplate((PLANEPTR)template
287 , 0 /* xsrc */
288 , 4 /* modulo */
289 , w->RPort
290 , 50, 50 /* xdest, ydest */
291 , 16 , 2 /* width, height */
294 return;
297 VOID test_bltpattern(struct Window *w)
299 UWORD afpt[] = { 0xAAAA , 0x5555 };
302 SetDrMd(w->RPort, JAM2);
303 SetAPen(w->RPort, 1);
304 SetBPen(w->RPort, 2);
307 SetAfPt(w->RPort, afpt, 1);
309 BltPattern(w->RPort, NULL, 50, 50, 100, 100, 0);
311 return;
315 VOID test_linedrawing(struct Window *w1, struct Window *w2)
317 struct RastPort *rp;
318 struct Window *frontwin, *backwin, *tmp;
319 LONG x;
320 ULONG innerwidth;
322 rp = w1->RPort;
323 frontwin = w2;
324 backwin = w1;
326 SetAPen(rp, 3);
327 SetDrMd(rp, COMPLEMENT);
329 innerwidth = W1_WIDTH - w1->BorderLeft - w1->BorderRight;
331 for (x = 0; x < innerwidth; x ++) {
332 Move(rp, x + w1->BorderLeft, w1->BorderTop);
333 Draw(rp, w1->BorderLeft + innerwidth - x - 1, W1_HEIGHT - w1->BorderBottom - 1);
336 Delay(25);
337 WindowToFront(backwin);
338 Delay(25);
339 /* Wait for IDCMP_CHANGEWINDOW */
340 kprintf("WAITING FOR TOFRONT ON %s\n", backwin->Title);
341 handleevents(backwin, IDCMP_CHANGEWINDOW);
343 tmp = backwin;
344 backwin = frontwin;
345 frontwin = tmp;
347 Move(rp, x + w1->BorderLeft, w1->BorderTop);
348 Draw(rp, w1->BorderLeft + innerwidth - x - 1, W1_HEIGHT - w1->BorderBottom - 1);
350 Delay(25);
353 WindowToFront(backwin);
354 Delay(25);
355 /* Wait for IDCMP_CHANGEWINDOW */
356 kprintf("WAITING FOR TOFRONT ON %s\n", backwin->Title);
357 handleevents(backwin, IDCMP_CHANGEWINDOW);
359 tmp = backwin;
360 backwin = frontwin;
361 frontwin = tmp;
368 ULONG handleevents(struct Window *win, ULONG idcmp)
370 struct IntuiMessage *imsg;
371 struct MsgPort *port = win->UserPort;
372 BOOL terminated = FALSE;
373 ULONG retidcmp = 0;
375 while (!terminated)
377 if ((imsg = (struct IntuiMessage *)GetMsg(port)) != NULL)
380 switch (imsg->Class)
382 case IDCMP_REFRESHWINDOW:
383 BeginRefresh(win);
384 EndRefresh(win, TRUE);
385 break;
387 case IDCMP_CLOSEWINDOW:
388 terminated = TRUE;
389 break;
391 default:
392 if ((idcmp & imsg->Class) == imsg->Class) {
393 retidcmp = imsg->Class;
394 terminated = TRUE;
396 break;
398 } /* switch (imsg->Class) */
399 ReplyMsg((struct Message *)imsg);
402 } /* if ((imsg = GetMsg(port)) != NULL) */
403 else
405 Wait(1L << port->mp_SigBit);
407 } /* while (!terminated) */
409 return retidcmp;
411 } /* HandleEvents() */