home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff214.lzh / MandelVroom / src / getint.c < prev    next >
C/C++ Source or Header  |  1989-05-30  |  6KB  |  257 lines

  1. /*
  2.  * MandelVroom 2.0
  3.  *
  4.  * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
  5.  *
  6.  * All rights reserved.
  7.  *
  8.  * Permission is hereby granted to distribute this program's source
  9.  * executable, and documentation for non-comercial purposes, so long as the
  10.  * copyright notices are not removed from the sources, executable or
  11.  * documentation.  This program may not be distributed for a profit without
  12.  * the express written consent of the author Kevin L. Clague.
  13.  *
  14.  * This program is not in the public domain.
  15.  *
  16.  * Fred Fish is expressly granted permission to distribute this program's
  17.  * source and executable as part of the "Fred Fish freely redistributable
  18.  * Amiga software library."
  19.  *
  20.  * Permission is expressly granted for this program and it's source to be
  21.  * distributed as part of the Amicus Amiga software disks, and the
  22.  * First Amiga User Group's Hot Mix disks.
  23.  *
  24.  * contents: this file implements a requester like window to get an integer
  25.  * value from the user.
  26.  */
  27.  
  28. #include "mandp.h"
  29.  
  30. struct Window *GetIWind;
  31.  
  32. #define GIWIDTH  190
  33. #define GIHEIGHT 50
  34.  
  35. static
  36. struct NewWindow NewGetI = {
  37.    (320-GIWIDTH)/2,(200-GIHEIGHT)/2, /* start position           */
  38.    GIWIDTH,GIHEIGHT,                 /* width, height            */
  39.    (UBYTE) 0, (UBYTE) 1,     /* detail pen, block pen    */
  40.    NULL,                     /* IDCMP flags */
  41.    SMART_REFRESH,            /* MandWind flags */
  42.    (struct Gadget *) NULL,   /* first gadget             */
  43.    (struct Image *) NULL,    /* user checkmark           */
  44.    (UBYTE *) NULL,           /* window title             */
  45.    (struct Screen *) NULL,   /* pointer to screen        */
  46.    (struct BitMap *) NULL,   /* pointer to superbitmap   */
  47.    80,80,80,80,              /* sizing                   */
  48.    CUSTOMSCREEN              /* type of screen           */
  49. };
  50. #define GETINOTDONE 0
  51. #define GETIDONEOK  1
  52. #define GETICANCEL  2
  53.  
  54. UBYTE IDone;
  55.  
  56. char *IString;
  57.  
  58. /*
  59.  * Allocate all the gadgets and things for the get int window
  60.  */
  61. struct Gadget *MakeGetInt( Title, IVal )
  62.   char *Title;
  63.   LONG IVal;
  64. {
  65.  
  66.   register struct Gadget *NextGadget;
  67.   register SHORT *Height;
  68.   register struct StringInfo *StringInfo;
  69.   register struct Gadget *FirstGadget, *OldGadget;
  70.  
  71.   char string[80];
  72.  
  73.   extern struct Gadget *MakeBool();
  74.   extern struct Gadget *MakeString();
  75.   extern struct IntuiText *MakeIntui();
  76.  
  77.   LONG i;
  78.  
  79. #define GETICANID  0xffff
  80. #define GETIOKID   0xfffe
  81. #define GETISTRID  0xfffd
  82.  
  83.   FirstGadget = MakeBool(127, 32, 54, 12, 1, GETICANID, NULL);
  84.   if (FirstGadget == NULL) {
  85.     goto error;
  86.   }
  87.   FirstGadget->GadgetText = ShadowIntui("Cancel", 4, 3);
  88.  
  89.   if ( FirstGadget->GadgetText == NULL ) goto error;
  90.  
  91.   NextGadget = OldGadget = MakeBool(6, 32, 54, 12, 1, GETIOKID, NULL);
  92.  
  93.   if (NextGadget == NULL) goto error;
  94.  
  95.   NextGadget->GadgetText = ShadowIntui("  OK", 4, 3);
  96.  
  97.   if ( NextGadget->GadgetText == NULL ) goto error;
  98.  
  99.   FirstGadget->NextGadget = NextGadget;
  100.  
  101.   sprintf( string,"%d",IVal );
  102.   NextGadget = MakeString( 55, 16, 10, GETISTRID, string );
  103.  
  104.   if (NextGadget == NULL) goto error;
  105.  
  106.   NextGadget->GadgetText = ShadowIntui(Title,-10,-11);
  107.  
  108.   if ( NextGadget->GadgetText == NULL ) goto error;
  109.  
  110. /*i = IntuiTextLength(NextGadget->GadgetText);
  111.   NextGadget->GadgetText->LeftEdge = (GIWIDTH-i)/2;  */
  112.  
  113.   OldGadget->NextGadget = NextGadget;
  114.  
  115.   StringInfo = (struct StringInfo *) NextGadget->SpecialInfo;
  116.   IString = (char *) StringInfo->Buffer;
  117.  
  118.   return( FirstGadget );
  119.  
  120. error:
  121.   FreeGadgets(FirstGadget);
  122.   return((struct Gadget *) NULL);
  123.  
  124. } /* MakeGetInt */
  125.  
  126. static struct Gadget *GetGadgets;
  127.  
  128. /*
  129.  * Get an Integr from the user
  130.  */
  131. GetInt( Title, IVal)
  132.   char *Title;
  133.   LONG *IVal;
  134. {
  135.   register struct Gadget *Gadgets;
  136.   register struct Window *Window;
  137.   register LONG   i;
  138.   register struct RastPort *Rp;
  139.  
  140.   struct Window *OpenMyWind();
  141.  
  142.   IDone = GETINOTDONE;
  143.  
  144.   if (GetIWind == NULL ) {
  145.  
  146.     Gadgets = MakeGetInt( Title, *IVal );
  147.  
  148.     if (Gadgets == NULL) {
  149.       DispErrMsg("Panic. No Gadgets\n",0);
  150.       return( 0 );
  151.     } else {
  152.       Window = OpenMyWind( &NewGetI, screen, NULL, GIWIDTH, GIHEIGHT);
  153.  
  154.       GetIWind = Window;
  155.  
  156.       if (Window) {
  157.  
  158.         Rp = Window->RPort;
  159.  
  160.         CurWind = Window;
  161.  
  162.         SetAPen( Rp, NORMALPEN );
  163.         RectFill( Rp,0,0,Window->Width,Window->Height);
  164.  
  165.         GetGadgets = Gadgets;
  166.  
  167.         AddGList( Window, Gadgets, -1, -1);
  168.  
  169.         RefreshGadgets( Gadgets, Window, NULL );
  170.  
  171.         SetAPen( Rp, HIGHLIGHTPEN );
  172.         Move( Rp, 0,               Window->Height-1 );
  173.         Draw( Rp, 0,               0 );
  174.         Draw( Rp, Window->Width-1, 0 );
  175.  
  176.         SetAPen( Rp, SHADOWPEN );
  177.         Draw( Rp, Window->Width-1, Window->Height-1 );
  178.         Draw( Rp, 0,               Window->Height-1 );
  179.  
  180.         DoIGet();
  181.         if (IDone == GETIDONEOK) {
  182.           sscanf( IString,"%d", IVal);
  183.         }
  184.         CloseGetIWind();
  185.       } else {
  186.         return( 0 );
  187.       }
  188.     }
  189.   }
  190.   return( IDone == GETIDONEOK );
  191. } /* OpenGetIWind */
  192.  
  193. /*
  194.  * Close the get integer window
  195.  */
  196. CloseGetIWind()
  197. {
  198.   if (GetIWind != NULL) {
  199.     CloseMyWind( GetIWind, GetGadgets );
  200.     GetIWind = NULL;
  201.   }
  202. } /* CloseGetIWind */
  203.  
  204. /*
  205.  * Wait and process a message
  206.  */
  207. DoIGet()
  208. {
  209.   while (IDone == GETINOTDONE) {
  210.  
  211.     Wait( 1 << BackWind->UserPort->mp_SigBit );
  212.  
  213.     DoIMsg();
  214.   }
  215. }
  216.  
  217. /*
  218.  * if there is a message, process it
  219.  */
  220. DoIMsg()
  221. {
  222.   register ULONG Class;
  223.   register struct IntuiMessage *message;
  224.   register struct Gadget *gadget;
  225.  
  226.   while (message = (struct IntuiMessage *) GetMsg( BackWind->UserPort)) {
  227.  
  228.     Class = message->Class;
  229.     gadget = (struct Gadget *) message->IAddress;
  230.  
  231.     /* got a message */
  232.  
  233.     ReplyMsg(message);
  234.  
  235.     CheckButtons( gadget, Class );
  236.   }
  237. } /* DoIMsg */
  238.  
  239. CheckButtons( gadget, class )
  240.   struct Gadget *gadget;
  241.   ULONG class;
  242. {
  243.   if (class == GADGETDOWN) {
  244.  
  245.     switch( gadget->GadgetID ) {
  246.  
  247.       case GETICANID:
  248.            IDone = GETICANCEL;
  249.            break;
  250.  
  251.       case GETIOKID:
  252.            IDone = GETIDONEOK;
  253.            break;
  254.     }
  255.   }
  256. } /* CheckButtons */
  257.