home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / CMAPPUT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  9.1 KB  |  364 lines

  1. /*
  2.     cmapput.c    3/23/88
  3.  
  4.     % Functions that draw into a cmap
  5.     By Ted.
  6.  
  7.     OWL 1.1
  8.     Copyright (c) 1988, by Oakland Group, Inc.
  9.     ALL RIGHTS RESERVED.
  10.  
  11.     Revision History:
  12.     -----------------
  13. */
  14. /* -------------------------------------------------------------------------- */
  15. #include "oakhead.h"
  16. #include "disppriv.h"
  17. #include "cmapdecl.h"
  18. /* -------------------------------------------------------------------------- */
  19.  
  20. char *cmap_psa(cmap, row, col, string, attrbuf, attr, slen)
  21.     cmap_type cmap;
  22.     int row;
  23.     int col;
  24.     char *string;            /* terminated string */
  25.     byte *attrbuf;
  26.     byte attr;
  27.     int slen;
  28. /*
  29.     Places string within current cmap, clipping against cmap edges.
  30.     Puts blanks from end of string to slen if string was too short.
  31.     String is not read after a newline or a '\0'.
  32.     Coords are relative to cmap.
  33.     If attrbuf is NULL, 'attr' is used as the attribute for all chars.
  34.     For blanks past the end of the string, attribute 'attr' is used even if
  35.     attrbuf is not NULL.
  36.     Returns pointer to char after last one put into cmap.
  37. */
  38. {
  39.     register int  i;
  40.     int        height, width;
  41.     char    *charptr, *cmapchar;
  42.     byte    *attrptr, *cmapattr;
  43.  
  44.     height = cmap->nrows;
  45.     width = cmap->ncols;
  46.  
  47.     /* clip against edges of cmap */
  48.     if (row < 0 || row >= height || col >= width || slen < 1) {
  49.         return(string);
  50.     }
  51.     slen = ((slen + col) >= width) ? (width - col): slen;
  52.  
  53.     charptr = string;
  54.     attrptr = attrbuf;
  55.     if (col < 0) {
  56.         /* find start of string */
  57.         for (i = col; i < 0; i++) {
  58.             if (*charptr == '\0' || *charptr == '\n') {
  59.                 break;
  60.             }
  61.             charptr++;
  62.             attrptr++;            /* we'll ignore this if attrbuf == NULL */
  63.         }
  64.         slen += col;
  65.         col = 0;
  66.     }
  67.  
  68.     cmapchar = &(cmap->charbuf[row * cmap->ncols + col]);
  69.     cmapattr = (byte *)(cmapchar + cmap->bufsize);
  70.  
  71.     if (attrbuf != NULL) {
  72.         /* fill cmap with chars and attrs from strings */
  73.         for (i = 0; *charptr != '\0' && *charptr != '\n' && i < slen; i++) {
  74.             *cmapchar++ = *charptr++;
  75.             *cmapattr++ = *attrptr++;
  76.         }
  77.     }
  78.     else {
  79.         /* fill cmap with chars and attrs from string */
  80.         for (i = 0; *charptr != '\0' && *charptr != '\n' && i < slen; i++) {
  81.             *cmapchar++ = *charptr++;
  82.             *cmapattr++ = attr;
  83.         }
  84.     }
  85.     /* write blanks past end of the line */
  86.     for ( ; i < slen; i++) {
  87.         *cmapchar++ = ' ';
  88.         *cmapattr++ = attr;
  89.     }
  90.     return(charptr);
  91. }
  92. /* -------------------------------------------------------------------------- */
  93.  
  94. void cmap_PutBox(cmap, boxchar, cboxp, attr)
  95.     cmap_type cmap;
  96.     char *boxchar;
  97.     ocbox *cboxp;
  98.     byte attr;
  99. /*
  100.     DESCRIPTION:
  101.  
  102.     Draws box in cmap
  103. */
  104. {
  105.     /* yes the corners get drawn twice, but oh well... jd */
  106.  
  107.     /* trick cmap_PutLine */
  108.     boxchar[8] = boxchar[0];
  109.  
  110.     /* top side */
  111.     cmap_PutHzLine(cmap, boxchar,     cboxp->toprow, cboxp->leftcol,
  112.                                     ocbox_GetWidth(cboxp), attr);
  113.     /* right side */
  114.     cmap_PutVtLine(cmap, boxchar + 2, cboxp->toprow, cboxp->rightcol,
  115.                                     ocbox_GetHeight(cboxp), attr);
  116.     /* bottom side */
  117.     cmap_PutHzLine(cmap, boxchar + 4, cboxp->botrow, cboxp->rightcol,
  118.                                     -ocbox_GetWidth(cboxp), attr);
  119.      /* left side */
  120.     cmap_PutVtLine(cmap, boxchar + 6, cboxp->botrow, cboxp->leftcol,
  121.                                     -ocbox_GetHeight(cboxp), attr);
  122.     /* restore boxchar */
  123.     boxchar[8] = '\0';
  124. }
  125. /* -------------------------------------------------------------------------- */
  126.  
  127. void cmap_PutHzLine(cmap, linechar, row1, col1, length, attr)
  128.     cmap_type cmap;
  129.     char *linechar;
  130.     int row1, col1, length;
  131.     byte attr;
  132. /*
  133.     DESCRIPTION:
  134.  
  135.     Draw line using the characters in linechar and the
  136.     attribute specified by attr.
  137.     The start point of the line is (row1, col1).
  138.     The 3 characters in the linechar string represent the line in the 
  139.     following manner:
  140.  
  141.     linechar[0]        first character.
  142.     linechar[1]        line character.
  143.     linechar[2]        last character.
  144.  
  145.     example:
  146.     cmap_PutHzLine(win, "123", 0, 0, 10, '\x07');
  147.  
  148.     12222222223
  149. */
  150. {
  151.     register int    delta;
  152.  
  153.     /* determine direction of line */
  154.     if (length == 0) return;
  155.     else if (length > 0)
  156.         delta = 1;
  157.     else
  158.         delta = -1;
  159.  
  160.     cmap_PutChar(cmap, row1, col1, linechar[0], attr);
  161.     length -= delta;
  162.     if (length != 0) {
  163.         cmap_PutChar(cmap, row1, col1+length, linechar[2], attr);
  164.         length -= delta;
  165.         for ( ; length != 0; length -= delta)
  166.             cmap_PutChar(cmap, row1, col1+length, linechar[1], attr);
  167.     }
  168. }
  169. /* -------------------------------------------------------------------------- */
  170.  
  171. void cmap_PutVtLine(cmap, linechar, row1, col1, length, attr)
  172.     cmap_type cmap;
  173.     char *linechar;
  174.     int row1, col1, length;
  175.     byte attr;
  176. /*
  177.     DESCRIPTION:
  178.  
  179.     Draw a line using the characters in linechar and the
  180.     attribute specified by attr.
  181.     The start point of the line is (row1, col1).
  182.     The 3 characters in the linechar string represent the line in the 
  183.     following manner:
  184.  
  185.     linechar[0]        first character.
  186.     linechar[1]        line character.
  187.     linechar[2]        last character.
  188.  
  189.     example:
  190.     cmap_PutVtLine(win, "123", 0, 0, '\x07');
  191.  
  192.     1
  193.     2
  194.     2
  195.     3
  196. */
  197. {
  198.     register int    delta;
  199.  
  200.     /* determine direction of line */
  201.     if (length == 0) return;
  202.     else if (length > 0)
  203.         delta = 1;
  204.     else
  205.         delta = -1;
  206.  
  207.     cmap_PutChar(cmap, row1, col1, linechar[0], attr);
  208.     length -= delta;
  209.     if (length != 0) {
  210.         cmap_PutChar(cmap, row1+length, col1, linechar[2], attr);
  211.         length -= delta;
  212.         for ( ; length != 0; length -= delta)
  213.             cmap_PutChar(cmap, row1+length, col1, linechar[1], attr);
  214.     }
  215. }
  216. /* -------------------------------------------------------------------------- */
  217.  
  218. void cmap_ClearBox(cmap, cboxp, attr)
  219.     cmap_type cmap;
  220.     ocbox *cboxp;
  221.     byte attr;
  222. /*
  223.     Clears a region of an image.
  224.     WARNING: if cboxp is not clipped within the cmap, disastrous assignments
  225.     will occur. For speed, no clipping is done at this level.
  226. */
  227. {
  228.     int row, width;
  229.     char *charptr;
  230.     byte *attrptr;
  231.  
  232.     width  = ocbox_GetWidth(cboxp);
  233.  
  234.     charptr = &(cmap->charbuf[
  235.                     cboxp->toprow * cmap->ncols + cboxp->leftcol]);
  236.     attrptr = (byte *)(charptr + cmap->bufsize);
  237.     for (row = ocbox_GetHeight(cboxp); row > 0; row--) {
  238.         memset(charptr, ' ', width);
  239.         memset(attrptr, attr, width);
  240.         charptr += cmap->ncols;
  241.         attrptr += cmap->ncols;
  242.     }
  243. }
  244. /* -------------------------------------------------------------------------- */
  245.  
  246. void cmap_ScrollBoxVt(cmap, cboxp, nlines)
  247.     cmap_type cmap;
  248.     ocbox *cboxp;
  249.     int nlines;
  250. /*
  251.     Scrolls an image map.
  252.     The direction of scrolling depends on the sign of 'nlines'. 
  253.     If 'nlines' is positive    the image is scrolled up, otherwise
  254.     the image is scrolled down. The image is cleared if 'nlines' is 0.
  255.     WARNING: if cboxp is not clipped within the cmap, disastrous assignments
  256.     will occur. For speed, no clipping is done at this level.
  257. */
  258. {
  259.     int row1, row2;
  260.     int height, width;
  261.     char *charptr1;
  262.     byte *attrptr1;
  263.     char *charptr2;
  264.     byte *attrptr2;
  265.     int delta;
  266.  
  267.     height = ocbox_GetHeight(cboxp);
  268.     width  = ocbox_GetWidth(cboxp);
  269.  
  270.     if (nlines > 0) {
  271.         /* scroll up */
  272.         if (nlines < height) {
  273.             row2 = cboxp->toprow;
  274.             row1 = row2 + nlines;
  275.             delta = cmap->ncols;
  276.         }
  277.     }
  278.     else if (nlines < 0) {
  279.         /* scroll down */
  280.         nlines = -nlines;
  281.         if (nlines < height) {
  282.             row2 = cboxp->botrow;
  283.             row1 = row2 - nlines;
  284.             delta = -cmap->ncols;
  285.          }
  286.     }
  287.     height -= nlines;
  288.  
  289.     /* Scroll the map */
  290.     charptr2 = &(cmap->charbuf[row2*cmap->ncols + cboxp->leftcol]);
  291.     attrptr2 = (byte *)(charptr2 + cmap->bufsize);
  292.     charptr1 = &(cmap->charbuf[row1*cmap->ncols + cboxp->leftcol]);
  293.     attrptr1 = (byte *)(charptr1 + cmap->bufsize);
  294.  
  295.     for ( ; height > 0; height--) {
  296.         memmove(charptr2, charptr1, width);
  297.         memmove(attrptr2, attrptr1, width);
  298.  
  299.         charptr2 += delta;
  300.         charptr1 += delta;
  301.         attrptr2 += delta;
  302.         attrptr1 += delta;
  303.     }
  304. }
  305. /* -------------------------------------------------------------------------- */
  306.  
  307. void cmap_ScrollBoxHz(cmap, cboxp, nlines)
  308.     cmap_type cmap;
  309.     ocbox *cboxp;
  310.     int nlines;
  311. /*
  312.     Scrolls an image map.
  313.     The direction of scrolling depends on the sign of 'nlines'. 
  314.     If 'nlines' is positive    the image is scrolled left, otherwise
  315.     the image is scrolled right. The image is cleared if 'nlines' is 0.
  316.     WARNING: if cboxp is not clipped within the cmap, disastrous assignments
  317.     will occur. For speed, no clipping is done at this level.
  318. */
  319. {
  320.     int col1, col2;
  321.     int height, width;
  322.     char *charptr1;
  323.     byte *attrptr1;
  324.     char *charptr2;
  325.     byte *attrptr2;
  326.  
  327.     width  = ocbox_GetWidth(cboxp);
  328.     height = ocbox_GetHeight(cboxp);
  329.  
  330.     col1 = col2 = cboxp->leftcol;
  331.     if (nlines > 0) {
  332.         /* scroll left */
  333.         if (nlines < width) {
  334.             col1 += nlines;
  335.         }
  336.     }
  337.     else if (nlines < 0) {
  338.         /* scroll right */
  339.         nlines = - nlines;
  340.         if (nlines < width) {
  341.             col2 += nlines;
  342.          }
  343.     }
  344.     width -= nlines;
  345.  
  346.     /* Scroll the map */
  347.     charptr2 = &(cmap->charbuf[cboxp->toprow*cmap->ncols + col2]);
  348.     attrptr2 = (byte *)(charptr2 + cmap->bufsize);
  349.     charptr1 = &(cmap->charbuf[cboxp->toprow*cmap->ncols + col1]);
  350.     attrptr1 = (byte *)(charptr1 + cmap->bufsize);
  351.  
  352.     for ( ; height > 0; height--) {
  353.         memmove(charptr2, charptr1, width);
  354.         memmove(attrptr2, attrptr1, width);
  355.  
  356.         charptr2 += cmap->ncols;
  357.         charptr1 += cmap->ncols;
  358.         attrptr2 += cmap->ncols;
  359.         attrptr1 += cmap->ncols;
  360.     }
  361. }
  362. /* -------------------------------------------------------------------------- */
  363.  
  364.