You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Xregion.h 5.8KB

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