home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / CMAPPUT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-03  |  8.9 KB  |  340 lines

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