home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / region.h < prev    next >
C/C++ Source or Header  |  1999-11-02  |  6KB  |  192 lines

  1. /* $XConsortium: region.h,v 11.14 94/04/17 20:22:20 rws Exp $ */
  2. /************************************************************************
  3.  
  4. Copyright (c) 1987  X Consortium
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  19. X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22.  
  23. Except as contained in this notice, the name of the X Consortium shall not be
  24. used in advertising or otherwise to promote the sale, use or other dealings
  25. in this Software without prior written authorization from the X Consortium.
  26.  
  27.  
  28. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  29.  
  30.                         All Rights Reserved
  31.  
  32. Permission to use, copy, modify, and distribute this software and its 
  33. documentation for any purpose and without fee is hereby granted, 
  34. provided that the above copyright notice appear in all copies and that
  35. both that copyright notice and this permission notice appear in 
  36. supporting documentation, and that the name of Digital not be
  37. used in advertising or publicity pertaining to distribution of the
  38. software without specific, written prior permission.  
  39.  
  40. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  41. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  42. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  43. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  44. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  45. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  46. SOFTWARE.
  47.  
  48. ************************************************************************/
  49.  
  50. #ifndef _XREGION_H
  51. #define _XREGION_H
  52.  
  53. typedef struct {
  54.     short x1, x2, y1, y2;
  55. } Box, BOX, BoxRec, *BoxPtr;
  56.  
  57. typedef struct {
  58.     short x, y, width, height;
  59. }RECTANGLE, RectangleRec, *RectanglePtr;
  60.  
  61. #define TRUE 1
  62. #define FALSE 0
  63. #define MAXSHORT 32767
  64. #define MINSHORT -MAXSHORT
  65. #ifndef MAX
  66. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  67. #endif
  68. #ifndef MIN
  69. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  70. #endif
  71.  
  72.  
  73. /* 
  74.  *   clip region
  75.  */
  76.  
  77. typedef struct _XRegion {
  78.     long size;
  79.     long numRects;
  80.     BOX *rects;
  81.     BOX extents;
  82. } REGION;
  83.  
  84. /* Xutil.h contains the declaration: 
  85.  * typedef struct _XRegion *Region; 
  86.  */   
  87.  
  88. /*  1 if two BOXs overlap.
  89.  *  0 if two BOXs do not overlap.
  90.  *  Remember, x2 and y2 are not in the region 
  91.  */
  92. #define EXTENTCHECK(r1, r2) \
  93.     ((r1)->x2 > (r2)->x1 && \
  94.      (r1)->x1 < (r2)->x2 && \
  95.      (r1)->y2 > (r2)->y1 && \
  96.      (r1)->y1 < (r2)->y2)
  97.  
  98. /*
  99.  *  update region extents
  100.  */
  101. #define EXTENTS(r,idRect){\
  102.             if((r)->x1 < (idRect)->extents.x1)\
  103.               (idRect)->extents.x1 = (r)->x1;\
  104.             if((r)->y1 < (idRect)->extents.y1)\
  105.               (idRect)->extents.y1 = (r)->y1;\
  106.             if((r)->x2 > (idRect)->extents.x2)\
  107.               (idRect)->extents.x2 = (r)->x2;\
  108.             if((r)->y2 > (idRect)->extents.y2)\
  109.               (idRect)->extents.y2 = (r)->y2;\
  110.         }
  111.  
  112. /*
  113.  *   Check to see if there is enough memory in the present region.
  114.  */
  115. #define MEMCHECK(reg, rect, firstrect){\
  116.         if ((reg)->numRects >= ((reg)->size - 1)){\
  117.           (firstrect) = (BOX *) Xrealloc \
  118.           ((char *)(firstrect), (unsigned) (2 * (sizeof(BOX)) * ((reg)->size)));\
  119.           if ((firstrect) == 0)\
  120.             return(0);\
  121.           (reg)->size *= 2;\
  122.           (rect) = &(firstrect)[(reg)->numRects];\
  123.          }\
  124.        }
  125.  
  126. /*  this routine checks to see if the previous rectangle is the same
  127.  *  or subsumes the new rectangle to add.
  128.  */
  129.  
  130. #define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
  131.                (!(((Reg)->numRects > 0)&&\
  132.                   ((R-1)->y1 == (Ry1)) &&\
  133.                   ((R-1)->y2 == (Ry2)) &&\
  134.                   ((R-1)->x1 <= (Rx1)) &&\
  135.                   ((R-1)->x2 >= (Rx2))))
  136.  
  137. /*  add a rectangle to the given Region */
  138. #define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
  139.     if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
  140.         CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
  141.               (r)->x1 = (rx1);\
  142.               (r)->y1 = (ry1);\
  143.               (r)->x2 = (rx2);\
  144.               (r)->y2 = (ry2);\
  145.               EXTENTS((r), (reg));\
  146.               (reg)->numRects++;\
  147.               (r)++;\
  148.             }\
  149.         }
  150.  
  151.  
  152.  
  153. /*  add a rectangle to the given Region */
  154. #define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
  155.             if ((rx1 < rx2) && (ry1 < ry2) &&\
  156.                 CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
  157.               (r)->x1 = (rx1);\
  158.               (r)->y1 = (ry1);\
  159.               (r)->x2 = (rx2);\
  160.               (r)->y2 = (ry2);\
  161.               (reg)->numRects++;\
  162.               (r)++;\
  163.             }\
  164.         }
  165.  
  166. #define EMPTY_REGION(pReg) pReg->numRects = 0
  167.  
  168. #define REGION_NOT_EMPTY(pReg) pReg->numRects
  169.  
  170. #define INBOX(r, x, y) \
  171.       ( ( ((r).x2 >  x)) && \
  172.         ( ((r).x1 <= x)) && \
  173.         ( ((r).y2 >  y)) && \
  174.         ( ((r).y1 <= y)) )
  175.  
  176. /*
  177.  * number of points to buffer before sending them off
  178.  * to scanlines() :  Must be an even number
  179.  */
  180. #define NUMPTSTOBUFFER 200
  181.  
  182. /*
  183.  * used to allocate buffers for points and link
  184.  * the buffers together
  185.  */
  186. typedef struct _POINTBLOCK {
  187.     XPoint pts[NUMPTSTOBUFFER];
  188.     struct _POINTBLOCK *next;
  189. } POINTBLOCK;
  190.  
  191. #endif
  192.