/***************************************
 *                                     *
 * Program: Proportional-Gadget.c      *
 * =================================== *
 *                                     *
 * Author:  Date:      Comments:       *
 * ------  ----------  ----------      *
 * Wgb     10/16/1987  for testing     *
 *                     only            *
 *                                     *
 ***************************************/


#include <exec/types.h>
#include <intuition/intuition.h>


struct IntuitionBase *IntuitionBase;
struct Window        *FirstWindow;
struct IntuiMessage  *message;

WORD Buffer[4];

struct PropInfo ExampleProp =
{
   AUTOKNOB | FREEVERT, /*    Flags            */
   0x8000,              /*    HorizPot         */
   0x8000,              /*    VertPot          */
   0x0800,              /*    HorizBody        */
   0x0800,              /*    VertBody         */
   0,                   /*    CWidth           */
   0,                   /*    CHeight          */
   0,                   /*    HPotRes          */
   0,                   /*    VPotRes          */
   0,                   /*    LeftBorder       */
   0                    /*    TopBorder        */
};

struct Gadget PropGadget =
   {
   NULL,                /* NextGadget          */
   100, 20,             /* LeftEdge, TopEdge   */
   20, 60,              /* Width, Height       */
   GADGHCOMP,           /* Flags               */
   RELVERIFY,           /* Activation          */
   PROPGADGET,          /* Gadget Type         */
   (APTR)Buffer,        /* GadgetRender        */
   NULL,                /* Select Render       */
   NULL,                /* GadgetText          */
   NULL,                /* MutualExclude       */
   (APTR)&ExampleProp, /* SpecialInfo         */
   2,                   /* GadgetID            */
   NULL,                /* UserData            */
   };

struct NewWindow FirstNewWindow =
   {
   160, 50,             /* LeftEdge, TopEdge   */
   320, 150,            /* Width, Height       */
   0, 1,                /* DetailPen, BlockPen */
   CLOSEWINDOW |        /* IDCMP Flags         */
   GADGETUP,
   WINDOWDEPTH |        /* Flags               */
   WINDOWSIZING |
   WINDOWDRAG |
   WINDOWCLOSE |
   SMART_REFRESH,
   &PropGadget,         /* First Gadget        */
   NULL,                /* CheckMark           */
   (UBYTE *)"Gadget Programmng Test",
   NULL,                /* Screen              */
   NULL,                /* BitMap              */
   100, 50,             /* Min Width, Height   */
   640, 200,            /* Max Width, Height   */
   WBENCHSCREEN,        /* Type                */
   };




main()
   {
   ULONG MessageClass;
   USHORT code, nr = 0;

   struct Message *GetMsg();

   Open_All();
   
   FOREVER
      {
      if ((message = (struct IntuiMessage *)
          GetMsg(FirstWindow->UserPort)) == NULL)
         {
         Wait(1L << FirstWindow->UserPort->mp_SigBit);
         continue;
         }
      MessageClass = message->Class;
      code = message->Code;
      ReplyMsg(message);
      switch (MessageClass)
         {
         case GADGETUP    : printf("Position: %u\n", ExampleProp.VertPot);
                            break;
         
         case CLOSEWINDOW : Close_All();
                            exit(TRUE);
                            break;
         
         case GADGETDOWN  : nr += 1;
                            printf("Gadget activated %d. times!\n", nr);
                            break;
         
         }
      }
   }


/***************************************
 *                                     *
 * Function: Library and Window open   *
 *                                     *
 ***************************************/

Open_All()

   {
   void          *OpenLibrary();
   struct Window *OpenWindow();
   
   if (!(IntuitionBase = (struct IntuitionBase *)
       OpenLibrary("intuition.library", 0L)))
      {
      printf("Intuition Library not found!\n");
      Close_All();
      exit(FALSE);
      }
   
   if (!(FirstWindow = (struct Window *)
       OpenWindow(&FirstNewWindow)))
      {
      printf("Window will not open!\n");
      Close_All();
      exit(FALSE);
      }
   }


/***************************************
 *                                     *
 * Function: Close all                 *
 *                                     *
 ***************************************/

Close_All()

   {
   if (FirstWindow)     CloseWindow(FirstWindow);
   if (IntuitionBase)   CloseLibrary(IntuitionBase);
   }

