2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
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 if ((screen
= OpenScreenTags(NULL
,
174 SA_Title
, "gfx hidd demo",
178 screen
= OpenScreenTags(NULL
,
181 SA_Title
, "gfx hidd demo",
186 LoadRGB32(&screen
->ViewPort
, patterncoltab
);
188 /* screen->RastPort.longreserved[0] = window->RPort->longreserved[0];
190 Draw(&screen->RastPort, 100, 100);
196 VOID
test_readpixel(struct Window
*w
)
200 for (i
= 0; i
< 16; i
++) {
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
;
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
));
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
254 VOID
test_bltmask(struct Window
*w
)
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
275 , MASK_WIDTH, MASK_HEIGHT
284 VOID
test_blttemplate(struct Window
*w
)
286 UBYTE
template[] = { 0xAA, 0xAA, 0xAA, 0xAA
287 , 0xAA, 0xAA, 0xAA, 0xAA };
289 BltTemplate((PLANEPTR
)template
293 , 50, 50 /* xdest, ydest */
294 , 16 , 2 /* width, height */
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);
318 VOID
test_linedrawing(struct Window
*w1
, struct Window
*w2
)
321 struct Window
*frontwin
, *backwin
, *tmp
;
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);
340 WindowToFront(backwin
);
342 /* Wait for IDCMP_CHANGEWINDOW */
343 kprintf("WAITING FOR TOFRONT ON %s\n", backwin
->Title
);
344 handleevents(backwin
, IDCMP_CHANGEWINDOW
);
350 Move(rp
, x
+ w1
->BorderLeft
, w1
->BorderTop
);
351 Draw(rp
, w1
->BorderLeft
+ innerwidth
- x
- 1, W1_HEIGHT
- w1
->BorderBottom
- 1);
356 WindowToFront(backwin
);
358 /* Wait for IDCMP_CHANGEWINDOW */
359 kprintf("WAITING FOR TOFRONT ON %s\n", backwin
->Title
);
360 handleevents(backwin
, IDCMP_CHANGEWINDOW
);
371 ULONG
handleevents(struct Window
*win
, ULONG idcmp
)
373 struct IntuiMessage
*imsg
;
374 struct MsgPort
*port
= win
->UserPort
;
375 BOOL terminated
= FALSE
;
380 if ((imsg
= (struct IntuiMessage
*)GetMsg(port
)) != NULL
)
385 case IDCMP_REFRESHWINDOW
:
387 EndRefresh(win
, TRUE
);
390 case IDCMP_CLOSEWINDOW
:
395 if ((idcmp
& imsg
->Class
) == imsg
->Class
) {
396 retidcmp
= imsg
->Class
;
401 } /* switch (imsg->Class) */
402 ReplyMsg((struct Message
*)imsg
);
405 } /* if ((imsg = GetMsg(port)) != NULL) */
408 Wait(1L << port
->mp_SigBit
);
410 } /* while (!terminated) */
414 } /* HandleEvents() */