home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 1: Collection A / 17Bit_Collection_A.iso / files / 223.dms / 223.adf / Source / star9.c < prev    next >
C/C++ Source or Header  |  1988-07-25  |  15KB  |  487 lines

  1. /*=========================================================================
  2.   Star9.c -- This module builds and submits a requester in response to
  3.   the user's choice of 'change clock rate' from the OPTIONS  menu
  4.   of the Star Chart program. The requester lets the user modify the 
  5.   number of seconds of simulated time that pass for each second of real
  6.   time.
  7.  
  8.   Credits for Star Chart:
  9.        Robert L. Hill of the Orange County, CA. Amiga Friends User Group
  10.                       wrote the original version of StarChart in AmigaBasic
  11.                       The star data and many of the main functions of this
  12.                       version are derived from that program.
  13.  
  14.        Ray R. Larson  wrote the c version 1.0 of StarChart, 'intuitionizing'
  15.                       and enhancing the speed and functions of the original.
  16.  
  17.   Copyright (c) 1986 by Ray R. Larson
  18.   
  19.   This program may be freely distributed and copied, but may not be sold
  20.   without the permission of the author. If you modify or enhance it, 
  21.   please include the above credits (and please send me a copy!).
  22.  
  23. Ray R. Larson
  24. 6425 Central Ave. #304
  25. El Cerrito, CA 94530
  26.  
  27. BitNet  LARSON@UCBCMSA
  28. =========================================================================*/
  29. /*------------Header file for all of the standard stuff----*/ 
  30. /*-------------plus definitions of global structures-------*/
  31. #include "star.h" 
  32.  
  33.  
  34. /**********************************************************************
  35.  *                    Gadget Structure Definitions
  36.  * 
  37.  * The following structures were defined using the Gadget Editor created 
  38.  * by the Programmer's Network.
  39.  * The credits for the Gadget Editor are:
  40.  * 
  41.  *     John Draper    - Initial design, coordination, and integration.
  42.  *     Ray Larson     - Images and Intuitext. 
  43.  *     Brent Southard - Saving and restoring gadgets in binary form.
  44.  *     Dave Milligan  - Gadget Editor Main menu.
  45.  * 
  46.  * 
  47.  **********************************************************************/
  48. /*  Definitions for Gadget ID numbers               */ 
  49. #define  TIMEINTGAD   0
  50. #define  WHITEGADGAD   1
  51. #define  CANTIMEGAD   2
  52. #define  OKTIMEGAD   3
  53.  
  54. /**********************************************************************
  55.  *  Text attribute structures used in rendering IntuiTexts
  56.  **********************************************************************/
  57. extern struct TextAttr TxtAt_Plain,TxtAt_BIU,TxtAt_BU,TxtAt_BI,TxtAt_B,
  58.         TxtAt_IU,TxtAt_I,TxtAt_U;
  59.  
  60.  
  61.  
  62. struct IntuiText Time_Error_Text = {
  63.    3, 2,     /* FrontPen, BackPen */
  64.    JAM2,       /* DrawMode */
  65.    0, 0,     /* LeftEdge, TopEdge */
  66.    &TxtAt_B, /* ITextFont Pointer */ 
  67.    /* The IText */
  68.    (UBYTE *)"?",
  69.    NULL    /* NextText */
  70.  };
  71.  
  72. /**********************************************************************
  73.  *  Border Definitions for TimeReq requester
  74.  **********************************************************************/
  75.  
  76. SHORT TimeReq_Pairs_1[] = {
  77.   0,     0,   
  78.   257,     0,   
  79.   257,     100,   
  80.   0,     100,   
  81.   0,     0    
  82. };
  83. struct Border TimeReq_bord_1 = {
  84.   1,  1,       /* LeftEdge, TopEdge */
  85.   7,  1,  JAM2,  /* FrontPen, BackPen, DrawMode*/
  86.   5,             /* Count of XY pairs */  
  87.   (SHORT *)&TimeReq_Pairs_1, /* XY pairs */
  88.   NULL           /* Next Border */
  89. };
  90.  
  91. SHORT TimeReq_Pairs_2[] = {
  92.   0,     0,   
  93.   251,     0,   
  94.   251,     97,   
  95.   0,     97,   
  96.   0,     0    
  97. };
  98. struct Border TimeReq_bord_2 = {
  99.   3,  3,       /* LeftEdge, TopEdge */
  100.   1,  7,  JAM2,  /* FrontPen, BackPen, DrawMode*/
  101.   5,             /* Count of XY pairs */  
  102.   (SHORT *)&TimeReq_Pairs_2, /* XY pairs */
  103.   &TimeReq_bord_1           /* Next Border */
  104. };
  105.  
  106.  
  107.  
  108. /**********************************************************************
  109.  *  Border Definitions for okTime gadget
  110.  **********************************************************************/
  111.  
  112. SHORT okTime_Pairs_2[] = {
  113.   0,     0,   
  114.   88,     0,   
  115.   88,     17,   
  116.   0,     17,   
  117.   0,     0    
  118. };
  119. struct Border okTime_bord_2 = {
  120.   -1,  -1,       /* LeftEdge, TopEdge */
  121.   1,  7,  JAM2,  /* FrontPen, BackPen, DrawMode*/
  122.   5,             /* Count of XY pairs */  
  123.   (SHORT *)&okTime_Pairs_2, /* XY pairs */
  124.   NULL           /* Next Border */
  125. };
  126.  
  127.  
  128. /**********************************************************************
  129.  *  IntuiTexts for the okTime gadget.
  130.  **********************************************************************/
  131.  
  132. struct IntuiText okTime_Text_0 = {
  133.    7, 0,     /* FrontPen, BackPen */
  134.    JAM2,       /* DrawMode */
  135.    12, 4,     /* LeftEdge, TopEdge */
  136.    &TxtAt_B, /* ITextFont Pointer */ 
  137.    /* The IText */
  138.    (UBYTE *)"   OK   ",
  139.    NULL
  140.  };
  141.  
  142.  
  143.  
  144. /**********************************************************************
  145.  *  Gadget Structure definition for the okTime gadget.
  146.  **********************************************************************/
  147.  
  148. struct Gadget okTime = {
  149.   NULL,     /* NextGadget pointer */
  150.   152, 76,    /* LeftEdge, TopEdge  */
  151.   88, 17,    /* Width, Height      */
  152.   /* Gadget Flags */
  153.   GADGHCOMP,
  154.   /* Activation Flags */
  155.   RELVERIFY | GADGIMMEDIATE,
  156.   /* GadgetType */
  157.   BOOLGADGET | REQGADGET,
  158.   (APTR)&okTime_bord_2,   /*  GadgetRender */
  159.   NULL,    /* SelectRender */
  160.    &okTime_Text_0,  /* GadgetText */
  161.   0x0,    /* MutualExclude */
  162.   NULL,   /* SpecialInfo */
  163.   OKTIMEGAD,    /* GadgetID         */
  164.   0x1     /* UserData Pointer */
  165. };
  166.  
  167.  
  168. /**********************************************************************
  169.  *  Border Definitions for canTime gadget
  170.  **********************************************************************/
  171.  
  172. SHORT canTime_Pairs_3[] = {
  173.   0,     0,   
  174.   88,     0,   
  175.   88,     17,   
  176.   0,     17,   
  177.   0,     0    
  178. };
  179. struct Border canTime_bord_3 = {
  180.   -1,  -1,       /* LeftEdge, TopEdge */
  181.   1,  7,  JAM2,  /* FrontPen, BackPen, DrawMode*/
  182.   5,             /* Count of XY pairs */  
  183.   (SHORT *)&canTime_Pairs_3, /* XY pairs */
  184.   NULL           /* Next Border */
  185. };
  186.  
  187.  
  188. /**********************************************************************
  189.  *  IntuiTexts for the canTime gadget.
  190.  **********************************************************************/
  191.  
  192. struct IntuiText canTime_Text_0 = {
  193.    7, 0,     /* FrontPen, BackPen */
  194.    JAM2,       /* DrawMode */
  195.    10, 4,     /* LeftEdge, TopEdge */
  196.    &TxtAt_B, /* ITextFont Pointer */ 
  197.    /* The IText */
  198.    (UBYTE *)" CANCEL ",
  199.    NULL
  200.  };
  201.  
  202.  
  203.  
  204. /**********************************************************************
  205.  *  Gadget Structure definition for the canTime gadget.
  206.  **********************************************************************/
  207.  
  208. struct Gadget canTime = {
  209.  &okTime,     /* NextGadget pointer */
  210.   29, 76,    /* LeftEdge, TopEdge  */
  211.   88, 17,    /* Width, Height      */
  212.   /* Gadget Flags */
  213.   GADGHCOMP,
  214.   /* Activation Flags */
  215.   RELVERIFY | GADGIMMEDIATE | ENDGADGET,
  216.   /* GadgetType */
  217.   BOOLGADGET | REQGADGET,
  218.   (APTR)&canTime_bord_3,   /*  GadgetRender */
  219.   NULL,    /* SelectRender */
  220.    &canTime_Text_0,  /* GadgetText */
  221.   0x0,    /* MutualExclude */
  222.   NULL,   /* SpecialInfo */
  223.   CANTIMEGAD,    /* GadgetID         */
  224.   0x1     /* UserData Pointer */
  225. };
  226.  
  227.  
  228. /**********************************************************************
  229.  *  Border Definitions for Timegad gadget
  230.  **********************************************************************/
  231.  
  232. SHORT Timegad_Pairs_5[] = {
  233.   0,     0,   
  234.   73,     0,   
  235.   73,     9,   
  236.   0,     9,   
  237.   0,     0    
  238. };
  239. struct Border Timegad_bord_5 = {
  240.   -1,  -1,       /* LeftEdge, TopEdge */
  241.   1,  7,  JAM2,  /* FrontPen, BackPen, DrawMode*/
  242.   5,             /* Count of XY pairs */  
  243.   (SHORT *)&Timegad_Pairs_5, /* XY pairs */
  244.   NULL           /* Next Border */
  245. };
  246.  
  247.  
  248. /**********************************************************************
  249.  *  IntuiTexts for the Timegad gadget.
  250.  **********************************************************************/
  251.  
  252. struct IntuiText Timegad_Text_2 = {
  253.    0, 2,     /* FrontPen, BackPen */
  254.    JAM2,       /* DrawMode */
  255.    -39, 10,     /* LeftEdge, TopEdge */
  256.    &TxtAt_I, /* ITextFont Pointer */ 
  257.    /* The IText */
  258.    (UBYTE *)"  (range 0 - 1800)",
  259.    NULL
  260.  };
  261.  
  262.  
  263. struct IntuiText Timegad_Text_1 = {
  264.    1, 2,     /* FrontPen, BackPen */
  265.    JAM2,       /* DrawMode */
  266.    -56, -10,     /* LeftEdge, TopEdge */
  267.    &TxtAt_B, /* ITextFont Pointer */ 
  268.    /* The IText */
  269.    (UBYTE *)" per second of real time:",
  270.    &Timegad_Text_2    /* NextText */
  271.  };
  272.  
  273.  
  274. struct IntuiText Timegad_Text_0 = {
  275.    1, 2,     /* FrontPen, BackPen */
  276.    JAM2,       /* DrawMode */
  277.    -64, -19,     /* LeftEdge, TopEdge */
  278.    &TxtAt_B, /* ITextFont Pointer */ 
  279.    /* The IText */
  280.    (UBYTE *)"  Seconds of Simulated Time",
  281.    &Timegad_Text_1    /* NextText */
  282.  };
  283.  
  284.  
  285.  
  286. /**********************************************************************
  287.  *  String information for the Timegad string gadget.
  288.  **********************************************************************/
  289.  
  290. UBYTE PlusTimeBuf[12];
  291. UBYTE Timegad_ubuf_2[12];
  292.  
  293. struct StringInfo PlusTimeTxt = {
  294.   PlusTimeBuf, Timegad_ubuf_2, /* Buffer, UndoBuffer  */
  295.   0, 11, 0,  /* BufferPos, MaxChars, DispPos   */
  296.   0, 0,      /* UndoPos, NumChars              */
  297.   0, 87, 39,  /* DispCount, CLeft, CTop         */
  298.   0x0, 0,   /* LayerPtr, LongInt              */
  299.   0x0        /* AltKeyMap                      */
  300. };
  301.  
  302.  
  303. /**********************************************************************
  304.  *  Gadget Structure definition for the Timegad gadget.
  305.  **********************************************************************/
  306.  
  307. struct Gadget Timegad = {
  308.  &canTime,     /* NextGadget pointer */
  309.   87, 39,    /* LeftEdge, TopEdge  */
  310.   73, 9,    /* Width, Height      */
  311.   /* Gadget Flags */
  312.   GADGHCOMP,
  313.   /* Activation Flags */
  314.   RELVERIFY | GADGIMMEDIATE | LONGINT | STRINGCENTER,
  315.   /* GadgetType */
  316.   STRGADGET | REQGADGET,
  317.   (APTR)&Timegad_bord_5,   /*  GadgetRender */
  318.   NULL,    /* SelectRender */
  319.    &Timegad_Text_0,  /* GadgetText */
  320.   0x0,    /* MutualExclude */
  321.   (APTR)&PlusTimeTxt,   /* SpecialInfo */
  322.   TIMEINTGAD,    /* GadgetID         */
  323.   0x1     /* UserData Pointer */
  324. };
  325.  
  326. /****************************************************************************
  327.  *  Global Structures 
  328.  ***************************************************************************/
  329.  
  330. /* the newwindow structure used in GT */
  331. extern struct NewWindow nw;
  332. extern struct Window *w;
  333. extern FLOAT MaxPlus, MaxWhite;
  334. extern SHORT TimeDelay;
  335.  
  336. /****************************************************************************
  337.  * External function definitions
  338.  ***************************************************************************/
  339. extern struct IntuiMessage *GetMsg();
  340. extern double atof();
  341.  
  342. /****************************************************************************
  343.  * Requester structure and global pointer to it's gadget list.
  344.  ***************************************************************************/
  345. struct Requester TimeRequester;
  346.  
  347. /****************************************************************************
  348.  *               The Code part of the GetTimes module.
  349.  ***************************************************************************/
  350. GetTimes()
  351. {
  352.   BOOL cancelchosen;
  353.   LONG iflags;
  354.   struct RastPort *reqrp;
  355.   SHORT worktimedel;
  356.  
  357.   /* fix the IDCMP flags to report requester set and clear */
  358.   iflags = nw.IDCMPFlags;
  359.   iflags |= REQCLEAR;
  360.   ModifyIDCMP(w,iflags);
  361.   
  362.  
  363.       /* initialize the times requester */ 
  364.       InitTimeReq();
  365.  
  366.       /* Put up the requester  */ 
  367.       Request(&TimeRequester,w);
  368.       
  369.       reqrp = TimeRequester.ReqLayer->rp;
  370.       
  371.       /* let the user fill in the parameters and wait for a cancel or ok. */  
  372.       worktimedel = TimeDelay;
  373.       cancelchosen = WaitTimeReq(reqrp,&worktimedel);
  374.       
  375.       /* if the user cancelled, just return -- otherwise set Time delay   */
  376.       /* and redisplay the star chart.                            */
  377.       if (cancelchosen) return(0);
  378.       TimeDelay = worktimedel;
  379.  
  380. } /* GetTimes */
  381.  
  382. /*
  383.  *  Init the time requester
  384.  */
  385. InitTimeReq()
  386.   struct RastPort *reqrp;
  387.   
  388.   InitRequester(&TimeRequester);
  389.   TimeRequester.LeftEdge  = 110;
  390.   TimeRequester.TopEdge   = 12;
  391.   TimeRequester.Width     = 260;
  392.   TimeRequester.Height    = 105;
  393.   TimeRequester.ReqGadget = &Timegad;
  394.   TimeRequester.ReqText   = NULL;
  395.   TimeRequester.BackFill  = 2;
  396.   TimeRequester.Flags     = 0;
  397.   TimeRequester.ReqBorder = &TimeReq_bord_2;
  398.   
  399.   sprintf(PlusTimeBuf,"%d",TimeDelay);
  400.   PlusTimeTxt.NumChars = (LONG)strlen(PlusTimeBuf);
  401.   *(Timegad_ubuf_2) = '\0';
  402. }
  403.  
  404.   
  405. /****************************************************************************
  406.  *  WaitTimeReq - permit user to change the values in the integer gadgets
  407.  *                 and check the values they install until either the 
  408.  *                 CANCEL gadget is clicked or the OK gadget is clicked AND
  409.  *                 there are no outstanding input errors
  410.  ***************************************************************************/
  411. BOOL WaitTimeReq(reqrp,worktime)
  412. struct RastPort *reqrp;
  413. SHORT *worktime;
  414. {
  415.   ULONG  class = GADGETDOWN;
  416.   struct IntuiMessage *message;
  417.   struct Gadget *gadget;
  418.   struct StringInfo *si;
  419.   BOOL cancelflag = FALSE;
  420.   LONG  errorflag = 0L;
  421.  
  422.   while (class != REQCLEAR)
  423.     {
  424.     if ((message=(struct IntuiMessage *) GetMsg(w->UserPort)) == 0L)
  425.       {
  426.       Wait(1L<<w->UserPort->mp_SigBit);
  427.       continue;
  428.       }
  429.  
  430.     class  = message->Class;
  431.     gadget = (struct Gadget *) message->IAddress;
  432.     ReplyMsg(message);
  433.     switch (class)
  434.       {
  435.       case GADGETDOWN:
  436.                       break;
  437.  
  438.       case GADGETUP: 
  439.          switch (gadget->GadgetID)
  440.         {
  441.         case  TIMEINTGAD: 
  442.                             si = (struct StringInfo *)gadget->SpecialInfo;
  443.                 if ((si->LongInt > 1800) || (si->LongInt < 1))
  444.                    /* put a "?" next to the gadget */
  445.                   { 
  446.                     errorflag = 1;
  447.                     DisplayBeep(w->WScreen);
  448.                     PrintIText(reqrp,&Time_Error_Text,
  449.                         (LONG)(gadget->LeftEdge - 10),
  450.                     (LONG)gadget->TopEdge);
  451.                   }
  452.                else
  453.                   { /* user must have fixed an error, so turn off the ? */
  454.                     errorflag = 0;
  455.                     *worktime = (SHORT)si->LongInt;
  456.                     Time_Error_Text.FrontPen = 2;
  457.                     PrintIText(reqrp,&Time_Error_Text,
  458.                         (LONG)(gadget->LeftEdge - 10),
  459.                     (LONG)gadget->TopEdge);
  460.                     Time_Error_Text.FrontPen = 3;
  461.                   }
  462.  
  463.              break;   
  464.              
  465.         case  CANTIMEGAD : 
  466.                      cancelflag = TRUE;
  467.                              break; 
  468.  
  469.                    case  OKTIMEGAD  :
  470.                   if (errorflag == 0) 
  471.                      EndRequest(&TimeRequester,w);
  472.                  else DisplayBeep(w->WScreen);    
  473.                  break;
  474.  
  475.              } /* end of GADGETUP switch */
  476.  
  477.         } /* end of CLASS switch */
  478.     }/* end of while loop */
  479.     
  480.  
  481. return(cancelflag);
  482.        
  483. } /* WaitTimeReq */
  484.    
  485.  
  486.