home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / CMWINDRA.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  8.3 KB  |  332 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.1
  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.  
  19. #include "oakhead.h"
  20. #include "disppriv.h"
  21. #include "cmwinobj.h"
  22. #include "cmapdecl.h"
  23. /* -------------------------------------------------------------------------- */
  24.  
  25. int cmwin_GetStringAttr(win, row, col, charbuf, attrbuf, maxlen)
  26.     win_type win;
  27.     int row;
  28.     int col;
  29.     char *charbuf;
  30.     byte *attrbuf;
  31.     int maxlen;
  32. /*
  33.     Fills charbuf and attrbuf with chars and attrs from a cmap window.
  34.     If the buffers asked for do not fall within the window's cmap, blanks are
  35.     used to fill charbuf and the window's default attribute is used to fill
  36.     attrbuf.
  37.     The buffers are not null-terminated.
  38.     The return value is the number of chars/attrs actually gotten from the cmap.
  39. */
  40. {
  41.     cmap_type cmap;
  42.     char *cp;
  43.     byte *ap;
  44.     int len, i;
  45.  
  46.     cmap = cmwin_GetCmap(win);
  47.  
  48.     row -= cmwin_GetRowoffs(win);
  49.     col -= cmwin_GetColoffs(win);
  50.  
  51. /* If row is out of cmap, fill up buffers with filler */
  52.     if (col < 0 || col >= cmap_GetHeight(cmap)) {
  53.         memset(charbuf, ' ', maxlen);
  54.         memset(attrbuf, win_GetAttr(win), maxlen);
  55.         return(0);
  56.     }
  57.     else {
  58.         cp = cmap_charbuf(cmap, row, col);
  59.         ap = cmap_charattrbuf(cmap, cp);
  60.  
  61.     /* Fill with filler at start of buffers if out of cmap on left. */
  62.         if (col < 0) {
  63.             len = -col;
  64.             if (len > maxlen) len = maxlen;
  65.             memset(charbuf, ' ', len);
  66.             memset(attrbuf, win_GetAttr(win), len);
  67.             charbuf += len;
  68.             attrbuf += len;
  69.         }
  70.         else {
  71.             len = 0;
  72.             cp += col;
  73.             ap += col;
  74.         }
  75.     /* Fill with chars/attrs from cmap. */
  76.         for (i = len; (i < maxlen) && (col+i < cmap_GetWidth(cmap)); i++) {
  77.             *(charbuf++) = *(cp++);
  78.             *(attrbuf++) = *(ap++);
  79.         }
  80.     /* Fill with filler at end of buffers if out of cmap on right. */
  81.         if (i < maxlen) {
  82.             len = maxlen - i;
  83.             memset(charbuf, ' ', len);
  84.             memset(attrbuf, win_GetAttr(win), len);
  85.         }
  86.         return(i);
  87.     }
  88. }
  89. /* -------------------------------------------------------------------------- */
  90.  
  91. char *cmwin_dsa(win, row, col, string, attrbuf, attr, slen)
  92.     win_type win;
  93.     int row;
  94.     int col;
  95.     char *string;            /* terminated string */
  96.     byte *attrbuf;
  97.     byte attr;
  98.     int slen;
  99. /*
  100.     EXTERN
  101.     Puts a string in a window.
  102.  
  103.     Coords are relative to window.
  104.  
  105.     Places string within current cmap image, clipping against cmap edges,
  106.     then calls win_PaintRow to clip against other windows.
  107.  
  108.     if attrbuf == NULL use attr as attribute.
  109. */
  110. {
  111.     char *t;
  112.  
  113.     t = cmap_psa(cmwin_GetCmap(win), row - cmwin_GetRowoffs(win),
  114.                                      col - cmwin_GetColoffs(win),
  115.                     string, attrbuf, attr, slen);
  116.  
  117.     if (win_IsEmployed(win)) {
  118.         win_PaintRow(win, row, col, slen);
  119.     }
  120.     return(t);
  121. }
  122. /* -------------------------------------------------------------------------- */
  123.  
  124. char *cmwin_DrawChar(win, row, col, c, attr)
  125.     win_type win;
  126.     int row;
  127.     int col;
  128.     char c;
  129.     byte attr;
  130. {
  131.     char s[2];
  132.     s[0] = c;
  133.     s[1] = '\0';
  134.     return(cmwin_dsa(win, row, col, s, NULL, attr, 1));
  135. }
  136. /* -------------------------------------------------------------------------- */
  137.  
  138. void cmwin_DrawBox(win, boxcp, cboxp, attr)
  139.     win_type win;    
  140.     char *boxcp;
  141.     ocbox *cboxp;
  142.     byte attr;
  143. /*
  144.     DESCRIPTION:
  145.  
  146.     This function draws a box using the characters in boxcp and the
  147.     attribute specified by attr.
  148.     The box coordinates are relative to window 'win'.
  149.     The 9 characters in the boxcp string represent the box in the 
  150.     following manner:
  151.  
  152.     boxcp[0]        upper left corner character.
  153.     boxcp[1]        upper side character.
  154.     boxcp[2]        upper right corner character.
  155.     boxcp[3]        right side character.
  156.     boxcp[4]        lower right corner character.
  157.     boxcp[5]        lower side character.
  158.     boxcp[6]        lower left corner character.
  159.     boxcp[7]        left side character.
  160.     boxcp[8]        '\0'  MUST be here...
  161.     
  162.     example:
  163.     cmwin_DrawBox("01234567", 0, 0, 4, 4, '\x07');
  164.  
  165.     0112
  166.     7  3
  167.     7  3
  168.     6554
  169. */        
  170. {
  171.     ocbox tcbox;
  172.  
  173.     /* Draw box in cmap  */
  174.     ocbox_copy(&tcbox, cboxp);
  175.     ocbox_trans(&tcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
  176.     cmap_PutBox(cmwin_GetCmap(win), boxcp, &tcbox, attr);
  177.  
  178.     /* Then paint to screen... */
  179.     /* top side */
  180.     win_PaintRow(win, cboxp->toprow, cboxp->leftcol, ocbox_GetWidth(cboxp)-1);
  181.     /* right side */
  182.     win_PaintCol(win, cboxp->toprow, cboxp->rightcol, ocbox_GetHeight(cboxp)-1);
  183.     /* bottom side */
  184.     win_PaintRow(win, cboxp->botrow, cboxp->leftcol+1, ocbox_GetWidth(cboxp)-1);
  185.     /* left side */
  186.     win_PaintCol(win, cboxp->toprow+1, cboxp->leftcol, ocbox_GetHeight(cboxp)-1);
  187. }
  188. /* -------------------------------------------------------------------------- */
  189.  
  190. void cmwin_DrawHzLine(win, linecp, row1, col1, length, attr)
  191.     win_type win;
  192.     char *linecp;
  193.     int row1, col1, length;
  194.     byte attr;
  195. /*
  196.     DESCRIPTION:
  197.  
  198.     Draw line using the characters in linecp and the
  199.     attribute specified by attr.
  200.     The start point of the line is (row1, col1).
  201.     The 3 characters in the linecp string represent the line in the 
  202.     following manner:
  203.  
  204.     linecp[0]        first character.
  205.     linecp[1]        line character.
  206.     linecp[2]        last character.
  207.  
  208.     example:
  209.     cmwin_DrawHzLine(win, "123", 0, 0, 10, '\x07');
  210.  
  211.     12222222223
  212. */
  213. {
  214.     /* Draw in cmap  */
  215.     cmap_PutHzLine(cmwin_GetCmap(win), linecp,
  216.                     row1 - cmwin_GetRowoffs(win),
  217.                     col1 - cmwin_GetColoffs(win), length, attr);
  218.     /* Then paint to screen */
  219.     win_PaintRow(win, row1, col1, length);
  220. }
  221. /* -------------------------------------------------------------------------- */
  222.  
  223. void cmwin_DrawVtLine(win, linecp, row1, col1, length, attr)
  224.     win_type win;
  225.     char *linecp;
  226.     int row1, col1, length;
  227.     byte attr;
  228. /*
  229.     DESCRIPTION:
  230.  
  231.     Draw a line using the characters in linecp and the
  232.     attribute specified by attr.
  233.     The start point of the line is (row1, col1).
  234.     The 3 characters in the linecp string represent the line in the 
  235.     following manner:
  236.  
  237.     linecp[0]        first character.
  238.     linecp[1]        line character.
  239.     linecp[2]        last character.
  240.  
  241.     example:
  242.     cmwin_DrawVtLine(win, "123", 0, 4, '\x07');
  243.  
  244.     1
  245.     2
  246.     2
  247.     3
  248. */
  249. {
  250.     /* Draw in cmap  */
  251.     cmap_PutVtLine(cmwin_GetCmap(win), linecp,
  252.                     row1 - cmwin_GetRowoffs(win),
  253.                     col1 - cmwin_GetColoffs(win), length, attr);
  254.     /* Then paint to screen */
  255.     win_PaintCol(win, row1, col1, length);
  256. }
  257. /* -------------------------------------------------------------------------- */
  258.  
  259. void cmwin_ScrollBoxVt(win, cboxp, n)
  260.     win_type win;
  261.     ocbox *cboxp;
  262.     int n;
  263. {
  264.     ocbox tcbox;
  265.     cmap_type cmap;
  266.  
  267.     cmap = cmwin_GetCmap(win);
  268.     ocbox_copy(&tcbox, cboxp);
  269.     ocbox_trans(&tcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
  270.     if (cmap_clipcbox(cmap, &tcbox)) {
  271.         cmap_ScrollBoxVt(cmap, &tcbox, n);
  272.  
  273.         if (ocbox_ScrollVtIn(&tcbox, n)) {
  274.             cmap_ClearBox(cmap, &tcbox, win_GetAttr(win));
  275.         }
  276.     }
  277.     win_ScrollBox(win, cboxp, n, 0);
  278. }
  279. /* -------------------------------------------------------------------------- */
  280.  
  281. void cmwin_ScrollBoxHz(win, cboxp, n)
  282.     win_type win;
  283.     ocbox *cboxp;
  284.     int n;
  285. {
  286.     ocbox tcbox;
  287.     cmap_type cmap;
  288.  
  289.     cmap = cmwin_GetCmap(win);
  290.     ocbox_copy(&tcbox, cboxp);
  291.     ocbox_trans(&tcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
  292.     if (cmap_clipcbox(cmap, &tcbox)) {
  293.         cmap_ScrollBoxHz(cmap, &tcbox, n);
  294.  
  295.         if (ocbox_ScrollHzIn(&tcbox, n)) {
  296.             cmap_ClearBox(cmap, &tcbox, win_GetAttr(win));
  297.         }
  298.     }
  299.     win_ScrollBox(win, cboxp, 0, n);
  300. }
  301. /* -------------------------------------------------------------------------- */
  302.  
  303. void cmwin_ClearBox(win, cboxp, attr)
  304.     win_type win;
  305.     ocbox *cboxp;
  306.     byte attr;
  307. {
  308.     ocbox tcbox;
  309.     cmap_type cmap;
  310.  
  311.     cmap = cmwin_GetCmap(win);
  312.     ocbox_copy(&tcbox, cboxp);
  313.     ocbox_trans(&tcbox, -cmwin_GetRowoffs(win), -cmwin_GetColoffs(win));
  314.     if (cmap_clipcbox(cmap, &tcbox)) {
  315.         cmap_ClearBox(cmap, &tcbox, attr);
  316.     }
  317.     win_ClearBox(win, cboxp, disp_GetAttrBgColor(attr));
  318. }
  319. /* -------------------------------------------------------------------------- */
  320.  
  321. void cmwin_Clear(win, attr)
  322.     win_type win;
  323.     byte attr;
  324. {
  325.     ocbox cbox;
  326.  
  327.     win_GetBox(win, &cbox);
  328.     cmwin_ClearBox(win, &cbox, (byte)attr);
  329. }
  330. /* -------------------------------------------------------------------------- */
  331.  
  332.