2 Copyright © 1995-2014, 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 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
);
56 int main(int argc
, char **argv
)
58 /* Intialize debugging */
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
;
71 if ((screen
= openscreen()))
73 w1
= openwindow(screen
, "Window 1", W1_LEFT
, W1_TOP
, W1_WIDTH
, W1_HEIGHT
);
77 #ifdef USE_TWO_WINDOWS
80 w2
= openwindow(screen
, "Window 2", W2_LEFT
, W2_TOP
, W2_WIDTH
, W2_HEIGHT
);
86 // test_readpixel(w1);
87 /* SetAPen(w1->RPort, 3);
88 SetBPen(w1->RPort, 4);
91 test_linedrawing(w1
, w2
);
92 /* handleevents(w1, 0);*/
94 #ifdef USE_TWO_WINDOWS
102 CloseLibrary((struct Library
*)DOSBase
);
104 CloseLibrary((struct Library
*)GfxBase
);
106 CloseLibrary((struct Library
*) IntuitionBase
);
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
,
125 WA_CustomScreen
, screen
,
127 WA_DepthGadget
, TRUE
,
128 WA_CloseGadget
, TRUE
,
129 WA_SmartRefresh
, TRUE
,
130 WA_NotifyDepth
, TRUE
,
135 printf("Window opened\n");
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 */
171 printf("Opening screen\n");
172 if ((screen
= OpenScreenTags(NULL
,
176 SA_Title
, "gfx hidd demo",
180 screen
= OpenScreenTags(NULL
,
183 SA_Title
, "gfx hidd demo",
188 LoadRGB32(&screen
->ViewPort
, patterncoltab
);
190 /* screen->RastPort.longreserved[0] = window->RPort->longreserved[0];
192 Draw(&screen->RastPort, 100, 100);
198 VOID
test_readpixel(struct Window
*w
)
202 for (i
= 0; i
< 16; i
++) {
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
;
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
));
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
256 VOID
test_bltmask(struct Window
*w
)
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
277 , MASK_WIDTH, MASK_HEIGHT
286 VOID
test_blttemplate(struct Window
*w
)
288 UBYTE
template[] = { 0xAA, 0xAA, 0xAA, 0xAA
289 , 0xAA, 0xAA, 0xAA, 0xAA };
291 BltTemplate((PLANEPTR
)template
295 , 50, 50 /* xdest, ydest */
296 , 16 , 2 /* width, height */
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);
320 VOID
test_linedrawing(struct Window
*w1
, struct Window
*w2
)
323 struct Window
*frontwin
, *backwin
, *tmp
;
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);
342 WindowToFront(backwin
);
344 /* Wait for IDCMP_CHANGEWINDOW */
345 kprintf("WAITING FOR TOFRONT ON %s\n", backwin
->Title
);
346 handleevents(backwin
, IDCMP_CHANGEWINDOW
);
352 Move(rp
, x
+ w1
->BorderLeft
, w1
->BorderTop
);
353 Draw(rp
, w1
->BorderLeft
+ innerwidth
- x
- 1, W1_HEIGHT
- w1
->BorderBottom
- 1);
358 WindowToFront(backwin
);
360 /* Wait for IDCMP_CHANGEWINDOW */
361 kprintf("WAITING FOR TOFRONT ON %s\n", backwin
->Title
);
362 handleevents(backwin
, IDCMP_CHANGEWINDOW
);
373 ULONG
handleevents(struct Window
*win
, ULONG idcmp
)
375 struct IntuiMessage
*imsg
;
376 struct MsgPort
*port
= win
->UserPort
;
377 BOOL terminated
= FALSE
;
382 if ((imsg
= (struct IntuiMessage
*)GetMsg(port
)) != NULL
)
387 case IDCMP_REFRESHWINDOW
:
389 EndRefresh(win
, TRUE
);
392 case IDCMP_CLOSEWINDOW
:
393 quit
= terminated
= TRUE
;
397 if ((idcmp
& imsg
->Class
) == imsg
->Class
) {
398 retidcmp
= imsg
->Class
;
403 } /* switch (imsg->Class) */
404 ReplyMsg((struct Message
*)imsg
);
407 } /* if ((imsg = GetMsg(port)) != NULL) */
410 Wait(1L << port
->mp_SigBit
);
412 } /* while (!terminated) */
416 } /* HandleEvents() */