home *** CD-ROM | disk | FTP | other *** search
- /*
- cmwindraw.c 1/26/88
-
- % functions that put stuff in a cmap and paint to display.
-
- OWL 1.2
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 8/13/88 jmd Added new win_GetAttr()
- 9/29/88 ted Added cmwin_GetStringAttr()
- 9/29/88 ted Added cmap-in-cmwin row+col offsets
- 3/08/89 ted Added cmap_clipping for Scrolls & Clear
- 3/28/89 ted Put in macros for cmwin offsets in xd structure.
-
- 11/29/89 jmd added mem... casts for DG
- 3/28/90 jmd ansi-fied
- 5/05/90 ted Cleaned up; removed charattrbuf macro.
- 9/21/90 pmcm fixed row out of cmap case in _GetStringAttr
- (changed reference from col to row)
- 9/27/90 pmcm/ted fixed map pointer offset in _GetStringAttr
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
- #include "cmwinobj.h"
- #include "cmapdecl.h"
- /* -------------------------------------------------------------------------- */
-
- int cmwin_GetStringAttr(win_type win, int row, int col, char *charbuf, byte *attrbuf, int maxlen)
- /*
- Fills charbuf and attrbuf with chars and attrs from a cmap window.
- If the buffers asked for do not fall within the window's cmap, blanks are
- used to fill charbuf and the window's default attribute is used to fill
- attrbuf.
- The buffers are not null-terminated.
- The return value is the number of chars/attrs actually gotten from the cmap.
- */
- {
- cmap_type cmap;
- char *cp;
- byte *ap;
- int len, i;
-
- cmap = cmwin_GetCmap(win);
-
- row -= cmwin_GetRowoffs(win);
- col -= cmwin_GetColoffs(win);
-
- /* If row is out of cmap, fill up buffers with filler */
- if (row < 0 || row >= cmap_GetHeight(cmap)) {
- memset((VOID *) charbuf, ' ', maxlen);
- memset((VOID *) attrbuf, win_GetAttr(win), maxlen);
- return(0);
- }
- else {
-
- cp = cmap_charbuf(cmap, row, 0);
- ap = cmap_attrbuf(cmap, row, 0);
-
- /* Fill with filler at start of buffers if out of cmap on left. */
- if (col < 0) {
- len = -col;
- if (len > maxlen) {
- len = maxlen;
- }
- memset((VOID *) charbuf, ' ', len);
- memset((VOID *) attrbuf, win_GetAttr(win), len);
- charbuf += len;
- attrbuf += len;
- }
- else {
- len = 0;
- cp += col;
- ap += col;
- }
-
- /* Fill with chars/attrs from cmap. */
- for (i = len; (i < maxlen) && (col+i < cmap_GetWidth(cmap)); i++) {
- *(charbuf++) = *(cp++);
- *(attrbuf++) = *(ap++);
- }
-
- /* Fill with filler at end of buffers if out of cmap on right. */
- if (i < maxlen) {
- len = maxlen - i;
- memset((VOID *) charbuf, ' ', len);
- memset((VOID *) attrbuf, win_GetAttr(win), len);
- }
- return(i);
- }
- }
- /* -------------------------------------------------------------------------- */
-
- char *cmwin_dsa(win_type win, int row, int col, char *string, byte *attrbuf, byte attr, int slen)
- /*
- EXTERN
- Puts a string in a window.
- Coords are relative to window.
- Places string within current cmap image, clipping against cmap edges,
- then calls win_PaintRow to clip against other windows.
- if attrbuf == NULL use attr as attribute.
- */
- {
- char *t;
-
- t = cmap_psa(cmwin_GetCmap(win), row - cmwin_GetRowoffs(win),
- col - cmwin_GetColoffs(win),
- string, attrbuf, attr, slen);
-
- if (win_IsEmployed(win)) {
- win_PaintRow(win, row, col, slen);
- }
- return(t);
- }
- /* -------------------------------------------------------------------------- */
-
- char *cmwin_DrawChar(win_type win, int row, int col, char c, byte attr)
- {
- char s[2];
-
- s[0] = c;
- s[1] = '\0';
- return(cmwin_dsa(win, row, col, s, NULL, attr, 1));
- }
- /* -------------------------------------------------------------------------- */
-
- void cmwin_DrawBox(win_type win, char *boxcp, ocbox *cboxp, byte attr)
- /*
- DESCRIPTION:
- This function draws a box using the characters in boxcp and the
- attribute specified by attr.
- The box coordinates are relative to window 'win'.
- The 9 characters in the boxcp string represent the box in the
- following manner:
- boxcp[0] upper left corner character.
- boxcp[1] upper side character.
- boxcp[2] upper right corner character.
- boxcp[3] right side character.
- boxcp[4] lower right corner character.
- boxcp[5] lower side character.
- boxcp[6] lower left corner character.
- boxcp[7] left side character.
- boxcp[8] '\0' MUST be here...
-
- example:
- cmwin_DrawBox("01234567", 0, 0, 4, 4, '\x07');
- 0112
- 7 3
- 7 3
- 6554
- */
- {
- ocbox tcbox;
-
- /* Draw box in cmap */
- ocbox_copy(&tcbox, cboxp);
- ocbox_trans(&tcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
- cmap_PutBox(cmwin_GetCmap(win), boxcp, &tcbox, attr);
-
- /* Then paint to screen... */
- /* top side */
- win_PaintRow(win, cboxp->toprow, cboxp->leftcol, ocbox_GetWidth(cboxp)-1);
- /* right side */
- win_PaintCol(win, cboxp->toprow, cboxp->rightcol, ocbox_GetHeight(cboxp)-1);
- /* bottom side */
- win_PaintRow(win, cboxp->botrow, cboxp->leftcol+1, ocbox_GetWidth(cboxp)-1);
- /* left side */
- win_PaintCol(win, cboxp->toprow+1, cboxp->leftcol, ocbox_GetHeight(cboxp)-1);
- }
- /* -------------------------------------------------------------------------- */
-
- void cmwin_DrawHzLine(win_type win, char *linecp, int row1, int col1, int length, byte attr)
- /*
- DESCRIPTION:
- Draw line using the characters in linecp and the
- attribute specified by attr.
- The start point of the line is (row1, col1).
- The 3 characters in the linecp string represent the line in the
- following manner:
- linecp[0] first character.
- linecp[1] line character.
- linecp[2] last character.
- example:
- cmwin_DrawHzLine(win, "123", 0, 0, 10, '\x07');
- 12222222223
- */
- {
- /* Draw in cmap */
- cmap_PutHzLine(cmwin_GetCmap(win), linecp,
- row1 - cmwin_GetRowoffs(win),
- col1 - cmwin_GetColoffs(win), length, attr);
- /* Then paint to screen */
- win_PaintRow(win, row1, col1, length);
- }
- /* -------------------------------------------------------------------------- */
-
- void cmwin_DrawVtLine(win_type win, char *linecp, int row1, int col1, int length, byte attr)
- /*
- DESCRIPTION:
- Draw a line using the characters in linecp and the
- attribute specified by attr.
- The start point of the line is (row1, col1).
- The 3 characters in the linecp string represent the line in the
- following manner:
- linecp[0] first character.
- linecp[1] line character.
- linecp[2] last character.
- example:
- cmwin_DrawVtLine(win, "123", 0, 4, '\x07');
- 1
- 2
- 2
- 3
- */
- {
- /* Draw in cmap */
- cmap_PutVtLine(cmwin_GetCmap(win), linecp,
- row1 - cmwin_GetRowoffs(win),
- col1 - cmwin_GetColoffs(win), length, attr);
- /* Then paint to screen */
- win_PaintCol(win, row1, col1, length);
- }
- /* -------------------------------------------------------------------------- */
-
- void cmwin_ScrollBoxVt(win_type win, ocbox *cboxp, int n)
- {
- ocbox tcbox;
- cmap_type cmap;
-
- cmap = cmwin_GetCmap(win);
- ocbox_copy(&tcbox, cboxp);
- ocbox_trans(&tcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
- if (cmap_clipcbox(cmap, &tcbox)) {
- cmap_ScrollBoxVt(cmap, &tcbox, n);
-
- if (ocbox_ScrollVtIn(&tcbox, n)) {
- cmap_ClearBox(cmap, &tcbox, win_GetAttr(win));
- }
- }
- win_ScrollBox(win, cboxp, n, 0);
- }
- /* -------------------------------------------------------------------------- */
-
- void cmwin_ScrollBoxHz(win_type win, ocbox *cboxp, int n)
- {
- ocbox tcbox;
- cmap_type cmap;
-
- cmap = cmwin_GetCmap(win);
- ocbox_copy(&tcbox, cboxp);
- ocbox_trans(&tcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
- if (cmap_clipcbox(cmap, &tcbox)) {
- cmap_ScrollBoxHz(cmap, &tcbox, n);
-
- if (ocbox_ScrollHzIn(&tcbox, n)) {
- cmap_ClearBox(cmap, &tcbox, win_GetAttr(win));
- }
- }
- win_ScrollBox(win, cboxp, 0, n);
- }
- /* -------------------------------------------------------------------------- */
-
- void cmwin_ClearBox(win_type win, ocbox *cboxp, byte attr)
- {
- ocbox tcbox;
- cmap_type cmap;
-
- cmap = cmwin_GetCmap(win);
- ocbox_copy(&tcbox, cboxp);
- ocbox_trans(&tcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
- if (cmap_clipcbox(cmap, &tcbox)) {
- cmap_ClearBox(cmap, &tcbox, attr);
- }
- win_ClearBox(win, cboxp, disp_GetAttrBgColor(attr));
- }
- /* -------------------------------------------------------------------------- */
-
- void cmwin_Clear(win_type win, byte attr)
- {
- ocbox cbox;
-
- win_GetBox(win, &cbox);
- cmwin_ClearBox(win, &cbox, (byte)attr);
- }
- /* -------------------------------------------------------------------------- */
-
-