home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / workbench / demos / demowin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  19.7 KB  |  961 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $VER: demowin.c 1.16 (2.10.96)
  4.  
  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
  10.  
  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/aros.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.  
  35. #if 0
  36. #   define D(x)    x
  37. #else
  38. #   define D(x)     /* eps */
  39. #endif
  40. #define bug    kprintf
  41.  
  42. struct Library *ConsoleDevice;
  43. struct IntuitionBase *IntuitionBase;
  44. struct GfxBase *GfxBase;
  45. Object * frame, * gadget;
  46.  
  47. void Refresh (struct RastPort * rp)
  48. {
  49.     int len;
  50.     int t, tend, pen;
  51.     int x, y;
  52.     WORD xy[8];
  53.  
  54.     SetAPen (rp, 1);
  55.     SetDrMd (rp, JAM2);
  56.  
  57.     Move (rp, 0, 0);
  58.     Draw (rp, 320, 150);
  59.  
  60.     Move (rp, 640, 0);
  61.     Draw (rp, 0, 300);
  62.  
  63.     SetDrPt (rp, 0xF0F0);
  64.     len = 150;
  65.     x = 340;
  66.     y = 150;
  67.     xy[0] = x; xy[1] = y;
  68.     xy[2] = x; xy[3] = y+len;
  69.     xy[4] = x+len; xy[5] = y+len;
  70.     xy[6] = x; xy[7] = y;
  71.     PolyDraw (rp, 4, xy);
  72.  
  73.     SetDrPt (rp, 0xAAAA);
  74.     x += 10;
  75.     y += 20;
  76.     len -= 30;
  77.     xy[0] = x; xy[1] = y;
  78.     xy[2] = x; xy[3] = y+len;
  79.     xy[4] = x+len; xy[5] = y+len;
  80.     xy[6] = x; xy[7] = y;
  81.     PolyDraw (rp, 4, xy);
  82.  
  83.     SetDrPt (rp, 0x3333);
  84.     x += 10;
  85.     y += 20;
  86.     len -= 30;
  87.     xy[0] = x; xy[1] = y;
  88.     xy[2] = x; xy[3] = y+len;
  89.     xy[4] = x+len; xy[5] = y+len;
  90.     xy[6] = x; xy[7] = y;
  91.     PolyDraw (rp, 4, xy);
  92.  
  93.     SetDrPt (rp, 0xF731);
  94.     x += 10;
  95.     y += 20;
  96.     len -= 30;
  97.     xy[0] = x; xy[1] = y;
  98.     xy[2] = x; xy[3] = y+len;
  99.     xy[4] = x+len; xy[5] = y+len;
  100.     xy[6] = x; xy[7] = y;
  101.     PolyDraw (rp, 4, xy);
  102.  
  103.     SetDrPt (rp, ~0);
  104.  
  105.     Move (rp, 300, 40);
  106.     Text (rp, "Hello World.", 12);
  107.  
  108.     SetAPen (rp, 3);
  109.     RectFill (rp, 90, 0, 120, 30);
  110.     SetAPen (rp, 0);
  111.     RectFill (rp, 100, 10, 110, 20);
  112.  
  113.     SetAPen (rp, 1);
  114.     RectFill (rp, 150, 10, 160, 20);
  115.  
  116.     SetAPen (rp, 2);
  117.     RectFill (rp, 200, 10, 210, 20);
  118.  
  119.     SetAPen (rp, 3);
  120.     RectFill (rp, 250, 10, 260, 20);
  121.  
  122.     len = TextLength (rp, "Hello World.", 12);
  123.  
  124.     SetAPen (rp, 2);
  125.     RectFill (rp, 299, 59, 300+len, 60+rp->Font->tf_YSize);
  126.  
  127.     SetAPen (rp, 1);
  128.     Move (rp, 300, 60 + rp->Font->tf_Baseline);
  129.     Text (rp, "Hello World.", 12);
  130.  
  131.     SetDrMd (rp, JAM1);
  132.     SetAPen (rp, 1);
  133.     Move (rp, 301, 101);
  134.     Text (rp, "Hello World.", 12);
  135.     SetAPen (rp, 2);
  136.     Move (rp, 300, 100);
  137.     Text (rp, "Hello World.", 12);
  138.  
  139.     Move (rp, 20, 350);
  140.     Text (rp, "Press \"Complement\" to flip PropGadgets", 39);
  141.  
  142.     tend = 10;
  143.     t = 0;
  144.  
  145.     for (pen=1; pen<16; pen++)
  146.     {
  147.     SetAPen (rp, pen);
  148.  
  149.     for ( ; t<tend; t++)
  150.     {
  151.         DrawEllipse (rp, 160, 150, t, t>>1);
  152.         DrawEllipse (rp, 160, 151, t, t>>1);
  153.     }
  154.  
  155.     tend += 10;
  156.     }
  157.  
  158.     SetAPen (rp, 0);
  159.     RectFill (rp, 450, 140, 549, 239);
  160.  
  161.     for (y=0; y<20; y++)
  162.     {
  163.     for (x=0; x<100; x++)
  164.     {
  165.         pen = (LONG)ReadPixel (rp, x+100,y+100);
  166.         SetAPen (rp, pen);
  167.         WritePixel (rp, x+450, y+140);
  168.     }
  169.     }
  170. }
  171.  
  172. #define GAD_WID     100
  173. #define GAD_HEI     30
  174. #define BORDER        20
  175.  
  176. WORD BorderData[6*2*2] =
  177. {
  178.     0, GAD_HEI-1, /* Top (lighter) edge */
  179.     1, GAD_HEI-2,
  180.     1, 1,
  181.     GAD_WID-2, 1,
  182.     GAD_WID-1, 0,
  183.     0, 0,
  184.  
  185.     0, -(GAD_HEI-2), /* Bottom (darker) edge */
  186.     -1, -(GAD_HEI-3),
  187.     -1, -1,
  188.     -(GAD_WID-3), -1,
  189.     -(GAD_WID-2), 0,
  190.     -1, 0,
  191. };
  192. struct Border
  193. DemoBottomBorder =
  194. {
  195.     GAD_WID-1, GAD_HEI-1,
  196.     1, 2,
  197.     JAM1,
  198.     6,
  199.     &BorderData[6*2],
  200.     NULL
  201. },
  202. DemoTopBorder =
  203. {
  204.     0, 0,
  205.     2, 1,
  206.     JAM1,
  207.     6,
  208.     &BorderData[0],
  209.     &DemoBottomBorder
  210. };
  211. struct Border DemoIBottomBorder =
  212. {
  213.     GAD_WID-1, GAD_HEI-1,
  214.     2, 1,
  215.     JAM1,
  216.     6,
  217.     &BorderData[6*2],
  218.     NULL
  219. },
  220. DemoITopBorder =
  221. {
  222.     0, 0,
  223.     1, 2,
  224.     JAM1,
  225.     6,
  226.     &BorderData[0],
  227.     &DemoIBottomBorder
  228. };
  229.  
  230. struct PropInfo
  231. DemoPropInfo1 =
  232. {
  233.     AUTOKNOB | FREEHORIZ | PROPNEWLOOK,
  234.     0, 0,
  235.     MAXBODY, MAXBODY,
  236.     0,0,0,0,0,0
  237. },
  238. DemoPropInfo2 =
  239. {
  240.     AUTOKNOB | FREEVERT | PROPNEWLOOK,
  241.     0, 0,
  242.     MAXBODY, MAXBODY,
  243.     0,0,0,0,0,0
  244. },
  245. DemoPropInfo3 =
  246. {
  247.     AUTOKNOB | FREEHORIZ | FREEVERT | PROPNEWLOOK,
  248.     0, 0,
  249.     MAXBODY, MAXBODY,
  250.     0,0,0,0,0,0
  251. };
  252.  
  253. struct IntuiText
  254. DemoIText =
  255. {
  256.     1, 2, /* Pens */
  257.     JAM1, /* Drawmode */
  258.     10, 10, /* Left, Top */
  259.     NULL, /* TextAttr */
  260.     "None", /* Text */
  261.     NULL /* Next */
  262. };
  263.  
  264. #include "images/ArrowUp0.h"
  265. #include "images/ArrowUp1.h"
  266. #include "images/ArrowDown0.h"
  267. #include "images/ArrowDown1.h"
  268. #include "images/ArrowLeft0.h"
  269. #include "images/ArrowLeft1.h"
  270. #include "images/ArrowRight0.h"
  271. #include "images/ArrowRight1.h"
  272. #include "images/ImageButton0.h"
  273. #include "images/ImageButton1.h"
  274.  
  275. struct Gadget
  276. DemoGadget12 =
  277. {
  278.     NULL, /* &DemoGadget, / * NextGadget */
  279.     -(BORDER+2*ARROWLEFT1_WIDTH), -((GAD_HEI+BORDER)*3),
  280.     ARROWLEFT1_WIDTH, ARROWLEFT1_HEIGHT, /* hit box */
  281.     GFLG_GADGHIMAGE
  282.     | GFLG_RELRIGHT
  283.     | GFLG_RELBOTTOM
  284.     | GFLG_GADGIMAGE
  285.     , /* Flags */
  286.     GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
  287.     GTYP_BOOLGADGET, /* Type */
  288.     &ArrowLeft0Image, &ArrowLeft1Image, /* Render */
  289.     NULL, /* Text */
  290.     0L, NULL, /* MutualExcl, SpecialInfo */
  291.     13, /* GadgetID */
  292.     NULL /* UserData */
  293. },
  294. DemoGadget11 =
  295. {
  296.     &DemoGadget12, /* NextGadget */
  297.     -(BORDER+1*ARROWLEFT1_WIDTH), -((GAD_HEI+BORDER)*3),
  298.     ARROWLEFT1_WIDTH, ARROWLEFT1_HEIGHT, /* hit box */
  299.     GFLG_GADGHIMAGE
  300.     | GFLG_RELRIGHT
  301.     | GFLG_RELBOTTOM
  302.     | GFLG_GADGIMAGE
  303.     , /* Flags */
  304.     GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
  305.     GTYP_BOOLGADGET, /* Type */
  306.     &ArrowRight0Image, &ArrowRight1Image, /* Render */
  307.     NULL, /* Text */
  308.     0L, NULL, /* MutualExcl, SpecialInfo */
  309.     12, /* GadgetID */
  310.     NULL /* UserData */
  311. },
  312. DemoGadget10 =
  313. {
  314.     &DemoGadget11, /* NextGadget */
  315.     -(BORDER+ARROWDOWN1_WIDTH), -((GAD_HEI+BORDER)*3+ARROWLEFT1_HEIGHT+0*ARROWDOWN1_HEIGHT-5),
  316.     ARROWDOWN1_WIDTH, ARROWDOWN1_HEIGHT, /* hit box */
  317.     GFLG_GADGHIMAGE
  318.     | GFLG_RELRIGHT
  319.     | GFLG_RELBOTTOM
  320.     | GFLG_GADGIMAGE
  321.     , /* Flags */
  322.     GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
  323.     GTYP_BOOLGADGET, /* Type */
  324.     &ArrowDown0Image, &ArrowDown1Image, /* Render */
  325.     NULL, /* Text */
  326.     0L, NULL, /* MutualExcl, SpecialInfo */
  327.     11, /* GadgetID */
  328.     NULL /* UserData */
  329. },
  330. DemoGadget9 =
  331. {
  332.     &DemoGadget10, /* NextGadget */
  333.     -(BORDER+ARROWDOWN1_WIDTH), -((GAD_HEI+BORDER)*3+ARROWLEFT1_HEIGHT+1*ARROWDOWN1_HEIGHT-5),
  334.     ARROWDOWN1_WIDTH, ARROWDOWN1_HEIGHT, /* hit box */
  335.     GFLG_GADGHIMAGE
  336.     | GFLG_RELRIGHT
  337.     | GFLG_RELBOTTOM
  338.     | GFLG_GADGIMAGE
  339.     , /* Flags */
  340.     GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
  341.     GTYP_BOOLGADGET, /* Type */
  342.     &ArrowUp0Image, &ArrowUp1Image, /* Render */
  343.     NULL, /* Text */
  344.     0L, NULL, /* MutualExcl, SpecialInfo */
  345.     10, /* GadgetID */
  346.     NULL /* UserData */
  347. },
  348. DemoGadget8 =
  349. {
  350.     &DemoGadget9, /* NextGadget */
  351.     -(BORDER+ARROWDOWN1_WIDTH+GAD_WID), -((GAD_HEI+BORDER)*3+GAD_WID),
  352.     GAD_WID, GAD_WID, /* hit box */
  353.     GFLG_GADGHIMAGE
  354.     | GFLG_RELRIGHT
  355.     | GFLG_RELBOTTOM
  356.     , /* Flags */
  357.     GACT_IMMEDIATE
  358.     | GACT_RELVERIFY
  359.     | GACT_TOGGLESELECT
  360.     , /* Activation */
  361.     GTYP_PROPGADGET, /* Type */
  362.     NULL, NULL, /* Render */
  363.     NULL, /* Text */
  364.     0L, (APTR)&DemoPropInfo3, /* MutualExcl, SpecialInfo */
  365.     9, /* GadgetID */
  366.     NULL /* UserData */
  367. },
  368. DemoGadget7 =
  369. {
  370.     &DemoGadget8, /* NextGadget */
  371.     -(BORDER+ARROWDOWN1_WIDTH), BORDER,
  372.     ARROWDOWN1_WIDTH, -(GAD_HEI*3+BORDER*4+2*ARROWDOWN1_HEIGHT), /* hit box */
  373.     GFLG_GADGHIMAGE
  374.     | GFLG_RELRIGHT
  375.     | GFLG_RELHEIGHT
  376.     , /* Flags */
  377.     GACT_IMMEDIATE
  378.     | GACT_RELVERIFY
  379.     | GACT_TOGGLESELECT
  380.     , /* Activation */
  381.     GTYP_PROPGADGET, /* Type */
  382.     NULL, NULL, /* Render */
  383.     NULL, /* Text */
  384.     0L, (APTR)&DemoPropInfo2, /* MutualExcl, SpecialInfo */
  385.     8, /* GadgetID */
  386.     NULL /* UserData */
  387. },
  388. DemoGadget6 =
  389. {
  390.     &DemoGadget7, /* NextGadget */
  391.     BORDER, -((GAD_HEI+BORDER)*3),
  392.     -(2*BORDER+2*ARROWLEFT0_WIDTH), ARROWLEFT0_HEIGHT, /* hit box */
  393.     GFLG_GADGHIMAGE
  394.     | GFLG_RELBOTTOM
  395.     | GFLG_RELWIDTH
  396.     , /* Flags */
  397.     GACT_IMMEDIATE
  398.     | GACT_RELVERIFY
  399.     | GACT_TOGGLESELECT
  400.     , /* Activation */
  401.     GTYP_PROPGADGET, /* Type */
  402.     NULL, NULL, /* Render */
  403.     NULL, /* Text */
  404.     0L, (APTR)&DemoPropInfo1, /* MutualExcl, SpecialInfo */
  405.     7, /* GadgetID */
  406.     NULL /* UserData */
  407. },
  408. DemoGadget5 =
  409. {
  410.     &DemoGadget6, /* NextGadget */
  411.     BORDER+(GAD_WID+BORDER)*4, -((GAD_HEI+BORDER)*2), GAD_WID, GAD_HEI, /* hit box */
  412.     GFLG_GADGHIMAGE
  413.     | GFLG_LABELSTRING
  414.     | GFLG_RELBOTTOM
  415.     , /* Flags */
  416.     GACT_IMMEDIATE
  417.     | GACT_RELVERIFY
  418.     | GACT_TOGGLESELECT
  419.     , /* Activation */
  420.     GTYP_BOOLGADGET, /* Type */
  421.     &DemoTopBorder, &DemoITopBorder, /* Render */
  422.     (struct IntuiText *)"_Toggle", /* Text */
  423.     0L, NULL, /* MutualExcl, SpecialInfo */
  424.     6, /* GadgetID */
  425.     NULL /* UserData */
  426. },
  427. DemoGadget4 =
  428. {
  429.     &DemoGadget5, /* NextGadget */
  430.     BORDER+(GAD_WID+BORDER)*3, -((GAD_HEI+BORDER)*2), GAD_WID, GAD_HEI, /* hit box */
  431.     GFLG_GADGHNONE
  432.     | GFLG_LABELITEXT
  433.     | GFLG_RELBOTTOM
  434.     , /* Flags */
  435.     GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
  436.     GTYP_BOOLGADGET, /* Type */
  437.     &DemoTopBorder, NULL, /* Render */
  438.     &DemoIText, /* Text */
  439.     0L, NULL, /* MutualExcl, SpecialInfo */
  440.     5, /* GadgetID */
  441.     NULL /* UserData */
  442. },
  443. DemoGadget3 =
  444. {
  445.     &DemoGadget4, /* NextGadget */
  446.     BORDER+(GAD_WID+BORDER)*2, -((GAD_HEI+BORDER)*2),
  447.     IMAGEBUTTON0_WIDTH, IMAGEBUTTON0_HEIGHT, /* hit box */
  448.     GFLG_GADGHIMAGE
  449.     | GFLG_LABELSTRING
  450.     | GFLG_RELBOTTOM
  451.     | GFLG_GADGIMAGE
  452.     , /* Flags */
  453.     GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
  454.     GTYP_BOOLGADGET, /* Type */
  455.     &ImageButton0Image, &ImageButton1Image, /* Render */
  456.     (struct IntuiText *)"_Image", /* Text */
  457.     0L, NULL, /* MutualExcl, SpecialInfo */
  458.     4, /* GadgetID */
  459.     NULL /* UserData */
  460. },
  461. DemoGadget2 =
  462. {
  463.     &DemoGadget3, /* NextGadget */
  464.     BORDER+(GAD_WID+BORDER)*1, -((GAD_HEI+BORDER)*2), GAD_WID, GAD_HEI, /* hit box */
  465.     GFLG_GADGHBOX
  466.     | GFLG_LABELSTRING
  467.     | GFLG_RELBOTTOM
  468.     , /* Flags */
  469.     GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
  470.     GTYP_BOOLGADGET, /* Type */
  471.     &DemoTopBorder, NULL, /* Render */
  472.     (struct IntuiText *)"_Box", /* Text */
  473.     0L, NULL, /* MutualExcl, SpecialInfo */
  474.     3, /* GadgetID */
  475.     NULL /* UserData */
  476. },
  477. DemoGadget1 =
  478. {
  479.     &DemoGadget2, /* NextGadget */
  480.     BORDER+(GAD_WID+BORDER)*0, -((GAD_HEI+BORDER)*2), GAD_WID, GAD_HEI, /* hit box */
  481.     GFLG_GADGHCOMP
  482.     | GFLG_LABELSTRING
  483.     | GFLG_RELBOTTOM
  484.     , /* Flags */
  485.     GACT_IMMEDIATE | GACT_RELVERIFY, /* Activation */
  486.     GTYP_BOOLGADGET, /* Type */
  487.     &DemoTopBorder, NULL, /* Render */
  488.     (struct IntuiText *)"_Complement", /* Text */
  489.     0L, NULL, /* MutualExcl, SpecialInfo */
  490.     2, /* GadgetID */
  491.     NULL /* UserData */
  492. },
  493. ExitGadget =
  494. {
  495.     &DemoGadget1, /* NextGadget */
  496.     BORDER, -(GAD_HEI+BORDER), GAD_WID, GAD_HEI, /* hit box */
  497.     GFLG_GADGHIMAGE
  498.     | GFLG_LABELSTRING
  499.     | GFLG_RELBOTTOM
  500.     , /* Flags */
  501.     GACT_RELVERIFY, /* Activation */
  502.     GTYP_BOOLGADGET, /* Type */
  503.     &DemoTopBorder, &DemoITopBorder, /* Render */
  504.     (struct IntuiText *)"E_xit", /* Text */
  505.     0L, NULL, /* MutualExcl, SpecialInfo */
  506.     1, /* GadgetID */
  507.     NULL /* UserData */
  508. };
  509.  
  510. int main (int argc, char ** argv)
  511. {
  512.     struct Window * win;
  513.     struct RastPort * rp;
  514.     struct IntuiMessage * im;
  515.     struct IOStdReq cioreq;
  516.     struct InputEvent ievent =
  517.     {
  518.     NULL,
  519.     IECLASS_RAWKEY,
  520.     /* ... */
  521.     };
  522.     int cont, draw;
  523.     int prop;
  524.  
  525.     printf ("Welcome to the window demo of AROS\n");
  526.  
  527.     GfxBase=(struct GfxBase *)OpenLibrary(GRAPHICSNAME,39);
  528.     IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",39);
  529.  
  530.     if (!GfxBase)
  531.     {
  532.     fprintf (stderr, "Couldn't open %s\n", GRAPHICSNAME);
  533.     goto end;
  534.     }
  535.  
  536.     if (!IntuitionBase)
  537.     {
  538.     fprintf (stderr, "Couldn't open intuition.library\n");
  539.     goto end;
  540.     }
  541.  
  542.     OpenDevice ("console.device", -1, (struct IORequest *)&cioreq, 0);
  543.     ConsoleDevice = (struct Library *)cioreq.io_Device;
  544.     /* printf ("Opening console.device=%p\n", ConsoleDevice); */
  545.  
  546.     if (!ConsoleDevice)
  547.     {
  548.     fprintf (stderr, "Couldn't open console\n");
  549.     return 10;
  550.     }
  551.  
  552.     frame = NewObject (NULL, FRAMEICLASS
  553.     , IA_Width,  GAD_WID
  554.     , IA_Height, GAD_HEI
  555.     , TAG_END
  556.     );
  557.  
  558.     gadget = NewObject (NULL, BUTTONGCLASS
  559.     , GA_Left,    BORDER*2+GAD_WID
  560.     , GA_RelBottom, -(GAD_HEI+BORDER)
  561.     , GA_Width,    GAD_WID
  562.     , GA_Height,    GAD_HEI
  563.     , GA_Previous,    &DemoGadget12
  564.     , GA_Text,    "_Exit"
  565.     , GA_RelVerify, TRUE
  566.     , GA_ID,    1
  567.     , GA_Image,    frame
  568.     , TAG_END
  569.     );
  570.  
  571.     win = OpenWindowTags (NULL
  572.     , WA_Title,        "Open a window demo"
  573.     , WA_Left,        100
  574.     , WA_Top,        100
  575.     , WA_Width,        640
  576.     , WA_Height,        512
  577.     , WA_IDCMP,        IDCMP_RAWKEY
  578.                 | IDCMP_REFRESHWINDOW
  579.                 | IDCMP_MOUSEBUTTONS
  580.                 | IDCMP_MOUSEMOVE
  581.                 | IDCMP_GADGETDOWN
  582.                 | IDCMP_GADGETUP
  583.     , WA_SimpleRefresh, TRUE
  584.     , WA_Gadgets,        &ExitGadget
  585.     , TAG_END
  586.     );
  587.     D(printf("OpenWindow win=%p\n", win));
  588.  
  589.     if (!win)
  590.     {
  591.     fprintf (stderr, "Couldn't open window\n");
  592.     return 10;
  593.     }
  594.  
  595.     rp = win->RPort;
  596.  
  597.     DemoIText.LeftEdge = GAD_WID/2 - rp->Font->tf_XSize*2;
  598.     DemoIText.TopEdge = GAD_HEI/2 - rp->Font->tf_YSize/2 + rp->Font->tf_Baseline;
  599.  
  600.     if (!gadget)
  601.     printf ("Warning: Couldn't create gadget\n");
  602.  
  603.     if (!frame)
  604.     printf ("Warning: Couldn't create frame\n");
  605.  
  606.     cont = 1;
  607.     draw = 0;
  608.     prop = 0;
  609.  
  610.     while (cont)
  611.     {
  612.     if ((im = (struct IntuiMessage *)GetMsg (win->UserPort)))
  613.     {
  614.         /* D("Got msg\n"); */
  615.         switch (im->Class)
  616.         {
  617.         case IDCMP_RAWKEY: {
  618.         UBYTE buf[10];
  619.         int   len;
  620.         int   t;
  621.  
  622.         ievent.ie_Code        = im->Code;
  623.         ievent.ie_Qualifier = im->Qualifier;
  624.  
  625.         len = RawKeyConvert (&ievent, buf, sizeof (buf), NULL);
  626.  
  627.         printf ("Key %s %3ld + Qual %08lx=\""
  628.             , (im->Code & 0x8000) ? "up  " : "down"
  629.             , (LONG)(im->Code & 0xFF)
  630.             , (LONG)im->Qualifier
  631.         );
  632.  
  633.         if (len < 0)
  634.         {
  635.             printf ("\" (buffer too short)");
  636.             break;
  637.         }
  638.  
  639.         for (t=0; t<len; t++)
  640.         {
  641.             if (buf[t] < 32 || (buf[t] >= 127 && buf[t] < 160))
  642.             {
  643.             switch (buf[t])
  644.             {
  645.             case '\n':
  646.                 printf ("\\n");
  647.                 break;
  648.  
  649.             case '\t':
  650.                 printf ("\\t");
  651.                 break;
  652.  
  653.             case '\b':
  654.                 printf ("\\b");
  655.                 break;
  656.  
  657.             case '\r':
  658.                 printf ("\\r");
  659.                 break;
  660.  
  661.             case 0x1B:
  662.                 printf ("^[");
  663.                 break;
  664.  
  665.             default:
  666.                 printf ("\\x%02x", buf[t]);
  667.                 break;
  668.             } /* switch */
  669.             }
  670.             else
  671.             putc (buf[t], stdout);
  672.         }
  673.         printf ("\"\n");
  674.  
  675.         if (*buf == '\x1b' && len == 1)
  676.         {
  677.             if (len == 1)
  678.             cont = 0;
  679.         }
  680.  
  681.         break; }
  682.  
  683.         case IDCMP_MOUSEBUTTONS:
  684.         switch (im->Code)
  685.         {
  686.         case SELECTDOWN:
  687.             SetAPen (rp, 2);
  688.             Move (rp, im->MouseX, im->MouseY);
  689.             draw = 1;
  690.             break;
  691.  
  692.         case SELECTUP:
  693.             draw = 0;
  694.             break;
  695.  
  696.         case MIDDLEDOWN:
  697.             SetAPen (rp, 1);
  698.             Move (rp, im->MouseX, im->MouseY);
  699.             draw = 1;
  700.             break;
  701.  
  702.         case MIDDLEUP:
  703.             draw = 0;
  704.             break;
  705.  
  706.         case MENUDOWN:
  707.             SetAPen (rp, 3);
  708.             Move (rp, im->MouseX, im->MouseY);
  709.             draw = 1;
  710.             break;
  711.  
  712.         case MENUUP:
  713.             draw = 0;
  714.             break;
  715.  
  716.         }
  717.  
  718.         break;
  719.  
  720.         case IDCMP_MOUSEMOVE:
  721.         if (draw)
  722.             Draw (rp, im->MouseX, im->MouseY);
  723.  
  724.         break;
  725.  
  726.         case IDCMP_REFRESHWINDOW:
  727.         printf ("REFRESHWINDOW\n");
  728.         BeginRefresh (win);
  729.         Refresh (rp);
  730.         EndRefresh (win, TRUE);
  731.         break;
  732.  
  733.         case IDCMP_GADGETDOWN: {
  734.         struct Gadget * gadget;
  735.         LONG pot;
  736.  
  737.         gadget = (struct Gadget *)im->IAddress;
  738.  
  739.         printf ("User pressed gadget %d\n", gadget->GadgetID);
  740.  
  741.         switch (gadget->GadgetID)
  742.         {
  743.         case 10: /* Up */
  744.             pot = DemoPropInfo3.VertPot - DemoPropInfo3.VertBody;
  745.  
  746.             if (pot < 0)
  747.             pot = 0;
  748.  
  749.             NewModifyProp (&DemoGadget7
  750.             , win
  751.             , NULL
  752.             , DemoPropInfo2.Flags
  753.             , DemoPropInfo2.HorizPot
  754.             , pot
  755.             , DemoPropInfo2.HorizBody
  756.             , DemoPropInfo2.VertBody
  757.             , 1
  758.             );
  759.             NewModifyProp (&DemoGadget8
  760.             , win
  761.             , NULL
  762.             , DemoPropInfo3.Flags
  763.             , DemoPropInfo3.HorizPot
  764.             , pot
  765.             , DemoPropInfo3.HorizBody
  766.             , DemoPropInfo3.VertBody
  767.             , 1
  768.             );
  769.  
  770.             break;
  771.  
  772.         case 11: /* Down */
  773.             pot = DemoPropInfo3.VertPot + DemoPropInfo3.VertBody;
  774.  
  775.             if (pot > MAXPOT)
  776.             pot = MAXPOT;
  777.  
  778.             NewModifyProp (&DemoGadget7
  779.             , win
  780.             , NULL
  781.             , DemoPropInfo2.Flags
  782.             , DemoPropInfo2.HorizPot
  783.             , pot
  784.             , DemoPropInfo2.HorizBody
  785.             , DemoPropInfo2.VertBody
  786.             , 1
  787.             );
  788.             NewModifyProp (&DemoGadget8
  789.             , win
  790.             , NULL
  791.             , DemoPropInfo3.Flags
  792.             , DemoPropInfo3.HorizPot
  793.             , pot
  794.             , DemoPropInfo3.HorizBody
  795.             , DemoPropInfo3.VertBody
  796.             , 1
  797.             );
  798.  
  799.             break;
  800.  
  801.         case 12: /* Right */
  802.             pot = DemoPropInfo1.HorizPot + DemoPropInfo1.HorizBody;
  803.  
  804.             if (pot > MAXPOT)
  805.             pot = MAXPOT;
  806.  
  807.             NewModifyProp (&DemoGadget6
  808.             , win
  809.             , NULL
  810.             , DemoPropInfo1.Flags
  811.             , pot
  812.             , DemoPropInfo1.VertPot
  813.             , DemoPropInfo1.HorizBody
  814.             , DemoPropInfo1.VertBody
  815.             , 1
  816.             );
  817.             NewModifyProp (&DemoGadget8
  818.             , win
  819.             , NULL
  820.             , DemoPropInfo3.Flags
  821.             , pot
  822.             , DemoPropInfo3.VertPot
  823.             , DemoPropInfo3.HorizBody
  824.             , DemoPropInfo3.VertBody
  825.             , 1
  826.             );
  827.  
  828.             break;
  829.  
  830.         case 13: /* Left */
  831.             pot = DemoPropInfo1.HorizPot - DemoPropInfo1.HorizBody;
  832.  
  833.             if (pot < 0)
  834.             pot = 0;
  835.  
  836.             NewModifyProp (&DemoGadget6
  837.             , win
  838.             , NULL
  839.             , DemoPropInfo1.Flags
  840.             , pot
  841.             , DemoPropInfo1.VertPot
  842.             , DemoPropInfo1.HorizBody
  843.             , DemoPropInfo1.VertBody
  844.             , 1
  845.             );
  846.             NewModifyProp (&DemoGadget8
  847.             , win
  848.             , NULL
  849.             , DemoPropInfo3.Flags
  850.             , pot
  851.             , DemoPropInfo3.VertPot
  852.             , DemoPropInfo3.HorizBody
  853.             , DemoPropInfo3.VertBody
  854.             , 1
  855.             );
  856.  
  857.             break;
  858.  
  859.         }
  860.  
  861.         break; }
  862.  
  863.         case IDCMP_GADGETUP: {
  864.         struct Gadget * gadget;
  865.  
  866.         gadget = (struct Gadget *)im->IAddress;
  867.  
  868.         printf ("User released gadget %d\n", gadget->GadgetID);
  869.  
  870.         if (gadget->GadgetID == 1)
  871.             cont = 0;
  872.         else if (gadget->GadgetID == 2)
  873.         {
  874.             prop ++;
  875.  
  876.             switch (prop)
  877.             {
  878.             case 0:
  879.             NewModifyProp (&DemoGadget6, win, NULL,
  880.                 DemoPropInfo1.Flags,
  881.                 0, 0, MAXBODY, MAXBODY, 1);
  882.             NewModifyProp (&DemoGadget7, win, NULL,
  883.                 DemoPropInfo2.Flags,
  884.                 0, 0, MAXBODY, MAXBODY, 1);
  885.             NewModifyProp (&DemoGadget8, win, NULL,
  886.                 DemoPropInfo3.Flags,
  887.                 0, 0, MAXBODY, MAXBODY, 1);
  888.             break;
  889.  
  890.             case 1:
  891.             NewModifyProp (&DemoGadget6, win, NULL,
  892.                 DemoPropInfo1.Flags,
  893.                 0, 0, MAXBODY/2, MAXBODY, 1);
  894.             NewModifyProp (&DemoGadget7, win, NULL,
  895.                 DemoPropInfo2.Flags,
  896.                 0, 0, MAXBODY, MAXBODY/2, 1);
  897.             NewModifyProp (&DemoGadget8, win, NULL,
  898.                 DemoPropInfo3.Flags,
  899.                 0, 0, MAXBODY/2, MAXBODY/2, 1);
  900.             break;
  901.  
  902.             case 2:
  903.             NewModifyProp (&DemoGadget6, win, NULL,
  904.                 DemoPropInfo1.Flags,
  905.                 MAXPOT, 0, MAXBODY/2, MAXBODY, 1);
  906.             NewModifyProp (&DemoGadget7, win, NULL,
  907.                 DemoPropInfo2.Flags,
  908.                 0, MAXPOT, MAXBODY, MAXBODY/2, 1);
  909.             NewModifyProp (&DemoGadget8, win, NULL,
  910.                 DemoPropInfo3.Flags,
  911.                 MAXPOT, MAXPOT, MAXBODY/2, MAXBODY/2, 1);
  912.             break;
  913.  
  914.             default:
  915.             NewModifyProp (&DemoGadget6, win, NULL,
  916.                 DemoPropInfo1.Flags,
  917.                 0, 0, MAXBODY/9, MAXBODY, 1);
  918.             NewModifyProp (&DemoGadget7, win, NULL,
  919.                 DemoPropInfo2.Flags,
  920.                 0, 0, MAXBODY, MAXBODY/9, 1);
  921.             NewModifyProp (&DemoGadget8, win, NULL,
  922.                 DemoPropInfo3.Flags,
  923.                 0, 0, MAXBODY/9, MAXBODY/9, 1);
  924.             prop = -1;
  925.             break;
  926.  
  927.             }
  928.         }
  929.  
  930.         break; }
  931.  
  932.         } /* switch */
  933.  
  934.         ReplyMsg ((struct Message *)im);
  935.     }
  936.     else
  937.     {
  938.         /* D("Waiting\n"); */
  939.         Wait (1L << win->UserPort->mp_SigBit);
  940.     }
  941.     }
  942.  
  943.     D(bug("CloseWindow (%p)\n", win));
  944.     CloseWindow (win);
  945.  
  946. end:
  947.     if (gadget)
  948.     DisposeObject (gadget);
  949.  
  950.     if (frame)
  951.     DisposeObject (frame);
  952.  
  953.     if (GfxBase)
  954.     CloseLibrary ((struct Library *)GfxBase);
  955.  
  956.     if (IntuitionBase)
  957.     CloseLibrary ((struct Library *)IntuitionBase);
  958.  
  959.     return 0;
  960. }
  961.