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

  1. /*=========================================================================
  2.   Star7.c -- This module displays star data in a window, it uses PrintItext
  3.    routine to do all of the writing to the screen. The routine has it's own
  4.    IDCMP loop that waits for the user to click the CONTINUE gadget.
  5.  
  6.   Credits for Star Chart:
  7.        Robert L. Hill of the Orange County, CA. Amiga Friends User Group
  8.                       wrote the original version of StarChart in AmigaBasic
  9.                       The star data and many of the main functions of this
  10.                       version are derived from that program.
  11.  
  12.        Ray R. Larson  wrote the c version 1.0 of StarChart, 'intuitionizing'
  13.                       and enhancing the speed and functions of the original.
  14.  
  15.   Copyright (c) 1986 by Ray R. Larson
  16.   
  17.   This program may be freely distributed and copied, but may not be sold
  18.   without the permission of the author. If you modify or enhance it, 
  19.   please include the above credits (and please send me a copy!).
  20.  
  21. Ray R. Larson
  22. 6425 Central Ave. #304
  23. El Cerrito, CA 94530
  24.  
  25. BitNet  LARSON@UCBCMSA
  26. =========================================================================*/
  27. /*------------Header file for all of the standard stuff----*/ 
  28. /*-------------plus definitions of global structures-------*/
  29. #include "star.h" 
  30.  
  31. /*------------ External function declarations ------------*/
  32.  
  33. extern struct Window *OpenWindow();
  34. extern struct IntuiMessage *GetMsg();
  35.  
  36. /*------------------ extern vars ------------------*/
  37.  
  38. extern struct star_rec StarTable[];
  39. extern struct Coord coords[];
  40. extern char *Greek[]; 
  41. extern struct cons_rec Constel[];
  42. extern struct ParamStruct Parms;
  43. extern FLOAT P1, P12;
  44.  
  45. /*------------------- global variables -------------------*/
  46.  
  47. extern struct Screen *scr;      /* pointer to the custom screen    - RRL */
  48.  
  49. /**********************************************************************
  50.  *  Text attribute structures used in rendering IntuiTexts
  51.  **********************************************************************/
  52. extern struct TextAttr TxtAt_Plain,TxtAt_BIU,TxtAt_BU,TxtAt_BI,TxtAt_B,
  53.         TxtAt_IU,TxtAt_I,TxtAt_U;
  54.  
  55. /**********************************************************************
  56.  *  IntuiTexts for the ContinueG gadget.
  57.  **********************************************************************/
  58.  
  59. struct IntuiText ContinueG_Text_0 = {
  60.    15, 2,     /* FrontPen, BackPen */
  61.    JAM2,       /* DrawMode */
  62.    0, 0,     /* LeftEdge, TopEdge */
  63.    &TxtAt_B, /* ITextFont Pointer */ 
  64.    /* The IText */
  65.    (UBYTE *)" CONTINUE ",
  66.    NULL
  67.  };
  68.  
  69.  
  70.  
  71. /**********************************************************************
  72.  *  Gadget Structure definition for the ContinueG gadget.
  73.  **********************************************************************/
  74. #define  CONTINUEGGAD   1
  75.  
  76. struct Gadget ContinueG = {
  77.   NULL,     /* NextGadget pointer */
  78.   -97,-8,    /* LeftEdge, TopEdge  */
  79.    80, 8,    /* Width, Height      */
  80.   /* Gadget Flags */
  81.   GADGHCOMP | GRELBOTTOM | GRELRIGHT ,
  82.   /* Activation Flags */
  83.   RELVERIFY | GADGIMMEDIATE | BOTTOMBORDER | ENDGADGET,
  84.   /* GadgetType */
  85.   BOOLGADGET,
  86.   NULL,   /*  GadgetRender */
  87.   NULL,    /* SelectRender */
  88.    &ContinueG_Text_0,  /* GadgetText */
  89.   0x0,    /* MutualExclude */
  90.   NULL,   /* SpecialInfo */
  91.   CONTINUEGGAD,    /* GadgetID         */
  92.   0x1     /* UserData Pointer */
  93. };
  94.  
  95.  
  96.  
  97. /**********************************************************************
  98.  *  IntuiTexts for the Display requester
  99.  **********************************************************************/
  100. UBYTE comment3_text[60];
  101. struct IntuiText disp_comment3 = {
  102.    2, 1,     /* FrontPen, BackPen */
  103.    JAM2,       /* DrawMode */
  104.    14, 91,     /* LeftEdge, TopEdge */
  105.    &TxtAt_Plain, /* ITextFont Pointer */ 
  106.    /* The IText */
  107.    comment3_text,
  108.    NULL
  109.  };
  110.  
  111. UBYTE comment2_text[60];
  112. struct IntuiText disp_comment2 = {
  113.    2, 1,     /* FrontPen, BackPen */
  114.    JAM2,       /* DrawMode */
  115.    14, 81,     /* LeftEdge, TopEdge */
  116.    &TxtAt_Plain, /* ITextFont Pointer */ 
  117.    /* The IText */
  118.    comment2_text,
  119.    &disp_comment3
  120.  };
  121.  
  122. UBYTE comment_text[60];
  123. struct IntuiText disp_comment = {
  124.    2, 1,     /* FrontPen, BackPen */
  125.    JAM2,       /* DrawMode */
  126.    14, 71,     /* LeftEdge, TopEdge */
  127.    &TxtAt_Plain, /* ITextFont Pointer */ 
  128.    /* The IText */
  129.    comment_text,
  130.    &disp_comment2
  131.  };
  132.  
  133.  
  134. UBYTE distance_text[50];
  135. struct IntuiText disp_distance = {
  136.    0, 1,     /* FrontPen, BackPen */
  137.    JAM2,       /* DrawMode */
  138.    14, 60,     /* LeftEdge, TopEdge */
  139.    &TxtAt_I, /* ITextFont Pointer */ 
  140.    /* The IText */
  141.    distance_text,
  142.    &disp_comment    /* NextText */
  143.  };
  144.  
  145. UBYTE magnitude_text[50];
  146. struct IntuiText disp_magnitude = {
  147.    0, 1,     /* FrontPen, BackPen */
  148.    JAM2,       /* DrawMode */
  149.    14, 51,     /* LeftEdge, TopEdge */
  150.    &TxtAt_I, /* ITextFont Pointer */ 
  151.    /* The IText */
  152.    magnitude_text,
  153.    &disp_distance    /* NextText */
  154.  };
  155.  
  156.  
  157. UBYTE declination_text[50];
  158. struct IntuiText disp_declination = {
  159.    0, 1,     /* FrontPen, BackPen */
  160.    JAM2,       /* DrawMode */
  161.    14, 41,     /* LeftEdge, TopEdge */
  162.    &TxtAt_I, /* ITextFont Pointer */ 
  163.    /* The IText */
  164.    declination_text,
  165.    &disp_magnitude    /* NextText */
  166.  };
  167.  
  168.  
  169. UBYTE RA_text[50];
  170. struct IntuiText disp_RA = {
  171.    0, 1,     /* FrontPen, BackPen */
  172.    JAM2,       /* DrawMode */
  173.    14, 32,     /* LeftEdge, TopEdge */
  174.    &TxtAt_I, /* ITextFont Pointer */ 
  175.    /* The IText */
  176.    RA_text,
  177.    &disp_declination    /* NextText */
  178.  };
  179.  
  180.  
  181. UBYTE constmeaning_text[50];
  182. struct IntuiText disp_consmeaning = {
  183.    2, 1,     /* FrontPen, BackPen */
  184.    JAM2,       /* DrawMode */
  185.    14, 22,     /* LeftEdge, TopEdge */
  186.    &TxtAt_Plain, /* ITextFont Pointer */ 
  187.    /* The IText */
  188.    constmeaning_text,
  189.    &disp_RA    /* NextText */
  190.  };
  191.  
  192.  
  193. UBYTE connames_text[50];
  194. struct IntuiText disp_greekcons = {
  195.    2, 1,     /* FrontPen, BackPen */
  196.    JAM2,       /* DrawMode */
  197.    14, 12,     /* LeftEdge, TopEdge */
  198.    &TxtAt_Plain, /* ITextFont Pointer */ 
  199.    /* The IText */
  200.    connames_text,
  201.    &disp_consmeaning    /* NextText */
  202.  };
  203.  
  204.  
  205. UBYTE starname_text[50];
  206. struct IntuiText disp_starname= {
  207.    11, 1,     /* FrontPen, BackPen */
  208.    JAM2,       /* DrawMode */
  209.    14, 3,     /* LeftEdge, TopEdge */
  210.    &TxtAt_BU, /* ITextFont Pointer */ 
  211.    /* The IText */
  212.    starname_text,
  213.    &disp_greekcons    /* NextText */
  214.  };
  215.  
  216.  
  217.  
  218. /*------------ Display Window Definition ------------*/
  219.  
  220.  
  221. /* new window structure */
  222. struct NewWindow dispNW = {
  223.    0, 0, 400, 125, 0, 1,
  224.  
  225. /* IDCMP Flags */
  226.  
  227.    GADGETDOWN
  228. |  NEWSIZE
  229. |  GADGETUP,
  230.  
  231. /* Flags */
  232.   WINDOWDEPTH
  233. | WINDOWSIZING
  234. | WINDOWDRAG
  235. | ACTIVATE,
  236.  
  237.   &ContinueG,               /* First gadget */
  238.   NULL,               /* Checkmark */
  239.  (UBYTE *)  "Star Information: ",  /* Window title */
  240.   NULL,               /* custom screen -if it exists*/
  241.   NULL,               /* Not a super bitmap window */
  242.   150, 31, 400, 125,     /* Not used, but set up anyway */
  243.   WBENCHSCREEN
  244. };
  245.  
  246. /*=========================================================================
  247.  DisplayInfo - star data display  routine of the StarChart program.
  248. ========================================================================*/
  249. DisplayInfo(list, numstars, defaultHL, shortdisp)
  250. SHORT list[];
  251. SHORT numstars, defaultHL, shortdisp;
  252. {
  253.     /*---------------- local vars ---------------*/
  254.     struct IntuiMessage *mes;          /* Message pointer */
  255.     ULONG class;                       /* Message class */
  256.     USHORT code;                       /* Message code */
  257.     struct Gadget *gad;                /* IAddress from Intuimessage */
  258.     struct Window *dispwin;
  259.     struct RastPort *disprp;
  260.     BOOL go = TRUE;
  261.     SHORT i, starnum;
  262.     FLOAT xRad,yRad,Xpos,Ypos;
  263.     SHORT yeardif;
  264.     struct star_rec *s;
  265.     UBYTE workstr[100], *workp, *index(), *rindex();
  266.  
  267.     /* Set window pointer to the custom screen, if needed */
  268.  
  269.     if (scr != NULL)
  270.        { dispNW.Screen = scr ;
  271.          dispNW.Type = CUSTOMSCREEN;
  272.        }
  273.  
  274.     /*----------- open window ----------*/
  275.     if ((dispwin = OpenWindow(&dispNW)) == NULL) {
  276.         DisplayBeep();
  277.         return(0);
  278.     }
  279.  
  280.     /* ------------- Initialize the display text -------------*/
  281.  
  282.     disprp = dispwin->RPort;
  283.     yeardif = Parms.Year - 1950;
  284.  
  285.     /* --------------- main loop -----------------*/
  286.     for (i=0; i < numstars; i++)
  287.       { 
  288.         /* get a pointer to the star record to be displayed */
  289.         s = &StarTable[list[i]];
  290.  
  291.         /* skip the star if the display flags indicate that the user */
  292.         /* has requested major star displays only, and the star is   */
  293.         /* not a major star.                         */
  294.         if ((shortdisp & 4) && (s->GreekNum == 0)) continue;
  295.         if ((shortdisp & 1))
  296.            HighLightStar(list[i],3,8);
  297.  
  298.  
  299.         /* clear the window to white */
  300.         SetAPen(disprp,1L);
  301.         RectFill(disprp,4L,10L,
  302.                  (LONG)(dispwin->Width - 4),(LONG)(dispwin->Height - 10));
  303.         
  304.         if (yeardif) {
  305.            /* convert right Asc. and declination of star to radians */
  306.            xRad = s->Ra * P12;
  307.            yRad = s->Dc * P1;
  308.        
  309.      
  310.           /* correct for year - uses mathffp routines*/
  311.           Xpos = s->Ra + 
  312.              (3.07 + 1.34 * (FLOAT)sin((DOUBLE)xRad) * (FLOAT)tan((DOUBLE)xRad))
  313.           * (FLOAT)yeardif / 3600.0;
  314.  
  315.       
  316.          Ypos = s->Dc + 20 * (FLOAT)cos((DOUBLE)yRad) * (FLOAT)yeardif / 3600.0;
  317.         }
  318.       else { /* year is 1950 - basis for the star table */
  319.            Xpos = s->Ra;
  320.            Ypos = s->Dc;
  321.            }
  322.  
  323.       /* put the infomation into the intuitext buffers */
  324.       if (coords[list[i]].x != 0L) sprintf(comment3_text," ");
  325.       else sprintf(comment3_text,"Not Currently Visible");
  326.  
  327.     
  328.       strcpy(workstr,s->Comment);
  329.       workp = rindex(workstr,'-');
  330.      
  331.       if (workp)
  332.          { workp--;
  333.            if (*workp == ' ')
  334.               { 
  335.                 *workp = '\0';
  336.                 workp++;
  337.                 sprintf(comment_text,"Comments: %s",workstr);
  338.                 sprintf(comment2_text,"   %s",workp);
  339.               }
  340.           else if (strlen(s->Comment) < 39)
  341.                   {sprintf(comment_text,"Comments: %s",s->Comment);
  342.                    comment2_text[0] = '\0';
  343.                   }
  344.                else
  345.                   {
  346.                    sprintf(comment_text,"Comments:");
  347.                    sprintf(comment2_text,"%s",s->Comment);
  348.                   }
  349.          }
  350.       else if (strlen(s->Comment) < 39)
  351.               {sprintf(comment_text,"Comments: %s",s->Comment);
  352.                comment2_text[0] = '\0';
  353.               }
  354.            else
  355.               {
  356.                 sprintf(comment_text,"Comments:");
  357.                 sprintf(comment2_text,"%s",s->Comment);
  358.               }
  359.  
  360.       
  361.       if (s->Dist > 0.0)
  362.          sprintf(distance_text,"     Distance:  %ld Light Years",
  363.                   (LONG)(s->Dist * 1000.0));
  364.       else 
  365.          sprintf(distance_text, "     Distance:  not available.");
  366.       sprintf(magnitude_text,  "     Magnitude:        %10.2f",s->Mag);
  367.       sprintf(declination_text,"     Declination:      %10.2f",s->Dc);
  368.       sprintf(RA_text,         "     Right Ascension:  %10.2f",s->Ra);
  369.       
  370.       if(s->GreekNum == 0)
  371.         { sprintf(constmeaning_text," - known as the %s",
  372.                    Constel[s->ConsNum].ConsMean);
  373.       sprintf(connames_text,"Located in the constellation %s",
  374.                 Constel[s->ConsNum].ConsName);
  375.         }
  376.       else  
  377.         { strcpy(workstr,Constel[s->ConsNum].ConsMean);
  378.           if (( workp = index(workstr,'-')) == NULL)
  379.         { sprintf(constmeaning_text,"");
  380.               sprintf(connames_text,"%s %s - The %s",
  381.                   Greek[s->GreekNum],Constel[s->ConsNum].ConsName,
  382.                   Constel[s->ConsNum].ConsMean);
  383.             }
  384.           else
  385.         { sprintf(constmeaning_text,workp);
  386.               *workp = '\0';
  387.               sprintf(connames_text,"%s %s - The %s",
  388.                   Greek[s->GreekNum],Constel[s->ConsNum].ConsName,
  389.                   workstr);
  390.             }
  391.         }
  392.       sprintf(starname_text," %s ",s->StarName);
  393.       
  394.       PrintIText(disprp,&disp_starname,2L,10L);
  395.       RefreshWindowFrame(dispwin);
  396.       RefreshGadgets(&ContinueG,dispwin,NULL);
  397.       
  398.       go = TRUE;
  399.  
  400.        while(go)
  401.          {  
  402.           if ((mes = GetMsg(dispwin->UserPort)) == NULL) 
  403.             {
  404.              Wait(1L << dispwin->UserPort->mp_SigBit);
  405.              continue;
  406.             }
  407.  
  408.          class = mes->Class;
  409.          code = mes->Code;
  410.          gad = (struct Gadget *)mes->IAddress;
  411.          ReplyMsg(mes);
  412.           
  413.          if ((class == GADGETUP) && (gad->GadgetID == CONTINUEGGAD))
  414.            go = FALSE;
  415.  
  416.          if (class == NEWSIZE) /* user resized the window, so redraw stuff */
  417.            {      
  418.               /* clear the window to white */
  419.              SetAPen(disprp,1L);
  420.              RectFill(disprp,4L,10L,
  421.                  (LONG)(dispwin->Width - 4),(LONG)(dispwin->Height - 10));
  422.              PrintIText(disprp,&disp_starname,2L,10L);
  423.          RefreshWindowFrame(dispwin);
  424.              RefreshGadgets(&ContinueG,dispwin,NULL);
  425.            }
  426.  
  427.         } /* end of while loop */
  428.         
  429.       if ((shortdisp & 1))
  430.           HighLightStar(list[i],defaultHL,8); 
  431.  
  432.       } /* end of for loop */
  433.   
  434.    CloseWindow(dispwin);
  435.  
  436. }/* end of displayinfo */
  437.  
  438.