home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / bcpp / file10 / fundmtls.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  14.7 KB  |  688 lines

  1. /**********************************************************************\
  2. *                                                                      *
  3. *  fundmtls.c -- graphics fundamentals: points, lines, rects, etc.     *
  4. *                                                                      *
  5. \**********************************************************************/
  6.  
  7. #include "defs.h"
  8.  
  9. /**********************************************************************\
  10. *                                                                      *
  11. *  do_boxes -- draw a bunch of hollow rectangles                       *
  12. *                                                                      *
  13. \**********************************************************************/
  14.  
  15. do_boxes()
  16. {
  17.    register int i,j;
  18.    int x0,x1,x2,y1,y2;
  19.    int xinc,yinc;
  20.    int color;
  21.  
  22.    x0 = 5;
  23.    x1 = x0;
  24.    xinc = (xlimit - x0 - 1) / 10;
  25.    x2 = x1 + xinc;
  26.  
  27.    yinc = (ylimit - menu_bottom) / 10;
  28.    y1 = menu_bottom;
  29.    y2 = y1 + yinc;
  30.  
  31.    color = 0;
  32.  
  33.    /* clear bottom part of screen */
  34.  
  35.    fg_mousevis(OFF);
  36.    fg_setcolor(15);
  37.    fg_rect(0,xlimit,menu_bottom,ylimit);
  38.  
  39.    /* draw 100 hollow rectangles */
  40.  
  41.    fg_mousevis(OFF);
  42.    fg_boxdepth(2,2);
  43.    for (i = 0; i < 10; i++)
  44.    {
  45.       for (j = 0; j < 10; j++)
  46.       {
  47.          fg_setcolor(color);
  48.          fg_box(x1,x2-1,y1,y2-1);
  49.  
  50.          color++;
  51.          if (color > 14) color = 0;
  52.  
  53.          x1 = x2;
  54.          x2 = x1 + xinc;
  55.       }
  56.       x1 = x0;
  57.       x2 = x1 + xinc;
  58.  
  59.       y1 = y2;
  60.       y2 = y1 + yinc;
  61.    }
  62.    fg_boxdepth(1,1);
  63.  
  64.    /* wait for a keystroke or mouse button */
  65.  
  66.    fg_mousevis(ON);
  67.    wait_for_keystroke();
  68.  
  69.    /* restore the screen and return to the menu */
  70.  
  71.    fg_mousevis(OFF);
  72.    fg_restore(0,xlimit,menu_bottom,ylimit);
  73.  
  74.    fg_mousevis(ON);
  75.    redraw = TRUE;
  76.  
  77.    return(OK);
  78. }
  79.  
  80. /**********************************************************************\
  81. *                                                                      *
  82. *  do_circles -- draw a bunch of circles                               *
  83. *                                                                      *
  84. \**********************************************************************/
  85.  
  86. do_circles()
  87. {
  88.    register int i;
  89.    int x1,x2,y1,y2;
  90.  
  91.    /* establish clipping limits */
  92.  
  93.    x1 = 0;
  94.    x2 = xlimit;
  95.    y1 = menu_bottom;
  96.    y2 = ylimit;
  97.  
  98.    fg_setclip(x1,x2,y1,y2);
  99.  
  100.    /* clear bottom part of screen */
  101.  
  102.    fg_mousevis(OFF);
  103.    if (mode06 || mode11)
  104.      fg_setcolor(0);
  105.    else
  106.      fg_setcolor(1);
  107.    fg_rect(x1,x2,y1,y2);
  108.  
  109.    /* move to the center of the screen */
  110.  
  111.    x1 = xlimit / 2;
  112.    y1 = (ylimit + menu_bottom) / 2;
  113.    fg_move(x1,y1);
  114.  
  115.    /* draw concentric circles */
  116.  
  117.    x2 = 4;
  118.    fg_setcolor(15);
  119.    for (i = 0; i < 25; i++)
  120.    {
  121.       fg_circle(x2);
  122.       x2 += 8;
  123.    }
  124.  
  125.    /* wait for a keystroke */
  126.  
  127.    fg_mousevis(ON);
  128.    wait_for_keystroke();
  129.  
  130.    /* restore clipping limits */
  131.  
  132.    fg_setclip(0,fg_getmaxx(),0,fg_getmaxy());
  133.  
  134.    /* restore the screen and return to the menu */
  135.  
  136.    fg_mousevis(OFF);
  137.    fg_restore(0,xlimit,menu_bottom,ylimit);
  138.  
  139.    fg_mousevis(ON);
  140.    redraw = TRUE;
  141.  
  142.    return(OK);
  143. }
  144.  
  145. /**********************************************************************\
  146. *                                                                      *
  147. *  do_clip -- do those lines, clipped to a small rectangle             *
  148. *                                                                      *
  149. \**********************************************************************/
  150.  
  151. int do_clip()
  152. {
  153.    register int i,j;
  154.    int x1,x2,y1,y2;
  155.    int xinc;
  156.  
  157.    static int lcolor[] = {2,1,9,11,11,9,1,2};
  158.  
  159.    /* establish clipping limits - small rectangle in middle of screen */
  160.  
  161.    fg_setclip(135,510,menu_bottom+55,ylimit-55);
  162.  
  163.    /* clear bottom of screen */
  164.  
  165.    fg_mousevis(OFF);
  166.    fg_restore(0,xlimit,menu_bottom,ylimit);
  167.    fg_setcolor(15);
  168.    fg_rect(135,510,menu_bottom+55,ylimit-55);
  169.  
  170.    /* draw horizontal lines */
  171.  
  172.    fg_setcolor(0);
  173.    for (i = menu_bottom; i < ylimit; i+=40)
  174.    {
  175.       for (j = 0; j < 8; j++)
  176.       {
  177.          if (mode14 || mode16)
  178.             fg_setcolor(lcolor[j]);
  179.  
  180.          y1 = i + 3*j;
  181.          fg_move(0,y1);
  182.          fg_draw(xlimit,y1);
  183.  
  184.       }
  185.    }
  186.  
  187.    /* draw vertical lines */
  188.  
  189.    y1 = menu_bottom;
  190.    y2 = ylimit;
  191.    for (i = 0; i < 640; i+=60)
  192.    {
  193.       for (j = 0; j < 8; j++)
  194.       {
  195.          if (mode14 || mode16)
  196.             fg_setcolor(lcolor[j]);
  197.  
  198.          x1 = i + 3*j;
  199.          fg_move(x1,y1);
  200.          fg_draw(x1,y2);
  201.       }
  202.    }
  203.  
  204.    /* draw red diagonal lines */
  205.  
  206.    y1 = menu_bottom;
  207.    y2 = ylimit;
  208.    xinc = ylimit - menu_bottom;
  209.    fg_setcolor(12);
  210.    for (x1 = -640; x1 < 640; x1+=60)
  211.    {
  212.       x2 = x1 + xinc;
  213.       fg_move(x1,y1);
  214.       fg_draw(x2,y2);
  215.    }
  216.  
  217.    y1 = menu_bottom;
  218.    y2 = ylimit;
  219.    xinc = ylimit - menu_bottom;
  220.  
  221.    /* draw red diagonal lines */
  222.  
  223.    fg_setcolor(4);
  224.    for (x1 = 0; x1 < 1280; x1+=60)
  225.    {
  226.       x2 = x1-xinc;
  227.       fg_move(x1,y1);
  228.       fg_draw(x2,y2);
  229.    }
  230.  
  231.    /* wait for a keystroke or mouse button */
  232.  
  233.    fg_mousevis(ON);
  234.    wait_for_keystroke();
  235.  
  236.    /* clear the screen and return to the menu */
  237.  
  238.    fg_mousevis(OFF);
  239.    fg_setclip(0,fg_getmaxx(),0,fg_getmaxy());
  240.    fg_restore(0,xlimit,menu_bottom,ylimit);
  241.  
  242.    fg_mousevis(ON);
  243.    redraw = TRUE;
  244.    return(OK);
  245. }
  246.  
  247. /**********************************************************************\
  248. *                                                                      *
  249. *  do_ellipses -- draw a bunch of elipses                              *
  250. *                                                                      *
  251. \**********************************************************************/
  252.  
  253. do_ellipses()
  254. {
  255.    register int i;
  256.    int x1,x2,x3,y1;
  257.  
  258.    /* clear the screen */
  259.  
  260.    fg_mousevis(OFF);
  261.    if (mode06 || mode11)
  262.      fg_setcolor(1);
  263.    else
  264.      fg_setcolor(9);
  265.    fg_rect(0,xlimit,menu_bottom,ylimit);
  266.  
  267.    /* move to the center of the screen */
  268.  
  269.    x1 = xlimit / 2;
  270.    y1 = (ylimit + menu_bottom) / 2;
  271.    fg_move(x1,y1);
  272.  
  273.    /* draw concentric ellipses */
  274.  
  275.    x2 = 4;
  276.    x3 = 1;
  277.    fg_setcolor(0);
  278.    for (i = 0; i < 80; i++)
  279.    {
  280.       fg_ellipse(x2,x3);
  281.       x2 += 3;
  282.       x3++;
  283.    }
  284.  
  285.    /* wait for a keystroke or mouse button */
  286.  
  287.    fg_mousevis(ON);
  288.    wait_for_keystroke();
  289.  
  290.    /* restore the screen and return to the menu */
  291.  
  292.    fg_mousevis(OFF);
  293.    fg_restore(0,xlimit,menu_bottom,ylimit);
  294.  
  295.    fg_mousevis(ON);
  296.    redraw = TRUE;
  297.  
  298.    return(OK);
  299. }
  300.  
  301. /**********************************************************************\
  302. *                                                                      *
  303. *  do_lines -- draw lines to create a plaid pattern                    *
  304. *                                                                      *
  305. \**********************************************************************/
  306.  
  307. do_lines()
  308. {
  309.    register int i,j;
  310.    int x1,x2,y1,y2;
  311.    int xinc;
  312.  
  313.    static int lcolor[] = {2,1,9,11,11,9,1,2};
  314.  
  315.    /* clear bottom part of screen */
  316.  
  317.    fg_mousevis(OFF);
  318.    fg_setcolor(15);
  319.    fg_rect(0,xlimit,menu_bottom,ylimit);
  320.  
  321.    /* draw horizontal lines */
  322.  
  323.    fg_setcolor(0);
  324.    for (i = menu_bottom; i < ylimit; i+=40)
  325.    {
  326.       for (j = 0; j < 8; j++)
  327.       {
  328.          if (mode14 || mode16)
  329.             fg_setcolor(lcolor[j]);
  330.  
  331.          y1 = i + 3*j;
  332.          fg_move(0,y1);
  333.          fg_draw(xlimit,y1);
  334.  
  335.       }
  336.    }
  337.  
  338.    /* draw vertical lines */
  339.  
  340.    y1 = menu_bottom;
  341.    y2 = ylimit;
  342.    for (i = 0; i < 640; i+=60)
  343.    {
  344.       for (j = 0; j < 8; j++)
  345.       {
  346.          if (mode14 || mode16)
  347.             fg_setcolor(lcolor[j]);
  348.  
  349.          x1 = i + 3*j;
  350.          fg_move(x1,y1);
  351.          fg_draw(x1,y2);
  352.       }
  353.    }
  354.  
  355.    /* draw red diagonal lines */
  356.  
  357.    y1 = menu_bottom;
  358.    y2 = ylimit;
  359.    xinc = ylimit - menu_bottom;
  360.    fg_setcolor(12);
  361.    for (x1 = -640; x1 < 640; x1+=60)
  362.    {
  363.       x2 = x1 + xinc;
  364.       fg_move(x1,y1);
  365.       fg_draw(x2,y2);
  366.    }
  367.  
  368.    y1 = menu_bottom;
  369.    y2 = ylimit;
  370.    xinc = ylimit - menu_bottom;
  371.  
  372.    /* draw red diagonal lines */
  373.  
  374.    fg_setcolor(12);
  375.    for (x1 = 0; x1 < 1280; x1+=60)
  376.    {
  377.       x2 = x1 - xinc;
  378.       fg_move(x1,y1);
  379.       fg_draw(x2,y2);
  380.    }
  381.  
  382.    /* wait for a keystroke or mouse button */
  383.  
  384.    fg_mousevis(ON);
  385.    wait_for_keystroke();
  386.  
  387.    /* restore the screen and return to the menu */
  388.  
  389.    fg_mousevis(OFF);
  390.    fg_restore(0,xlimit,menu_bottom,ylimit);
  391.  
  392.    fg_mousevis(ON);
  393.    redraw = TRUE;
  394.  
  395.    return(OK);
  396. }
  397.  
  398. /**********************************************************************\
  399. *                                                                      *
  400. *  do_paint -- draw a quartered circle, then paint around it           *
  401. *                                                                      *
  402. \**********************************************************************/
  403.  
  404. do_paint()
  405. {
  406.    int x1,x2,y1,y2;
  407.  
  408.    /* restor the screen */
  409.  
  410.    fg_mousevis(OFF);
  411.    fg_restore(0,xlimit,menu_bottom,ylimit);
  412.  
  413.    /* draw a rectangle */
  414.  
  415.    y1 = menu_bottom + scale(20);
  416.    y2 = ylimit - scale(20);
  417.    x1 = 40;
  418.    x2 = xlimit - 40;
  419.  
  420.    if (mode06 || mode11)
  421.       fg_setcolor(0);
  422.    else
  423.       fg_setcolor(11);
  424.  
  425.    fg_rect(x1,x2,y1,y2);
  426.  
  427.    /* outline the rectangle */
  428.  
  429.    if (mode06 || mode11)
  430.       fg_setcolor(1);
  431.    else
  432.       fg_setcolor(0);
  433.    fg_box(x1,x2,y1,y2);
  434.  
  435.    y1 = (ylimit + menu_bottom) / 2;
  436.    x1 = xlimit / 2;
  437.    fg_move(x1,y1);
  438.  
  439.    /* draw the circle */
  440.  
  441.    if (mode06 || mode11)
  442.       fg_setcolor(1);
  443.    else
  444.       fg_setcolor(0);
  445.    fg_circle(80);
  446.  
  447.    /* draw cross bars in the circle */
  448.  
  449.    y2 = scale(80);
  450.    fg_move(x1,y1-y2);
  451.    fg_draw(x1,y1+y2);
  452.  
  453.    x2 = 100;
  454.    fg_move(x1-x2,y1);
  455.    fg_draw(x1+x2,y1);
  456.  
  457.    /* paint each quarter of the circle */
  458.  
  459.    if (!mode06 && !mode11)
  460.    {
  461.       fg_setcolor(1);
  462.       fg_paint(x1-6,y1-6);
  463.  
  464.       fg_setcolor(2);
  465.       fg_paint(x1+6,y1+6);
  466.  
  467.       fg_setcolor(3);
  468.       fg_paint(x1+6,y1-6);
  469.  
  470.       fg_setcolor(4);
  471.       fg_paint(x1-6,y1+6);
  472.    }
  473.  
  474.    /* paint the box */
  475.  
  476.    x1 = 41;
  477.    y1 = menu_bottom + scale(20) + 1;
  478.  
  479.    if (mode06 || mode11)
  480.       fg_setcolor(1);
  481.    else
  482.       fg_setcolor(14);
  483.    fg_paint(x1,y1);
  484.  
  485.    /* wait for a keystroke or a mouse button */
  486.  
  487.    fg_mousevis(ON);
  488.    wait_for_keystroke();
  489.  
  490.    /* restore the screen and return to the menu */
  491.  
  492.    fg_mousevis(OFF);
  493.    fg_restore(0,xlimit,menu_bottom,ylimit);
  494.  
  495.    fg_mousevis(ON);
  496.    redraw = TRUE;
  497.  
  498.    return(OK);
  499. }
  500.  
  501. /**********************************************************************\
  502. *                                                                      *
  503. *  do_points -- draw a nice pattern of points                          *
  504. *                                                                      *
  505. \**********************************************************************/
  506.  
  507. do_points()
  508. {
  509.    register int i,j;
  510.    int yinc;
  511.  
  512.    /* clear the bottom part of the screen */
  513.  
  514.    fg_mousevis(OFF);
  515.    if (mode06 || mode11)
  516.      fg_setcolor(0);
  517.    else
  518.      fg_setcolor(1);
  519.    fg_rect(0,xlimit,menu_bottom,ylimit);
  520.  
  521.    yinc = scale(8);
  522.  
  523.    /* draw the patterns of points */
  524.  
  525.    fg_setcolor(15);
  526.    for (i = 5; i < xlimit; i+=20)
  527.    {
  528.       for (j = menu_bottom+2; j < ylimit; j+=yinc)
  529.          fg_point(i,j);
  530.    }
  531.  
  532.    for (i = 15; i < xlimit; i+=20)
  533.    {
  534.       for (j = menu_bottom+yinc/2+2; j < ylimit; j+=yinc)
  535.          fg_point(i,j);
  536.    }
  537.  
  538.    /* wait for a keystroke or mouse button */
  539.  
  540.    fg_mousevis(ON);
  541.    wait_for_keystroke();
  542.  
  543.    /* restore the screen and return to the menu */
  544.  
  545.    fg_mousevis(OFF);
  546.    fg_restore(0,xlimit,menu_bottom,ylimit);
  547.  
  548.    fg_mousevis(ON);
  549.    redraw = TRUE;
  550.  
  551.    return(OK);
  552. }
  553.  
  554. /**********************************************************************\
  555. *                                                                      *
  556. *  do_rects -- draw a bunch of solid rectangles                        *
  557. *                                                                      *
  558. \**********************************************************************/
  559.  
  560. do_rects()
  561. {
  562.    register int i,j;
  563.    int x0,x1,x2,y1,y2;
  564.    int xinc,yinc;
  565.    int color;
  566.  
  567.    x0 = 5;
  568.    x1 = x0;
  569.    xinc = (xlimit - x0 - 1) / 10;
  570.    x2 = x1 + xinc;
  571.  
  572.    yinc = (ylimit - menu_bottom) / 10;
  573.    y1 = menu_bottom;
  574.    y2 = y1 + yinc;
  575.  
  576.    color = 0;
  577.  
  578.    /* draw 100 solid rectangles */
  579.  
  580.    fg_mousevis(OFF);
  581.    for (i = 0; i < 10; i++)
  582.    {
  583.       for (j = 0; j < 10; j++)
  584.       {
  585.          fg_setcolor(color);
  586.          fg_rect(x1,x2,y1,y2);
  587.  
  588.          color++;
  589.          if (color > 14) color = 0;
  590.  
  591.          x1 = x2;
  592.          x2 = x1 + xinc;
  593.       }
  594.       x1 = x0;
  595.       x2 = x1 + xinc;
  596.  
  597.       y1 = y2;
  598.       y2 = y1 + yinc;
  599.    }
  600.  
  601.    /* wait for a keystroke or mouse button */
  602.  
  603.    fg_mousevis(ON);
  604.    wait_for_keystroke();
  605.  
  606.    /* restore the screen and return to the menu */
  607.  
  608.    fg_mousevis(OFF);
  609.    fg_restore(0,xlimit,menu_bottom,ylimit);
  610.  
  611.    fg_mousevis(ON);
  612.    redraw = TRUE;
  613.  
  614.    return(OK);
  615. }
  616.  
  617. /**********************************************************************\
  618. *                                                                      *
  619. *  do_text -- demonstrate ROM text                                     *
  620. *                                                                      *
  621. \**********************************************************************/
  622.  
  623. do_text()
  624. {
  625.    register int i;
  626.    register int row;
  627.    int x1,x2,y1,y2;
  628.  
  629.    static char *string[] = {
  630.    "Fastgraph allows you to display",
  631.    "ROM text, a stroke character font,",
  632.    "or define your own bitmapped font.",
  633.    "This message is displayed using",
  634.    "ROM text.  The menus use bitmapped",
  635.    "characters."
  636.    };
  637.  
  638.    fg_mousevis(OFF);
  639.  
  640.    fg_restore(0,xlimit,menu_bottom,ylimit);
  641.  
  642.    /* convert rows and columns to x's and y's */
  643.  
  644.    x1 = fg_xconvert(20);
  645.    x2 = fg_xconvert(60);
  646.  
  647.    y1 = fg_yconvert(5);
  648.    y2 = fg_yconvert(13);
  649.  
  650.    /* draw a small rectangle */
  651.  
  652.    if (mode06 || mode11)
  653.      fg_setcolor(0);
  654.    else
  655.      fg_setcolor(1);
  656.    fg_rect(x1,x2,y1,y2);
  657.  
  658.    /* draw a white boarder around the box */
  659.  
  660.    fg_setcolor(15);
  661.    fg_box(x1+1,x2-1,y1+1,y2-1);
  662.  
  663.    /* put ROM text in the box */
  664.  
  665.    row = 6;
  666.    for (i = 0; i < 6; i++)
  667.    {
  668.       fg_locate(row,23);
  669.       fg_text(string[i],strlen(string[i]));
  670.       row++;
  671.    }
  672.  
  673.    /* wait for a keystroke or mouse button */
  674.  
  675.    fg_mousevis(ON);
  676.    wait_for_keystroke();
  677.  
  678.    /* restore the screen and return to the menu */
  679.  
  680.    fg_mousevis(OFF);
  681.    fg_restore(0,xlimit,menu_bottom,ylimit);
  682.  
  683.    fg_mousevis(ON);
  684.    redraw = TRUE;
  685.  
  686.    return(OK);
  687. }
  688.