2 Copyright © 1995-96, The AROS Development Team. All rights reserved.
5 Desc: A short demo for the features of Intuition and Graphics
9 #define ENABLE_PURIFY 1
11 #include <exec/memory.h>
13 #include <dos/exall.h>
14 #include <dos/datetime.h>
15 #include <proto/exec.h>
16 #include <proto/dos.h>
17 #include <proto/arossupport.h>
18 #include <proto/alib.h>
19 #include <proto/utility.h>
20 #include <proto/graphics.h>
21 #include <proto/intuition.h>
22 #include <proto/console.h>
23 #include <intuition/intuitionbase.h>
24 #include <intuition/intuition.h>
25 #include <graphics/gfxbase.h>
26 #include <graphics/rastport.h>
27 #include <graphics/gfxmacros.h>
31 #include <intuition/classusr.h>
32 #include <intuition/gadgetclass.h>
33 #include <intuition/imageclass.h>
34 #include <devices/keymap.h>
39 # define D(x) /* eps */
43 static const char version
[] __attribute__((used
)) = "$VER: demowin 41.1 (14.3.1997)\n";
45 struct Device
*ConsoleDevice
;
46 struct IntuitionBase
*IntuitionBase
;
47 struct GfxBase
*GfxBase
;
48 Object
* frame
, * gadget
;
50 void Refresh (struct RastPort
* rp
)
71 xy
[0] = x
; xy
[1] = y
+len
;
72 xy
[2] = x
+len
; xy
[3] = y
+len
;
81 xy
[0] = x
; xy
[1] = y
+len
;
82 xy
[2] = x
+len
; xy
[3] = y
+len
;
91 xy
[0] = x
; xy
[1] = y
+len
;
92 xy
[2] = x
+len
; xy
[3] = y
+len
;
101 xy
[0] = x
; xy
[1] = y
;
102 xy
[2] = x
; xy
[3] = y
+len
;
103 xy
[4] = x
+len
; xy
[5] = y
+len
;
104 xy
[6] = x
; xy
[7] = y
;
105 PolyDraw (rp
, 4, xy
);
110 Text (rp
, "Hello World.", 12);
113 RectFill (rp
, 90, 0, 120, 30);
115 RectFill (rp
, 100, 10, 110, 20);
118 RectFill (rp
, 150, 10, 160, 20);
121 RectFill (rp
, 200, 10, 210, 20);
124 RectFill (rp
, 250, 10, 260, 20);
126 len
= TextLength (rp
, "Hello World.", 12);
129 RectFill (rp
, 299, 59, 300+len
, 60+rp
->Font
->tf_YSize
);
132 Move (rp
, 300, 60 + rp
->Font
->tf_Baseline
);
133 Text (rp
, "Hello World.", 12);
138 Text (rp
, "Hello World.", 12);
141 Text (rp
, "Hello World.", 12);
144 Text (rp
, "Press \"Complement\" to flip PropGadgets", 38);
149 for (pen
=1; pen
<16; pen
++)
155 DrawEllipse (rp
, 160, 150, t
, t
>>1);
156 DrawEllipse (rp
, 160, 151, t
, t
>>1);
163 RectFill (rp
, 450, 140, 549, 239);
167 for (x
=0; x
<100; x
++)
169 pen
= (LONG
)ReadPixel (rp
, x
+100,y
+100);
171 WritePixel (rp
, x
+450, y
+140);
180 WORD BorderData
[6*2*2] =
182 0, GAD_HEI
-1, /* Top (lighter) edge */
189 0, -(GAD_HEI
-2), /* Bottom (darker) edge */
199 GAD_WID
-1, GAD_HEI
-1,
215 struct Border DemoIBottomBorder
=
217 GAD_WID
-1, GAD_HEI
-1,
237 AUTOKNOB
| FREEHORIZ
| PROPNEWLOOK
,
244 AUTOKNOB
| FREEVERT
| PROPNEWLOOK
,
251 AUTOKNOB
| FREEHORIZ
| FREEVERT
| PROPNEWLOOK
,
262 0, 0, /* Left, Top */
268 #include "images/ArrowUp0.h"
269 #include "images/ArrowUp1.h"
270 #include "images/ArrowDown0.h"
271 #include "images/ArrowDown1.h"
272 #include "images/ArrowLeft0.h"
273 #include "images/ArrowLeft1.h"
274 #include "images/ArrowRight0.h"
275 #include "images/ArrowRight1.h"
276 #include "images/ImageButton0.h"
277 #include "images/ImageButton1.h"
282 NULL
, /* &DemoGadget, / * NextGadget */
283 -(BORDER
+2*ARROWLEFT1_WIDTH
), -((GAD_HEI
+BORDER
)*3),
284 ARROWLEFT1_WIDTH
, ARROWLEFT1_HEIGHT
, /* hit box */
290 GACT_IMMEDIATE
| GACT_RELVERIFY
, /* Activation */
291 GTYP_BOOLGADGET
, /* Type */
292 &ArrowLeft0Image
, &ArrowLeft1Image
, /* Render */
294 0L, NULL
, /* MutualExcl, SpecialInfo */
300 &DemoGadget12
, /* NextGadget */
301 -(BORDER
+1*ARROWLEFT1_WIDTH
), -((GAD_HEI
+BORDER
)*3),
302 ARROWLEFT1_WIDTH
, ARROWLEFT1_HEIGHT
, /* hit box */
308 GACT_IMMEDIATE
| GACT_RELVERIFY
, /* Activation */
309 GTYP_BOOLGADGET
, /* Type */
310 &ArrowRight0Image
, &ArrowRight1Image
, /* Render */
312 0L, NULL
, /* MutualExcl, SpecialInfo */
318 &DemoGadget11
, /* NextGadget */
319 -(BORDER
+ARROWDOWN1_WIDTH
), -((GAD_HEI
+BORDER
)*3+ARROWLEFT1_HEIGHT
+0*ARROWDOWN1_HEIGHT
-5),
320 ARROWDOWN1_WIDTH
, ARROWDOWN1_HEIGHT
, /* hit box */
326 GACT_IMMEDIATE
| GACT_RELVERIFY
, /* Activation */
327 GTYP_BOOLGADGET
, /* Type */
328 &ArrowDown0Image
, &ArrowDown1Image
, /* Render */
330 0L, NULL
, /* MutualExcl, SpecialInfo */
336 &DemoGadget10
, /* NextGadget */
337 -(BORDER
+ARROWDOWN1_WIDTH
), -((GAD_HEI
+BORDER
)*3+ARROWLEFT1_HEIGHT
+1*ARROWDOWN1_HEIGHT
-5),
338 ARROWDOWN1_WIDTH
, ARROWDOWN1_HEIGHT
, /* hit box */
344 GACT_IMMEDIATE
| GACT_RELVERIFY
, /* Activation */
345 GTYP_BOOLGADGET
, /* Type */
346 &ArrowUp0Image
, &ArrowUp1Image
, /* Render */
348 0L, NULL
, /* MutualExcl, SpecialInfo */
354 &DemoGadget9
, /* NextGadget */
355 -(BORDER
+ARROWDOWN1_WIDTH
+GAD_WID
), -((GAD_HEI
+BORDER
)*3+GAD_WID
),
356 GAD_WID
, GAD_WID
, /* hit box */
365 GTYP_PROPGADGET
, /* Type */
366 NULL
, NULL
, /* Render */
368 0L, (APTR
)&DemoPropInfo3
, /* MutualExcl, SpecialInfo */
374 &DemoGadget8
, /* NextGadget */
375 -(BORDER
+ARROWDOWN1_WIDTH
), BORDER
,
376 ARROWDOWN1_WIDTH
, -(GAD_HEI
*3+BORDER
*4+2*ARROWDOWN1_HEIGHT
), /* hit box */
385 GTYP_PROPGADGET
, /* Type */
386 NULL
, NULL
, /* Render */
388 0L, (APTR
)&DemoPropInfo2
, /* MutualExcl, SpecialInfo */
394 &DemoGadget7
, /* NextGadget */
395 BORDER
, -((GAD_HEI
+BORDER
)*3),
396 -(1+2*BORDER
+2*ARROWLEFT0_WIDTH
), ARROWLEFT0_HEIGHT
, /* hit box */
405 GTYP_PROPGADGET
, /* Type */
406 NULL
, NULL
, /* Render */
408 0L, (APTR
)&DemoPropInfo1
, /* MutualExcl, SpecialInfo */
414 &DemoGadget6
, /* NextGadget */
415 BORDER
+(GAD_WID
+BORDER
)*4, -((GAD_HEI
+BORDER
)*2), GAD_WID
, GAD_HEI
, /* hit box */
424 GTYP_BOOLGADGET
, /* Type */
425 &DemoTopBorder
, &DemoITopBorder
, /* Render */
426 (struct IntuiText
*)"_Toggle", /* Text */
427 0L, NULL
, /* MutualExcl, SpecialInfo */
433 &DemoGadget5
, /* NextGadget */
434 BORDER
+(GAD_WID
+BORDER
)*3, -((GAD_HEI
+BORDER
)*2), GAD_WID
, GAD_HEI
, /* hit box */
439 GACT_IMMEDIATE
| GACT_RELVERIFY
, /* Activation */
440 GTYP_BOOLGADGET
, /* Type */
441 &DemoTopBorder
, NULL
, /* Render */
442 &DemoIText
, /* Text */
443 0L, NULL
, /* MutualExcl, SpecialInfo */
449 &DemoGadget4
, /* NextGadget */
450 BORDER
+(GAD_WID
+BORDER
)*2, -((GAD_HEI
+BORDER
)*2),
451 IMAGEBUTTON0_WIDTH
, IMAGEBUTTON0_HEIGHT
, /* hit box */
457 GACT_IMMEDIATE
| GACT_RELVERIFY
, /* Activation */
458 GTYP_BOOLGADGET
, /* Type */
459 &ImageButton0Image
, &ImageButton1Image
, /* Render */
460 (struct IntuiText
*)"_Image", /* Text */
461 0L, NULL
, /* MutualExcl, SpecialInfo */
467 &DemoGadget3
, /* NextGadget */
468 BORDER
+(GAD_WID
+BORDER
)*1, -((GAD_HEI
+BORDER
)*2), GAD_WID
, GAD_HEI
, /* hit box */
473 GACT_IMMEDIATE
| GACT_RELVERIFY
, /* Activation */
474 GTYP_BOOLGADGET
, /* Type */
475 &DemoTopBorder
, NULL
, /* Render */
476 (struct IntuiText
*)"_Box", /* Text */
477 0L, NULL
, /* MutualExcl, SpecialInfo */
483 &DemoGadget2
, /* NextGadget */
484 BORDER
+(GAD_WID
+BORDER
)*0, -((GAD_HEI
+BORDER
)*2), GAD_WID
, GAD_HEI
, /* hit box */
489 GACT_IMMEDIATE
| GACT_RELVERIFY
, /* Activation */
490 GTYP_BOOLGADGET
, /* Type */
491 &DemoTopBorder
, NULL
, /* Render */
492 (struct IntuiText
*)"_Complement", /* Text */
493 0L, NULL
, /* MutualExcl, SpecialInfo */
499 &DemoGadget1
, /* NextGadget */
500 BORDER
, -(GAD_HEI
+BORDER
), GAD_WID
, GAD_HEI
, /* hit box */
505 GACT_RELVERIFY
, /* Activation */
506 GTYP_BOOLGADGET
, /* Type */
507 &DemoTopBorder
, &DemoITopBorder
, /* Render */
508 (struct IntuiText
*)"E_xit", /* Text */
509 0L, NULL
, /* MutualExcl, SpecialInfo */
514 int main (int argc
, char ** argv
)
517 struct RastPort
* rp
;
518 struct IntuiMessage
* im
;
519 struct IOStdReq cioreq
;
520 struct InputEvent ievent
=
531 printf ("Welcome to the window demo of AROS\n");
533 GfxBase
=(struct GfxBase
*)OpenLibrary(GRAPHICSNAME
,39);
534 IntuitionBase
=(struct IntuitionBase
*)OpenLibrary(INTUITIONNAME
,39);
538 fprintf (stderr
, "Couldn't open %s\n", GRAPHICSNAME
);
544 fprintf (stderr
, "Couldn't open %s\n", INTUITIONNAME
);
548 cioreq
.io_Message
.mn_Length
= sizeof(struct IOStdReq
);
550 OpenDevice ("console.device", -1, (struct IORequest
*)&cioreq
, 0);
551 ConsoleDevice
= cioreq
.io_Device
;
552 printf ("Opening console.device=%p (%s)\n", ConsoleDevice
,
553 ConsoleDevice
&& ConsoleDevice
->dd_Library
.lib_Node
.ln_Name
?
554 (const char *)ConsoleDevice
->dd_Library
.lib_Node
.ln_Name
:
559 fprintf (stderr
, "Couldn't open console\n");
563 frame
= NewObject (NULL
, FRAMEICLASS
569 gadget
= NewObject (NULL
, FRBUTTONCLASS
570 , GA_Left
, BORDER
*2+GAD_WID
571 , GA_RelBottom
, -(GAD_HEI
+BORDER
)
574 , GA_Previous
, (IPTR
)&DemoGadget12
575 , GA_Text
, (IPTR
)"_Exit"
578 , GA_Image
, (IPTR
)frame
582 win
= OpenWindowTags (NULL
583 , WA_Title
, (IPTR
)"Open a window demo"
589 , WA_CloseGadget
, TRUE
590 , WA_DepthGadget
, TRUE
591 , WA_IDCMP
, IDCMP_RAWKEY
592 | IDCMP_REFRESHWINDOW
598 , WA_SimpleRefresh
, TRUE
599 , WA_GimmeZeroZero
, TRUE
600 , WA_Gadgets
, (IPTR
)&ExitGadget
603 D(printf("OpenWindow win=%p\n", win
));
607 fprintf (stderr
, "Couldn't open window\n");
613 DemoIText
.LeftEdge
= GAD_WID
/2 - rp
->Font
->tf_XSize
*2;
614 DemoIText
.TopEdge
= GAD_HEI
/2 - rp
->Font
->tf_YSize
/2;
615 RefreshGList(&DemoGadget4
,win
,NULL
,1);
618 printf ("Warning: Couldn't create gadget\n");
621 printf ("Warning: Couldn't create frame\n");
627 /* Refresh the window contents */
632 if ((im
= (struct IntuiMessage
*)GetMsg (win
->UserPort
)))
634 /* D("Got msg\n"); */
637 case IDCMP_CLOSEWINDOW
:
646 ievent
.ie_Code
= im
->Code
;
647 ievent
.ie_Qualifier
= im
->Qualifier
;
649 len
= RawKeyConvert (&ievent
, buf
, sizeof (buf
), NULL
);
651 printf ("Key %s %3ld + Qual %08lx=\""
652 , (im
->Code
& 0x8000) ? "up " : "down"
653 , (long)(im
->Code
& 0xFF)
654 , (unsigned long)im
->Qualifier
659 printf ("\" (buffer too short)");
663 for (t
=0; t
<len
; t
++)
665 if (buf
[t
] < 32 || (buf
[t
] >= 127 && buf
[t
] < 160))
690 printf ("\\x%02x", buf
[t
]);
695 putc (buf
[t
], stdout
);
699 if (*buf
== '\x1b' && len
== 1)
707 case IDCMP_MOUSEBUTTONS
:
712 Move (rp
, im
->MouseX
, im
->MouseY
);
722 Move (rp
, im
->MouseX
, im
->MouseY
);
732 Move (rp
, im
->MouseX
, im
->MouseY
);
744 case IDCMP_MOUSEMOVE
:
746 Draw (rp
, im
->MouseX
, im
->MouseY
);
750 case IDCMP_REFRESHWINDOW
:
751 printf ("REFRESHWINDOW\n");
754 EndRefresh (win
, TRUE
);
757 case IDCMP_GADGETDOWN
: {
758 struct Gadget
* gadget
;
761 gadget
= (struct Gadget
*)im
->IAddress
;
763 printf ("User pressed gadget %d\n", gadget
->GadgetID
);
765 switch (gadget
->GadgetID
)
768 pot
= DemoPropInfo3
.VertPot
- DemoPropInfo3
.VertBody
;
773 NewModifyProp (&DemoGadget7
776 , DemoPropInfo2
.Flags
777 , DemoPropInfo2
.HorizPot
779 , DemoPropInfo2
.HorizBody
780 , DemoPropInfo2
.VertBody
783 NewModifyProp (&DemoGadget8
786 , DemoPropInfo3
.Flags
787 , DemoPropInfo3
.HorizPot
789 , DemoPropInfo3
.HorizBody
790 , DemoPropInfo3
.VertBody
797 pot
= DemoPropInfo3
.VertPot
+ DemoPropInfo3
.VertBody
;
802 NewModifyProp (&DemoGadget7
805 , DemoPropInfo2
.Flags
806 , DemoPropInfo2
.HorizPot
808 , DemoPropInfo2
.HorizBody
809 , DemoPropInfo2
.VertBody
812 NewModifyProp (&DemoGadget8
815 , DemoPropInfo3
.Flags
816 , DemoPropInfo3
.HorizPot
818 , DemoPropInfo3
.HorizBody
819 , DemoPropInfo3
.VertBody
826 pot
= DemoPropInfo1
.HorizPot
+ DemoPropInfo1
.HorizBody
;
831 NewModifyProp (&DemoGadget6
834 , DemoPropInfo1
.Flags
836 , DemoPropInfo1
.VertPot
837 , DemoPropInfo1
.HorizBody
838 , DemoPropInfo1
.VertBody
841 NewModifyProp (&DemoGadget8
844 , DemoPropInfo3
.Flags
846 , DemoPropInfo3
.VertPot
847 , DemoPropInfo3
.HorizBody
848 , DemoPropInfo3
.VertBody
855 pot
= DemoPropInfo1
.HorizPot
- DemoPropInfo1
.HorizBody
;
860 NewModifyProp (&DemoGadget6
863 , DemoPropInfo1
.Flags
865 , DemoPropInfo1
.VertPot
866 , DemoPropInfo1
.HorizBody
867 , DemoPropInfo1
.VertBody
870 NewModifyProp (&DemoGadget8
873 , DemoPropInfo3
.Flags
875 , DemoPropInfo3
.VertPot
876 , DemoPropInfo3
.HorizBody
877 , DemoPropInfo3
.VertBody
887 case IDCMP_GADGETUP
: {
888 struct Gadget
* gadget
;
890 gadget
= (struct Gadget
*)im
->IAddress
;
892 printf ("User released gadget %d\n", gadget
->GadgetID
);
894 if (gadget
->GadgetID
== 1)
896 else if (gadget
->GadgetID
== 2)
903 NewModifyProp (&DemoGadget6
, win
, NULL
,
905 0, 0, MAXBODY
, MAXBODY
, 1);
906 NewModifyProp (&DemoGadget7
, win
, NULL
,
908 0, 0, MAXBODY
, MAXBODY
, 1);
909 NewModifyProp (&DemoGadget8
, win
, NULL
,
911 0, 0, MAXBODY
, MAXBODY
, 1);
915 NewModifyProp (&DemoGadget6
, win
, NULL
,
917 0, 0, MAXBODY
/2, MAXBODY
, 1);
918 NewModifyProp (&DemoGadget7
, win
, NULL
,
920 0, 0, MAXBODY
, MAXBODY
/2, 1);
921 NewModifyProp (&DemoGadget8
, win
, NULL
,
923 0, 0, MAXBODY
/2, MAXBODY
/2, 1);
927 NewModifyProp (&DemoGadget6
, win
, NULL
,
929 MAXPOT
, 0, MAXBODY
/2, MAXBODY
, 1);
930 NewModifyProp (&DemoGadget7
, win
, NULL
,
932 0, MAXPOT
, MAXBODY
, MAXBODY
/2, 1);
933 NewModifyProp (&DemoGadget8
, win
, NULL
,
935 MAXPOT
, MAXPOT
, MAXBODY
/2, MAXBODY
/2, 1);
939 NewModifyProp (&DemoGadget6
, win
, NULL
,
941 0, 0, MAXBODY
/9, MAXBODY
, 1);
942 NewModifyProp (&DemoGadget7
, win
, NULL
,
944 0, 0, MAXBODY
, MAXBODY
/9, 1);
945 NewModifyProp (&DemoGadget8
, win
, NULL
,
947 0, 0, MAXBODY
/9, MAXBODY
/9, 1);
958 ReplyMsg ((struct Message
*)im
);
962 /* D("Waiting\n"); */
963 Wait (1L << win
->UserPort
->mp_SigBit
);
967 D(bug("CloseWindow (%p)\n", win
));
972 DisposeObject (gadget
);
975 DisposeObject (frame
);
978 CloseLibrary ((struct Library
*)GfxBase
);
981 CloseLibrary ((struct Library
*)IntuitionBase
);
984 CloseDevice ((struct IORequest
*)&cioreq
);