home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / CMAP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-28  |  3.1 KB  |  108 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.2
  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.     11/29/89 jmd    added memset casts for DG
  20.      3/28/90 jmd    ansi-fied
  21. */
  22. /* -------------------------------------------------------------------------- */
  23. #include "oakhead.h"
  24. #include "disppriv.h"
  25. #include "cmapdecl.h"
  26. /* -------------------------------------------------------------------------- */
  27.  
  28. cmap_type cmap_Open(int nrows, int ncols)
  29. /*
  30.     Allocates a character image map;
  31.     The image map is an array of characters and attributes.
  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((VOID *) cmap->charbuf, ' ',  cmap->bufsize);
  56.     memset((VOID *) cmap->attrbuf, 0x07, cmap->bufsize);
  57.  
  58.     return(cmap);
  59. }
  60. /* -------------------------------------------------------------------------- */
  61.  
  62. void cmap_Close(cmap_type cmap)
  63. /*
  64.     Free an image map;
  65. */
  66. {
  67.     ofree(OA_CMAPBUF, (VOID *) cmap->charbuf);    /* attrbuf is allocated in same block as charbuf */
  68.     ofree(OA_CMAP, (VOID *) cmap);
  69. }
  70. /* -------------------------------------------------------------------------- */
  71.  
  72. unsigned cmap_clipcbox(cmap_type cmap, ocbox *cboxp)
  73. /*
  74.     Return Sutherland clip code for box in cmap: 0 if box is completely
  75.     out of cmap; otherwise bits saying which side(s) it was clipped on:
  76.     1, 2, 4, 8 for right, top, left, bottom; 16 for coming through at all.
  77. */
  78. {
  79.     unsigned tlcode, brcode;
  80.  
  81.     tlcode = cmap_clippos(cmap, &cboxp->toprow, &cboxp->leftcol);
  82.     brcode = cmap_clippos (cmap, &cboxp->botrow, &cboxp->rightcol); 
  83.  
  84.     if ((tlcode & brcode) != 0) {
  85.         return(0);
  86.     }
  87.     else return(tlcode | brcode | 16);
  88. }
  89. /* -------------------------------------------------------------------------- */
  90.  
  91. unsigned cmap_clippos(cmap_type cmap, int *rowp, int *colp)
  92. /*
  93.     Return Sutherland clip code for point in cmap: 0 if point is
  94.     in cmap; otherwise bits saying which side it's out on.
  95. */
  96. {
  97.     unsigned scode;
  98.  
  99.     scode = 0;
  100.     if (*rowp < 0)                        { scode |= 4; *rowp = 0; }
  101.     if (*colp < 0)                        { scode |= 2; *colp = 0; }
  102.     if (*rowp >= cmap_GetHeight(cmap))    { scode |= 8; *rowp = cmap_GetHeight(cmap) - 1; }
  103.     if (*colp >= cmap_GetWidth(cmap))    { scode |= 1; *colp = cmap_GetWidth(cmap) - 1; }
  104.     return scode;
  105. }
  106. /* -------------------------------------------------------------------------- */
  107.  
  108.