force CC/CXX to the passed in compiler to use.
[AROS.git] / workbench / demos / demowin.c
blob8e05e207ff3bbe60c48e9084f211b2b5cb32104c
1 /*
2 Copyright © 1995-96, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: A short demo for the features of Intuition and Graphics
6 Lang: english
7 */
8 #define ENABLE_RT 1
9 #define ENABLE_PURIFY 1
11 #include <exec/memory.h>
12 #include <dos/dos.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>
28 #include <ctype.h>
29 #include <stdio.h>
30 #include <aros/rt.h>
31 #include <intuition/classusr.h>
32 #include <intuition/gadgetclass.h>
33 #include <intuition/imageclass.h>
34 #include <devices/keymap.h>
36 #if 0
37 # define D(x) x
38 #else
39 # define D(x) /* eps */
40 #endif
41 #define bug kprintf
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)
52 int len;
53 int t, tend, pen;
54 int x, y;
55 WORD xy[8];
57 SetAPen (rp, 1);
58 SetDrMd (rp, JAM2);
60 Move (rp, 0, 0);
61 Draw (rp, 320, 150);
63 Move (rp, 640, 0);
64 Draw (rp, 0, 300);
66 SetDrPt (rp, 0xF0F0);
67 len = 150;
68 x = 320;
69 y = 170;
71 xy[0] = x; xy[1] = y+len;
72 xy[2] = x+len; xy[3] = y+len;
73 xy[4] = x; xy[5] = y;
74 Move(rp,x,y);
75 PolyDraw (rp, 3, xy);
77 SetDrPt (rp, 0xAAAA);
78 x += 10;
79 y += 20;
80 len -= 30;
81 xy[0] = x; xy[1] = y+len;
82 xy[2] = x+len; xy[3] = y+len;
83 xy[4] = x; xy[5] = y;
84 Move(rp,x,y);
85 PolyDraw (rp, 3, xy);
87 SetDrPt (rp, 0x3333);
88 x += 10;
89 y += 20;
90 len -= 30;
91 xy[0] = x; xy[1] = y+len;
92 xy[2] = x+len; xy[3] = y+len;
93 xy[4] = x; xy[5] = y;
94 Move(rp,x,y);
95 PolyDraw (rp, 3, xy);
97 SetDrPt (rp, 0xF731);
98 x += 10;
99 y += 20;
100 len -= 30;
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);
107 SetDrPt (rp, ~0);
109 Move (rp, 300, 40);
110 Text (rp, "Hello World.", 12);
112 SetAPen (rp, 3);
113 RectFill (rp, 90, 0, 120, 30);
114 SetAPen (rp, 0);
115 RectFill (rp, 100, 10, 110, 20);
117 SetAPen (rp, 1);
118 RectFill (rp, 150, 10, 160, 20);
120 SetAPen (rp, 2);
121 RectFill (rp, 200, 10, 210, 20);
123 SetAPen (rp, 3);
124 RectFill (rp, 250, 10, 260, 20);
126 len = TextLength (rp, "Hello World.", 12);
128 SetAPen (rp, 2);
129 RectFill (rp, 299, 59, 300+len, 60+rp->Font->tf_YSize);
131 SetAPen (rp, 1);
132 Move (rp, 300, 60 + rp->Font->tf_Baseline);
133 Text (rp, "Hello World.", 12);
135 SetDrMd (rp, JAM1);
136 SetAPen (rp, 1);
137 Move (rp, 301, 101);
138 Text (rp, "Hello World.", 12);
139 SetAPen (rp, 2);
140 Move (rp, 300, 100);
141 Text (rp, "Hello World.", 12);
143 Move (rp, 20, 360);
144 Text (rp, "Press \"Complement\" to flip PropGadgets", 38);
146 tend = 10;
147 t = 0;
149 for (pen=1; pen<16; pen++)
151 SetAPen (rp, pen);
153 for ( ; t<tend; t++)
155 DrawEllipse (rp, 160, 150, t, t>>1);
156 DrawEllipse (rp, 160, 151, t, t>>1);
159 tend += 10;
162 SetAPen (rp, 0);
163 RectFill (rp, 450, 140, 549, 239);
165 for (y=0; y<20; y++)
167 for (x=0; x<100; x++)
169 pen = (LONG)ReadPixel (rp, x+100,y+100);
170 SetAPen (rp, pen);
171 WritePixel (rp, x+450, y+140);
176 #define GAD_WID 100
177 #define GAD_HEI 30
178 #define BORDER 20
180 WORD BorderData[6*2*2] =
182 0, GAD_HEI-1, /* Top (lighter) edge */
183 1, GAD_HEI-2,
184 1, 1,
185 GAD_WID-2, 1,
186 GAD_WID-1, 0,
187 0, 0,
189 0, -(GAD_HEI-2), /* Bottom (darker) edge */
190 -1, -(GAD_HEI-3),
191 -1, -1,
192 -(GAD_WID-3), -1,
193 -(GAD_WID-2), 0,
194 -1, 0,
196 struct Border
197 DemoBottomBorder =
199 GAD_WID-1, GAD_HEI-1,
200 1, 2,
201 JAM1,
203 &BorderData[6*2],
204 NULL
206 DemoTopBorder =
208 0, 0,
209 2, 1,
210 JAM1,
212 &BorderData[0],
213 &DemoBottomBorder
215 struct Border DemoIBottomBorder =
217 GAD_WID-1, GAD_HEI-1,
218 2, 1,
219 JAM1,
221 &BorderData[6*2],
222 NULL
224 DemoITopBorder =
226 0, 0,
227 1, 2,
228 JAM1,
230 &BorderData[0],
231 &DemoIBottomBorder
234 struct PropInfo
235 DemoPropInfo1 =
237 AUTOKNOB | FREEHORIZ | PROPNEWLOOK,
238 0, 0,
239 MAXBODY, MAXBODY,
240 0,0,0,0,0,0
242 DemoPropInfo2 =
244 AUTOKNOB | FREEVERT | PROPNEWLOOK,
245 0, 0,
246 MAXBODY, MAXBODY,
247 0,0,0,0,0,0
249 DemoPropInfo3 =
251 AUTOKNOB | FREEHORIZ | FREEVERT | PROPNEWLOOK,
252 0, 0,
253 MAXBODY, MAXBODY,
254 0,0,0,0,0,0
257 struct IntuiText
258 DemoIText =
260 1, 2, /* Pens */
261 JAM1, /* Drawmode */
262 0, 0, /* Left, Top */
263 NULL, /* TextAttr */
264 "None", /* Text */
265 NULL /* Next */
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"
279 struct Gadget
280 DemoGadget12 =
282 NULL, /* &DemoGadget, / * NextGadget */
283 -(BORDER+2*ARROWLEFT1_WIDTH), -((GAD_HEI+BORDER)*3),
284 ARROWLEFT1_WIDTH, ARROWLEFT1_HEIGHT, /* hit box */
285 GFLG_GADGHIMAGE
286 | GFLG_RELRIGHT
287 | GFLG_RELBOTTOM
288 | GFLG_GADGIMAGE
289 , /* Flags */
290 GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
291 GTYP_BOOLGADGET, /* Type */
292 &ArrowLeft0Image, &ArrowLeft1Image, /* Render */
293 NULL, /* Text */
294 0L, NULL, /* MutualExcl, SpecialInfo */
295 13, /* GadgetID */
296 NULL /* UserData */
298 DemoGadget11 =
300 &DemoGadget12, /* NextGadget */
301 -(BORDER+1*ARROWLEFT1_WIDTH), -((GAD_HEI+BORDER)*3),
302 ARROWLEFT1_WIDTH, ARROWLEFT1_HEIGHT, /* hit box */
303 GFLG_GADGHIMAGE
304 | GFLG_RELRIGHT
305 | GFLG_RELBOTTOM
306 | GFLG_GADGIMAGE
307 , /* Flags */
308 GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
309 GTYP_BOOLGADGET, /* Type */
310 &ArrowRight0Image, &ArrowRight1Image, /* Render */
311 NULL, /* Text */
312 0L, NULL, /* MutualExcl, SpecialInfo */
313 12, /* GadgetID */
314 NULL /* UserData */
316 DemoGadget10 =
318 &DemoGadget11, /* NextGadget */
319 -(BORDER+ARROWDOWN1_WIDTH), -((GAD_HEI+BORDER)*3+ARROWLEFT1_HEIGHT+0*ARROWDOWN1_HEIGHT-5),
320 ARROWDOWN1_WIDTH, ARROWDOWN1_HEIGHT, /* hit box */
321 GFLG_GADGHIMAGE
322 | GFLG_RELRIGHT
323 | GFLG_RELBOTTOM
324 | GFLG_GADGIMAGE
325 , /* Flags */
326 GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
327 GTYP_BOOLGADGET, /* Type */
328 &ArrowDown0Image, &ArrowDown1Image, /* Render */
329 NULL, /* Text */
330 0L, NULL, /* MutualExcl, SpecialInfo */
331 11, /* GadgetID */
332 NULL /* UserData */
334 DemoGadget9 =
336 &DemoGadget10, /* NextGadget */
337 -(BORDER+ARROWDOWN1_WIDTH), -((GAD_HEI+BORDER)*3+ARROWLEFT1_HEIGHT+1*ARROWDOWN1_HEIGHT-5),
338 ARROWDOWN1_WIDTH, ARROWDOWN1_HEIGHT, /* hit box */
339 GFLG_GADGHIMAGE
340 | GFLG_RELRIGHT
341 | GFLG_RELBOTTOM
342 | GFLG_GADGIMAGE
343 , /* Flags */
344 GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
345 GTYP_BOOLGADGET, /* Type */
346 &ArrowUp0Image, &ArrowUp1Image, /* Render */
347 NULL, /* Text */
348 0L, NULL, /* MutualExcl, SpecialInfo */
349 10, /* GadgetID */
350 NULL /* UserData */
352 DemoGadget8 =
354 &DemoGadget9, /* NextGadget */
355 -(BORDER+ARROWDOWN1_WIDTH+GAD_WID), -((GAD_HEI+BORDER)*3+GAD_WID),
356 GAD_WID, GAD_WID, /* hit box */
357 GFLG_GADGHIMAGE
358 | GFLG_RELRIGHT
359 | GFLG_RELBOTTOM
360 , /* Flags */
361 GACT_IMMEDIATE
362 | GACT_RELVERIFY
363 | GACT_TOGGLESELECT
364 , /* Activation */
365 GTYP_PROPGADGET, /* Type */
366 NULL, NULL, /* Render */
367 NULL, /* Text */
368 0L, (APTR)&DemoPropInfo3, /* MutualExcl, SpecialInfo */
369 9, /* GadgetID */
370 NULL /* UserData */
372 DemoGadget7 =
374 &DemoGadget8, /* NextGadget */
375 -(BORDER+ARROWDOWN1_WIDTH), BORDER,
376 ARROWDOWN1_WIDTH, -(GAD_HEI*3+BORDER*4+2*ARROWDOWN1_HEIGHT), /* hit box */
377 GFLG_GADGHIMAGE
378 | GFLG_RELRIGHT
379 | GFLG_RELHEIGHT
380 , /* Flags */
381 GACT_IMMEDIATE
382 | GACT_RELVERIFY
383 | GACT_TOGGLESELECT
384 , /* Activation */
385 GTYP_PROPGADGET, /* Type */
386 NULL, NULL, /* Render */
387 NULL, /* Text */
388 0L, (APTR)&DemoPropInfo2, /* MutualExcl, SpecialInfo */
389 8, /* GadgetID */
390 NULL /* UserData */
392 DemoGadget6 =
394 &DemoGadget7, /* NextGadget */
395 BORDER, -((GAD_HEI+BORDER)*3),
396 -(1+2*BORDER+2*ARROWLEFT0_WIDTH), ARROWLEFT0_HEIGHT, /* hit box */
397 GFLG_GADGHIMAGE
398 | GFLG_RELBOTTOM
399 | GFLG_RELWIDTH
400 , /* Flags */
401 GACT_IMMEDIATE
402 | GACT_RELVERIFY
403 | GACT_TOGGLESELECT
404 , /* Activation */
405 GTYP_PROPGADGET, /* Type */
406 NULL, NULL, /* Render */
407 NULL, /* Text */
408 0L, (APTR)&DemoPropInfo1, /* MutualExcl, SpecialInfo */
409 7, /* GadgetID */
410 NULL /* UserData */
412 DemoGadget5 =
414 &DemoGadget6, /* NextGadget */
415 BORDER+(GAD_WID+BORDER)*4, -((GAD_HEI+BORDER)*2), GAD_WID, GAD_HEI, /* hit box */
416 GFLG_GADGHIMAGE
417 | GFLG_LABELSTRING
418 | GFLG_RELBOTTOM
419 , /* Flags */
420 GACT_IMMEDIATE
421 | GACT_RELVERIFY
422 | GACT_TOGGLESELECT
423 , /* Activation */
424 GTYP_BOOLGADGET, /* Type */
425 &DemoTopBorder, &DemoITopBorder, /* Render */
426 (struct IntuiText *)"_Toggle", /* Text */
427 0L, NULL, /* MutualExcl, SpecialInfo */
428 6, /* GadgetID */
429 NULL /* UserData */
431 DemoGadget4 =
433 &DemoGadget5, /* NextGadget */
434 BORDER+(GAD_WID+BORDER)*3, -((GAD_HEI+BORDER)*2), GAD_WID, GAD_HEI, /* hit box */
435 GFLG_GADGHNONE
436 | GFLG_LABELITEXT
437 | GFLG_RELBOTTOM
438 , /* Flags */
439 GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
440 GTYP_BOOLGADGET, /* Type */
441 &DemoTopBorder, NULL, /* Render */
442 &DemoIText, /* Text */
443 0L, NULL, /* MutualExcl, SpecialInfo */
444 5, /* GadgetID */
445 NULL /* UserData */
447 DemoGadget3 =
449 &DemoGadget4, /* NextGadget */
450 BORDER+(GAD_WID+BORDER)*2, -((GAD_HEI+BORDER)*2),
451 IMAGEBUTTON0_WIDTH, IMAGEBUTTON0_HEIGHT, /* hit box */
452 GFLG_GADGHIMAGE
453 | GFLG_LABELSTRING
454 | GFLG_RELBOTTOM
455 | GFLG_GADGIMAGE
456 , /* Flags */
457 GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
458 GTYP_BOOLGADGET, /* Type */
459 &ImageButton0Image, &ImageButton1Image, /* Render */
460 (struct IntuiText *)"_Image", /* Text */
461 0L, NULL, /* MutualExcl, SpecialInfo */
462 4, /* GadgetID */
463 NULL /* UserData */
465 DemoGadget2 =
467 &DemoGadget3, /* NextGadget */
468 BORDER+(GAD_WID+BORDER)*1, -((GAD_HEI+BORDER)*2), GAD_WID, GAD_HEI, /* hit box */
469 GFLG_GADGHBOX
470 | GFLG_LABELSTRING
471 | GFLG_RELBOTTOM
472 , /* Flags */
473 GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
474 GTYP_BOOLGADGET, /* Type */
475 &DemoTopBorder, NULL, /* Render */
476 (struct IntuiText *)"_Box", /* Text */
477 0L, NULL, /* MutualExcl, SpecialInfo */
478 3, /* GadgetID */
479 NULL /* UserData */
481 DemoGadget1 =
483 &DemoGadget2, /* NextGadget */
484 BORDER+(GAD_WID+BORDER)*0, -((GAD_HEI+BORDER)*2), GAD_WID, GAD_HEI, /* hit box */
485 GFLG_GADGHCOMP
486 | GFLG_LABELSTRING
487 | GFLG_RELBOTTOM
488 , /* Flags */
489 GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
490 GTYP_BOOLGADGET, /* Type */
491 &DemoTopBorder, NULL, /* Render */
492 (struct IntuiText *)"_Complement", /* Text */
493 0L, NULL, /* MutualExcl, SpecialInfo */
494 2, /* GadgetID */
495 NULL /* UserData */
497 ExitGadget =
499 &DemoGadget1, /* NextGadget */
500 BORDER, -(GAD_HEI+BORDER), GAD_WID, GAD_HEI, /* hit box */
501 GFLG_GADGHIMAGE
502 | GFLG_LABELSTRING
503 | GFLG_RELBOTTOM
504 , /* Flags */
505 GACT_RELVERIFY, /* Activation */
506 GTYP_BOOLGADGET, /* Type */
507 &DemoTopBorder, &DemoITopBorder, /* Render */
508 (struct IntuiText *)"E_xit", /* Text */
509 0L, NULL, /* MutualExcl, SpecialInfo */
510 1, /* GadgetID */
511 NULL /* UserData */
514 int main (int argc, char ** argv)
516 struct Window * win;
517 struct RastPort * rp;
518 struct IntuiMessage * im;
519 struct IOStdReq cioreq;
520 struct InputEvent ievent =
522 NULL,
523 IECLASS_RAWKEY,
524 /* ... */
526 int cont, draw;
527 int prop;
529 RT_Init ();
531 printf ("Welcome to the window demo of AROS\n");
533 GfxBase=(struct GfxBase *)OpenLibrary(GRAPHICSNAME,39);
534 IntuitionBase=(struct IntuitionBase *)OpenLibrary(INTUITIONNAME,39);
536 if (!GfxBase)
538 fprintf (stderr, "Couldn't open %s\n", GRAPHICSNAME);
539 goto end;
542 if (!IntuitionBase)
544 fprintf (stderr, "Couldn't open %s\n", INTUITIONNAME);
545 goto end;
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 :
555 "(NULL)");
557 if (!ConsoleDevice)
559 fprintf (stderr, "Couldn't open console\n");
560 return 10;
563 frame = NewObject (NULL, FRAMEICLASS
564 , IA_Width, GAD_WID
565 , IA_Height, GAD_HEI
566 , TAG_END
569 gadget = NewObject (NULL, FRBUTTONCLASS
570 , GA_Left, BORDER*2+GAD_WID
571 , GA_RelBottom, -(GAD_HEI+BORDER)
572 , GA_Width, GAD_WID
573 , GA_Height, GAD_HEI
574 , GA_Previous, (IPTR)&DemoGadget12
575 , GA_Text, (IPTR)"_Exit"
576 , GA_RelVerify, TRUE
577 , GA_ID, 1
578 , GA_Image, (IPTR)frame
579 , TAG_END
582 win = OpenWindowTags (NULL
583 , WA_Title, (IPTR)"Open a window demo"
584 , WA_Left, 100
585 , WA_Top, 50
586 , WA_Width, 640
587 , WA_Height, 512
588 , WA_DragBar, TRUE
589 , WA_CloseGadget, TRUE
590 , WA_DepthGadget, TRUE
591 , WA_IDCMP, IDCMP_RAWKEY
592 | IDCMP_REFRESHWINDOW
593 | IDCMP_MOUSEBUTTONS
594 | IDCMP_MOUSEMOVE
595 | IDCMP_GADGETDOWN
596 | IDCMP_GADGETUP
597 | IDCMP_CLOSEWINDOW
598 , WA_SimpleRefresh, TRUE
599 , WA_GimmeZeroZero, TRUE
600 , WA_Gadgets, (IPTR)&ExitGadget
601 , TAG_END
603 D(printf("OpenWindow win=%p\n", win));
605 if (!win)
607 fprintf (stderr, "Couldn't open window\n");
608 return 10;
611 rp = win->RPort;
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);
617 if (!gadget)
618 printf ("Warning: Couldn't create gadget\n");
620 if (!frame)
621 printf ("Warning: Couldn't create frame\n");
623 cont = 1;
624 draw = 0;
625 prop = 0;
627 /* Refresh the window contents */
628 Refresh(win->RPort);
630 while (cont)
632 if ((im = (struct IntuiMessage *)GetMsg (win->UserPort)))
634 /* D("Got msg\n"); */
635 switch (im->Class)
637 case IDCMP_CLOSEWINDOW:
638 cont = 0;
639 break;
641 case IDCMP_RAWKEY: {
642 UBYTE buf[10];
643 int len;
644 int t;
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
657 if (len < 0)
659 printf ("\" (buffer too short)");
660 break;
663 for (t=0; t<len; t++)
665 if (buf[t] < 32 || (buf[t] >= 127 && buf[t] < 160))
667 switch (buf[t])
669 case '\n':
670 printf ("\\n");
671 break;
673 case '\t':
674 printf ("\\t");
675 break;
677 case '\b':
678 printf ("\\b");
679 break;
681 case '\r':
682 printf ("\\r");
683 break;
685 case 0x1B:
686 printf ("^[");
687 break;
689 default:
690 printf ("\\x%02x", buf[t]);
691 break;
692 } /* switch */
694 else
695 putc (buf[t], stdout);
697 printf ("\"\n");
699 if (*buf == '\x1b' && len == 1)
701 if (len == 1)
702 cont = 0;
705 break; }
707 case IDCMP_MOUSEBUTTONS:
708 switch (im->Code)
710 case SELECTDOWN:
711 SetAPen (rp, 2);
712 Move (rp, im->MouseX, im->MouseY);
713 draw = 1;
714 break;
716 case SELECTUP:
717 draw = 0;
718 break;
720 case MIDDLEDOWN:
721 SetAPen (rp, 1);
722 Move (rp, im->MouseX, im->MouseY);
723 draw = 1;
724 break;
726 case MIDDLEUP:
727 draw = 0;
728 break;
730 case MENUDOWN:
731 SetAPen (rp, 3);
732 Move (rp, im->MouseX, im->MouseY);
733 draw = 1;
734 break;
736 case MENUUP:
737 draw = 0;
738 break;
742 break;
744 case IDCMP_MOUSEMOVE:
745 if (draw)
746 Draw (rp, im->MouseX, im->MouseY);
748 break;
750 case IDCMP_REFRESHWINDOW:
751 printf ("REFRESHWINDOW\n");
752 BeginRefresh (win);
753 Refresh (rp);
754 EndRefresh (win, TRUE);
755 break;
757 case IDCMP_GADGETDOWN: {
758 struct Gadget * gadget;
759 LONG pot;
761 gadget = (struct Gadget *)im->IAddress;
763 printf ("User pressed gadget %d\n", gadget->GadgetID);
765 switch (gadget->GadgetID)
767 case 10: /* Up */
768 pot = DemoPropInfo3.VertPot - DemoPropInfo3.VertBody;
770 if (pot < 0)
771 pot = 0;
773 NewModifyProp (&DemoGadget7
774 , win
775 , NULL
776 , DemoPropInfo2.Flags
777 , DemoPropInfo2.HorizPot
778 , pot
779 , DemoPropInfo2.HorizBody
780 , DemoPropInfo2.VertBody
783 NewModifyProp (&DemoGadget8
784 , win
785 , NULL
786 , DemoPropInfo3.Flags
787 , DemoPropInfo3.HorizPot
788 , pot
789 , DemoPropInfo3.HorizBody
790 , DemoPropInfo3.VertBody
794 break;
796 case 11: /* Down */
797 pot = DemoPropInfo3.VertPot + DemoPropInfo3.VertBody;
799 if (pot > MAXPOT)
800 pot = MAXPOT;
802 NewModifyProp (&DemoGadget7
803 , win
804 , NULL
805 , DemoPropInfo2.Flags
806 , DemoPropInfo2.HorizPot
807 , pot
808 , DemoPropInfo2.HorizBody
809 , DemoPropInfo2.VertBody
812 NewModifyProp (&DemoGadget8
813 , win
814 , NULL
815 , DemoPropInfo3.Flags
816 , DemoPropInfo3.HorizPot
817 , pot
818 , DemoPropInfo3.HorizBody
819 , DemoPropInfo3.VertBody
823 break;
825 case 12: /* Right */
826 pot = DemoPropInfo1.HorizPot + DemoPropInfo1.HorizBody;
828 if (pot > MAXPOT)
829 pot = MAXPOT;
831 NewModifyProp (&DemoGadget6
832 , win
833 , NULL
834 , DemoPropInfo1.Flags
835 , pot
836 , DemoPropInfo1.VertPot
837 , DemoPropInfo1.HorizBody
838 , DemoPropInfo1.VertBody
841 NewModifyProp (&DemoGadget8
842 , win
843 , NULL
844 , DemoPropInfo3.Flags
845 , pot
846 , DemoPropInfo3.VertPot
847 , DemoPropInfo3.HorizBody
848 , DemoPropInfo3.VertBody
852 break;
854 case 13: /* Left */
855 pot = DemoPropInfo1.HorizPot - DemoPropInfo1.HorizBody;
857 if (pot < 0)
858 pot = 0;
860 NewModifyProp (&DemoGadget6
861 , win
862 , NULL
863 , DemoPropInfo1.Flags
864 , pot
865 , DemoPropInfo1.VertPot
866 , DemoPropInfo1.HorizBody
867 , DemoPropInfo1.VertBody
870 NewModifyProp (&DemoGadget8
871 , win
872 , NULL
873 , DemoPropInfo3.Flags
874 , pot
875 , DemoPropInfo3.VertPot
876 , DemoPropInfo3.HorizBody
877 , DemoPropInfo3.VertBody
881 break;
885 break; }
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)
895 cont = 0;
896 else if (gadget->GadgetID == 2)
898 prop ++;
900 switch (prop)
902 case 0:
903 NewModifyProp (&DemoGadget6, win, NULL,
904 DemoPropInfo1.Flags,
905 0, 0, MAXBODY, MAXBODY, 1);
906 NewModifyProp (&DemoGadget7, win, NULL,
907 DemoPropInfo2.Flags,
908 0, 0, MAXBODY, MAXBODY, 1);
909 NewModifyProp (&DemoGadget8, win, NULL,
910 DemoPropInfo3.Flags,
911 0, 0, MAXBODY, MAXBODY, 1);
912 break;
914 case 1:
915 NewModifyProp (&DemoGadget6, win, NULL,
916 DemoPropInfo1.Flags,
917 0, 0, MAXBODY/2, MAXBODY, 1);
918 NewModifyProp (&DemoGadget7, win, NULL,
919 DemoPropInfo2.Flags,
920 0, 0, MAXBODY, MAXBODY/2, 1);
921 NewModifyProp (&DemoGadget8, win, NULL,
922 DemoPropInfo3.Flags,
923 0, 0, MAXBODY/2, MAXBODY/2, 1);
924 break;
926 case 2:
927 NewModifyProp (&DemoGadget6, win, NULL,
928 DemoPropInfo1.Flags,
929 MAXPOT, 0, MAXBODY/2, MAXBODY, 1);
930 NewModifyProp (&DemoGadget7, win, NULL,
931 DemoPropInfo2.Flags,
932 0, MAXPOT, MAXBODY, MAXBODY/2, 1);
933 NewModifyProp (&DemoGadget8, win, NULL,
934 DemoPropInfo3.Flags,
935 MAXPOT, MAXPOT, MAXBODY/2, MAXBODY/2, 1);
936 break;
938 default:
939 NewModifyProp (&DemoGadget6, win, NULL,
940 DemoPropInfo1.Flags,
941 0, 0, MAXBODY/9, MAXBODY, 1);
942 NewModifyProp (&DemoGadget7, win, NULL,
943 DemoPropInfo2.Flags,
944 0, 0, MAXBODY, MAXBODY/9, 1);
945 NewModifyProp (&DemoGadget8, win, NULL,
946 DemoPropInfo3.Flags,
947 0, 0, MAXBODY/9, MAXBODY/9, 1);
948 prop = -1;
949 break;
954 break; }
956 } /* switch */
958 ReplyMsg ((struct Message *)im);
960 else
962 /* D("Waiting\n"); */
963 Wait (1L << win->UserPort->mp_SigBit);
967 D(bug("CloseWindow (%p)\n", win));
968 CloseWindow (win);
970 end:
971 if (gadget)
972 DisposeObject (gadget);
974 if (frame)
975 DisposeObject (frame);
977 if (GfxBase)
978 CloseLibrary ((struct Library *)GfxBase);
980 if (IntuitionBase)
981 CloseLibrary ((struct Library *)IntuitionBase);
983 if (ConsoleDevice)
984 CloseDevice ((struct IORequest *)&cioreq);
986 RT_Exit ();
988 return 0;