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

  1. /*
  2.     cmap.c    1/26/88
  3.  
  4.     % Character Map handling routines
  5.     by Joe DeSantis.
  6.     recreated by Ted Peck.
  7.  
  8.     OWL 1.1
  9.     Copyright (c) 1988, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      3/08/88 jdc     cmap clears to 0x07 space chars
  15.      3/18/88 ted    made cmap a structure, not just a char **
  16.      8/17/88 jmd      removed  eNOMEM, added omalloc
  17.      5/09/89 ted    Changed Alloc/Free terms to Open/Close.
  18. */
  19. /* -------------------------------------------------------------------------- */
  20. #include "oakhead.h"
  21. #include "disppriv.h"
  22. #include "cmapdecl.h"
  23. /* -------------------------------------------------------------------------- */
  24.  
  25. cmap_type cmap_Open(nrows, ncols)
  26.     int nrows, ncols;
  27. /*
  28.     Allocates a character image map;
  29.  
  30.     The image map is an array of characters and attributes.
  31.  
  32.     Returns NULL if out of memory.
  33. */
  34. {
  35.     cmap_type cmap;
  36.  
  37.     /* allocate character image map structure */
  38.     if ((cmap = (cmap_type) omalloc(OA_CMAP, sizeof(struct cmap_struct))) == NULL) {
  39.         return(NULL);
  40.     }
  41.  
  42.     cmap->nrows = nrows;
  43.     cmap->ncols = ncols;
  44.     cmap->bufsize = ncols * nrows;
  45.  
  46.     /* allocate attrbuf in same block as charbuf */
  47.     if ((cmap->charbuf =
  48.             (char *) omalloc(OA_CMAPBUF, 2 * cmap->bufsize)) == NULL) {
  49.         ofree(OA_CMAP, (VOID *) cmap);
  50.         return(NULL);
  51.     }
  52.     cmap->attrbuf = (byte *)(cmap->charbuf + cmap->bufsize);
  53.  
  54.     /* initialize buffers to black on white spaces */
  55.     memset(cmap->charbuf, ' ',  cmap->bufsize);
  56.     memset(cmap->attrbuf, 0x07, cmap->bufsize);
  57.  
  58.     return(cmap);
  59. }
  60. /* -------------------------------------------------------------------------- */
  61.  
  62. void cmap_Close(cmap)
  63.     cmap_type cmap;
  64. /*
  65.     Free an image map;
  66. */
  67. {
  68.     ofree(OA_CMAPBUF, (VOID *) cmap->charbuf);    /* attrbuf is allocated in same block as charbuf */
  69.     ofree(OA_CMAP, (VOID *) cmap);
  70. }
  71. /* -------------------------------------------------------------------------- */
  72.  
  73. unsigned cmap_clipcbox(cmap, cboxp)
  74.     cmap_type cmap;
  75.     ocbox *cboxp;
  76. /*
  77.     Return Sutherland clip code for box in cmap: 0 if box is completely
  78.     out of cmap; otherwise bits saying which side(s) it was clipped on:
  79.     1, 2, 4, 8 for right, top, left, bottom; 16 for coming through at all.
  80. */
  81. {
  82.     unsigned tlcode, brcode;
  83.  
  84.     tlcode = cmap_clippos(cmap, &cboxp->toprow, &cboxp->leftcol);
  85.     brcode = cmap_clippos (cmap, &cboxp->botrow, &cboxp->rightcol); 
  86.  
  87.     if ((tlcode & brcode) != 0) {
  88.         return(0);
  89.     }
  90.     else return(tlcode | brcode | 16);
  91. }
  92. /* -------------------------------------------------------------------------- */
  93.  
  94. unsigned cmap_clippos(cmap, rowp, colp)
  95.     cmap_type cmap;
  96.     int *rowp, *colp;
  97. /*
  98.     Return Sutherland clip code for point in cmap: 0 if point is
  99.     in cmap; otherwise bits saying which side it's out on.
  100. */
  101. {
  102.     unsigned scode;
  103.  
  104.     scode = 0;
  105.     if (*rowp < 0)                        { scode |= 4; *rowp = 0; }
  106.     if (*colp < 0)                        { scode |= 2; *colp = 0; }
  107.     if (*rowp >= cmap_GetHeight(cmap))    { scode |= 8; *rowp = cmap_GetHeight(cmap) - 1; }
  108.     if (*colp >= cmap_GetWidth(cmap))    { scode |= 1; *colp = cmap_GetWidth(cmap) - 1; }
  109.     return scode;
  110. }
  111. /* -------------------------------------------------------------------------- */
  112.  
  113.