home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / PTDLINE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  5.6 KB  |  241 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.1
  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.  
  17. #include "oakhead.h"
  18. #include "disppriv.h"
  19.  
  20. OSTATIC void OWLPRIV d_char(_arg5(ptd_struct *, int, int, char, byte));
  21. OSTATIC void OWLPRIV d_hline(_arg6(ptd_struct *, int, int, int, char, byte));
  22. OSTATIC void OWLPRIV d_vline(_arg6(ptd_struct *, int, int, int, char, byte));
  23. /* -------------------------------------------------------------------------- */
  24.  
  25. void ptd_DrawCharBox(ptd, boxchar, cboxp, attr)
  26.     ptd_struct *ptd;
  27.     char *boxchar;
  28.     ocbox *cboxp;
  29.     byte attr;
  30. /*
  31.     DESCRIPTION:
  32.  
  33.     This function draws a box using the characters in boxchar and the
  34.     attribute specified by attr.
  35.     The box coordinates are relative to window 'win'.
  36.     The 9 characters in the boxchar string represent the box in the 
  37.     following manner:
  38.  
  39.     boxchar[0]        upper left corner character.
  40.     boxchar[1]        upper side character.
  41.     boxchar[2]        upper right corner character.
  42.     boxchar[3]        right side character.
  43.     boxchar[4]        lower right corner character.
  44.     boxchar[5]        lower side character.
  45.     boxchar[6]        lower left corner character.
  46.     boxchar[7]        left side character.
  47.     
  48.     example:
  49.  
  50.     0112
  51.     7  3
  52.     7  3
  53.     6554
  54. */        
  55. {
  56.     ocbox cbox;
  57.     char linechar[3];
  58.  
  59.     ocbox_copy(&cbox, cboxp);
  60.     
  61.     cbox.botrow = cbox.toprow;
  62.     ptd_DrawCharLine(ptd, &boxchar[0], &cbox, attr);
  63.     cbox.botrow = cboxp->botrow;
  64.  
  65.     cbox.toprow = cbox.botrow;
  66.     linechar[0] = boxchar[6];
  67.     linechar[1] = boxchar[5];
  68.     linechar[2] = boxchar[4];
  69.     ptd_DrawCharLine(ptd, linechar, &cbox, attr);
  70.     cbox.toprow = cboxp->toprow+1;
  71.     cbox.botrow = cboxp->botrow-1;
  72.  
  73.     if (cbox.toprow <= cbox.botrow) {
  74.  
  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.         cbox.leftcol = cbox.rightcol;
  81.         linechar[0] = linechar[1] = linechar[2] = boxchar[3];
  82.         ptd_DrawCharLine(ptd, linechar, &cbox, attr);
  83.     }
  84. }
  85. /* -------------------------------------------------------------------------- */
  86.  
  87. void ptd_DrawCharLine(ptd, linechar, cboxp, attr)
  88.     ptd_struct *ptd;
  89.     char *linechar;
  90.     ocbox *cboxp;
  91.     byte attr;
  92. /*
  93.     DESCRIPTION:
  94.  
  95.     Draw line using the characters in linechar and the
  96.     attribute specified by attr.
  97.     The start point of the line is (cbox.toprow, cbox.leftcol).
  98.     The 3 characters in the linechar string represent the line in the 
  99.     following manner:
  100.  
  101.     linechar[0]        first character.
  102.     linechar[1]        line character.
  103.     linechar[2]        last character.
  104.  
  105.     12222222223
  106. */
  107. {
  108.     unsigned clip1, clip2;
  109.     ocbox     relcbox;
  110.     int     len, temp;
  111.     int        row1, row2, col1, col2;
  112.     boolean is_hz;
  113.  
  114.     row1 = cboxp->toprow;
  115.     row2 = cboxp->botrow;
  116.     col1 = cboxp->leftcol;
  117.     col2 = cboxp->rightcol;
  118.  
  119.     /* determine direction of line */
  120.     if (row1 == row2) {
  121.         is_hz = TRUE;
  122.     }
  123.     else if (col1 == col2) {
  124.         is_hz = FALSE;
  125.     }
  126.     else {
  127.         /* not a line, you hoser */
  128.         return;
  129.     }
  130.         
  131.     opbox_charcoords(ptd->relboxp, win_GetFont(ptd->win), &relcbox);
  132.  
  133.     if (row1 > row2) {
  134.         temp = row1;
  135.         row1 = row2;
  136.         row2 = temp;
  137.     }
  138.  
  139.     if (col1 > col2) {
  140.         temp = col1;
  141.         col1 = col2;
  142.         col2 = temp;
  143.     }
  144.  
  145.     clip1 = ocbox_clippos(&relcbox, &row1, &col1);
  146.     clip2 = ocbox_clippos(&relcbox, &row2, &col2);
  147.     if (clip1 & clip2) {
  148.         return;    /* quit if not in clipbox at all */
  149.     }
  150.     if (is_hz) {            /* hline */
  151.         if ((clip1&(2+8+1))==0 && (clip2&(2+8+4))==0) {
  152.             if ((clip1&(4))==0) {    /* left end in */
  153.                 d_char(ptd, row1, col1, linechar[0], attr);
  154.                 col1++;
  155.             }
  156.             if ((clip2&(1))==0) {    /* right end in */
  157.                 d_char(ptd, row1, col2, linechar[2], attr);
  158.                 col2--;
  159.             }
  160.             len = col2 - col1 + 1;
  161.             if (len > 0) {
  162.                 d_hline(ptd, row1, col1, len, linechar[1], attr);
  163.             }
  164.         }
  165.     }
  166.     else {    /* vline */
  167.         if ((clip1&(1+4+8))==0 && (clip2&(1+4+2))==0) {
  168.             if ((clip1&(2))==0) {    /* top end in */
  169.                 d_char(ptd, row1, col1, linechar[0], attr);
  170.                 row1++;
  171.             }
  172.             if ((clip2&(8))==0) {    /* bottom end in */
  173.                 d_char(ptd, row2, col1, linechar[2], attr);
  174.                 row2--;
  175.             }
  176.             len = row2 - row1 + 1;
  177.             if (len > 0) {
  178.                 d_vline(ptd, row1, col1, len, linechar[1], attr);
  179.             }
  180.         }
  181.     }
  182. }
  183. /* -------------------------------------------------------------------------- */
  184.  
  185. static void OWLPRIV d_char(ptd, row, col, ch, attr)
  186.     ptd_struct *ptd;
  187.     int row;
  188.     int col;
  189.     char ch;
  190.     byte attr;
  191. {
  192.     opcoord x, y;
  193.  
  194.     x = col * ofont_GetWidth(win_GetFont(ptd->win));
  195.     y = (row+1) * ofont_GetHeight(win_GetFont(ptd->win));
  196.     ptd_PlotChar(ptd, x, y, ch, attr, 1);
  197. }
  198. /* -------------------------------------------------------------------------- */
  199.  
  200. static void OWLPRIV d_hline(ptd, row, col, len, ch, attr)
  201.     ptd_struct *ptd;
  202.     int row;
  203.     int col;
  204.     int len;
  205.     char ch;
  206.     byte attr;
  207. {
  208.     opcoord x, y;
  209.  
  210.     if (len != 0) {
  211.         x = col * ofont_GetWidth(win_GetFont(ptd->win));
  212.         y = (row+1) * ofont_GetHeight(win_GetFont(ptd->win));
  213.         ptd_PlotChar(ptd, x, y, ch, attr, len);
  214.     }
  215. }
  216. /* -------------------------------------------------------------------------- */
  217.  
  218. static void OWLPRIV d_vline(ptd, row, col, len, ch, attr)
  219.     ptd_struct *ptd;
  220.     int row;
  221.     int col;
  222.     int len;
  223.     char ch;
  224.     byte attr;
  225. {
  226.     opcoord x, y;
  227.     opcoord fheight;
  228.  
  229.     if (len != 0) {
  230.         x = col * ofont_GetWidth(win_GetFont(ptd->win));
  231.         fheight = ofont_GetHeight(win_GetFont(ptd->win));
  232.         y = (row+1) * fheight;
  233.         for ( ; len != 0; len--) {
  234.             ptd_PlotChar(ptd, x, y, ch, attr, 1);
  235.             y += fheight;
  236.         }
  237.     }
  238. }
  239. /* -------------------------------------------------------------------------- */
  240.  
  241.