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
[] = "$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
? ConsoleDevice
->dd_Library
.lib_Node
.ln_Name
: "(NULL)");
557 fprintf (stderr
, "Couldn't open console\n");
561 frame
= NewObject (NULL
, FRAMEICLASS
567 gadget
= NewObject (NULL
, FRBUTTONCLASS
568 , GA_Left
, BORDER
*2+GAD_WID
569 , GA_RelBottom
, -(GAD_HEI
+BORDER
)
572 , GA_Previous
, (IPTR
)&DemoGadget12
573 , GA_Text
, (IPTR
)"_Exit"
576 , GA_Image
, (IPTR
)frame
580 win
= OpenWindowTags (NULL
581 , WA_Title
, (IPTR
)"Open a window demo"
587 , WA_CloseGadget
, TRUE
588 , WA_DepthGadget
, TRUE
589 , WA_IDCMP
, IDCMP_RAWKEY
590 | IDCMP_REFRESHWINDOW
596 , WA_SimpleRefresh
, TRUE
597 , WA_Gadgets
, (IPTR
)&ExitGadget
600 D(printf("OpenWindow win=%p\n", win
));
604 fprintf (stderr
, "Couldn't open window\n");
610 DemoIText
.LeftEdge
= GAD_WID
/2 - rp
->Font
->tf_XSize
*2;
611 DemoIText
.TopEdge
= GAD_HEI
/2 - rp
->Font
->tf_YSize
/2;
612 RefreshGList(&DemoGadget4
,win
,NULL
,1);
615 printf ("Warning: Couldn't create gadget\n");
618 printf ("Warning: Couldn't create frame\n");
624 /* Refresh the window contents */
629 if ((im
= (struct IntuiMessage
*)GetMsg (win
->UserPort
)))
631 /* D("Got msg\n"); */
634 case IDCMP_CLOSEWINDOW
:
643 ievent
.ie_Code
= im
->Code
;
644 ievent
.ie_Qualifier
= im
->Qualifier
;
646 len
= RawKeyConvert (&ievent
, buf
, sizeof (buf
), NULL
);
648 printf ("Key %s %3ld + Qual %08lx=\""
649 , (im
->Code
& 0x8000) ? "up " : "down"
650 , (long)(im
->Code
& 0xFF)
651 , (unsigned long)im
->Qualifier
656 printf ("\" (buffer too short)");
660 for (t
=0; t
<len
; t
++)
662 if (buf
[t
] < 32 || (buf
[t
] >= 127 && buf
[t
] < 160))
687 printf ("\\x%02x", buf
[t
]);
692 putc (buf
[t
], stdout
);
696 if (*buf
== '\x1b' && len
== 1)
704 case IDCMP_MOUSEBUTTONS
:
709 Move (rp
, im
->MouseX
, im
->MouseY
);
719 Move (rp
, im
->MouseX
, im
->MouseY
);
729 Move (rp
, im
->MouseX
, im
->MouseY
);
741 case IDCMP_MOUSEMOVE
:
743 Draw (rp
, im
->MouseX
, im
->MouseY
);
747 case IDCMP_REFRESHWINDOW
:
748 printf ("REFRESHWINDOW\n");
751 EndRefresh (win
, TRUE
);
754 case IDCMP_GADGETDOWN
: {
755 struct Gadget
* gadget
;
758 gadget
= (struct Gadget
*)im
->IAddress
;
760 printf ("User pressed gadget %d\n", gadget
->GadgetID
);
762 switch (gadget
->GadgetID
)
765 pot
= DemoPropInfo3
.VertPot
- DemoPropInfo3
.VertBody
;
770 NewModifyProp (&DemoGadget7
773 , DemoPropInfo2
.Flags
774 , DemoPropInfo2
.HorizPot
776 , DemoPropInfo2
.HorizBody
777 , DemoPropInfo2
.VertBody
780 NewModifyProp (&DemoGadget8
783 , DemoPropInfo3
.Flags
784 , DemoPropInfo3
.HorizPot
786 , DemoPropInfo3
.HorizBody
787 , DemoPropInfo3
.VertBody
794 pot
= DemoPropInfo3
.VertPot
+ DemoPropInfo3
.VertBody
;
799 NewModifyProp (&DemoGadget7
802 , DemoPropInfo2
.Flags
803 , DemoPropInfo2
.HorizPot
805 , DemoPropInfo2
.HorizBody
806 , DemoPropInfo2
.VertBody
809 NewModifyProp (&DemoGadget8
812 , DemoPropInfo3
.Flags
813 , DemoPropInfo3
.HorizPot
815 , DemoPropInfo3
.HorizBody
816 , DemoPropInfo3
.VertBody
823 pot
= DemoPropInfo1
.HorizPot
+ DemoPropInfo1
.HorizBody
;
828 NewModifyProp (&DemoGadget6
831 , DemoPropInfo1
.Flags
833 , DemoPropInfo1
.VertPot
834 , DemoPropInfo1
.HorizBody
835 , DemoPropInfo1
.VertBody
838 NewModifyProp (&DemoGadget8
841 , DemoPropInfo3
.Flags
843 , DemoPropInfo3
.VertPot
844 , DemoPropInfo3
.HorizBody
845 , DemoPropInfo3
.VertBody
852 pot
= DemoPropInfo1
.HorizPot
- DemoPropInfo1
.HorizBody
;
857 NewModifyProp (&DemoGadget6
860 , DemoPropInfo1
.Flags
862 , DemoPropInfo1
.VertPot
863 , DemoPropInfo1
.HorizBody
864 , DemoPropInfo1
.VertBody
867 NewModifyProp (&DemoGadget8
870 , DemoPropInfo3
.Flags
872 , DemoPropInfo3
.VertPot
873 , DemoPropInfo3
.HorizBody
874 , DemoPropInfo3
.VertBody
884 case IDCMP_GADGETUP
: {
885 struct Gadget
* gadget
;
887 gadget
= (struct Gadget
*)im
->IAddress
;
889 printf ("User released gadget %d\n", gadget
->GadgetID
);
891 if (gadget
->GadgetID
== 1)
893 else if (gadget
->GadgetID
== 2)
900 NewModifyProp (&DemoGadget6
, win
, NULL
,
902 0, 0, MAXBODY
, MAXBODY
, 1);
903 NewModifyProp (&DemoGadget7
, win
, NULL
,
905 0, 0, MAXBODY
, MAXBODY
, 1);
906 NewModifyProp (&DemoGadget8
, win
, NULL
,
908 0, 0, MAXBODY
, MAXBODY
, 1);
912 NewModifyProp (&DemoGadget6
, win
, NULL
,
914 0, 0, MAXBODY
/2, MAXBODY
, 1);
915 NewModifyProp (&DemoGadget7
, win
, NULL
,
917 0, 0, MAXBODY
, MAXBODY
/2, 1);
918 NewModifyProp (&DemoGadget8
, win
, NULL
,
920 0, 0, MAXBODY
/2, MAXBODY
/2, 1);
924 NewModifyProp (&DemoGadget6
, win
, NULL
,
926 MAXPOT
, 0, MAXBODY
/2, MAXBODY
, 1);
927 NewModifyProp (&DemoGadget7
, win
, NULL
,
929 0, MAXPOT
, MAXBODY
, MAXBODY
/2, 1);
930 NewModifyProp (&DemoGadget8
, win
, NULL
,
932 MAXPOT
, MAXPOT
, MAXBODY
/2, MAXBODY
/2, 1);
936 NewModifyProp (&DemoGadget6
, win
, NULL
,
938 0, 0, MAXBODY
/9, MAXBODY
, 1);
939 NewModifyProp (&DemoGadget7
, win
, NULL
,
941 0, 0, MAXBODY
, MAXBODY
/9, 1);
942 NewModifyProp (&DemoGadget8
, win
, NULL
,
944 0, 0, MAXBODY
/9, MAXBODY
/9, 1);
955 ReplyMsg ((struct Message
*)im
);
959 /* D("Waiting\n"); */
960 Wait (1L << win
->UserPort
->mp_SigBit
);
964 D(bug("CloseWindow (%p)\n", win
));
969 DisposeObject (gadget
);
972 DisposeObject (frame
);
975 CloseLibrary ((struct Library
*)GfxBase
);
978 CloseLibrary ((struct Library
*)IntuitionBase
);
981 CloseDevice ((struct IORequest
*)&cioreq
);