home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d031 / mxexample.lha / MxExample / mxexample.c next >
Encoding:
C/C++ Source or Header  |  1986-08-30  |  12.8 KB  |  431 lines

  1. /*
  2.  *
  3.  *            Copywrite (C) 1986 by Davide P. Cervone
  4.  *
  5.  *    Permission is granted for any individual or institution to use,
  6.  *    copy, or redistribute this software, provided this copywrite
  7.  *    notice is retained.
  8.  *
  9.  */
  10.  
  11. #include "exec/types.h"
  12. #include "exec/devices.h"
  13. #include "libraries/dos.h"
  14. #include "intuition/intuition.h"
  15. #include "intuition/intuitionbase.h"
  16. #include "graphics/gfxbase.h"
  17. #include "graphics/regions.h"
  18. #include "graphics/copper.h"
  19. #include "graphics/gels.h"
  20. #include "devices/keymap.h"
  21. #include "hardware/blit.h"
  22.  
  23. #include "mxgadget.h"
  24.  
  25. #define INTUITION_REV 0
  26. #define GRAPHICS_REV 0
  27.  
  28. #define ERROR_EXIT 10    /* Error number to return on error exit */
  29.  
  30. struct IntuitionBase *IntuitionBase = NULL;
  31. struct GfxBase *GfxBase = NULL;
  32.  
  33.  
  34. /*
  35.  *  These are the title texts of all the gadgets:
  36.  */
  37.  
  38. struct IntuiText Title[] = {
  39.    {
  40.       1,0,                /* Text pen colors */
  41.       JAM1,               /* drawing mode */
  42.       30,1,               /* Offset */
  43.       NULL,               /* font */
  44.       "Choice 1",         /* text of message */
  45.       NULL                /* next IntuiText */
  46.    },
  47.    {1,0, JAM1, 30,1, NULL, "Choice 2", NULL},
  48.    {1,0, JAM1, 30,1, NULL, "Choice 3, with Sub-Items", NULL},
  49.    {1,0, JAM1, 30,1, NULL, "Sub-Choice 1", NULL},
  50.    {1,0, JAM1, 30,1, NULL, "Sub-Choice 2", NULL},
  51.  
  52.    {1,0, JAM1, -4,-12, NULL, "A String, or", NULL},
  53.    {1,0, JAM1, -13,-11, NULL, "A Flag", NULL},
  54.  
  55.    {3,0, JAM1, 8,2, NULL, "1", NULL},
  56.    {3,0, JAM1, 8,2, NULL, "2", NULL},
  57.    {3,0, JAM1, 8,2, NULL, "4", NULL},
  58.    {3,0, JAM1, 8,2, NULL, "8   Items", NULL},
  59.  
  60.    {1,0, JAM1, 4,2, NULL, "OK", NULL}
  61. };
  62.  
  63.  
  64. /*
  65.  *  These are the border coordinates and border structures for
  66.  *  the gadgets:
  67.  */
  68.  
  69. USHORT Button[] = {0,0, 25,0, 25,13, 0,13, 0,0};    /* Boarder coordinates */
  70. USHORT StrBox[] = {0,0, 92,0, 92,13, 0,13, 0,0};    /* string border */
  71. USHORT ReqBox[] = {0,0,399,0,399,149,0,149,0,0};    /* Requester border */
  72.  
  73. struct Border ButtonBrdr = {
  74.    -1,-1,              /* starting position of boarder lines */
  75.    1,0,                /* front and back pens */
  76.    JAM1,               /* Drawing mode */
  77.    5,                  /* Number of points in Button Boarder */
  78.    &Button[0],         /* pointer to outline */
  79.    NULL                /* pointer to next boarder */
  80. };
  81.  
  82. struct Border StrBoxBrdr  = {-6,-3, 1,0, JAM1, 5, &StrBox[0], NULL};
  83. struct Border RequestBrdr = { 0, 0, 1,0, JAM1, 5, &ReqBox[0], NULL};
  84.  
  85.  
  86. /*
  87.  *  These are the image data for the box and the box with an X in it:
  88.  */
  89.  
  90. USHORT EmptyBoxData[] =
  91. {
  92.    0xFFFF, 0xFC00,
  93.    0xC000, 0x0C00,
  94.    0xC000, 0x0C00,
  95.    0xC000, 0x0C00,
  96.    0xC000, 0x0C00,
  97.    0xC000, 0x0C00,
  98.    0xC000, 0x0C00,
  99.    0xC000, 0x0C00,
  100.    0xC000, 0x0C00,
  101.    0xC000, 0x0C00,
  102.    0xFFFF, 0xFC00
  103. };
  104.  
  105. USHORT CheckBoxData[] =
  106. {
  107. /* plane 1 */
  108.    0xFFFF, 0xFC00,
  109.    0xF000, 0x3C00,
  110.    0xCC00, 0xCC00,
  111.    0xC303, 0x0C00,
  112.    0xC0CC, 0x0C00,
  113.    0xC030, 0x0C00,
  114.    0xC0CC, 0x0C00,
  115.    0xC303, 0x0C00,
  116.    0xCC00, 0xCC00,
  117.    0xF000, 0x3C00,
  118.    0xFFFF, 0xFC00,
  119. /* plane 2 */
  120.    0xFFFF, 0xFC00,
  121.    0xC000, 0x0C00,
  122.    0xC000, 0x0C00,
  123.    0xC000, 0x0C00,
  124.    0xC000, 0x0C00,
  125.    0xC000, 0x0C00,
  126.    0xC000, 0x0C00,
  127.    0xC000, 0x0C00,
  128.    0xC000, 0x0C00,
  129.    0xC000, 0x0C00,
  130.    0xFFFF, 0xFC00
  131. };
  132.  
  133. struct Image EmptyBox = {
  134.    0,0,                         /* left, top */
  135.    22,11,1,                     /* width, height, depth */
  136.    (USHORT *) &EmptyBoxData,    /* the image data */
  137.    0x1,0x0,                     /* PlanePick, PlaneOnOff */
  138.    NULL                         /* next image */
  139. };
  140.  
  141. struct Image CheckBox = {
  142.    0,0, 22,11,2, (USHORT *) &CheckBoxData, 0x3,0x0, NULL
  143. };
  144.  
  145.  
  146. /*
  147.  * String gadget special info:
  148.  */
  149.  
  150. char StrBuf[11];                /* string buffer area */
  151.  
  152. struct StringInfo StrBoxInfo = {
  153.    (UBYTE *) &StrBuf[0],        /* pointer to string buffer area */
  154.    NULL,                        /* UNDO buffer */
  155.    0,                           /* initial cursor position */
  156.    11,                          /* buffer size */
  157.    0,                           /* position of first character in display */
  158.    0,                           /* UNDO position */
  159.    0,                           /* number of chars in the buffer */
  160.    0,                           /* number of characters visiable */
  161.    0,0,                         /* position of left and top of container */
  162.    NULL,                        /* layer pointer */
  163.    0L,                          /* long it value (if INTEGER gadget) */
  164.    NULL                         /* alternate kymao for input */
  165. };
  166.  
  167.  
  168. /*
  169.  * These are the gadgets themselves:
  170.  *   the array is a linked list, and is completely initalized here,
  171.  *   so these gadgets can be used without additional initialization code.
  172.  *   They are linked into the Requester structure below.
  173.  */
  174.  
  175. #define OKGADGET 11      /* This is the gagdet number of the end gadget */
  176.  
  177. struct Gadget Choice[12] = {
  178.    {
  179.       &Choice[1],         /* Next Gadget */
  180.       60,20, 22,11,       /* left and top edges, width and height */
  181.       GADGIMAGE | SELECTED | GADGHIMAGE,          /* flags */
  182.       GADGIMMEDIATE,      /* activation flags */
  183.       BOOLGADGET | REQGADGET,  /* Boolean requseter gadget */
  184.       (APTR) &EmptyBox,   /* Pointer to Image */
  185.       (APTR) &CheckBox,   /* Pointer to select rendering */
  186.       &Title[0],          /* text for gadget */
  187.       1+2,                /* Mutual Exclude group 1, disable group 2 */
  188.       NULL,               /* special info (PropInfo or StringInfo) */
  189.       0,                  /* identification */
  190.       (APTR) MXDISABLEGADG
  191.          /* This one is pre-selected (SELECTED) and is an IMAGE gadget
  192.             (GADGHIMAGE); it disabled group 2 (MXDISABLEGADG); group 2
  193.             is specified as a disable group by a call to SetMxGadgetMasks in
  194.             the OpenMyWindow procedure */
  195.    },{
  196.       &Choice[2], 60,35, 22,11, GADGIMAGE | GADGHIMAGE,
  197.       GADGIMMEDIATE, BOOLGADGET | REQGADGET,
  198.       (APTR) &EmptyBox, (APTR) &CheckBox, &Title[1],
  199.       1+2,   /* Mutual Exclude group 1, disable group 2 */
  200.       NULL, 1, (APTR) MXDISABLEGADG
  201.    },{
  202.       &Choice[3], 60,50, 22,11, GADGIMAGE | GADGHIMAGE,
  203.       GADGIMMEDIATE, BOOLGADGET | REQGADGET,
  204.       (APTR) &EmptyBox, (APTR) &CheckBox, &Title[2],
  205.       1+2,   /* Mutual Exclude group 1, enable group 2 */
  206.       NULL, 2, (APTR) MXENABLEGADG
  207.          /* This one enables group 2 (MXENABLEGADG), which are
  208.             the sub-choices */
  209.    },{
  210.       &Choice[4], 100,65, 22,11, GADGIMAGE | GADGDISABLED | GADGHBOX,
  211.       GADGIMMEDIATE, BOOLGADGET | REQGADGET,
  212.       (APTR) &EmptyBox, NULL, &Title[3],
  213.       2+4,   /* Mutual Exclude group 4, disabled by group 2 */
  214.       NULL, 3, (APTR) (MXGADGONOFF | MXSELECT)
  215.          /* Disabled when a member of Mutual Exclude group 2 is enabled
  216.             (MXGADGONOFF), start out disabled (GADGDISABLED), but selected
  217.             when enabled (MXSELECT) */
  218.    },{
  219.       &Choice[5], 260,65, 22,11, GADGIMAGE | GADGDISABLED | GADGHBOX,
  220.       GADGIMMEDIATE, BOOLGADGET | REQGADGET,
  221.       (APTR) &EmptyBox, NULL, &Title[4],
  222.       2+4,   /* Mutual Exclude group 4, disabled by group 2 */
  223.       NULL, 4, (APTR) MXGADGONOFF
  224.          /* Disabled when a member of Mutual Exclude group 2 is enabled
  225.             (MXGADGONOFF) and starts out disabled (GADGDISABLED) */
  226.    },{
  227.       &Choice[6], 60,105, 81,8, GADGHCOMP,
  228.       GADGIMMEDIATE | RELVERIFY, STRGADGET | REQGADGET,
  229.       (APTR) &StrBoxBrdr, NULL, &Title[5],
  230.       8,   /* Disabled by group 8 */
  231.       (APTR) &StrBoxInfo, 5, (APTR) MXGADGONOFF
  232.          /* Disabled by mutual exclude group 8 (MXGADGONOFF),
  233.             but starts out enabled */
  234.    },{
  235.       &Choice[7], 190,104, 22,11, GADGIMAGE | GADGHIMAGE,
  236.       GADGIMMEDIATE | TOGGLESELECT, BOOLGADGET | REQGADGET,
  237.       (APTR) &EmptyBox, (APTR) &CheckBox, &Title[6],
  238.       8,   /* Disable members of group 8 */
  239.       NULL, 6, (APTR) MXDISABLEGADG
  240.          /* Disables Mutual Exclude group 8 (MXDISABLEGADG),
  241.             toggles to re-enable it (TOGGLESELECT) */
  242.    },{
  243.       &Choice[8], 130,130, 24,12, GADGHCOMP | SELECTED,
  244.       GADGIMMEDIATE, BOOLGADGET | REQGADGET,
  245.       (APTR) &ButtonBrdr, NULL, &Title[7],
  246.       16,   /* Mutual Exclude group 16 */
  247.       NULL, 7, NULL
  248.          /* Exclude members of group 16, and complement (GADGHCOMP) */
  249.    },{
  250.       &Choice[9], 156,130, 24,12, GADGHCOMP,
  251.       GADGIMMEDIATE, BOOLGADGET | REQGADGET,
  252.       (APTR) &ButtonBrdr, NULL, &Title[8],
  253.       16,   /* Mutual Exclude group 16 */
  254.       NULL, 8, NULL
  255.          /* Exclude members of group 16, and complement (GADGHCOMP) */
  256.    },{
  257.       &Choice[10], 182,130, 24,12, GADGHCOMP,
  258.       GADGIMMEDIATE, BOOLGADGET | REQGADGET,
  259.       (APTR) &ButtonBrdr, NULL, &Title[9],
  260.       16,   /* Mutual Exclude group 16 */
  261.       NULL, 9, NULL
  262.          /* Exclude members of group 16, and complement (GADGHCOMP) */
  263.    },{
  264.       &Choice[11], 208,130, 24,12, GADGHCOMP,
  265.       GADGIMMEDIATE, BOOLGADGET | REQGADGET,
  266.       (APTR) &ButtonBrdr, NULL, &Title[10],
  267.       16,   /* Mutual Exclude group 16 */
  268.       NULL, 10, NULL
  269.          /* Exclude members of group 16, and complement (GADGHCOMP) */
  270.    },{
  271.       NULL, 320,104, 24,12, GADGHCOMP,
  272.       RELVERIFY, BOOLGADGET | REQGADGET,
  273.       (APTR) &ButtonBrdr, NULL, &Title[11],
  274.       0, NULL, OKGADGET, NULL
  275.          /* OK button, this one closes the requester */
  276.          /* it is not a Mutual Exclude gadget */
  277.    }
  278. };
  279.  
  280.  
  281. /*
  282.  * This is the requester that uses the gadgets defined above:
  283.  */
  284.  
  285. struct Requester myRequester =
  286.    {
  287.       NULL,            /* Next requester */
  288.       120,20, 400,150, /* left-edge, top-edge, width, height */
  289.       0,0,             /* relLeft, relRight */
  290.       &Choice[0],      /* first Gadget */
  291.       &RequestBrdr,    /* border */
  292.       NULL,            /* Text */
  293.       NULL,            /* Flags */
  294.       2,               /* Back Fill */
  295.       NULL,            /* Clip region */
  296.       NULL,            /* Bit map */
  297.       NULL             /* other bitmap */
  298.    };
  299.  
  300.  
  301. /*
  302.  * This is the window in which the requester will be placed:
  303.  */
  304.  
  305. struct NewWindow NewWindow = {
  306.    0,0, 640,200,       /* left, top, width, height */
  307.    0,1,                /* detail and block pens */
  308.    GADGETDOWN | GADGETUP,  /* flags */
  309.    WINDOWDEPTH | WINDOWSIZING | WINDOWDRAG | SMART_REFRESH | ACTIVATE,
  310.    NULL,               /* first gadget */
  311.    NULL,               /* check image */
  312.    "Mutual Exclude Gadgets",  /* title */
  313.    NULL,               /* screen */
  314.    NULL,               /* bit map */
  315.    100, 35,            /* min size */
  316.    640, 200,           /* max size */
  317.    WBENCHSCREEN        /* screen type */
  318. };
  319.  
  320. struct Window *myWindow = NULL;
  321.  
  322.  
  323. main()
  324. {
  325.    CheckLibOpen(&IntuitionBase,"intuition.library",INTUITION_REV);
  326.    CheckLibOpen(&GfxBase,"graphics.library",GRAPHICS_REV);
  327.    OpenMyWindow();
  328.    if (Request(&myRequester,myWindow))
  329.    {
  330.       WaitForAction();
  331.       EndRequest(&myRequester,myWindow);
  332.    } else {
  333.       printf("Can't open requester\n");
  334.    }
  335.    DoExit(0);
  336. }
  337.  
  338. DoExit(status)
  339. int status;
  340. {
  341.    CloseMyWindow();
  342.    CloseLibraries();
  343.    exit(status);
  344. }
  345.  
  346. CheckLibOpen(lib,name,rev)
  347. APTR **lib;
  348. char *name;
  349. long rev;
  350. {
  351.    if ((*lib = (APTR) OpenLibrary(name,rev)) == NULL)
  352.    {
  353.       printf("Can't open %s\n",name);
  354.       DoExit(ERROR_EXIT);
  355.    }
  356. }
  357.  
  358. OpenMyWindow()
  359. {
  360.    if ((myWindow = (struct Window *) MxOpenWindow(&NewWindow)) == NULL)
  361.    {
  362.       printf("Can't open my window\n");
  363.       DoExit(ERROR_EXIT);
  364.    } else {
  365.       SetMxGadgetMasks(myWindow,2,8+2);
  366.          /* Mutual Exclude group  2 is an Enable group */
  367.          /* Mutual Exclude groups 8 and 2 are Disable groups */
  368.    }
  369. }
  370.  
  371. CloseLibraries()
  372. {
  373.    if (IntuitionBase != NULL) CloseLibrary(IntuitionBase);
  374.    IntuitionBase = NULL;
  375.    if (GfxBase != NULL) CloseLibrary(GfxBase);
  376.    GfxBase = NULL;
  377. }
  378.  
  379. CloseMyWindow()
  380. {
  381.    if (myWindow != NULL) MxCloseWindow(myWindow);
  382.    myWindow = NULL;
  383. }
  384.  
  385.  
  386. WaitForAction()
  387. {
  388.    int class,code, NotDone = 1;
  389.    extern struct MenuItem *ItemAddress();
  390.    struct IntuiMessage *NewMessage;
  391.    struct Gadget *theGadget;
  392.  
  393.    while (NotDone)
  394.    {
  395.       Wait(1 << myWindow->UserPort->mp_SigBit);
  396.       while (NewMessage = (struct IntuiMessage *)GetMsg(myWindow->UserPort))
  397.       {
  398.          class = NewMessage->Class;
  399.          code  = NewMessage->Code;
  400.          switch (class)
  401.          {
  402.             case GADGETDOWN:
  403.                theGadget = (struct Gadget *) NewMessage->IAddress;
  404.  
  405. /*
  406.  *  This is the call to the mutual exclude gadget handler.  Call
  407.  *  SelectGadget whenever a mutual exclude gadget is selected.  Note that
  408.  *  you can call it for ANY gadget, as SelecteGadget checks whether the
  409.  *  gadget has the mutual exclude flags set.
  410.  */
  411.                SelectGadget(theGadget,myWindow,&myRequester);
  412.  
  413.                /* do any other stuff with the gadgets here */
  414.  
  415.                break;
  416.  
  417.             case GADGETUP:
  418.                theGadget = (struct Gadget *) NewMessage->IAddress;
  419.                if (theGadget->GadgetID == OKGADGET) NotDone = 0;
  420.  
  421.                /*  if you have RELVERIFY gadgets, do their stuff here */
  422.                /*  Mutual Exclude gadgets should not be RELVERIFY gadgets */
  423.  
  424.                break;
  425.  
  426.          }
  427.          ReplyMsg(NewMessage);
  428.       }
  429.    }
  430. }
  431.