home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / CMWINDRA.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-27  |  8.2 KB  |  290 lines

  1. /*
  2.     cmwindraw.c    1/26/88
  3.  
  4.     % functions that put stuff in a cmap and paint to display.
  5.  
  6.     OWL 1.2
  7.     Copyright (c) 1988, by Oakland Group, Inc.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12.      8/13/88 jmd    Added new win_GetAttr()
  13.      9/29/88 ted    Added cmwin_GetStringAttr()
  14.      9/29/88 ted    Added cmap-in-cmwin row+col offsets
  15.      3/08/89 ted    Added cmap_clipping for Scrolls & Clear
  16.      3/28/89 ted    Put in macros for cmwin offsets in xd structure.
  17.  
  18.     11/29/89 jmd    added mem... casts for DG
  19.      3/28/90 jmd    ansi-fied
  20.      5/05/90 ted    Cleaned up; removed charattrbuf macro.
  21.      9/21/90 pmcm    fixed row out of cmap case in _GetStringAttr 
  22.                         (changed reference from col to row)
  23.      9/27/90 pmcm/ted    fixed map pointer offset in _GetStringAttr 
  24. */
  25.  
  26. #include "oakhead.h"
  27. #include "disppriv.h"
  28. #include "cmwinobj.h"
  29. #include "cmapdecl.h"
  30. /* -------------------------------------------------------------------------- */
  31.  
  32. int cmwin_GetStringAttr(win_type win, int row, int col, char *charbuf, byte *attrbuf, int maxlen)
  33. /*
  34.     Fills charbuf and attrbuf with chars and attrs from a cmap window.
  35.     If the buffers asked for do not fall within the window's cmap, blanks are
  36.     used to fill charbuf and the window's default attribute is used to fill
  37.     attrbuf.
  38.     The buffers are not null-terminated.
  39.     The return value is the number of chars/attrs actually gotten from the cmap.
  40. */
  41. {
  42.     cmap_type cmap;
  43.     char      *cp;
  44.     byte      *ap;
  45.     int       len, i;
  46.  
  47.     cmap = cmwin_GetCmap(win);
  48.  
  49.     row -= cmwin_GetRowoffs(win);
  50.     col -= cmwin_GetColoffs(win);
  51.  
  52.     /* If row is out of cmap, fill up buffers with filler */
  53.     if (row < 0 || row >= cmap_GetHeight(cmap)) {
  54.         memset((VOID *) charbuf, ' ', maxlen);
  55.         memset((VOID *) attrbuf, win_GetAttr(win), maxlen);
  56.         return(0);
  57.     }
  58.     else {
  59.  
  60.         cp = cmap_charbuf(cmap, row, 0);
  61.         ap = cmap_attrbuf(cmap, row, 0);
  62.  
  63.         /* Fill with filler at start of buffers if out of cmap on left. */
  64.         if (col < 0) {
  65.             len = -col;
  66.             if (len > maxlen) {
  67.                 len = maxlen;
  68.             }
  69.             memset((VOID *) charbuf, ' ', len);
  70.             memset((VOID *) attrbuf, win_GetAttr(win), len);
  71.             charbuf += len;
  72.             attrbuf += len;
  73.         }
  74.         else {
  75.             len = 0;
  76.             cp += col;
  77.             ap += col;
  78.         }
  79.  
  80.         /* Fill with chars/attrs from cmap. */
  81.         for (i = len; (i < maxlen) && (col+i < cmap_GetWidth(cmap)); i++) {
  82.             *(charbuf++) = *(cp++);
  83.             *(attrbuf++) = *(ap++);
  84.         }
  85.  
  86.         /* Fill with filler at end of buffers if out of cmap on right. */
  87.         if (i < maxlen) {
  88.             len = maxlen - i;
  89.             memset((VOID *) charbuf, ' ', len);
  90.             memset((VOID *) attrbuf, win_GetAttr(win), len);
  91.         }
  92.         return(i);
  93.     }
  94. }
  95. /* -------------------------------------------------------------------------- */
  96.  
  97. char *cmwin_dsa(win_type win, int row, int col, char *string, byte *attrbuf, byte attr, int slen)
  98. /*
  99.     EXTERN
  100.     Puts a string in a window.
  101.     Coords are relative to window.
  102.     Places string within current cmap image, clipping against cmap edges,
  103.     then calls win_PaintRow to clip against other windows.
  104.     if attrbuf == NULL use attr as attribute.
  105. */
  106. {
  107.     char *t;
  108.  
  109.     t = cmap_psa(cmwin_GetCmap(win), row - cmwin_GetRowoffs(win),
  110.                                      col - cmwin_GetColoffs(win),
  111.                     string, attrbuf, attr, slen);
  112.  
  113.     if (win_IsEmployed(win)) {
  114.         win_PaintRow(win, row, col, slen);
  115.     }
  116.     return(t);
  117. }
  118. /* -------------------------------------------------------------------------- */
  119.  
  120. char *cmwin_DrawChar(win_type win, int row, int col, char c, byte attr)
  121. {
  122.     char s[2];
  123.  
  124.     s[0] = c;
  125.     s[1] = '\0';
  126.     return(cmwin_dsa(win, row, col, s, NULL, attr, 1));
  127. }
  128. /* -------------------------------------------------------------------------- */
  129.  
  130. void cmwin_DrawBox(win_type win, char *boxcp, ocbox *cboxp, byte attr)
  131. /*
  132.     DESCRIPTION:
  133.     This function draws a box using the characters in boxcp and the
  134.     attribute specified by attr.
  135.     The box coordinates are relative to window 'win'.
  136.     The 9 characters in the boxcp string represent the box in the 
  137.     following manner:
  138.     boxcp[0]        upper left corner character.
  139.     boxcp[1]        upper side character.
  140.     boxcp[2]        upper right corner character.
  141.     boxcp[3]        right side character.
  142.     boxcp[4]        lower right corner character.
  143.     boxcp[5]        lower side character.
  144.     boxcp[6]        lower left corner character.
  145.     boxcp[7]        left side character.
  146.     boxcp[8]        '\0'  MUST be here...
  147.     
  148.     example:
  149.     cmwin_DrawBox("01234567", 0, 0, 4, 4, '\x07');
  150.     0112
  151.     7  3
  152.     7  3
  153.     6554
  154. */        
  155. {
  156.     ocbox tcbox;
  157.  
  158.     /* Draw box in cmap  */
  159.     ocbox_copy(&tcbox, cboxp);
  160.     ocbox_trans(&tcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
  161.     cmap_PutBox(cmwin_GetCmap(win), boxcp, &tcbox, attr);
  162.  
  163.     /* Then paint to screen... */
  164.     /* top side */
  165.     win_PaintRow(win, cboxp->toprow, cboxp->leftcol, ocbox_GetWidth(cboxp)-1);
  166.     /* right side */
  167.     win_PaintCol(win, cboxp->toprow, cboxp->rightcol, ocbox_GetHeight(cboxp)-1);
  168.     /* bottom side */
  169.     win_PaintRow(win, cboxp->botrow, cboxp->leftcol+1, ocbox_GetWidth(cboxp)-1);
  170.     /* left side */
  171.     win_PaintCol(win, cboxp->toprow+1, cboxp->leftcol, ocbox_GetHeight(cboxp)-1);
  172. }
  173. /* -------------------------------------------------------------------------- */
  174.  
  175. void cmwin_DrawHzLine(win_type win, char *linecp, int row1, int col1, int length, byte attr)
  176. /*
  177.     DESCRIPTION:
  178.     Draw line using the characters in linecp and the
  179.     attribute specified by attr.
  180.     The start point of the line is (row1, col1).
  181.     The 3 characters in the linecp string represent the line in the 
  182.     following manner:
  183.     linecp[0]        first character.
  184.     linecp[1]        line character.
  185.     linecp[2]        last character.
  186.     example:
  187.     cmwin_DrawHzLine(win, "123", 0, 0, 10, '\x07');
  188.     12222222223
  189. */
  190. {
  191.     /* Draw in cmap  */
  192.     cmap_PutHzLine(cmwin_GetCmap(win), linecp,
  193.                     row1 - cmwin_GetRowoffs(win),
  194.                     col1 - cmwin_GetColoffs(win), length, attr);
  195.     /* Then paint to screen */
  196.     win_PaintRow(win, row1, col1, length);
  197. }
  198. /* -------------------------------------------------------------------------- */
  199.  
  200. void cmwin_DrawVtLine(win_type win, char *linecp, int row1, int col1, int length, byte attr)
  201. /*
  202.     DESCRIPTION:
  203.     Draw a line using the characters in linecp and the
  204.     attribute specified by attr.
  205.     The start point of the line is (row1, col1).
  206.     The 3 characters in the linecp string represent the line in the 
  207.     following manner:
  208.     linecp[0]        first character.
  209.     linecp[1]        line character.
  210.     linecp[2]        last character.
  211.     example:
  212.     cmwin_DrawVtLine(win, "123", 0, 4, '\x07');
  213.     1
  214.     2
  215.     2
  216.     3
  217. */
  218. {
  219.     /* Draw in cmap  */
  220.     cmap_PutVtLine(cmwin_GetCmap(win), linecp,
  221.                     row1 - cmwin_GetRowoffs(win),
  222.                     col1 - cmwin_GetColoffs(win), length, attr);
  223.     /* Then paint to screen */
  224.     win_PaintCol(win, row1, col1, length);
  225. }
  226. /* -------------------------------------------------------------------------- */
  227.  
  228. void cmwin_ScrollBoxVt(win_type win, ocbox *cboxp, int n)
  229. {
  230.     ocbox tcbox;
  231.     cmap_type cmap;
  232.  
  233.     cmap = cmwin_GetCmap(win);
  234.     ocbox_copy(&tcbox, cboxp);
  235.     ocbox_trans(&tcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
  236.     if (cmap_clipcbox(cmap, &tcbox)) {
  237.         cmap_ScrollBoxVt(cmap, &tcbox, n);
  238.  
  239.         if (ocbox_ScrollVtIn(&tcbox, n)) {
  240.             cmap_ClearBox(cmap, &tcbox, win_GetAttr(win));
  241.         }
  242.     }
  243.     win_ScrollBox(win, cboxp, n, 0);
  244. }
  245. /* -------------------------------------------------------------------------- */
  246.  
  247. void cmwin_ScrollBoxHz(win_type win, ocbox *cboxp, int n)
  248. {
  249.     ocbox tcbox;
  250.     cmap_type cmap;
  251.  
  252.     cmap = cmwin_GetCmap(win);
  253.     ocbox_copy(&tcbox, cboxp);
  254.     ocbox_trans(&tcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
  255.     if (cmap_clipcbox(cmap, &tcbox)) {
  256.         cmap_ScrollBoxHz(cmap, &tcbox, n);
  257.  
  258.         if (ocbox_ScrollHzIn(&tcbox, n)) {
  259.             cmap_ClearBox(cmap, &tcbox, win_GetAttr(win));
  260.         }
  261.     }
  262.     win_ScrollBox(win, cboxp, 0, n);
  263. }
  264. /* -------------------------------------------------------------------------- */
  265.  
  266. void cmwin_ClearBox(win_type win, ocbox *cboxp, byte attr)
  267. {
  268.     ocbox tcbox;
  269.     cmap_type cmap;
  270.  
  271.     cmap = cmwin_GetCmap(win);
  272.     ocbox_copy(&tcbox, cboxp);
  273.     ocbox_trans(&tcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
  274.     if (cmap_clipcbox(cmap, &tcbox)) {
  275.         cmap_ClearBox(cmap, &tcbox, attr);
  276.     }
  277.     win_ClearBox(win, cboxp, disp_GetAttrBgColor(attr));
  278. }
  279. /* -------------------------------------------------------------------------- */
  280.  
  281. void cmwin_Clear(win_type win, byte attr)
  282. {
  283.     ocbox cbox;
  284.  
  285.     win_GetBox(win, &cbox);
  286.     cmwin_ClearBox(win, &cbox, (byte)attr);
  287. }
  288. /* -------------------------------------------------------------------------- */
  289.  
  290.