home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 12sbuf / sb_box.c next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  1.5 KB  |  60 lines

  1. /*
  2.  *    sb_box -- draw a box around the perimeter of a window
  3.  *    using the appropriate IBM graphics characters
  4.  */
  5.  
  6. #include <local\sbuf.h>
  7. #include <local\video.h>
  8. #include <local\box.h>
  9.  
  10. int
  11. sb_box(win, type, attr)
  12. struct REGION *win;
  13. short type;
  14. unsigned char attr;
  15. {
  16.     register short r;    /* row index */
  17.     short x;        /* interior horizontal line length */
  18.     short maxr, maxc;    /* maximum row and col values */
  19.     BOXTYPE *boxp;        /* pointer to box drawing character struct */
  20.     static BOXTYPE box[] = {
  21.         '+',   '+',   '+',   '+',   '-',   '-',   '|',   '|',
  22.         ULC11, URC11, LLC11, LRC11, HBAR1, HBAR1, VBAR1, VBAR1,
  23.         ULC22, URC22, LLC22, LRC22, HBAR2, HBAR2, VBAR2, VBAR2,
  24.         ULC12, URC12, LLC12, LRC12, HBAR1, HBAR1, VBAR2, VBAR2,
  25.         ULC21, URC21, LLC21, LRC21, HBAR2, HBAR2, VBAR1, VBAR1,
  26.         BLOCK, BLOCK, BLOCK, BLOCK, HBART, HBARB, BLOCK, BLOCK
  27.     };
  28.  
  29.     boxp = &box[type];
  30.     maxc = win->c1 - win->c0;
  31.     maxr = win->r1 - win->r0;
  32.     x = maxc - 1;
  33.  
  34.     /* draw top row */
  35.     sb_move(win, 0, 0);
  36.     sb_wca(win, boxp->ul, attr, 1);
  37.     sb_move(win, 0, 1);
  38.     sb_wca(win, boxp->tbar, attr, x);
  39.     sb_move(win, 0, maxc);
  40.     sb_wca(win, boxp->ur, attr, 1);
  41.  
  42.     /* draw left and right sides */
  43.     for (r = 1; r < maxr; ++r) {
  44.         sb_move(win, r, 0);
  45.         sb_wca(win, boxp->lbar, attr, 1);
  46.         sb_move(win, r, maxc);
  47.         sb_wca(win, boxp->rbar, attr, 1);
  48.     }
  49.  
  50.     /* draw bottom row */
  51.     sb_move(win, maxr, 0);
  52.     sb_wca(win, boxp->ll, attr, 1);
  53.     sb_move(win, maxr, 1);
  54.     sb_wca(win, boxp->bbar, attr, x);
  55.     sb_move(win, maxr, maxc);
  56.     sb_wca(win, boxp->lr, attr, 1);
  57.     
  58.     return SB_OK;
  59. }
  60.