home *** CD-ROM | disk | FTP | other *** search
- /*
- ptdline.c 7/11/88
-
- % Character oriented window painting code for line drawing
- By Ted.
-
- OWL 1.1
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 7/27/88 jmd Converted DrawLine to take an opbox
- 8/22/88 jmd Fixed HZ line bug in DrawLine
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
-
- OSTATIC void OWLPRIV d_char(_arg5(ptd_struct *, int, int, char, byte));
- OSTATIC void OWLPRIV d_hline(_arg6(ptd_struct *, int, int, int, char, byte));
- OSTATIC void OWLPRIV d_vline(_arg6(ptd_struct *, int, int, int, char, byte));
- /* -------------------------------------------------------------------------- */
-
- void ptd_DrawCharBox(ptd, boxchar, cboxp, attr)
- ptd_struct *ptd;
- char *boxchar;
- ocbox *cboxp;
- byte attr;
- /*
- DESCRIPTION:
-
- This function draws a box using the characters in boxchar and the
- attribute specified by attr.
- The box coordinates are relative to window 'win'.
- The 9 characters in the boxchar string represent the box in the
- following manner:
-
- boxchar[0] upper left corner character.
- boxchar[1] upper side character.
- boxchar[2] upper right corner character.
- boxchar[3] right side character.
- boxchar[4] lower right corner character.
- boxchar[5] lower side character.
- boxchar[6] lower left corner character.
- boxchar[7] left side character.
-
- example:
-
- 0112
- 7 3
- 7 3
- 6554
- */
- {
- ocbox cbox;
- char linechar[3];
-
- ocbox_copy(&cbox, cboxp);
-
- cbox.botrow = cbox.toprow;
- ptd_DrawCharLine(ptd, &boxchar[0], &cbox, attr);
- cbox.botrow = cboxp->botrow;
-
- cbox.toprow = cbox.botrow;
- linechar[0] = boxchar[6];
- linechar[1] = boxchar[5];
- linechar[2] = boxchar[4];
- ptd_DrawCharLine(ptd, linechar, &cbox, attr);
- cbox.toprow = cboxp->toprow+1;
- cbox.botrow = cboxp->botrow-1;
-
- if (cbox.toprow <= cbox.botrow) {
-
- cbox.rightcol = cbox.leftcol;
- linechar[0] = linechar[1] = linechar[2] = boxchar[7];
- ptd_DrawCharLine(ptd, linechar, &cbox, attr);
- cbox.rightcol = cboxp->rightcol;
-
- cbox.leftcol = cbox.rightcol;
- linechar[0] = linechar[1] = linechar[2] = boxchar[3];
- ptd_DrawCharLine(ptd, linechar, &cbox, attr);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- void ptd_DrawCharLine(ptd, linechar, cboxp, attr)
- ptd_struct *ptd;
- char *linechar;
- ocbox *cboxp;
- byte attr;
- /*
- DESCRIPTION:
-
- Draw line using the characters in linechar and the
- attribute specified by attr.
- The start point of the line is (cbox.toprow, cbox.leftcol).
- The 3 characters in the linechar string represent the line in the
- following manner:
-
- linechar[0] first character.
- linechar[1] line character.
- linechar[2] last character.
-
- 12222222223
- */
- {
- unsigned clip1, clip2;
- ocbox relcbox;
- int len, temp;
- int row1, row2, col1, col2;
- boolean is_hz;
-
- row1 = cboxp->toprow;
- row2 = cboxp->botrow;
- col1 = cboxp->leftcol;
- col2 = cboxp->rightcol;
-
- /* determine direction of line */
- if (row1 == row2) {
- is_hz = TRUE;
- }
- else if (col1 == col2) {
- is_hz = FALSE;
- }
- else {
- /* not a line, you hoser */
- return;
- }
-
- opbox_charcoords(ptd->relboxp, win_GetFont(ptd->win), &relcbox);
-
- if (row1 > row2) {
- temp = row1;
- row1 = row2;
- row2 = temp;
- }
-
- if (col1 > col2) {
- temp = col1;
- col1 = col2;
- col2 = temp;
- }
-
- clip1 = ocbox_clippos(&relcbox, &row1, &col1);
- clip2 = ocbox_clippos(&relcbox, &row2, &col2);
- if (clip1 & clip2) {
- return; /* quit if not in clipbox at all */
- }
- if (is_hz) { /* hline */
- if ((clip1&(2+8+1))==0 && (clip2&(2+8+4))==0) {
- if ((clip1&(4))==0) { /* left end in */
- d_char(ptd, row1, col1, linechar[0], attr);
- col1++;
- }
- if ((clip2&(1))==0) { /* right end in */
- d_char(ptd, row1, col2, linechar[2], attr);
- col2--;
- }
- len = col2 - col1 + 1;
- if (len > 0) {
- d_hline(ptd, row1, col1, len, linechar[1], attr);
- }
- }
- }
- else { /* vline */
- if ((clip1&(1+4+8))==0 && (clip2&(1+4+2))==0) {
- if ((clip1&(2))==0) { /* top end in */
- d_char(ptd, row1, col1, linechar[0], attr);
- row1++;
- }
- if ((clip2&(8))==0) { /* bottom end in */
- d_char(ptd, row2, col1, linechar[2], attr);
- row2--;
- }
- len = row2 - row1 + 1;
- if (len > 0) {
- d_vline(ptd, row1, col1, len, linechar[1], attr);
- }
- }
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static void OWLPRIV d_char(ptd, row, col, ch, attr)
- ptd_struct *ptd;
- int row;
- int col;
- char ch;
- byte attr;
- {
- opcoord x, y;
-
- x = col * ofont_GetWidth(win_GetFont(ptd->win));
- y = (row+1) * ofont_GetHeight(win_GetFont(ptd->win));
- ptd_PlotChar(ptd, x, y, ch, attr, 1);
- }
- /* -------------------------------------------------------------------------- */
-
- static void OWLPRIV d_hline(ptd, row, col, len, ch, attr)
- ptd_struct *ptd;
- int row;
- int col;
- int len;
- char ch;
- byte attr;
- {
- opcoord x, y;
-
- if (len != 0) {
- x = col * ofont_GetWidth(win_GetFont(ptd->win));
- y = (row+1) * ofont_GetHeight(win_GetFont(ptd->win));
- ptd_PlotChar(ptd, x, y, ch, attr, len);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static void OWLPRIV d_vline(ptd, row, col, len, ch, attr)
- ptd_struct *ptd;
- int row;
- int col;
- int len;
- char ch;
- byte attr;
- {
- opcoord x, y;
- opcoord fheight;
-
- if (len != 0) {
- x = col * ofont_GetWidth(win_GetFont(ptd->win));
- fheight = ofont_GetHeight(win_GetFont(ptd->win));
- y = (row+1) * fheight;
- for ( ; len != 0; len--) {
- ptd_PlotChar(ptd, x, y, ch, attr, 1);
- y += fheight;
- }
- }
- }
- /* -------------------------------------------------------------------------- */
-
-