home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c040 / 1.ddi / SAMPLES / CHRTOPT.C$ / CHRTOPT.bin
Encoding:
Text File  |  1990-02-27  |  24.8 KB  |  916 lines

  1. /* CHRTOPT.C - Options module for presentation graphics demonstration
  2.  * program.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <conio.h>
  7. #include <string.h>
  8. #include <graph.h>
  9. #include <pgchart.h>
  10. #include "chrtdemo.h"
  11.  
  12. /* Structures for system configuration and chart environment. */
  13. extern struct videoconfig vc;
  14. extern chartenv ce;
  15.  
  16. /* Variable used to track control and screen position.  */
  17. extern struct SCREENINFO si;
  18.  
  19. /* Colors of menus and prompts. */
  20. extern struct tagColor co;
  21.  
  22. /* Arrays of strings used by the Menu function. The first string is the
  23.  * menu title. The next non-null strings are the menu selections. A null
  24.  * string indicates the end of the list.
  25.  */
  26. char *pszAxes[] =
  27.     { "Axis", "X Axis", "Y Axis", "" };
  28.  
  29. char *pszAxis[] =
  30.     { "? Options", "Grid", "Axis Title", "Color",
  31.       "Range Type", "Scale", "Tic Marks", "" };
  32.  
  33. char *pszAuto[] =
  34.     { "Auto", "Auto", "Manual", "" };
  35.  
  36. char *pszBorder[] =
  37.     { "Type", "Color", "Style", "" };
  38.  
  39. char *pszChartWindow[] =
  40.     { "Chart", "Size", "Color (Background)", "Border", "" };
  41.  
  42. char *pszDataWindow[] =
  43.     { "Data", "Color (Background)", "Border", "" };
  44.  
  45. char * pszFontOpt[] =
  46.     { "Font Options", "Change Typeface", "Set Character Size", "" };
  47.  
  48. char *pszJustify[] =
  49.     { "Justify", "Left", "Center", "Right", "" };
  50.  
  51. char *pszLegendWindow[] =
  52.     { "Options", "Place", "Text Color", "Size", "Color (Background)",
  53.       "Border", "" };
  54.  
  55. char *pszPlace[] =
  56.     { "Place", "Right", "Bottom", "Overlay", "" };
  57.  
  58. char *pszScale[] =
  59.     { "Scale", "Low (Min)", "High (Max)", "Scale Factor", "Title", "" };
  60.  
  61. char *pszSize[] =
  62.     { "Size", "Top", "Left", "Bottom", "Right", "" };
  63.  
  64. char *pszTic[] =
  65.     { "Tic Type", "Interval", "Format", "Decimals", "" };
  66.  
  67. char *pszTitleOpt[] =
  68.     { "", "Text", "Color", "Justify", "" };
  69.  
  70. char *pszTitles[] =
  71.     { "Title", "Main Title", "Sub Title", "" };
  72.  
  73. char *pszTypeface[] =
  74.     { "Type Faces", "Courier", "Helv", "Tms Rmn", "Modern", "Script",
  75.            "Roman", "None", "" };
  76.  
  77. char *pszWindows[] =
  78.     { "Window", "Chart Window", "Data Window", "" };
  79.  
  80. /*  Axes - Selects X or Y axis.
  81.  *
  82.  *  Params: none
  83.  */
  84. void Axes()
  85. {
  86.     int iChoice;
  87.     static axistype *patAxis[2] = { &ce.xaxis, &ce.yaxis };
  88.  
  89.     /* Get menu choice and call appropriate axis Menu. */
  90.     PushTitle( pszAxes[0] );
  91.     Help( "Choose 'X' or 'Y' Axis", co.InputColor );
  92.     while( (iChoice = Menu( pszAxes )) != ESCAPE )
  93.     {
  94.         /* Modify axis title, depending on choice. */
  95.         pszAxis[0][0] = (--iChoice == 0) ? 'X' : 'Y';
  96.  
  97.         /* Obtain axis information for appropriate axis. */
  98.         Axis( patAxis[iChoice] );
  99.     }
  100.     PopTitle();
  101. }
  102.  
  103. /*  Axis - Selects axis options.
  104.  *
  105.  *  Params: pat - Pointer to axistype variable
  106.  */
  107. void Axis( axistype *pat )
  108. {
  109.     int iChoice;
  110.  
  111.     PushTitle( pszAxis[0] );
  112.     while( (iChoice = Menu( pszAxis )) != ESCAPE )
  113.     {
  114.  
  115.         /* Get Axis option.  */
  116.         switch( iChoice )
  117.         {
  118.             case 1:
  119.                 /* Grid or not? */
  120.                 iChoice = BlankMenu( "Grid", "Grid", "No Grid" );
  121.                 switch( iChoice )
  122.                 {
  123.  
  124.                     case 1:
  125.                         /* If yes, set grid flag and get the grid style. */
  126.                         pat->grid = TRUE;
  127.                         Help( "Enter a number in the range 0-10.",
  128.                               co.InputColor );
  129.                         pat->gridstyle =
  130.                             InputInt( "Grid Style? ", pat->gridstyle, 0, 10 );
  131.                         break;
  132.  
  133.                     case 2:
  134.                         /* If no, clear grid flag.  */
  135.                         pat->grid = FALSE;
  136.                 }
  137.                 PopTitle();
  138.                 break;
  139.  
  140.             case 2:
  141.                 /* Select axis title options. */
  142.                 pszTitleOpt[0] = "Axis Title";
  143.                 TitleOpt( &pat->axistitle );
  144.                 break;
  145.  
  146.             case 3:
  147.                 /* Select color. */
  148.                 Help( "Enter a number in the range 0-15.", co.InputColor );
  149.                 pat->axiscolor =
  150.                     InputInt( "Axis Color? ", pat->axiscolor, 0, 15 );
  151.                 break;
  152.  
  153.             case 4:
  154.                 /* Get the axis range.  */
  155.                 AxisRange( pat );
  156.                 break;
  157.  
  158.             case 5:
  159.                 /* Get the axis scale.  */
  160.                 AxisScale( pat );
  161.                 break;
  162.  
  163.             case 6:
  164.                 /* Get axis tic mark options.  */
  165.                 AxisTics( pat );
  166.                 break;
  167.  
  168.         }
  169.     }
  170.     PopTitle();
  171. }
  172.  
  173. /*  AxisRange - Selects range for an axis.
  174.  *
  175.  *  Params: pat - pointer to axistype variable
  176.  */
  177. void AxisRange( axistype *pat )
  178. {
  179.     int iChoice;
  180.  
  181.     iChoice = BlankMenu( "Range Type", "Normal", "Log" );
  182.     switch( iChoice )
  183.     {
  184.         case 1:
  185.             /* Set range type to linear.  */
  186.             pat->rangetype = _PG_LINEARAXIS;
  187.             break;
  188.  
  189.         case 2:
  190.             /* Set range type to log, then query for log base.  */
  191.             pat->rangetype = _PG_LOGAXIS;
  192.             Help( "Enter a value greater than or equal 2.", co.InputColor );
  193.             pat->logbase = (float)InputInt( "Log base? ",
  194.                                             (int)pat->logbase, 2, 0 );
  195.             break;
  196.     }
  197.     PopTitle();
  198. }
  199.  
  200. /*  AxisScale - Selects scale options for an axis.
  201.  *
  202.  *  Params: pat - pointer to axistype variable
  203.  */
  204. void AxisScale( axistype *pat )
  205. {
  206.     int iChoice;
  207.  
  208.     PushTitle( pszAuto[0] );
  209.     iChoice = Menu( pszAuto );
  210.     switch( iChoice )
  211.     {
  212.  
  213.         case 1:
  214.             /* Set AutoScale flag.  */
  215.             pat->autoscale = TRUE;
  216.             break;
  217.  
  218.         case 2:
  219.  
  220.             /* Clear AutoScale flag and get scale options.  */
  221.             pat->autoscale = FALSE;
  222.             PushTitle( pszScale[0] );
  223.             while( (iChoice = Menu( pszScale )) != ESCAPE )
  224.             {
  225.  
  226.                 switch( iChoice )
  227.                 {
  228.  
  229.                     case 1:  
  230.                         /* Query for scale minimum.  */
  231.                         Help( "Enter the range minimum value.", co.InputColor );
  232.                         pat->scalemin =
  233.                             (float)InputInt( "Minimum? ",
  234.                                              (int)pat->scalemin, 1, 0 );
  235.                         break;
  236.  
  237.                     case 2:  
  238.                         /* Query for scale maximum.  */
  239.                         Help( "Enter the range maximum value.", co.InputColor );
  240.                         pat->scalemin =
  241.                             (float)InputInt( "Minimum? ",
  242.                                              (int)pat->scalemin, 1, 0 );
  243.                         break;
  244.  
  245.                     case 3:
  246.                         /* Query for scale factor.  */
  247.                         Help( "Enter scale factor (must be 1 or greater).",
  248.                                  co.InputColor );
  249.                         pat->scalefactor =
  250.                             (float)InputInt( "Scale Factor? ",
  251.                                              (int)pat->scalefactor, 1, 0 );
  252.                         break;
  253.  
  254.                     case 4:  
  255.                         /* Modify scale title, then use menu to get
  256.                          * title options.
  257.                          */
  258.                         pszTitleOpt[0] = "Scale Title";
  259.                         TitleOpt( &pat->scaletitle );
  260.  
  261.                 }
  262.             }
  263.             PopTitle();
  264.     }
  265.     PopTitle();
  266. }
  267.  
  268. /*  AxisTics - Selects tic options for an axis.
  269.  *
  270.  *  Params: pat - pointer to axistype variable
  271.  */
  272. void AxisTics( axistype *pat )
  273. {
  274.     int iChoice;
  275.  
  276.     PushTitle( pszTic[0] );
  277.     while( (iChoice = Menu( pszTic )) != ESCAPE )
  278.     {
  279.         switch( iChoice )
  280.         {
  281.  
  282.             case 1:
  283.                 /* Query for tic interval.  */
  284.                 Help( "Enter distance in data units.", co.InputColor );
  285.                 pat->ticinterval =
  286.                     InputFloat( "Distance between tic marks? ",
  287.                                pat->ticinterval );
  288.                 pat->autoscale = FALSE;
  289.                 break;
  290.  
  291.             case 2:
  292.                 /* Query for tic format.  */
  293.                 iChoice = BlankMenu( "Tic Format", "Normal", "Log" );
  294.                 if( iChoice != ESCAPE )
  295.                     pat->ticformat = iChoice;
  296.                 break;
  297.  
  298.             case 3:
  299.                 /* Query for number of decimal places per tic.  */
  300.                 pat->ticdecimals =
  301.                     InputInt( "Enter decimal places (0 to 9). ",
  302.                                pat->ticdecimals, 0, 9 );
  303.                 pat->autoscale = FALSE;
  304.                 break;
  305.         }
  306.  
  307.     }
  308.     PopTitle();
  309. }
  310.  
  311. /*  Border - Specifies border information for a window.
  312.  *
  313.  *  Params: pwt - Pointer to windowtype variable
  314.  */
  315. void Border( windowtype *pwt )
  316. {
  317.     int iChoice;
  318.  
  319.     /* Ask whether a border is wanted.  */
  320.     iChoice = BlankMenu( "Border", "Border", "No Border" );
  321.     switch( iChoice )
  322.     {
  323.  
  324.         case 1:
  325.  
  326.             /* If border, set Border flag and query for border options.  */
  327.             pwt->border= TRUE;
  328.             PushTitle( pszBorder[0] );
  329.             while( (iChoice = Menu( pszBorder )) != ESCAPE )
  330.             {
  331.                 switch( iChoice )
  332.                 {
  333.                     case 1:
  334.                         /* Query for border color.  */
  335.                         Help( "Enter a color in the range 0-15.",
  336.                             co.InputColor );
  337.                         pwt->bordercolor =
  338.                             InputInt( "Border color? ",
  339.                                        pwt->bordercolor, 0, 15 );
  340.                         break;
  341.  
  342.                     case 2:
  343.                         /* Query for border style.  */
  344.                         Help( "Enter a style in the range 0-10.", co.InputColor );
  345.                         pwt->borderstyle =
  346.                             InputInt( "Border style? ",
  347.                                        pwt->borderstyle, 0, 10 );
  348.                 }
  349.             }
  350.             PopTitle();
  351.             break;
  352.  
  353.         case 2:
  354.             /* If no border, clear Border flag.  */
  355.             pwt->border= FALSE;
  356.     }
  357.     PopTitle();
  358. }
  359.  
  360. /*  ChangeTypeface - Allow the user to specify a new type face.
  361.  *
  362.  *  Params: iFaceIndex - index of last typeface
  363.  *
  364.  *  Return: index of new typeface
  365.  */
  366.  
  367. int ChangeTypeface( int iFaceIndex )
  368. {
  369.     int iChoice;
  370.  
  371.     /* Get menu choice and call appropriate axis Menu. */
  372.     PushTitle( pszFontOpt[0] );
  373.     Help( "Choose one of the type faces listed.", co.InputColor );
  374.  
  375.     if( (iChoice = Menu( pszTypeface ) - 1) != ESCAPE )
  376.     {
  377.         /* If the user wants the system font, unregister the other fonts. */
  378.         if( iChoice == NOFONT )
  379.             _unregisterfonts();
  380.  
  381.         /* If the user wants any font but the system font, make sure the
  382.          *   fonts are registered.
  383.          */
  384.         else
  385.         {
  386.             /* If last face was NOFONT, register fonts. */
  387.             if( iFaceIndex == NOFONT )
  388.             {
  389.                 /* Assumes font files are in current directory.
  390.                  * Could be enhanced to handle any directory.
  391.                  */
  392.                 if( _registerfonts( "*.FON" ) < 0 )
  393.                     ErrorMsg( "Font files must be in current directory" );
  394.                 else
  395.                     iFaceIndex = iChoice;
  396.             }
  397.             else
  398.                 iFaceIndex = iChoice;
  399.         }
  400.     }
  401.  
  402.     PopTitle();
  403.     return iFaceIndex;
  404. }
  405.  
  406. /*  ChooseFont - Chooses a font from the font library.
  407.  *
  408.  *  Params: WhichFont - A member of the set [COURIER, HELV, TMS_RMN,
  409.  *                        MODERN, SCRIPT, ROMAN, NOFONT]
  410.  *          Height    - The desired height of the text (in pixels)
  411.  */
  412.  
  413. void ChooseFont( int WhichFont, int Height )
  414. {
  415.     static char *FontIds[] =
  416.     {
  417.         "courier", "helv", "tms rmn", "modern", "script", "roman"
  418.     };
  419.     char SetCommand[30];
  420.  
  421.     /* Construct the command to send to _setfont. */
  422.     sprintf( SetCommand, "t'%s'h%dw0b", FontIds[WhichFont], Height );
  423.  
  424.     if( _setfont( SetCommand ) < 0 )
  425.     {
  426.         _outtext( "Could not set. Try different font or size" );
  427.         getch();
  428.     }
  429. }
  430.  
  431. /*  ChartWindow - Gets chart window information.
  432.  *
  433.  *  Params: None
  434.  */
  435. void ChartWindow()
  436. {
  437.     int iChoice;
  438.  
  439.     PushTitle( pszChartWindow[0] );
  440.     while( (iChoice = Menu( pszChartWindow )) != ESCAPE )
  441.     {
  442.  
  443.         /* Get window options.  */
  444.         switch( iChoice )
  445.         {
  446.  
  447.             case 1:
  448.                 /* Get window size.  */
  449.                 WindowSize( &ce.chartwindow );
  450.                 break;
  451.  
  452.             case 2:
  453.                 /* Query for background color.  */
  454.                 Help( "Enter a number in the range 0-15", co.InputColor );
  455.                 ce.chartwindow.background =
  456.                     InputInt( "Background Color? ", ce.chartwindow.background,
  457.                               0, 15 );
  458.                 break;
  459.  
  460.             case 3:
  461.  
  462.                 /* Get border options.  */
  463.                 Border( &ce.chartwindow );
  464.  
  465.         }
  466.     }
  467.     PopTitle();
  468. }
  469.  
  470. /*  DataWindow - Geta data window information.
  471.  *
  472.  *  Params: None
  473.  */
  474. void DataWindow()
  475. {
  476.     int iChoice;
  477.  
  478.     PushTitle( pszDataWindow[0] );
  479.     while( (iChoice = Menu( pszDataWindow )) != ESCAPE )
  480.     {
  481.  
  482.         /* Get data window menu options.  */
  483.         switch( iChoice )
  484.         {
  485.  
  486.             case 1: 
  487.                 /* Query for background color.  */
  488.                 Help( "Enter a number in the range 0-15", co.InputColor );
  489.                 ce.datawindow.background =
  490.                     InputInt( "Background Color? ",
  491.                                ce.datawindow.background,
  492.                                0, 15 );
  493.                 break;
  494.  
  495.             case 2:
  496.                 /* Get border options.  */
  497.                 Border( &ce.datawindow );
  498.                 break;
  499.  
  500.         }
  501.     }
  502.     PopTitle();
  503. }
  504.  
  505. /*  FontOptions - Allows the user to modify the font used for display.
  506.  *
  507.  *  Params: None
  508.  */
  509.  
  510. void FontOptions()
  511. {
  512.     int iChoice;
  513.     static int iFaceIndex = NOFONT;
  514.     static int iTypeSize = 8;
  515.  
  516.     /* Get menu choice and call appropriate axis Menu. */
  517.     PushTitle( pszFontOpt[0] );
  518.  
  519.     while( (iChoice = Menu( pszFontOpt )) != ESCAPE )
  520.     {
  521.         switch( iChoice )
  522.         {
  523.             /* Change Typeface. */
  524.             case 1:
  525.                 iFaceIndex = ChangeTypeface( iFaceIndex );
  526.                 ChooseFont( iFaceIndex, iTypeSize );
  527.                 break;
  528.  
  529.             /* Change Type Size. */
  530.             case 2:
  531.  
  532.                 if( iFaceIndex == NOFONT )
  533.                 {
  534.                     ErrorMsg( "Select a font first" );
  535.                     break;
  536.                 }
  537.  
  538.                 iTypeSize = InputInt( "Enter a type size. ", iTypeSize,
  539.                                        8, 128 );
  540.  
  541.                 ChooseFont( iFaceIndex, iTypeSize );
  542.                 break;
  543.  
  544.             default:
  545.                 break;
  546.         }
  547.     }
  548.     PopTitle();
  549. }
  550.  
  551. /*  Justify - Gets title justification option.
  552.  *
  553.  *  Params: Pointer to titletype variable
  554.  */
  555. void Justify( titletype *ptt )
  556. {
  557.     int iChoice;
  558.  
  559.     PushTitle( pszJustify[0] );
  560.     iChoice = Menu( pszJustify );
  561.     switch( iChoice )
  562.     {
  563.  
  564.         /* Set justification.  */
  565.         case 1:
  566.         case 2:
  567.         case 3:
  568.             ptt->justify = iChoice;
  569.     }
  570.     PopTitle();
  571. }
  572.  
  573. /*  Legend - Asks whether a legend is desired, and if so, gets
  574.  *  legend options.
  575.  *
  576.  *  Params: None
  577.  */
  578. void Legend()
  579. {
  580.     int iChoice;
  581.  
  582.     /* Is legend desired?  */
  583.     iChoice = BlankMenu( "Legend", "Legend", "No Legend" );
  584.     switch( iChoice )
  585.     {
  586.         case 1:
  587.             /* If legend, set legend flag and get options.  */
  588.             ce.legend.legend = TRUE;
  589.             PushTitle( pszLegendWindow[0] );
  590.             do
  591.             {
  592.                 iChoice = Menu( pszLegendWindow );
  593.                 switch( iChoice )
  594.                 {
  595.  
  596.                     case 1:
  597.                         /* Get legend place.  */
  598.                         LegendPlace();
  599.                         break;
  600.  
  601.                     case 2:
  602.                         /* Query for legend color.  */
  603.                         Help( "Enter a number in the range 0-15.", co.InputColor );
  604.                         ce.legend.textcolor =
  605.                             InputInt( "Text color? ",
  606.                                        ce.legend.textcolor,
  607.                                        0, 15 );
  608.                         break;
  609.  
  610.                     case 3:
  611.                         /* Get auto or manual sizing.  */
  612.                         PushTitle( "Auto Legend" );
  613.                         iChoice = Menu( pszAuto );
  614.  
  615.                         /* Set or clear the autosize flag. If manual
  616.                          * sizing was selected, get legend size.
  617.                          */
  618.                         switch( iChoice )
  619.                         {
  620.                             case 1:
  621.                                 ce.legend.autosize = TRUE;
  622.                                 break;
  623.  
  624.                             case 2:
  625.                                 ce.legend.autosize = FALSE;
  626.                                 WindowSize( &ce.legend.legendwindow );
  627.                         }
  628.                         PopTitle();
  629.                         break;
  630.  
  631.                     case 4:
  632.                         /* Query for background color.  */
  633.                         Help( "Type a number in the range 0-15.", co.InputColor );
  634.                         ce.legend.legendwindow.background =
  635.                             InputInt( "Background color? ",
  636.                                        ce.legend.legendwindow.background,
  637.                                        0, 15 );
  638.                         break;
  639.  
  640.                     case 5:
  641.                         /* Get border options for legend window.  */
  642.                         Border( &ce.legend.legendwindow );
  643.                 }
  644.  
  645.             } while( iChoice != ESCAPE );
  646.             PopTitle();
  647.             break;
  648.  
  649.         case 2:
  650.             /* If no legend wanted, clear flag.  */
  651.             ce.legend.legend = FALSE;
  652.  
  653.     }
  654.     PopTitle();
  655. }
  656.  
  657. /*  LegendPlace - Gets legend placement option.
  658.  *
  659.  *  Params: None
  660.  */
  661. void LegendPlace()
  662. {
  663.     int iChoice;
  664.  
  665.     /* Get legend placement.  */
  666.     PushTitle( pszPlace[0] );
  667.     iChoice = Menu( pszPlace );
  668.     switch( iChoice )
  669.     {
  670.  
  671.         case 1:
  672.             ce.legend.place = _PG_RIGHT;
  673.             break;
  674.  
  675.         case 2:
  676.             ce.legend.place = _PG_BOTTOM;
  677.             break;
  678.  
  679.         case 3:
  680.             ce.legend.place = _PG_OVERLAY;
  681.     }
  682.     PopTitle();
  683. }
  684.  
  685. /*  ScreenMode - Gets a new screen mode.
  686.  *
  687.  *  Params: None
  688.  */
  689. void ScreenMode()
  690. {
  691.     int iMode, i;
  692.     char szTmp[80], szHlp[80];
  693.     static int iLegal[5][11] =
  694.     {
  695.         { 3, 4, 5, 6 },
  696.         { 4, 4, 5, 6, 64 },
  697.         { 4, 4, 5, 6, 19 },
  698.         { 7, 4, 5, 6, 13, 14, 15, 16 },
  699.         { 10, 4, 5, 6, 13, 14, 15, 16, 17, 18, 19 }
  700.     };
  701.     int iAdaptor;
  702.  
  703.     PushTitle( "Screen Mode" );
  704.  
  705.     /* Show appropriate help line for adaptor.  */
  706.     switch( vc.adapter )
  707.     {
  708.         case _HGC:
  709.             PopTitle();
  710.             return;
  711.         case _CGA:
  712.             iAdaptor = 0;
  713.             break;
  714.         case _OCGA:
  715.             iAdaptor = 1;
  716.             break;
  717.         case _MCGA:
  718.             iAdaptor = 2;
  719.             break;
  720.         case _EGA:
  721.         case _OEGA:
  722.             if( vc.adapter == _MONO )
  723.             {
  724.                 PopTitle();
  725.                 return;
  726.             }
  727.             else
  728.                 iAdaptor = 3;
  729.             break;
  730.         case _VGA:
  731.         case _OVGA:
  732.             iAdaptor = 4;
  733.             break;
  734.     }
  735.  
  736.     /* Form the help line (which gives the choices legal for
  737.      * the adaptor sensed in the user's machine).
  738.      */
  739.     for( iMode = 0, szHlp[0] = '\0'; iMode <= iLegal[iAdaptor][0]; ++iMode )
  740.     {
  741.         if( iMode == 0 )
  742.             strcpy( szTmp, "Enter " );
  743.         else if( iMode < iLegal[iAdaptor][0] )
  744.             sprintf( szTmp, "%d, ", iLegal[iAdaptor][iMode] );
  745.         else
  746.             sprintf( szTmp, "or %d", iLegal[iAdaptor][iMode] );
  747.         strcat( szHlp, szTmp );
  748.     }
  749.  
  750.     WrtForm( 18 );
  751.     Help( szHlp, co.InputColor );
  752.  
  753.     /* Query for screen mode. */
  754.     for( ;; )
  755.     {
  756.         iMode = InputInt( "Screen Mode? ", si.mode, 1, 64 );
  757.         for( i = 1; i <= iLegal[iAdaptor][0]; ++i ) /* Test legal values    */
  758.             if( iMode == iLegal[iAdaptor][i] )      /* If a match is found  */
  759.                 break;                              /* Terminate for loop   */
  760.         if( iMode == iLegal[iAdaptor][i] )          /* If it's a match,     */
  761.             break;                                  /* terminate do loop,   */
  762.         else                                        /* otherwise BEEP, and  */
  763.             putchar( BEEP );                        /* solicit correct data */
  764.     }
  765.  
  766.     PopTitle();
  767.     if( SetGraphMode( iMode ) )
  768.         _setvideomode( _DEFAULTMODE );
  769.     else
  770.         ShowError( _PG_BADSCREENMODE );
  771.  
  772.     /* Force rescaling of the chart by resetting the window
  773.      * rectangles for the chart and data windows to zero size.
  774.      */
  775.     ce.chartwindow.x1 = ce.chartwindow.x2 = ce.chartwindow.y1 =
  776.         ce.chartwindow.y2 = 0;
  777.     ce.datawindow = ce.chartwindow;
  778. }
  779.  
  780. /*  TitleOpt - Gets title options.
  781.  *
  782.  *  Params: ptt - Pointer to titletype variable
  783.  */
  784. void TitleOpt( titletype *ptt )
  785. {
  786.     int iChoice;
  787.  
  788.     PushTitle( pszTitleOpt[0] );
  789.     do
  790.     {
  791.         iChoice = Menu( pszTitleOpt );
  792.         switch( iChoice )
  793.         {
  794.  
  795.             case 1: 
  796.                 /* Query for title text.  */
  797.                 Help( "70 characters maximum length.", co.InputColor );
  798.                 InputStr( "Enter Text: ", ptt->title );
  799.                 break;
  800.  
  801.             case 2: 
  802.                 /* Query for title color color.  */
  803.                 Help( "Enter a number in the range 0-15.", co.InputColor );
  804.                 ptt->titlecolor =
  805.                     InputInt( "Title Color? ", ptt->titlecolor, 0, 15 );
  806.                 break;
  807.  
  808.             case 3:
  809.                 /* Get justify option.  */
  810.                 Justify( ptt );
  811.         }
  812.         ClrHelp();
  813.  
  814.     } while( iChoice != ESCAPE );
  815.     PopTitle();
  816. }
  817.  
  818. /*  Titles - Manages Main and Sub title menus.
  819.  *
  820.  *  Params: None
  821.  */
  822. void Titles()
  823. {
  824.     int iChoice;
  825.  
  826.     PushTitle( pszTitles[0] );
  827.     do
  828.     {
  829.         iChoice = Menu( pszTitles );
  830.         switch( iChoice )
  831.         {
  832.  
  833.             case 1:
  834.                 /* Fix menu title and get options for main title.  */
  835.                 pszTitleOpt[0] = "MainTitle";
  836.                 TitleOpt( &ce.maintitle );
  837.                 break;
  838.  
  839.             case 2:
  840.                 /* Fix menu title and get options for subtitle.  */
  841.                 pszTitleOpt[0] = "Sub Title";
  842.                 TitleOpt( &ce.subtitle );
  843.         }
  844.     } while( iChoice != ESCAPE );
  845.     PopTitle();
  846. }
  847.  
  848. /*  Windows - Selects chart or data window, and gets options for either.
  849.  *
  850.  *  Params: None
  851.  */
  852. void Windows()
  853. {
  854.     int iChoice;
  855.  
  856.     PushTitle( pszWindows[0] );
  857.     do
  858.     {
  859.  
  860.         /* Select window and get options for it.  */
  861.         iChoice = Menu( pszWindows );
  862.         switch( iChoice )
  863.         {
  864.  
  865.             case 1:
  866.                 ChartWindow();
  867.                 break;
  868.  
  869.             case 2:
  870.                 DataWindow();
  871.  
  872.         }
  873.     } while( iChoice != ESCAPE );
  874.     PopTitle();
  875. }
  876.  
  877. /*  WindowSize - Gets coordinates for window location and size.
  878.  *
  879.  *  Params: pwt - pointer to windowtype variable
  880.  */
  881. void WindowSize( windowtype *pwt )
  882. {
  883.     int iChoice;
  884.  
  885.     /* Get window size settings.  */
  886.     PushTitle( pszSize[0] );
  887.     do
  888.     {
  889.         /* Query for top, bottom, left, or right of window.  */
  890.         iChoice = Menu( pszSize );
  891.         switch( iChoice )
  892.         {
  893.  
  894.             case 1:
  895.                 Help( "Enter window top in pixels.", co.InputColor );
  896.                 pwt->y1 = InputInt( "Top? ", pwt->y1, 0, si.yMax );
  897.                 break;
  898.  
  899.             case 2:
  900.                 Help( "Enter window Left in pixels.", co.InputColor );
  901.                 pwt->x1 = InputInt( "Left? ", pwt->x1, 0, si.xMax );
  902.                 break;
  903.  
  904.             case 3:
  905.                 Help( "Enter window bottom in pixels.", co.InputColor );
  906.                 pwt->y2 = InputInt( "Bottom? ", pwt->y2, 0, si.yMax );
  907.                 break;
  908.  
  909.             case 4:
  910.                 Help( "Enter window right in pixels.", co.InputColor );
  911.                 pwt->x2 = InputInt( "Right? ", pwt->x2, 0, si.xMax );
  912.         }
  913.     } while( iChoice != ESCAPE );
  914.     PopTitle();
  915. }
  916.