home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / vrac / pclcjs.zip / MENUBOX.C < prev    next >
C/C++ Source or Header  |  1993-01-23  |  5KB  |  185 lines

  1. /* Menubox Library Function Copyright 1991 by Chuck Steenburgh 
  2.    This function will draw a box border at the specified coordinates 
  3.    Optionally, a drop shadow can be defined around the box           */
  4.    
  5. #include <stdlib.h>
  6. #include <bios.h>
  7.  
  8. /* The following data are passed to the function:
  9.  
  10.     r1, c1:  The row and column location of the upper left-hand
  11.             corner of the box
  12.     r2, c2:  The row and column location of the lower right-hand
  13.             corner of the box.
  14.     color:   The color attributes of the box border (see colortext
  15.             function for explanation)
  16.     boxtype: Single or double line box as indicated below:
  17.     
  18.           Value                    Type Box
  19.           =====                    ========
  20.             1                       Single
  21.             2                       Double
  22.             3                       Double Horizontal
  23.             4                       Double Vertical
  24.             5                       Thick solid line
  25.             6                       Medium solid line
  26.             7                       Shaded solid line (ASCII 176)
  27.             8                       Shaded solid line (ASCII 177)
  28.             9                       Shaded solid line (ASCII 178)
  29.             
  30.     shadow: 0 for no shadow, 1 for dropshadow
  31.     
  32.     shade:  Enter the number of the shading type desired:
  33.     
  34.           Value                    ASCII Char used for shadow
  35.           =====                    ==========================
  36.             1                               176 
  37.             2                               177
  38.             3                               178
  39.             
  40.     The same color is used for the shadow as for box itself.*/
  41.             
  42.              
  43. int menubox(int r1, c1, r2, c2, color, boxtype, shadow, shade, max_rows)
  44. {
  45.    int shad_char,count1,tl,tr,bl,br,h,v;
  46.    
  47.    
  48. /*  Input constaints:  Box must be at least 3x3; must be completely within 
  49.     the bounds of the screen; color must be valid; boxtype must be one of
  50.     the nine values listed above.                                         */
  51.     
  52.     if (((r2-r1)<2) || (r1<0) || (r2>max_rows) || ((c2-c1)<2) || (c1<0) || (c2>79) || (color<0) || (color>255) || (boxtype<1) || (boxtype>9)) {
  53.         return 1;
  54.     }
  55.  
  56. /*  ASCII values of various "pieces" of the box are determined by boxtype */    
  57.     
  58.     switch (boxtype) {
  59.         case 1: {
  60.             tl=218; /* top left corner */
  61.             tr=191; /* top right corner */
  62.             bl=192; /* bottom left corner */
  63.             br=217; /* bottom right corner */
  64.             h=196; /* horizontal side */
  65.             v=179; /* vertical side */
  66.         }
  67.         break;
  68.         case 2: {
  69.             tl=201;
  70.             tr=187;
  71.             bl=200;
  72.             br=188;
  73.             h=205;
  74.             v=186;
  75.         }
  76.         break;
  77.         case 3: {
  78.             tl=213;
  79.             tr=184;
  80.             bl=212;
  81.             br=190;
  82.             h=205;
  83.             v=179;
  84.         }
  85.         break;
  86.         case 4: {
  87.             tl=214;
  88.             tr=183;
  89.             bl=211;
  90.             br=189;
  91.             h=196;
  92.             v=186;
  93.         }
  94.         break;
  95.         case 5: {
  96.             tl=219;
  97.             tr=219;
  98.             bl=219;
  99.             br=219;
  100.             h=219;
  101.             v=219;
  102.         }
  103.         break;
  104.         case 6: {
  105.             tl=220;
  106.             tr=220;
  107.             bl=219;
  108.             br=219;
  109.             h=220;
  110.             v=219;
  111.         }
  112.         break;
  113.         case 7: {
  114.             tl=176;
  115.             tr=176;
  116.             bl=176;
  117.             br=176;
  118.             h=176;
  119.             v=176;
  120.         }
  121.         break;
  122.         case 8: {
  123.             tl=177;
  124.             tr=177;
  125.             bl=177;
  126.             br=177;
  127.             h=177;
  128.             v=177;
  129.         }
  130.         break;
  131.         case 9: {
  132.             tl=178;
  133.             tr=178;
  134.             bl=178;
  135.             br=178;
  136.             h=178;
  137.             v=178;
  138.         }
  139.         break;
  140.     }    
  141.     poscurs(r1,c1); /* position cursor in top left corner */
  142.     writechs(tl,color,1); /* draw top left corner piece */
  143.     poscurs(r1,c1+1); 
  144.     writechs(h,color,c2-c1-1); /* draw top side of box */
  145.     poscurs(r1,c2); /* position cursor in top right corner */
  146.     writechs(tr,color,1); /* draw top right corner piece */
  147.     poscurs(r2,c1); /* position cursor in bottom left corner */
  148.     writechs(bl,color,1); /* draw bottom left piece */
  149.     poscurs(r2,c1+1);
  150.     writechs(h,color,c2-c1-1); /* draw bottom side of box */
  151.     poscurs(r2,c2); /* position cursor in bottom right corner */
  152.     writechs(br,color,1); /* draw bottom right corner piece */
  153.     for (count1=1;count1<(r2-r1);count1++) {
  154.         poscurs(count1+r1,c1);  /* simulaneously draw left and right sides */
  155.         writechs(v,color,1);
  156.         poscurs(count1+r1,c2);
  157.         writechs(v,color,1);
  158.     }
  159.     /* Check for dropshadow */
  160.     if (shadow == 0)
  161.         return 0;
  162.     
  163.     /* Check if space exists for shadow */
  164.     if (((r2-r1)<2) || (r1<0) || (r2>max_rows-2) || ((c2-c1)<2) || (c1<0) || (c2>78) || (color<0) || (color>255) || (shade<1) || (shade>3)) {
  165.         return 2;
  166.     }
  167.     
  168.     /* Shade character is set to ASCII 176,177, or 178 */
  169.     shad_char = shade + 175;
  170.     
  171.     /* The bottom shadow is drawn */
  172.     poscurs(r2+1,c1+2);
  173.     writechs(shad_char,color,c2-c1+1);
  174.     
  175.     /* The right shadow is drawn */
  176.     for (count1=0;count1<(r2-r1);count1++) {
  177.         poscurs(r1+1+count1,c2+1);
  178.         writechs(shad_char,color,2);
  179.     }
  180.     
  181.     return 0;
  182.  
  183. }
  184.     
  185.