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

  1. /*=========================================================================
  2.   Starhlp.c -- This module handles all help requests for the starchart
  3.                program.             
  4.  
  5.   Credits for Star Chart:
  6.        Robert L. Hill of the Orange County, CA. Amiga Friends User Group
  7.                       wrote the original version of StarChart in AmigaBasic
  8.                       The star data and many of the main functions of this
  9.                       version are derived from that program.
  10.  
  11.        Ray R. Larson  wrote the c version 1.0 of StarChart, 'intuitionizing'
  12.                       and enhancing the speed and functions of the original.
  13.  
  14.   Copyright (c) 1986 by Ray R. Larson
  15.   
  16.   This program may be freely distributed and copied, but may not be sold
  17.   without the permission of the author. If you modify or enhance it, 
  18.   please include the above credits (and please send me a copy!).
  19.  
  20. Ray R. Larson
  21. 6425 Central Ave. #304
  22. El Cerrito, CA 94530
  23.  
  24. BitNet  LARSON@UCBCMSA
  25. =========================================================================*/
  26. /*------------Header file for all of the standard stuff----*/ 
  27. /*-------------plus definitions of global structures-------*/
  28. #include "star.h" 
  29.  
  30. #include <clib/macros.h>
  31.  
  32. /* macros for checking userport and timerport bits */
  33. #define USERBIT  1L << hlpwin->UserPort->mp_SigBit
  34. #define TIMERBIT 1L << timerport->mp_SigBit
  35. extern struct MsgPort *timerport; /* for timing signals */
  36. extern struct timerequest timermsg;
  37.  
  38. /* symbolic gadget names */
  39. #define UPGADGET 1
  40. #define DOWNGADGET 2
  41. #define POTGADGET 3
  42.  
  43. extern struct Window *w, *OpenWindow();
  44. extern struct IntuiMessage *GetMsg();
  45.  
  46. /*************************************************************** 
  47. * All of the text and gadgets needed for the HELP window follow.
  48. **************************************************************/
  49.                             
  50. /***********************************************
  51.  * The Scroll Selection List up (arrow) gadget *
  52.  **********************************************/
  53. UWORD UpArrowData[15] = {
  54.    0xfffc,
  55.    0xfcfc,
  56.    0xf87c,
  57.    0xf03c,
  58.    0xe01c,
  59.    0xc00c,
  60.    0x8004,
  61.    0xfcfc,
  62.    0xfcfc,
  63.    0xfcfc,
  64.    0xfcfc,
  65.    0xfcfc,
  66.    0xfcfc,
  67.    0xfffc
  68. };
  69.  
  70. struct Image UpArrow = 
  71.   {
  72.    0,0,
  73.    14,
  74.    14,
  75.    1,
  76.    &UpArrowData[0],
  77.    0x1, 0x0,
  78.    NULL
  79.    };
  80.  
  81. struct Gadget UpGadget =
  82.   { /* Up a line gadget */
  83.   NULL,           /* next gadget */
  84.   626,10,                  /* location    */
  85.   12,14,
  86.   GADGIMAGE|GADGHNONE,     /* flags       */
  87.   GADGIMMEDIATE,           /* activation  */
  88.   BOOLGADGET|REQGADGET,    /* type        */
  89.   (APTR) &UpArrow,         /* rendering   */
  90.   NULL,                    /* rendering   */
  91.   NULL,                    /* text        */
  92.   0,                       /* mutual exlcude */
  93.   NULL,                    /* string info */
  94.   UPGADGET,                /* gadget id   */
  95.   NULL                     /* special info*/
  96.   };
  97.  
  98. /*************************************************
  99.  * The Scroll Selection List down (arrow) gadget *
  100.  ************************************************/
  101. UWORD DownArrowData[15] = {
  102.    0xfffc,
  103.    0xfcfc,
  104.    0xfcfc,
  105.    0xfcfc,
  106.    0xfcfc,
  107.    0xfcfc,
  108.    0xfcfc,
  109.    0x8004,
  110.    0xc00c,
  111.    0xe01c,
  112.    0xf03c,
  113.    0xf87c,
  114.    0xfcfc,
  115.    0xfffc
  116. };
  117.  
  118. struct Image DownArrow = 
  119.   {
  120.    0,0,
  121.    14,
  122.    14,
  123.    1,
  124.    &DownArrowData[0],
  125.    0x1, 0x0,
  126.    NULL
  127.    };
  128.  
  129. struct Gadget DownGadget =
  130.   { /* Down a line gadget */
  131.   &UpGadget,               /* next gadget */
  132.   626,185,                  /* location    */
  133.   12,14,
  134.   GADGIMAGE|GADGHNONE,     /* flags       */
  135.   GADGIMMEDIATE,           /* activation  */
  136.   BOOLGADGET|REQGADGET,    /* type        */
  137.   (APTR) &DownArrow,       /* rendering   */
  138.   NULL,                    /* rendering   */
  139.   NULL,                    /* text        */
  140.   0,                       /* mutual exlcude */
  141.   NULL,                    /* string info */
  142.   DOWNGADGET,              /* gadget id   */
  143.   NULL                     /* special info*/
  144.   };
  145.  
  146. /***************************************************
  147.  * The Scroll Selection list up down Potentiometer *
  148.  **************************************************/
  149. struct PropInfo KnobInfo =
  150.   {
  151.   AUTOKNOB | FREEVERT | PROPBORDERLESS,
  152.   0,
  153.   0, /* VertPot */
  154.   0,
  155.   0x7fff, /* VertBody */
  156.   0,0,0,0,0,0
  157.   };
  158.  
  159. struct Image KnobImage =
  160.   {
  161.   0,0,
  162.   0,0,0,
  163.   NULL,
  164.   0,0,
  165.   NULL
  166.   };
  167.  
  168. struct Gadget scroll_control =
  169.   { /* Potentiometer line gadget */
  170.   &DownGadget,             /* next gadget */
  171.   626,24,                  /* location    */
  172.   14,161,
  173.   GADGHNONE,               /* flags       */
  174.   RELVERIFY,               /* activation  */
  175.   PROPGADGET|REQGADGET,    /* type        */
  176.   (APTR) &KnobImage,       /* rendering   */
  177.   NULL,                    /* rendering   */
  178.   NULL,                    /* text        */
  179.   0,                       /* mutual exlcude */
  180.   (APTR)&KnobInfo,         /* string info */
  181.   POTGADGET,               /* gadget id   */
  182.   NULL                     /* special info*/
  183.   };
  184.  
  185.     
  186. extern struct Screen *scr;
  187.  
  188. struct NewWindow helpwind =
  189.    { 0,0,    /* Left and Top edges            */
  190.      640,200,    /* Width and Height            */
  191.      0,1,    /* DetailPen and BlockPen colors    */
  192.      GADGETUP | GADGETDOWN
  193.      | CLOSEWINDOW,/* IDCMPFlags for the window*/
  194.         /* Flags for the window            */
  195.      WINDOWCLOSE | ACTIVATE,
  196.  
  197.      &scroll_control,/* First gadget in list        */
  198.      NULL,      /* Checkmark - use the default check    */
  199.      NULL,      /* Title    -set later        */
  200.      NULL,    /* Screen - set after screen is opened    */
  201.      NULL,    /* No Custom bitmap here either        */
  202.      640,    /* MinWidth, MinHeight, MaxW & MaxH    */
  203.      200,    /*  no window sizing so these should be ignored */
  204.      6400,
  205.      200,
  206.      CUSTOMSCREEN, /* sure is */
  207.      };
  208.  
  209.  
  210. /**************************************************************************
  211.  * Help data is located in starhlpdat.c, it is stored as a set of *char[]   
  212.  * initialized structures;
  213.  *************************************************************************/   
  214.  
  215. /*  ABOUT STARCHART help */
  216. extern SHORT abouthelplines;
  217. extern char *abouthelptext[];
  218.  
  219. /*  project menu help */
  220. extern SHORT projhelplines;
  221. extern char *projhelptext[];
  222.  
  223. /* parameters menu help */
  224. extern SHORT parmhelplines;
  225. extern char *parmhelptext[];
  226.  
  227. /* options menu help */
  228. extern SHORT opthelplines;
  229. extern char *opthelptext[];
  230.  
  231. /* constellations menu help */
  232. extern SHORT conshelplines;
  233. extern char *conshelptext[];
  234.  
  235. #define PROJECT 0L
  236. #define PARMS   1L
  237. #define OPTIONS 2L
  238. #define ABOUTHELP 4L
  239. #define CONHELP 7L
  240.  
  241.  
  242. do_help_req(HelpNum)
  243. LONG HelpNum;
  244.     { 
  245.       struct Window *hlpwin;
  246.       struct Gadget *curgadget;
  247.       struct IntuiMessage *msg;
  248.       BOOL result, finished, timeout=FALSE;
  249.       SHORT i, j, topline, code, nlines;
  250.       ULONG class, vpot, vbody, flags, linesize;
  251.       char **text;
  252.       
  253.     switch (HelpNum)
  254.        {
  255.     case PROJECT:
  256.          helpwind.Title = (UBYTE *)"StarChart Help for Project Menu";
  257.          nlines = projhelplines;
  258.              text = &projhelptext[0];
  259.          break;
  260.              
  261.     case PARMS:
  262.          helpwind.Title = (UBYTE *)"StarChart Help for Parameters Menu";
  263.          nlines = parmhelplines;
  264.              text = &parmhelptext[0];
  265.          break;
  266.              
  267.     case OPTIONS:
  268.           helpwind.Title = (UBYTE *)"StarChart Help for Options Menu";
  269.          nlines = opthelplines;
  270.              text = &opthelptext[0];
  271.          break;
  272.    
  273.         case ABOUTHELP:
  274.           helpwind.Title = (UBYTE *)"About StarChart and how to use it.";
  275.          nlines = abouthelplines;
  276.              text = &abouthelptext[0];
  277.          break;
  278.              
  279.     case CONHELP:
  280.          helpwind.Title = (UBYTE *)"StarChart Help for Constellations Menus";
  281.          nlines = conshelplines;
  282.              text = &conshelptext[0];
  283.          break;
  284.     
  285.        }  
  286.  
  287.     /* set the proportional gadget body size */
  288.     flags = FREEVERT | AUTOKNOB;
  289.     KnobInfo.Flags = FREEVERT | AUTOKNOB;
  290.     
  291.     vbody = (ULONG)(0xFFFF / (nlines/16));
  292.     KnobInfo.VertBody = (USHORT)vbody;
  293.     linesize = vbody / 16L;
  294.     KnobInfo.HorizBody= 0;
  295.     KnobInfo.VertPot = 0;
  296.     topline = 0;
  297.      
  298.     helpwind.Screen = scr;
  299.  
  300.     if((hlpwin = OpenWindow(&helpwind)) == NULL)
  301.       { puts("Can't open the help window!!\n");
  302.         return(FALSE);
  303.       }
  304.  
  305.     finished = FALSE;
  306.     PrintPage(hlpwin,text,0,nlines);    
  307.  
  308.     while (!finished)
  309.         {  
  310.        
  311.         if ((msg = GetMsg(hlpwin->UserPort)) == NULL) 
  312.           {
  313.             Wait((USERBIT));
  314.             continue;
  315.           }
  316.  
  317.        if (msg == NULL) continue;
  318.         class = msg->Class;
  319.         code = msg->Code;
  320.         curgadget = (struct Gadget *)msg->IAddress;
  321.         ReplyMsg(msg);
  322.           
  323.   
  324.         switch (class) {
  325.  
  326.                case CLOSEWINDOW: finished = TRUE;   break;
  327.  
  328.                case GADGETUP: 
  329.                      if (curgadget->GadgetID == POTGADGET)
  330.                        { 
  331.             if(KnobInfo.VertPot == 0xFFFF)
  332.               topline = nlines - 17;
  333.                else topline = (KnobInfo.VertPot / linesize) - 3;
  334.                if (topline < 0) topline = 0;
  335.                         if ((topline+17) >= nlines) 
  336.                            topline = nlines-17;
  337.                         
  338.                }
  339.               PrintPage(hlpwin,text,topline,nlines);    
  340.              break;
  341.  
  342.  
  343.                case GADGETDOWN:
  344.                         switch (curgadget->GadgetID)
  345.                {
  346.                case  UPGADGET:
  347.                                      topline--; 
  348.                                      if (topline <= 0)
  349.                         { topline = 0;
  350.                           break;
  351.                          }
  352.                      vpot = KnobInfo.VertPot - linesize;
  353.                      if (vpot < 0) vpot = 0;  
  354.                      PrintPage(hlpwin,text,topline,nlines);    
  355.                      ModifyProp(&scroll_control,hlpwin,NULL,
  356.                     flags,0L,vpot,0L,vbody);
  357.                                      break;
  358.                                      
  359.                            case DOWNGADGET:
  360.                                      topline++; 
  361.                                      if (topline >= nlines-17) 
  362.                                         { topline = nlines-17;
  363.                                           break;
  364.                                         }
  365.                      vpot = KnobInfo.VertPot + linesize;
  366.                      if (vpot > 0xFFFF) vpot = 0xFFFF; 
  367.                      PrintPage(hlpwin,text,topline,nlines);    
  368.                      ModifyProp(&scroll_control,hlpwin,NULL,
  369.                     flags,0L,vpot,0L,vbody);
  370.                                      break;    
  371.                    } /* end of gadget switch */
  372.                        break;
  373.  
  374.                    } /* end of class switch */
  375.     } /* end while-not finished  main loop */
  376.  
  377.     CloseWindow(hlpwin);
  378.     return(TRUE);
  379.     
  380. } /* end of do_help_req */
  381.  
  382.  
  383. /*********** print out the next set of lines ********/
  384. PrintPage(win,text,topline, maxline)
  385. struct Window *win;
  386. char *text[];
  387. SHORT topline,maxline;
  388. {
  389.    SHORT i, j;
  390.    /* clear the screen */
  391.    SetAPen(win->RPort,0L);   
  392.    RectFill(win->RPort,2L,11L,625L,188L);
  393.             
  394.    /* put out some text */
  395.    SetAPen(win->RPort,1L);
  396.    for (i = topline, j = 0;j < 19 && i < maxline; j++, i++)
  397.       {
  398.     Move(win->RPort,5L,(LONG)((j*9)+20));
  399.     Text(win->RPort,text[i],(LONG)strlen(text[i]));
  400.       }
  401.   
  402. } /* end of PrintPage */
  403.  
  404.  
  405. PrintHelp(filename)
  406. UBYTE *filename;
  407. {
  408.   FILE *outfile, *fopen();
  409.   ULONG saveflags;
  410.   SHORT i;
  411.  
  412.   outfile = fopen(filename,"w");
  413.   if (outfile == NULL) return(-1);
  414.  
  415.   do_Snooze(w); /* put up a sleepy cloud pointer */
  416.   
  417.   saveflags = w->IDCMPFlags;
  418.  
  419.   ModifyIDCMP(w,0L); /* block intuition messages */
  420.  
  421. /*  ABOUT STARCHART help */
  422.   for(i=0; i<abouthelplines; i++)
  423.      fprintf(outfile,"%s\n",abouthelptext[i]);
  424.   fprintf(outfile,"\n\n\n");
  425.  
  426. /*  project menu help */
  427.   for(i=0; i<projhelplines; i++)
  428.      fprintf(outfile,"%s\n",projhelptext[i]);
  429.   fprintf(outfile,"\n\n\n");
  430.  
  431. /* parameters menu help */
  432.   for(i=0; i<parmhelplines; i++)
  433.      fprintf(outfile,"%s\n",parmhelptext[i]);
  434.   fprintf(outfile,"\n\n\n");
  435.  
  436. /* options menu help */
  437.   for(i=0; i<opthelplines; i++)
  438.      fprintf(outfile,"%s\n",opthelptext[i]);
  439.   fprintf(outfile,"\n\n\n");
  440.  
  441. /* constellations menu help */
  442.   for(i=0; i<conshelplines; i++)
  443.      fprintf(outfile,"%s\n",conshelptext[i]);
  444.   fprintf(outfile,"\n\n\n");
  445.  
  446.  
  447.   fclose(outfile);
  448.  
  449.   ModifyIDCMP(w,saveflags); /* restore intuition messages */
  450.   
  451.   do_StarSprite(w); /* put back the star pointer */
  452.   
  453.   return(0);
  454. }