home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FGDEMO40.ZIP / SOURCE.COM / FGDEMO.C < prev    next >
Text File  |  1995-02-12  |  13KB  |  430 lines

  1. /**********************************************************************\
  2. *                                                                      *
  3. *  main.c -- Fastgraph (tm) and Fastgraph/Light (tm) demo program v4.0 *
  4. *                                                                      *
  5. *  This program is provided without warranty of any kind.  It may      *
  6. *  be distributed freely as long as the files are not modified.  You   *
  7. *  may use this source code in your own applications as long as it     *
  8. *  clearly understood that we are not responsible for any bugs in      *
  9. *  this code or in your code.  Use this code freely, use it in good    *
  10. *  health, but use it at your own risk.  Further disclaimers are       *
  11. *  listed at the end of this file.                                     *
  12. *                                                                      *
  13. *  This program requires Fastgraph 4.0 or Fastgraph/Light 4.0 to link. *
  14. *  Please call Ted Gruber Software at (702) 735-1980 for information   *
  15. *  about Fastgraph.                                                    *
  16. *                                                                      *
  17. \**********************************************************************/
  18.  
  19. #include "defs.h"
  20.  
  21. /**********************************************************************\
  22. *                                                                      *
  23. *                                 main                                 *
  24. *                                                                      *
  25. \**********************************************************************/
  26.  
  27. void main()
  28. {
  29.    int current;
  30.  
  31.    /* save the original video mode number */
  32.  
  33.    old_mode = fg_getmode();
  34.  
  35.    /* make sure the required video modes are available */
  36.  
  37.    if (fg_testmode(16,PAGES) == 0 || fg_testmode(20,4) == 0)
  38.       abort_program("This program requires VGA graphics.\n");
  39.  
  40.    /* benchmark the system speed */
  41.  
  42.    clockspeed = fg_measure();
  43.  
  44.    /* spawn the TGSDEMO program as a 320x200x256 intro to FGDEMO */
  45.  
  46.    if (exists("TGSDEMO.EXE") && exists("TGSDEMO.FGI"))
  47.       spawnlp(P_WAIT,"TGSDEMO.EXE",NULL);
  48.  
  49.    /* now switch to 640x350x16 graphics for the remainder of FGDEMO */
  50.  
  51.    initialize();
  52.  
  53.    /* read the 14pt bitmapped font */
  54.  
  55.    get_font();
  56.  
  57.    /* construct the main menu on the hidden page */
  58.  
  59.    current = 0;
  60.    draw_screen(current);
  61.  
  62.    /* display the main FGDEMO menu */
  63.  
  64.    fg_mousevis(OFF);
  65.    outward_tunnel_effect(clockspeed/8);
  66.  
  67.    /* and start the tour! */
  68.  
  69.    fg_mousevis(ON);
  70.    redraw = TRUE;
  71.    selection = 0;
  72.    horizontal_menu(main_menu,ITEMS,current);
  73.    terminate();
  74. }
  75.  
  76. /**********************************************************************\
  77. *                                                                      *
  78. *  draw_screen -- draw the main menu screen on the hidden page         *
  79. *                                                                      *
  80. \**********************************************************************/
  81.  
  82. void draw_screen(int current)
  83. {
  84.     int y2, y3;
  85.  
  86.     y2 = 21; y3 = 38;
  87.  
  88.    fg_mousevis(OFF);
  89.  
  90.     menu_top = y2 + 1;
  91.     menu_bottom = y3 + 1;
  92.  
  93.     /* erase the hidden page */
  94.  
  95.     background = 15;
  96.     fg_setpage(hidden);
  97.     fg_erase();
  98.  
  99.     /* draw some rectangles */
  100.  
  101.    fg_setcolor(15);
  102.    fg_rect(0,xlimit,0,ylimit);
  103.  
  104.    fg_setcolor(0);
  105.    fg_rect(0,xlimit,0,y2);
  106.  
  107.    /* draw the large dithered rectangles */
  108.  
  109.    fg_setcolor(9);
  110.    fg_drect(0,xlimit,0,20,matrix1);
  111.    fg_setcolor(11);
  112.    fg_drect(0,xlimit,39,ylimit,matrix2);
  113.  
  114.    /* put the title in the title bar */
  115.  
  116.    fg_setcolor(15);
  117.    center_pstring("Fastgraph Demo",0,xlimit,20);
  118.  
  119.    fg_setcolor(8);
  120.    fg_box(0,xlimit,0,ylimit);
  121.  
  122.    /* draw some black and grey outlines */
  123.  
  124.    fg_setcolor(7);
  125.    fg_boxdepth(2,2);
  126.    fg_box(1,xlimit-1,1,ylimit-1);
  127.    fg_boxdepth(1,1);
  128.  
  129.    fg_setcolor(0);
  130.    fg_box(3,xlimit-3,3,38);
  131.    fg_box(3,xlimit-3,3,ylimit-3);
  132.    fg_box(4,xlimit-4,3,ylimit-3);
  133.  
  134.    /* draw those little boxes in the corners */
  135.  
  136.    fg_setcolor(7);
  137.    fg_rect(5,25,4,20);
  138.    fg_rect(xlimit-25,xlimit-5,4,20);
  139.  
  140.    /* display the horizontal menu */
  141.  
  142.    horizontal_menu(main_menu,-ITEMS,current);
  143.    fg_setpage(visual);
  144. }
  145.  
  146. /**********************************************************************\
  147. *                                                                      *
  148. *  draw_window -- display a pop-up window                              *
  149. *                                                                      *
  150. \**********************************************************************/
  151.  
  152. void draw_window(int xmin,int xmax,int ymin,int ymax,char *string)
  153. {
  154.    register int y;
  155.  
  156.    /* display the window and its border */
  157.  
  158.    fg_setcolor(15);
  159.    fg_rect(xmin,xmax,ymin,ymax);
  160.    fg_setcolor(0);
  161.    fg_boxdepth(1,2);
  162.    fg_box(xmin,xmax,ymin,ymax);
  163.    fg_boxdepth(1,1);
  164.  
  165.    /* display the header bar at the top of the window */
  166.  
  167.    y = ymin + PTSIZE + 1;
  168.    fg_rect(xmin,xmax,ymin,y+1);
  169.  
  170.    /* dither the header bar */
  171.  
  172.    fg_setcolor(7);
  173.    fg_rect(xmin+2,xmin+22,ymin+1,y);
  174.    fg_rect(xmax-22,xmax-2,ymin+1,y);
  175.    fg_setcolor(9);
  176.    fg_drect(xmin+23,xmax-23,ymin+1,y,matrix1);
  177.  
  178.    /* display the text in the window's header bar */
  179.  
  180.    fg_setcolor(15);
  181.    center_pstring(string,xmin,xmax,y+1);
  182.  
  183.    /* display the window's shadow */
  184.  
  185.    fg_setcolor(8);
  186.  
  187.    fg_rect(xmin+3,xmax+3,ymax+1,ymax+2);
  188.    fg_rect(xmax+1,xmax+3,ymin+2,ymax);
  189. }
  190.  
  191. /**********************************************************************\
  192. *                                                                      *
  193. *  erase_window -- erase the previously displayed pop-up window        *
  194. *                                                                      *
  195. \**********************************************************************/
  196.  
  197. void erase_window(int xmin,int xmax,int ymin,int ymax)
  198. {
  199.    register int x1, x2;
  200.  
  201.    /* restore the original area underneath the window */
  202.  
  203.    x1 = xmin & 0xFFF8;
  204.    x2 = ((xmax+3) & 0xFFF8) + 7;
  205.    fg_mousevis(OFF);
  206.    fg_restore(x1,x2,ymin,ymax+2);
  207.  
  208.    /* redraw the dither pattern on the hidden page */
  209.  
  210.    fg_setpage(hidden);
  211.    fg_setcolor(15);
  212.    fg_rect(x1,x2,ymin,ymax+2);
  213.    fg_setcolor(11);
  214.    fg_drect(x1,x2,ymin,ymax+2,matrix2);
  215.  
  216.    fg_setpage(visual);
  217. }
  218.  
  219. /**********************************************************************\
  220. *                                                                      *
  221. *  get_answer -- accept a YES or NO answer from the keyboard or mouse  *
  222. *                                                                      *
  223. \**********************************************************************/
  224.  
  225. get_answer(int xmin,int xmax,int y)
  226. {
  227.    int color;
  228.    int count, lastx, lasty;
  229.    int return_value;
  230.    int x;
  231.    int x1, x2, y1, y2;
  232.    char yes_no[4];
  233.    unsigned char key, aux;
  234.  
  235.    /* if using a mouse, display the "Yes" and "No" buttons */
  236.  
  237.    if (mouse)
  238.    {
  239.       color = fg_getcolor();
  240.       x1 = ((3 * xmin) + xmax) / 4;
  241.       x2 = ((3 * xmax) + xmin) / 4;
  242.       y1 = y - PTSIZE/2 - 1;
  243.       y2 = y + PTSIZE/2 + 1;
  244.       fg_setcolor(0);
  245.       fg_boxdepth(1,2);
  246.       fg_box(x1-25,x1+25,y1,y2);
  247.       fg_box(x2-25,x2+25,y1,y2);
  248.       fg_boxdepth(1,1);
  249.       center_pstring("Yes",x1,x1,y2);
  250.       center_pstring("No",x2,x2,y2);
  251.       fg_setcolor(8);
  252.       fg_rect(x1-23,x1+27,y2+1,y2+2);
  253.       fg_rect(x1+26,x1+27,y1+2,y2);
  254.       fg_rect(x2-23,x2+27,y2+1,y2+2);
  255.       fg_rect(x2+26,x2+27,y1+2,y2);
  256.       fg_mousevis(ON);
  257.    }
  258.  
  259.    /* read keystrokes until Y, y, N, n, or Esc is pressed */
  260.  
  261.    flushkey();
  262.    for (;;)
  263.    {
  264.       fg_waitfor(2);
  265.       fg_intkey(&key,&aux);
  266.       key = (unsigned char)tolower(key);
  267.  
  268.       if (mouse)
  269.       {
  270.          fg_mousebut(1,&count,&lastx,&lasty);
  271.          if (BETWEEN(lastx,x1-25,x1+25) && BETWEEN(lasty,y1,y2))
  272.             key = 'y';
  273.          else if (BETWEEN(lastx,x2-25,x2+25) && BETWEEN(lasty,y1,y2))
  274.             key = 'n';
  275.       }
  276.  
  277.       if (key == 'y')
  278.       {
  279.          x = x1;
  280.          strcpy(yes_no,"Yes");
  281.          return_value = TRUE;
  282.          break;
  283.       }
  284.       else if (key == 'n' || key == ESC)
  285.       {
  286.          x = x2;
  287.          strcpy(yes_no,"No");
  288.          return_value = FALSE;
  289.          break;
  290.       }
  291.    }
  292.  
  293.    /* if using the mouse, flash the selected button */
  294.  
  295.    if (mouse)
  296.    {
  297.       fg_mousevis(OFF);
  298.       fg_setcolor(0);
  299.       fg_rect(x-23,x+23,y1+1,y2-1);
  300.       fg_setcolor(15);
  301.       center_pstring(yes_no,x,x,y2);
  302.       fg_waitfor(2);
  303.       fg_setcolor(15);
  304.       fg_rect(x-23,x+23,y1+1,y2-1);
  305.       fg_setcolor(0);
  306.       center_pstring(yes_no,x,x,y2);
  307.       fg_waitfor(2);
  308.       fg_setcolor(color);
  309.    }
  310.  
  311.    return(return_value);
  312. }
  313.  
  314. /**********************************************************************\
  315. *                                                                      *
  316. *  info_window -- display text information in a window                 *
  317. *                                                                      *
  318. \**********************************************************************/
  319.  
  320. void info_window(int xmin,int xmax,int ymin,char *string[],int nstrings)
  321. {
  322.    register int i;
  323.    int x, y;
  324.    int miny, maxy;
  325.    int len, maxlen;
  326.  
  327.    /* center text in window according to length of longest string */
  328.  
  329.    maxlen = 0;
  330.    for (i = 1; i < nstrings; i++)
  331.    {
  332.       len = length_pstring(string[i]);
  333.       if (len > maxlen) maxlen = len;
  334.    }
  335.  
  336.    /* calculate top and bottom of info window */
  337.  
  338.    miny = ymin;
  339.    maxy = miny + (nstrings+1) * (PTSIZE+1);
  340.  
  341.    /* draw the info window on the hidden page first */
  342.  
  343.    fg_setpage(hidden);
  344.  
  345.    /* draw the window and put the first string in the header bar */
  346.  
  347.    draw_window(xmin,xmax,miny,maxy,string[0]);
  348.  
  349.    /* calculate starting point for text */
  350.  
  351.    x = xmin + ((xmax - xmin) - maxlen) / 2;
  352.    y = miny + ((PTSIZE+1)*2) + PTSIZE/2;
  353.  
  354.    /* put all the strings in the rest of the window */
  355.  
  356.    fg_setcolor(0);
  357.    for (i = 1; i < nstrings; i++)
  358.    {
  359.       put_pstring(string[i],x,y);
  360.       y += PTSIZE+1;
  361.    }
  362.  
  363.    /* restore the window to the visual page */
  364.  
  365.    fg_setpage(visual);
  366.    fg_restore(xmin,xmax+3,miny,maxy+2);
  367.  
  368.    /* redraw the dither pattern on the hidden page */
  369.  
  370.    fg_setpage(hidden);
  371.    fg_setcolor(15);
  372.    fg_rect(xmin,xmax+3,miny,maxy+2);
  373.    fg_setcolor(11);
  374.    fg_drect(xmin,xmax+3,miny,maxy+2,matrix2);
  375.  
  376.    fg_setpage(visual);
  377.  
  378. }
  379.  
  380. /**********************************************************************\
  381. *                                                                      *
  382. *  outward_tunnel_effect                                               *
  383. *                                                                      *
  384. *  Starting at the screen center, reveal the hidden page contents      *
  385. *  through a series of concentric hollow rectangles.                   *
  386. *                                                                      *
  387. \**********************************************************************/
  388.  
  389. void outward_tunnel_effect(delay)
  390. int delay;
  391. {
  392.    int xmin, xmax;
  393.    int ymin, ymax;
  394.  
  395.    xmin = 312;
  396.    xmax = 327;
  397.    ymin = 170;
  398.    ymax = 179;
  399.  
  400.    while (xmin >= 0)
  401.    {
  402.       fg_restore(xmin,xmax,ymin,ymin+5);
  403.       fg_restore(xmax-7,xmax,ymin,ymax);
  404.       fg_restore(xmin,xmax,ymax-4,ymax);
  405.       fg_restore(xmin,xmin+7,ymin,ymax);
  406.       fg_stall(delay);
  407.  
  408.       xmin -= 8;
  409.       xmax += 8;
  410.       ymin -= 5;
  411.       ymax += 5;
  412.    }
  413. }
  414.  
  415. /**********************************************************************\
  416. *                                                                      *
  417. *                         Further Disclaimers                          *
  418. *                                                                      *
  419. * Under no circumstances shall Ted Gruber Software be liable for any   *
  420. * loss of profit or any other commercial damage, including but not     *
  421. * limited to special, incidental, consequential, or other damages      *
  422. * resulting from the use of or the inability to use the software,      *
  423. * even if Ted Gruber Software has been notified of the possiblity      *
  424. * of such damages. Ted Gruber Software disclaims all other warranties, *
  425. * either expressed or implied, regarding the merchantability or        *
  426. * fitness of this software and accompanying documentation for any      *
  427. * particular application or purpose.                                   *
  428. *                                                                      *
  429. \**********************************************************************/
  430.