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", 39);
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_Gadgets
, (IPTR
)&ExitGadget
602 D(printf("OpenWindow win=%p\n", win
));
606 fprintf (stderr
, "Couldn't open window\n");
612 DemoIText
.LeftEdge
= GAD_WID
/2 - rp
->Font
->tf_XSize
*2;
613 DemoIText
.TopEdge
= GAD_HEI
/2 - rp
->Font
->tf_YSize
/2;
614 RefreshGList(&DemoGadget4
,win
,NULL
,1);
617 printf ("Warning: Couldn't create gadget\n");
620 printf ("Warning: Couldn't create frame\n");
626 /* Refresh the window contents */
631 if ((im
= (struct IntuiMessage
*)GetMsg (win
->UserPort
)))
633 /* D("Got msg\n"); */
636 case IDCMP_CLOSEWINDOW
:
645 ievent
.ie_Code
= im
->Code
;
646 ievent
.ie_Qualifier
= im
->Qualifier
;
648 len
= RawKeyConvert (&ievent
, buf
, sizeof (buf
), NULL
);
650 printf ("Key %s %3ld + Qual %08lx=\""
651 , (im
->Code
& 0x8000) ? "up " : "down"
652 , (long)(im
->Code
& 0xFF)
653 , (unsigned long)im
->Qualifier
658 printf ("\" (buffer too short)");
662 for (t
=0; t
<len
; t
++)
664 if (buf
[t
] < 32 || (buf
[t
] >= 127 && buf
[t
] < 160))
689 printf ("\\x%02x", buf
[t
]);
694 putc (buf
[t
], stdout
);
698 if (*buf
== '\x1b' && len
== 1)
706 case IDCMP_MOUSEBUTTONS
:
711 Move (rp
, im
->MouseX
, im
->MouseY
);
721 Move (rp
, im
->MouseX
, im
->MouseY
);
731 Move (rp
, im
->MouseX
, im
->MouseY
);
743 case IDCMP_MOUSEMOVE
:
745 Draw (rp
, im
->MouseX
, im
->MouseY
);
749 case IDCMP_REFRESHWINDOW
:
750 printf ("REFRESHWINDOW\n");
753 EndRefresh (win
, TRUE
);
756 case IDCMP_GADGETDOWN
: {
757 struct Gadget
* gadget
;
760 gadget
= (struct Gadget
*)im
->IAddress
;
762 printf ("User pressed gadget %d\n", gadget
->GadgetID
);
764 switch (gadget
->GadgetID
)
767 pot
= DemoPropInfo3
.VertPot
- DemoPropInfo3
.VertBody
;
772 NewModifyProp (&DemoGadget7
775 , DemoPropInfo2
.Flags
776 , DemoPropInfo2
.HorizPot
778 , DemoPropInfo2
.HorizBody
779 , DemoPropInfo2
.VertBody
782 NewModifyProp (&DemoGadget8
785 , DemoPropInfo3
.Flags
786 , DemoPropInfo3
.HorizPot
788 , DemoPropInfo3
.HorizBody
789 , DemoPropInfo3
.VertBody
796 pot
= DemoPropInfo3
.VertPot
+ DemoPropInfo3
.VertBody
;
801 NewModifyProp (&DemoGadget7
804 , DemoPropInfo2
.Flags
805 , DemoPropInfo2
.HorizPot
807 , DemoPropInfo2
.HorizBody
808 , DemoPropInfo2
.VertBody
811 NewModifyProp (&DemoGadget8
814 , DemoPropInfo3
.Flags
815 , DemoPropInfo3
.HorizPot
817 , DemoPropInfo3
.HorizBody
818 , DemoPropInfo3
.VertBody
825 pot
= DemoPropInfo1
.HorizPot
+ DemoPropInfo1
.HorizBody
;
830 NewModifyProp (&DemoGadget6
833 , DemoPropInfo1
.Flags
835 , DemoPropInfo1
.VertPot
836 , DemoPropInfo1
.HorizBody
837 , DemoPropInfo1
.VertBody
840 NewModifyProp (&DemoGadget8
843 , DemoPropInfo3
.Flags
845 , DemoPropInfo3
.VertPot
846 , DemoPropInfo3
.HorizBody
847 , DemoPropInfo3
.VertBody
854 pot
= DemoPropInfo1
.HorizPot
- DemoPropInfo1
.HorizBody
;
859 NewModifyProp (&DemoGadget6
862 , DemoPropInfo1
.Flags
864 , DemoPropInfo1
.VertPot
865 , DemoPropInfo1
.HorizBody
866 , DemoPropInfo1
.VertBody
869 NewModifyProp (&DemoGadget8
872 , DemoPropInfo3
.Flags
874 , DemoPropInfo3
.VertPot
875 , DemoPropInfo3
.HorizBody
876 , DemoPropInfo3
.VertBody
886 case IDCMP_GADGETUP
: {
887 struct Gadget
* gadget
;
889 gadget
= (struct Gadget
*)im
->IAddress
;
891 printf ("User released gadget %d\n", gadget
->GadgetID
);
893 if (gadget
->GadgetID
== 1)
895 else if (gadget
->GadgetID
== 2)
902 NewModifyProp (&DemoGadget6
, win
, NULL
,
904 0, 0, MAXBODY
, MAXBODY
, 1);
905 NewModifyProp (&DemoGadget7
, win
, NULL
,
907 0, 0, MAXBODY
, MAXBODY
, 1);
908 NewModifyProp (&DemoGadget8
, win
, NULL
,
910 0, 0, MAXBODY
, MAXBODY
, 1);
914 NewModifyProp (&DemoGadget6
, win
, NULL
,
916 0, 0, MAXBODY
/2, MAXBODY
, 1);
917 NewModifyProp (&DemoGadget7
, win
, NULL
,
919 0, 0, MAXBODY
, MAXBODY
/2, 1);
920 NewModifyProp (&DemoGadget8
, win
, NULL
,
922 0, 0, MAXBODY
/2, MAXBODY
/2, 1);
926 NewModifyProp (&DemoGadget6
, win
, NULL
,
928 MAXPOT
, 0, MAXBODY
/2, MAXBODY
, 1);
929 NewModifyProp (&DemoGadget7
, win
, NULL
,
931 0, MAXPOT
, MAXBODY
, MAXBODY
/2, 1);
932 NewModifyProp (&DemoGadget8
, win
, NULL
,
934 MAXPOT
, MAXPOT
, MAXBODY
/2, MAXBODY
/2, 1);
938 NewModifyProp (&DemoGadget6
, win
, NULL
,
940 0, 0, MAXBODY
/9, MAXBODY
, 1);
941 NewModifyProp (&DemoGadget7
, win
, NULL
,
943 0, 0, MAXBODY
, MAXBODY
/9, 1);
944 NewModifyProp (&DemoGadget8
, win
, NULL
,
946 0, 0, MAXBODY
/9, MAXBODY
/9, 1);
957 ReplyMsg ((struct Message
*)im
);
961 /* D("Waiting\n"); */
962 Wait (1L << win
->UserPort
->mp_SigBit
);
966 D(bug("CloseWindow (%p)\n", win
));
971 DisposeObject (gadget
);
974 DisposeObject (frame
);
977 CloseLibrary ((struct Library
*)GfxBase
);
980 CloseLibrary ((struct Library
*)IntuitionBase
);
983 CloseDevice ((struct IORequest
*)&cioreq
);