home *** CD-ROM | disk | FTP | other *** search
- /*
- cmapput.c 3/23/88
-
- % Functions that draw into a cmap
- By Ted.
-
- OWL 1.1
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- */
- /* -------------------------------------------------------------------------- */
- #include "oakhead.h"
- #include "disppriv.h"
- #include "cmapdecl.h"
- /* -------------------------------------------------------------------------- */
-
- char *cmap_psa(cmap, row, col, string, attrbuf, attr, slen)
- cmap_type cmap;
- int row;
- int col;
- char *string; /* terminated string */
- byte *attrbuf;
- byte attr;
- int slen;
- /*
- Places string within current cmap, clipping against cmap edges.
- Puts blanks from end of string to slen if string was too short.
- String is not read after a newline or a '\0'.
- Coords are relative to cmap.
- If attrbuf is NULL, 'attr' is used as the attribute for all chars.
- For blanks past the end of the string, attribute 'attr' is used even if
- attrbuf is not NULL.
- Returns pointer to char after last one put into cmap.
- */
- {
- register int i;
- int height, width;
- char *charptr, *cmapchar;
- byte *attrptr, *cmapattr;
-
- height = cmap->nrows;
- width = cmap->ncols;
-
- /* clip against edges of cmap */
- if (row < 0 || row >= height || col >= width || slen < 1) {
- return(string);
- }
- slen = ((slen + col) >= width) ? (width - col): slen;
-
- charptr = string;
- attrptr = attrbuf;
- if (col < 0) {
- /* find start of string */
- for (i = col; i < 0; i++) {
- if (*charptr == '\0' || *charptr == '\n') {
- break;
- }
- charptr++;
- attrptr++; /* we'll ignore this if attrbuf == NULL */
- }
- slen += col;
- col = 0;
- }
-
- cmapchar = &(cmap->charbuf[row * cmap->ncols + col]);
- cmapattr = (byte *)(cmapchar + cmap->bufsize);
-
- if (attrbuf != NULL) {
- /* fill cmap with chars and attrs from strings */
- for (i = 0; *charptr != '\0' && *charptr != '\n' && i < slen; i++) {
- *cmapchar++ = *charptr++;
- *cmapattr++ = *attrptr++;
- }
- }
- else {
- /* fill cmap with chars and attrs from string */
- for (i = 0; *charptr != '\0' && *charptr != '\n' && i < slen; i++) {
- *cmapchar++ = *charptr++;
- *cmapattr++ = attr;
- }
- }
- /* write blanks past end of the line */
- for ( ; i < slen; i++) {
- *cmapchar++ = ' ';
- *cmapattr++ = attr;
- }
- return(charptr);
- }
- /* -------------------------------------------------------------------------- */
-
- void cmap_PutBox(cmap, boxchar, cboxp, attr)
- cmap_type cmap;
- char *boxchar;
- ocbox *cboxp;
- byte attr;
- /*
- DESCRIPTION:
-
- Draws box in cmap
- */
- {
- /* yes the corners get drawn twice, but oh well... jd */
-
- /* trick cmap_PutLine */
- boxchar[8] = boxchar[0];
-
- /* top side */
- cmap_PutHzLine(cmap, boxchar, cboxp->toprow, cboxp->leftcol,
- ocbox_GetWidth(cboxp), attr);
- /* right side */
- cmap_PutVtLine(cmap, boxchar + 2, cboxp->toprow, cboxp->rightcol,
- ocbox_GetHeight(cboxp), attr);
- /* bottom side */
- cmap_PutHzLine(cmap, boxchar + 4, cboxp->botrow, cboxp->rightcol,
- -ocbox_GetWidth(cboxp), attr);
- /* left side */
- cmap_PutVtLine(cmap, boxchar + 6, cboxp->botrow, cboxp->leftcol,
- -ocbox_GetHeight(cboxp), attr);
- /* restore boxchar */
- boxchar[8] = '\0';
- }
- /* -------------------------------------------------------------------------- */
-
- void cmap_PutHzLine(cmap, linechar, row1, col1, length, attr)
- cmap_type cmap;
- char *linechar;
- int row1, col1, length;
- byte attr;
- /*
- DESCRIPTION:
-
- Draw line using the characters in linechar and the
- attribute specified by attr.
- The start point of the line is (row1, col1).
- 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.
-
- example:
- cmap_PutHzLine(win, "123", 0, 0, 10, '\x07');
-
- 12222222223
- */
- {
- register int delta;
-
- /* determine direction of line */
- if (length == 0) return;
- else if (length > 0)
- delta = 1;
- else
- delta = -1;
-
- cmap_PutChar(cmap, row1, col1, linechar[0], attr);
- length -= delta;
- if (length != 0) {
- cmap_PutChar(cmap, row1, col1+length, linechar[2], attr);
- length -= delta;
- for ( ; length != 0; length -= delta)
- cmap_PutChar(cmap, row1, col1+length, linechar[1], attr);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- void cmap_PutVtLine(cmap, linechar, row1, col1, length, attr)
- cmap_type cmap;
- char *linechar;
- int row1, col1, length;
- byte attr;
- /*
- DESCRIPTION:
-
- Draw a line using the characters in linechar and the
- attribute specified by attr.
- The start point of the line is (row1, col1).
- 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.
-
- example:
- cmap_PutVtLine(win, "123", 0, 0, '\x07');
-
- 1
- 2
- 2
- 3
- */
- {
- register int delta;
-
- /* determine direction of line */
- if (length == 0) return;
- else if (length > 0)
- delta = 1;
- else
- delta = -1;
-
- cmap_PutChar(cmap, row1, col1, linechar[0], attr);
- length -= delta;
- if (length != 0) {
- cmap_PutChar(cmap, row1+length, col1, linechar[2], attr);
- length -= delta;
- for ( ; length != 0; length -= delta)
- cmap_PutChar(cmap, row1+length, col1, linechar[1], attr);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- void cmap_ClearBox(cmap, cboxp, attr)
- cmap_type cmap;
- ocbox *cboxp;
- byte attr;
- /*
- Clears a region of an image.
- WARNING: if cboxp is not clipped within the cmap, disastrous assignments
- will occur. For speed, no clipping is done at this level.
- */
- {
- int row, width;
- char *charptr;
- byte *attrptr;
-
- width = ocbox_GetWidth(cboxp);
-
- charptr = &(cmap->charbuf[
- cboxp->toprow * cmap->ncols + cboxp->leftcol]);
- attrptr = (byte *)(charptr + cmap->bufsize);
- for (row = ocbox_GetHeight(cboxp); row > 0; row--) {
- memset(charptr, ' ', width);
- memset(attrptr, attr, width);
- charptr += cmap->ncols;
- attrptr += cmap->ncols;
- }
- }
- /* -------------------------------------------------------------------------- */
-
- void cmap_ScrollBoxVt(cmap, cboxp, nlines)
- cmap_type cmap;
- ocbox *cboxp;
- int nlines;
- /*
- Scrolls an image map.
- The direction of scrolling depends on the sign of 'nlines'.
- If 'nlines' is positive the image is scrolled up, otherwise
- the image is scrolled down. The image is cleared if 'nlines' is 0.
- WARNING: if cboxp is not clipped within the cmap, disastrous assignments
- will occur. For speed, no clipping is done at this level.
- */
- {
- int row1, row2;
- int height, width;
- char *charptr1;
- byte *attrptr1;
- char *charptr2;
- byte *attrptr2;
- int delta;
-
- height = ocbox_GetHeight(cboxp);
- width = ocbox_GetWidth(cboxp);
-
- if (nlines > 0) {
- /* scroll up */
- if (nlines < height) {
- row2 = cboxp->toprow;
- row1 = row2 + nlines;
- delta = cmap->ncols;
- }
- }
- else if (nlines < 0) {
- /* scroll down */
- nlines = -nlines;
- if (nlines < height) {
- row2 = cboxp->botrow;
- row1 = row2 - nlines;
- delta = -cmap->ncols;
- }
- }
- height -= nlines;
-
- /* Scroll the map */
- charptr2 = &(cmap->charbuf[row2*cmap->ncols + cboxp->leftcol]);
- attrptr2 = (byte *)(charptr2 + cmap->bufsize);
- charptr1 = &(cmap->charbuf[row1*cmap->ncols + cboxp->leftcol]);
- attrptr1 = (byte *)(charptr1 + cmap->bufsize);
-
- for ( ; height > 0; height--) {
- memmove(charptr2, charptr1, width);
- memmove(attrptr2, attrptr1, width);
-
- charptr2 += delta;
- charptr1 += delta;
- attrptr2 += delta;
- attrptr1 += delta;
- }
- }
- /* -------------------------------------------------------------------------- */
-
- void cmap_ScrollBoxHz(cmap, cboxp, nlines)
- cmap_type cmap;
- ocbox *cboxp;
- int nlines;
- /*
- Scrolls an image map.
- The direction of scrolling depends on the sign of 'nlines'.
- If 'nlines' is positive the image is scrolled left, otherwise
- the image is scrolled right. The image is cleared if 'nlines' is 0.
- WARNING: if cboxp is not clipped within the cmap, disastrous assignments
- will occur. For speed, no clipping is done at this level.
- */
- {
- int col1, col2;
- int height, width;
- char *charptr1;
- byte *attrptr1;
- char *charptr2;
- byte *attrptr2;
-
- width = ocbox_GetWidth(cboxp);
- height = ocbox_GetHeight(cboxp);
-
- col1 = col2 = cboxp->leftcol;
- if (nlines > 0) {
- /* scroll left */
- if (nlines < width) {
- col1 += nlines;
- }
- }
- else if (nlines < 0) {
- /* scroll right */
- nlines = - nlines;
- if (nlines < width) {
- col2 += nlines;
- }
- }
- width -= nlines;
-
- /* Scroll the map */
- charptr2 = &(cmap->charbuf[cboxp->toprow*cmap->ncols + col2]);
- attrptr2 = (byte *)(charptr2 + cmap->bufsize);
- charptr1 = &(cmap->charbuf[cboxp->toprow*cmap->ncols + col1]);
- attrptr1 = (byte *)(charptr1 + cmap->bufsize);
-
- for ( ; height > 0; height--) {
- memmove(charptr2, charptr1, width);
- memmove(attrptr2, attrptr1, width);
-
- charptr2 += cmap->ncols;
- charptr1 += cmap->ncols;
- attrptr2 += cmap->ncols;
- attrptr1 += cmap->ncols;
- }
- }
- /* -------------------------------------------------------------------------- */
-
-