define __KERNEL_STRICT_NAMES to avoid inclusion of kernel types on systems that carry...
[cake.git] / workbench / demos / demowin.c
blob45e1156cf3c44a9f1b3c2590d6b133fd55009b28
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[] = "$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 = 340;
69 y = 150;
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, 350);
144 Text (rp, "Press \"Complement\" to flip PropGadgets", 39);
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 ? ConsoleDevice->dd_Library.lib_Node.ln_Name : "(NULL)");
555 if (!ConsoleDevice)
557 fprintf (stderr, "Couldn't open console\n");
558 return 10;
561 frame = NewObject (NULL, FRAMEICLASS
562 , IA_Width, GAD_WID
563 , IA_Height, GAD_HEI
564 , TAG_END
567 gadget = NewObject (NULL, FRBUTTONCLASS
568 , GA_Left, BORDER*2+GAD_WID
569 , GA_RelBottom, -(GAD_HEI+BORDER)
570 , GA_Width, GAD_WID
571 , GA_Height, GAD_HEI
572 , GA_Previous, (IPTR)&DemoGadget12
573 , GA_Text, (IPTR)"_Exit"
574 , GA_RelVerify, TRUE
575 , GA_ID, 1
576 , GA_Image, (IPTR)frame
577 , TAG_END
580 win = OpenWindowTags (NULL
581 , WA_Title, (IPTR)"Open a window demo"
582 , WA_Left, 100
583 , WA_Top, 50
584 , WA_Width, 640
585 , WA_Height, 512
586 , WA_DragBar, TRUE
587 , WA_CloseGadget, TRUE
588 , WA_DepthGadget, TRUE
589 , WA_IDCMP, IDCMP_RAWKEY
590 | IDCMP_REFRESHWINDOW
591 | IDCMP_MOUSEBUTTONS
592 | IDCMP_MOUSEMOVE
593 | IDCMP_GADGETDOWN
594 | IDCMP_GADGETUP
595 | IDCMP_CLOSEWINDOW
596 , WA_SimpleRefresh, TRUE
597 , WA_Gadgets, (IPTR)&ExitGadget
598 , TAG_END
600 D(printf("OpenWindow win=%p\n", win));
602 if (!win)
604 fprintf (stderr, "Couldn't open window\n");
605 return 10;
608 rp = win->RPort;
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);
614 if (!gadget)
615 printf ("Warning: Couldn't create gadget\n");
617 if (!frame)
618 printf ("Warning: Couldn't create frame\n");
620 cont = 1;
621 draw = 0;
622 prop = 0;
624 /* Refresh the window contents */
625 Refresh(win->RPort);
627 while (cont)
629 if ((im = (struct IntuiMessage *)GetMsg (win->UserPort)))
631 /* D("Got msg\n"); */
632 switch (im->Class)
634 case IDCMP_CLOSEWINDOW:
635 cont = 0;
636 break;
638 case IDCMP_RAWKEY: {
639 UBYTE buf[10];
640 int len;
641 int t;
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 , (LONG)im->Qualifier
654 if (len < 0)
656 printf ("\" (buffer too short)");
657 break;
660 for (t=0; t<len; t++)
662 if (buf[t] < 32 || (buf[t] >= 127 && buf[t] < 160))
664 switch (buf[t])
666 case '\n':
667 printf ("\\n");
668 break;
670 case '\t':
671 printf ("\\t");
672 break;
674 case '\b':
675 printf ("\\b");
676 break;
678 case '\r':
679 printf ("\\r");
680 break;
682 case 0x1B:
683 printf ("^[");
684 break;
686 default:
687 printf ("\\x%02x", buf[t]);
688 break;
689 } /* switch */
691 else
692 putc (buf[t], stdout);
694 printf ("\"\n");
696 if (*buf == '\x1b' && len == 1)
698 if (len == 1)
699 cont = 0;
702 break; }
704 case IDCMP_MOUSEBUTTONS:
705 switch (im->Code)
707 case SELECTDOWN:
708 SetAPen (rp, 2);
709 Move (rp, im->MouseX, im->MouseY);
710 draw = 1;
711 break;
713 case SELECTUP:
714 draw = 0;
715 break;
717 case MIDDLEDOWN:
718 SetAPen (rp, 1);
719 Move (rp, im->MouseX, im->MouseY);
720 draw = 1;
721 break;
723 case MIDDLEUP:
724 draw = 0;
725 break;
727 case MENUDOWN:
728 SetAPen (rp, 3);
729 Move (rp, im->MouseX, im->MouseY);
730 draw = 1;
731 break;
733 case MENUUP:
734 draw = 0;
735 break;
739 break;
741 case IDCMP_MOUSEMOVE:
742 if (draw)
743 Draw (rp, im->MouseX, im->MouseY);
745 break;
747 case IDCMP_REFRESHWINDOW:
748 printf ("REFRESHWINDOW\n");
749 BeginRefresh (win);
750 Refresh (rp);
751 EndRefresh (win, TRUE);
752 break;
754 case IDCMP_GADGETDOWN: {
755 struct Gadget * gadget;
756 LONG pot;
758 gadget = (struct Gadget *)im->IAddress;
760 printf ("User pressed gadget %d\n", gadget->GadgetID);
762 switch (gadget->GadgetID)
764 case 10: /* Up */
765 pot = DemoPropInfo3.VertPot - DemoPropInfo3.VertBody;
767 if (pot < 0)
768 pot = 0;
770 NewModifyProp (&DemoGadget7
771 , win
772 , NULL
773 , DemoPropInfo2.Flags
774 , DemoPropInfo2.HorizPot
775 , pot
776 , DemoPropInfo2.HorizBody
777 , DemoPropInfo2.VertBody
780 NewModifyProp (&DemoGadget8
781 , win
782 , NULL
783 , DemoPropInfo3.Flags
784 , DemoPropInfo3.HorizPot
785 , pot
786 , DemoPropInfo3.HorizBody
787 , DemoPropInfo3.VertBody
791 break;
793 case 11: /* Down */
794 pot = DemoPropInfo3.VertPot + DemoPropInfo3.VertBody;
796 if (pot > MAXPOT)
797 pot = MAXPOT;
799 NewModifyProp (&DemoGadget7
800 , win
801 , NULL
802 , DemoPropInfo2.Flags
803 , DemoPropInfo2.HorizPot
804 , pot
805 , DemoPropInfo2.HorizBody
806 , DemoPropInfo2.VertBody
809 NewModifyProp (&DemoGadget8
810 , win
811 , NULL
812 , DemoPropInfo3.Flags
813 , DemoPropInfo3.HorizPot
814 , pot
815 , DemoPropInfo3.HorizBody
816 , DemoPropInfo3.VertBody
820 break;
822 case 12: /* Right */
823 pot = DemoPropInfo1.HorizPot + DemoPropInfo1.HorizBody;
825 if (pot > MAXPOT)
826 pot = MAXPOT;
828 NewModifyProp (&DemoGadget6
829 , win
830 , NULL
831 , DemoPropInfo1.Flags
832 , pot
833 , DemoPropInfo1.VertPot
834 , DemoPropInfo1.HorizBody
835 , DemoPropInfo1.VertBody
838 NewModifyProp (&DemoGadget8
839 , win
840 , NULL
841 , DemoPropInfo3.Flags
842 , pot
843 , DemoPropInfo3.VertPot
844 , DemoPropInfo3.HorizBody
845 , DemoPropInfo3.VertBody
849 break;
851 case 13: /* Left */
852 pot = DemoPropInfo1.HorizPot - DemoPropInfo1.HorizBody;
854 if (pot < 0)
855 pot = 0;
857 NewModifyProp (&DemoGadget6
858 , win
859 , NULL
860 , DemoPropInfo1.Flags
861 , pot
862 , DemoPropInfo1.VertPot
863 , DemoPropInfo1.HorizBody
864 , DemoPropInfo1.VertBody
867 NewModifyProp (&DemoGadget8
868 , win
869 , NULL
870 , DemoPropInfo3.Flags
871 , pot
872 , DemoPropInfo3.VertPot
873 , DemoPropInfo3.HorizBody
874 , DemoPropInfo3.VertBody
878 break;
882 break; }
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)
892 cont = 0;
893 else if (gadget->GadgetID == 2)
895 prop ++;
897 switch (prop)
899 case 0:
900 NewModifyProp (&DemoGadget6, win, NULL,
901 DemoPropInfo1.Flags,
902 0, 0, MAXBODY, MAXBODY, 1);
903 NewModifyProp (&DemoGadget7, win, NULL,
904 DemoPropInfo2.Flags,
905 0, 0, MAXBODY, MAXBODY, 1);
906 NewModifyProp (&DemoGadget8, win, NULL,
907 DemoPropInfo3.Flags,
908 0, 0, MAXBODY, MAXBODY, 1);
909 break;
911 case 1:
912 NewModifyProp (&DemoGadget6, win, NULL,
913 DemoPropInfo1.Flags,
914 0, 0, MAXBODY/2, MAXBODY, 1);
915 NewModifyProp (&DemoGadget7, win, NULL,
916 DemoPropInfo2.Flags,
917 0, 0, MAXBODY, MAXBODY/2, 1);
918 NewModifyProp (&DemoGadget8, win, NULL,
919 DemoPropInfo3.Flags,
920 0, 0, MAXBODY/2, MAXBODY/2, 1);
921 break;
923 case 2:
924 NewModifyProp (&DemoGadget6, win, NULL,
925 DemoPropInfo1.Flags,
926 MAXPOT, 0, MAXBODY/2, MAXBODY, 1);
927 NewModifyProp (&DemoGadget7, win, NULL,
928 DemoPropInfo2.Flags,
929 0, MAXPOT, MAXBODY, MAXBODY/2, 1);
930 NewModifyProp (&DemoGadget8, win, NULL,
931 DemoPropInfo3.Flags,
932 MAXPOT, MAXPOT, MAXBODY/2, MAXBODY/2, 1);
933 break;
935 default:
936 NewModifyProp (&DemoGadget6, win, NULL,
937 DemoPropInfo1.Flags,
938 0, 0, MAXBODY/9, MAXBODY, 1);
939 NewModifyProp (&DemoGadget7, win, NULL,
940 DemoPropInfo2.Flags,
941 0, 0, MAXBODY, MAXBODY/9, 1);
942 NewModifyProp (&DemoGadget8, win, NULL,
943 DemoPropInfo3.Flags,
944 0, 0, MAXBODY/9, MAXBODY/9, 1);
945 prop = -1;
946 break;
951 break; }
953 } /* switch */
955 ReplyMsg ((struct Message *)im);
957 else
959 /* D("Waiting\n"); */
960 Wait (1L << win->UserPort->mp_SigBit);
964 D(bug("CloseWindow (%p)\n", win));
965 CloseWindow (win);
967 end:
968 if (gadget)
969 DisposeObject (gadget);
971 if (frame)
972 DisposeObject (frame);
974 if (GfxBase)
975 CloseLibrary ((struct Library *)GfxBase);
977 if (IntuitionBase)
978 CloseLibrary ((struct Library *)IntuitionBase);
980 if (ConsoleDevice)
981 CloseDevice ((struct IORequest *)&cioreq);
983 RT_Exit ();
985 return 0;