home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.1 / Libraries / Intuition / CustGad / cgmain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  4.2 KB  |  187 lines

  1. /* dialt.c -- test for dial gadget routines    */
  2.  
  3. /*
  4. Copyright (c) 1989 Commodore-Amiga, Inc.
  5.  
  6. Executables based on this information may be used in software
  7. for Commodore Amiga computers. All other rights reserved.
  8. This information is provided "as is"; no warranties are made.
  9. All use is at your own risk, and no liability or responsibility
  10. is assumed.
  11. */
  12.  
  13. #include "sysall.h"
  14.  
  15. struct  Window      *getNewWind();
  16.  
  17. struct  IntuitionBase   *IntuitionBase = NULL;
  18. struct  GfxBase         *GfxBase = NULL;
  19.  
  20. ULONG   flg = WINDOWCLOSE | NOCAREREFRESH | WINDOWDRAG
  21.     | WINDOWDEPTH | SIMPLE_REFRESH;
  22.  
  23. ULONG   iflg =    GADGETUP | GADGETDOWN |
  24.         RAWKEY | MOUSEMOVE | MOUSEBUTTONS | CLOSEWINDOW;
  25.  
  26. #define DIALID    (0xdead)    /* gadgetid for dial gadget    */
  27.  
  28. main()
  29. {
  30.     struct  IntuiMessage    *msg;
  31.     struct Window       *window = NULL;
  32.     WORD            exitval = 0;
  33.     struct Image    *CreateEllipseImage();
  34.     struct Image    *ellipseimage = NULL;
  35.     struct Gadget    *CreateDialGadget();
  36.     struct Gadget    *dg;
  37.     WORD        dialx, dialy;
  38.  
  39.     /* hold data from *msg  */
  40.     ULONG           class;
  41.     USHORT          code;
  42.     APTR            iaddr;
  43.     UWORD        qualifier;
  44.     Point        mouse;
  45.  
  46.     if ((IntuitionBase = 
  47.     (struct IntuitionBase *) OpenLibrary("intuition.library", 36L)
  48.     ) == NULL)
  49.     {
  50.     printf("NO INTUITION LIBRARY\n");
  51.     exitval = 1;
  52.     goto EXITING;
  53.     }
  54.  
  55.     if ((GfxBase = 
  56.     (struct GfxBase *) OpenLibrary("graphics.library", 36L)
  57.     ) == NULL)
  58.     {
  59.     printf("NO GRAPHICS LIBRARY\n");
  60.     exitval = 2;
  61.     goto EXITING;
  62.     }
  63.  
  64.     /* init libraries and window    */
  65.     window = getNewWind(400, 120, 160, 90, NULL, flg, iflg);
  66.     if (window == NULL)
  67.     {
  68.     exitval = 1;
  69.     goto EXITING;
  70.     }
  71.  
  72.     if ( ! (ellipseimage =  CreateEllipseImage( 100, 50, 2, 2, 3, 2, 4 )))
  73.     {
  74.         exitval = 1;
  75.     goto EXITING;
  76.     }
  77.  
  78.     if ( dg = CreateDialGadget( DIALID, ellipseimage ) )
  79.     {
  80.     /* finish the setup of the gadget    */
  81.     dg->LeftEdge = 30;
  82.     dg->TopEdge = 20;
  83.     dg->Activation |= GADGIMMEDIATE | RELVERIFY;
  84.  
  85.     AddGadget( window, dg, (long) ~0 );
  86.     RefreshGList( dg, window, NULL, 1L );
  87.     }
  88.     else
  89.     {
  90.         printf( "create dialg failed\n");
  91.     }
  92.  
  93.     printf("test program ok\n");
  94.  
  95.     FOREVER
  96.     {
  97.     if ((msg = (struct IntuiMessage *)GetMsg(window->UserPort)) == NULL)
  98.     {
  99.         Wait(1L<<window->UserPort->mp_SigBit);
  100.         continue;
  101.     }
  102.  
  103.     /* Stash message contents and reply,
  104.      * important when message triggers some
  105.      * lengthy processing
  106.      */
  107.  
  108.     class   = msg->Class;
  109.     code    = msg->Code;
  110.     iaddr   = msg->IAddress;
  111.     qualifier = msg->Qualifier;
  112.     mouse = *( (Point *) &msg->MouseX );
  113.  
  114.     ReplyMsg(msg);
  115.  
  116.     switch (class)
  117.     {
  118.     case GADGETUP:
  119.         printf(" gadgetup received\n");
  120.         if ( ((struct Gadget *) iaddr)->GadgetID == DIALID )
  121.         {
  122.             printf(" dial gadget has been used.\n");
  123.         GetDialCoords( iaddr, &dialx, &dialy );
  124.         printf("coords are: %d/%d\n", dialx, dialy );
  125.         }
  126.         else printf( "unrecognized gadget message\n" );
  127.  
  128.         break;
  129.  
  130.     case CLOSEWINDOW:
  131.         goto EXITING;
  132.     }
  133.     }
  134.  
  135. EXITING:
  136.     if ( dg )
  137.     {
  138.     RemoveGadget( window, dg );
  139.     DeleteDialGadget( dg );
  140.     }
  141.     DeleteImage( ellipseimage );
  142.  
  143.     if (window)
  144.     {
  145.         CloseWindow(window);
  146.     }
  147.  
  148.     if (GfxBase) CloseLibrary(GfxBase);
  149.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  150.  
  151.     exit (exitval);
  152. }
  153.  
  154.  
  155. struct  Window * getNewWind(left, top, width, height, screen, flg, iflg)
  156. SHORT   left, top, width, height;
  157. struct Screen    *screen;
  158. ULONG   flg, iflg;
  159. {
  160.     struct  Window  *OpenWindow();
  161.     struct  NewWindow   nw;
  162.  
  163.     nw.LeftEdge =   (SHORT) left;
  164.     nw.TopEdge  =   (SHORT) top;
  165.     nw.Width    =   (SHORT) width;
  166.     nw.Height   =   (SHORT) height;
  167.     nw.DetailPen    =   (UBYTE) -1;
  168.     nw.BlockPen =   (UBYTE) -1;
  169.     nw.IDCMPFlags   =   (ULONG) iflg;
  170.  
  171.     nw.Flags    =   (ULONG) flg;
  172.  
  173.     nw.FirstGadget  =   (struct Gadget *)   NULL;
  174.     nw.CheckMark    =   (struct Image *)    NULL;
  175.     nw.Title    =   (UBYTE *)   " Dial Test ";
  176.     nw.Screen   =   screen;
  177.     nw.BitMap   =   (struct BitMap *)   NULL;
  178.     nw.MinWidth =   (SHORT) 50;
  179.     nw.MinHeight=   (SHORT) 30;
  180.     /* work around bug  */
  181.     nw.MaxWidth =   (SHORT) nw.Width;
  182.     nw.MaxHeight    =   (SHORT) nw.Height;
  183.     nw.Type     =   (USHORT) (screen? CUSTOMSCREEN: WBENCHSCREEN);
  184.  
  185.     return ((struct Window *) OpenWindow(&nw));
  186. }
  187.