2 Copyright © 1995-2002, The AROS Development Team. All rights reserved.
5 Demo showing x11gfx.hidd
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>
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
);
54 int main(int argc
, char **argv
)
56 /* Intialize debugging */
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
;
69 if ((screen
= openscreen()))
71 w1
= openwindow(screen
, "Window 1", W1_LEFT
, W1_TOP
, W1_WIDTH
, W1_HEIGHT
);
75 #ifdef USE_TWO_WINDOWS
78 w2
= openwindow(screen
, "Window 2", W2_LEFT
, W2_TOP
, W2_WIDTH
, W2_HEIGHT
);
84 // test_readpixel(w1);
85 /* SetAPen(w1->RPort, 3);
86 SetBPen(w1->RPort, 4);
89 test_linedrawing(w1
, w2
);
92 #ifdef USE_TWO_WINDOWS
100 CloseLibrary((struct Library
*)DOSBase
);
102 CloseLibrary((struct Library
*)GfxBase
);
104 CloseLibrary((struct Library
*) IntuitionBase
);
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
,
123 WA_CustomScreen
, screen
,
125 WA_DepthGadget
, TRUE
,
126 WA_CloseGadget
, TRUE
,
127 WA_SmartRefresh
, TRUE
,
128 WA_NotifyDepth
, TRUE
,
133 printf("Window opened\n");
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 */
169 printf("Opening screen\n");
170 screen
= OpenScreenTags(NULL
,
174 SA_Title
, "X11 gfx hidd demo",
179 LoadRGB32(&screen
->ViewPort
, patterncoltab
);
182 screen
= LockPubScreen(NULL
);
185 /* screen->RastPort.longreserved[0] = window->RPort->longreserved[0];
187 Draw(&screen->RastPort, 100, 100);
193 VOID
test_readpixel(struct Window
*w
)
197 for (i
= 0; i
< 16; i
++) {
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
;
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
));
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
251 VOID
test_bltmask(struct Window
*w
)
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
272 , MASK_WIDTH, MASK_HEIGHT
281 VOID
test_blttemplate(struct Window
*w
)
283 UBYTE
template[] = { 0xAA, 0xAA, 0xAA, 0xAA
284 , 0xAA, 0xAA, 0xAA, 0xAA };
286 BltTemplate((PLANEPTR
)template
290 , 50, 50 /* xdest, ydest */
291 , 16 , 2 /* width, height */
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);
315 VOID
test_linedrawing(struct Window
*w1
, struct Window
*w2
)
318 struct Window
*frontwin
, *backwin
, *tmp
;
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);
337 WindowToFront(backwin
);
339 /* Wait for IDCMP_CHANGEWINDOW */
340 kprintf("WAITING FOR TOFRONT ON %s\n", backwin
->Title
);
341 handleevents(backwin
, IDCMP_CHANGEWINDOW
);
347 Move(rp
, x
+ w1
->BorderLeft
, w1
->BorderTop
);
348 Draw(rp
, w1
->BorderLeft
+ innerwidth
- x
- 1, W1_HEIGHT
- w1
->BorderBottom
- 1);
353 WindowToFront(backwin
);
355 /* Wait for IDCMP_CHANGEWINDOW */
356 kprintf("WAITING FOR TOFRONT ON %s\n", backwin
->Title
);
357 handleevents(backwin
, IDCMP_CHANGEWINDOW
);
368 ULONG
handleevents(struct Window
*win
, ULONG idcmp
)
370 struct IntuiMessage
*imsg
;
371 struct MsgPort
*port
= win
->UserPort
;
372 BOOL terminated
= FALSE
;
377 if ((imsg
= (struct IntuiMessage
*)GetMsg(port
)) != NULL
)
382 case IDCMP_REFRESHWINDOW
:
384 EndRefresh(win
, TRUE
);
387 case IDCMP_CLOSEWINDOW
:
392 if ((idcmp
& imsg
->Class
) == imsg
->Class
) {
393 retidcmp
= imsg
->Class
;
398 } /* switch (imsg->Class) */
399 ReplyMsg((struct Message
*)imsg
);
402 } /* if ((imsg = GetMsg(port)) != NULL) */
405 Wait(1L << port
->mp_SigBit
);
407 } /* while (!terminated) */
411 } /* HandleEvents() */