home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / PTDLINE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-28  |  5.6 KB  |  218 lines

  1. /*
  2.     ptdline.c    7/11/88
  3.  
  4.     % Character oriented window painting code for line drawing
  5.     By Ted.
  6.  
  7.     OWL 1.2
  8.     Copyright (c) 1988, by Oakland Group, Inc.
  9.     ALL RIGHTS RESERVED.
  10.  
  11.     Revision History:
  12.     -----------------
  13.      7/27/88 jmd    Converted DrawLine to take an opbox
  14.      8/22/88 jmd    Fixed HZ line bug in DrawLine
  15.  
  16.      3/13/90 ted    Added calls win_GetFontWidth/Height.
  17.      3/28/90 jmd    ansi-fied
  18. */
  19.  
  20. #include "oakhead.h"
  21. #include "disppriv.h"
  22.  
  23. OSTATIC void OWLPRIV d_char(ptd_struct *ptd, int row, int col, char ch, byte attr);
  24. OSTATIC void OWLPRIV d_hline(ptd_struct *ptd, int row, int col, int len, char ch, byte attr);
  25. OSTATIC void OWLPRIV d_vline(ptd_struct *ptd, int row, int col, int len, char ch, byte attr);
  26.  
  27. /* -------------------------------------------------------------------------- */
  28.  
  29. void ptd_DrawCharBox(ptd_struct *ptd, char *boxchar, ocbox *cboxp, byte attr)
  30. /*
  31.     DESCRIPTION:
  32.     This function draws a box using the characters in boxchar and the
  33.     attribute specified by attr.
  34.     The box coordinates are relative to window 'win'.
  35.     The 9 characters in the boxchar string represent the box in the 
  36.     following manner:
  37.     boxchar[0]        upper left corner character.
  38.     boxchar[1]        upper side character.
  39.     boxchar[2]        upper right corner character.
  40.     boxchar[3]        right side character.
  41.     boxchar[4]        lower right corner character.
  42.     boxchar[5]        lower side character.
  43.     boxchar[6]        lower left corner character.
  44.     boxchar[7]        left side character.
  45.     
  46.     example:
  47.     0112
  48.     7  3
  49.     7  3
  50.     6554
  51. */        
  52. {
  53.     ocbox cbox;
  54.     char linechar[3];
  55.  
  56.     ocbox_copy(&cbox, cboxp);
  57.     
  58.     /* Top line */
  59.     cbox.botrow = cbox.toprow;
  60.     ptd_DrawCharLine(ptd, boxchar, &cbox, attr);
  61.     cbox.botrow = cboxp->botrow;
  62.  
  63.     /* Bottom line */
  64.     cbox.toprow = cbox.botrow;
  65.     linechar[0] = boxchar[6];
  66.     linechar[1] = boxchar[5];
  67.     linechar[2] = boxchar[4];
  68.     ptd_DrawCharLine(ptd, linechar, &cbox, attr);
  69.     cbox.toprow = cboxp->toprow+1;
  70.     cbox.botrow = cboxp->botrow-1;
  71.  
  72.     if (cbox.toprow <= cbox.botrow) {
  73.  
  74.         /* Left line */
  75.         cbox.rightcol = cbox.leftcol;
  76.         linechar[0] = linechar[1] = linechar[2] = boxchar[7];
  77.         ptd_DrawCharLine(ptd, linechar, &cbox, attr);
  78.         cbox.rightcol = cboxp->rightcol;
  79.  
  80.         /* Right line */
  81.         cbox.leftcol = cbox.rightcol;
  82.         linechar[0] = linechar[1] = linechar[2] = boxchar[3];
  83.         ptd_DrawCharLine(ptd, linechar, &cbox, attr);
  84.     }
  85. }
  86. /* -------------------------------------------------------------------------- */
  87.  
  88. void ptd_DrawCharLine(ptd_struct *ptd, char *linechar, ocbox *cboxp, byte attr)
  89. /*
  90.     DESCRIPTION:
  91.     Draw line using the characters in linechar and the
  92.     attribute specified by attr.
  93.     The start point of the line is (cbox.toprow, cbox.leftcol).
  94.     The 3 characters in the linechar string represent the line in the 
  95.     following manner:
  96.     linechar[0]        first character.
  97.     linechar[1]        line character.
  98.     linechar[2]        last character.
  99.     12222222223
  100. */
  101. {
  102.     unsigned clip1, clip2;
  103.     ocbox     relcbox;
  104.     int     len, temp;
  105.     int        row1, row2, col1, col2;
  106.     boolean is_hz;
  107.  
  108.     row1 = cboxp->toprow;
  109.     row2 = cboxp->botrow;
  110.     col1 = cboxp->leftcol;
  111.     col2 = cboxp->rightcol;
  112.  
  113.     /* determine direction of line */
  114.     if (row1 == row2) {
  115.         is_hz = TRUE;
  116.     }
  117.     else if (col1 == col2) {
  118.         is_hz = FALSE;
  119.     }
  120.     else {
  121.         /* not a line, you hoser */
  122.         return;
  123.     }
  124.         
  125.     opbox_charcoords(ptd->relboxp, win_GetFont(ptd->win), &relcbox);
  126.  
  127.     if (row1 > row2) {
  128.         temp = row1;
  129.         row1 = row2;
  130.         row2 = temp;
  131.     }
  132.  
  133.     if (col1 > col2) {
  134.         temp = col1;
  135.         col1 = col2;
  136.         col2 = temp;
  137.     }
  138.  
  139.     clip1 = ocbox_clippos(&relcbox, &row1, &col1);
  140.     clip2 = ocbox_clippos(&relcbox, &row2, &col2);
  141.     if (clip1 & clip2) {
  142.         return;    /* quit if not in clipbox at all */
  143.     }
  144.     if (is_hz) {            /* hline */
  145.         if ((clip1&(2+8+1))==0 && (clip2&(2+8+4))==0) {
  146.             if ((clip1&(4))==0) {    /* left end in */
  147.                 d_char(ptd, row1, col1, linechar[0], attr);
  148.                 col1++;
  149.             }
  150.             if ((clip2&(1))==0) {    /* right end in */
  151.                 d_char(ptd, row1, col2, linechar[2], attr);
  152.                 col2--;
  153.             }
  154.             len = col2 - col1 + 1;
  155.             if (len > 0) {
  156.                 d_hline(ptd, row1, col1, len, linechar[1], attr);
  157.             }
  158.         }
  159.     }
  160.     else {    /* vline */
  161.         if ((clip1&(1+4+8))==0 && (clip2&(1+4+2))==0) {
  162.             if ((clip1&(2))==0) {    /* top end in */
  163.                 d_char(ptd, row1, col1, linechar[0], attr);
  164.                 row1++;
  165.             }
  166.             if ((clip2&(8))==0) {    /* bottom end in */
  167.                 d_char(ptd, row2, col1, linechar[2], attr);
  168.                 row2--;
  169.             }
  170.             len = row2 - row1 + 1;
  171.             if (len > 0) {
  172.                 d_vline(ptd, row1, col1, len, linechar[1], attr);
  173.             }
  174.         }
  175.     }
  176. }
  177. /* -------------------------------------------------------------------------- */
  178.  
  179. static void OWLPRIV d_char(ptd_struct *ptd, int row, int col, char ch, byte attr)
  180. {
  181.     opcoord x, y;
  182.  
  183.     x =  col    * win_GetFontWidth(ptd->win);
  184.     y = (row+1) * win_GetFontHeight(ptd->win);
  185.     ptd_PlotChar(ptd, x, y, ch, attr, 1);
  186. }
  187. /* -------------------------------------------------------------------------- */
  188.  
  189. static void OWLPRIV d_hline(ptd_struct *ptd, int row, int col, int len, char ch, byte attr)
  190. {
  191.     opcoord x, y;
  192.  
  193.     if (len != 0) {
  194.         x =  col    * win_GetFontWidth(ptd->win);
  195.         y = (row+1) * win_GetFontHeight(ptd->win);
  196.         ptd_PlotChar(ptd, x, y, ch, attr, len);
  197.     }
  198. }
  199. /* -------------------------------------------------------------------------- */
  200.  
  201. static void OWLPRIV d_vline(ptd_struct *ptd, int row, int col, int len, char ch, byte attr)
  202. {
  203.     opcoord x, y;
  204.     opcoord fheight;
  205.  
  206.     if (len != 0) {
  207.         x = col * win_GetFontWidth(ptd->win);
  208.         fheight = win_GetFontHeight(ptd->win);
  209.         y = (row+1) * fheight;
  210.         for ( ; len != 0; len--) {
  211.             ptd_PlotChar(ptd, x, y, ch, attr, 1);
  212.             y += fheight;
  213.         }
  214.     }
  215. }
  216. /* -------------------------------------------------------------------------- */
  217.  
  218.