Leaked source code of windows server 2003
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.

309 lines
6.6 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: rectl.hxx *
  3. * *
  4. * Contains common functions on RECTL and POINTL structures. *
  5. * *
  6. * Created: 13-Sep-1990 15:11:03 *
  7. * Author: Charles Whitmer [chuckwh] *
  8. * *
  9. * Copyright (c) 1990-1999 Microsoft Corporation *
  10. \**************************************************************************/
  11. // Convert array of POINTLs to POINTSs.
  12. #define POINTL_TO_POINTS(ppts, pptl, cpt) \
  13. { \
  14. for (DWORD i = 0; i < (cpt); i++) \
  15. ((PEPOINTS) (ppts))[i] = (pptl)[i]; \
  16. }
  17. // Convert array of POINTSs to POINTLs.
  18. #define POINTS_TO_POINTL(pptl, ppts, cpt) \
  19. { \
  20. for (DWORD i = 0; i < (cpt); i++) \
  21. ((PEPOINTL) (pptl))[i] = (ppts)[i]; \
  22. }
  23. /******************************Class***************************************\
  24. * EPOINTL. *
  25. * *
  26. * This is an "energized" version of the common POINTL. *
  27. * *
  28. * History: *
  29. * Thu 13-Sep-1990 15:11:42 -by- Charles Whitmer [chuckwh] *
  30. * Wrote it. *
  31. \**************************************************************************/
  32. class EPOINTL : public _POINTL /* eptl */
  33. {
  34. public:
  35. // Constructor -- This one is to allow EPOINTLs inside other classes.
  36. EPOINTL() {}
  37. // Constructor -- Fills the EPOINTL.
  38. EPOINTL(LONG x1,LONG y1)
  39. {
  40. x = x1;
  41. y = y1;
  42. }
  43. // Destructor -- Does nothing.
  44. ~EPOINTL() {}
  45. // Initializer -- Initialize the point.
  46. VOID vInit(LONG x1,LONG y1)
  47. {
  48. x = x1;
  49. y = y1;
  50. }
  51. // Operator= -- initialize POINTL given POINTS
  52. VOID operator=(CONST POINTS& pts)
  53. {
  54. x = (LONG) pts.x;
  55. y = (LONG) pts.y;
  56. }
  57. // Operator+= -- Add to another POINTL.
  58. VOID operator+=(POINTL& ptl)
  59. {
  60. x += ptl.x;
  61. y += ptl.y;
  62. }
  63. };
  64. typedef EPOINTL *PEPOINTL;
  65. /******************************Class***************************************\
  66. * EPOINTS. *
  67. * *
  68. * This is an "energized" version of the common POINTS. *
  69. * *
  70. * History: *
  71. * Sat Mar 07 17:07:33 1992 -by- Hock San Lee [hockl]
  72. * Wrote it. *
  73. \**************************************************************************/
  74. class EPOINTS : public tagPOINTS /* epts */
  75. {
  76. public:
  77. // Constructor -- This one is to allow EPOINTSs inside other classes.
  78. EPOINTS() {}
  79. // Constructor -- Fills the EPOINTS.
  80. EPOINTS(SHORT x1,SHORT y1)
  81. {
  82. x = x1;
  83. y = y1;
  84. }
  85. // Destructor -- Does nothing.
  86. ~EPOINTS() {}
  87. // Initializer -- Initialize the point.
  88. VOID vInit(SHORT x1,SHORT y1)
  89. {
  90. x = x1;
  91. y = y1;
  92. }
  93. // Operator= -- initialize POINTS given POINTL
  94. VOID operator=(CONST POINTL& ptl)
  95. {
  96. x = (SHORT) ptl.x;
  97. y = (SHORT) ptl.y;
  98. }
  99. };
  100. typedef EPOINTS *PEPOINTS;
  101. /******************************Class***************************************\
  102. * ERECTL *
  103. * *
  104. * This is an "energized" version of the common RECTL. *
  105. * *
  106. * History: *
  107. * Thu 13-Sep-1990 15:11:42 -by- Charles Whitmer [chuckwh] *
  108. * Wrote it. *
  109. \**************************************************************************/
  110. class ERECTL : public _RECTL
  111. {
  112. public:
  113. // Constructor -- Allows ERECTLs inside other classes.
  114. ERECTL() {}
  115. // Destructor -- Does nothing.
  116. ~ERECTL() {}
  117. // Initializer -- Initialize the rectangle.
  118. VOID vInit(LONG x1,LONG y1,LONG x2,LONG y2)
  119. {
  120. left = x1;
  121. top = y1;
  122. right = x2;
  123. bottom = y2;
  124. }
  125. // Initializer -- energize given rectangle so that it can be manipulated
  126. VOID vInit(RECTL& rcl)
  127. {
  128. left = rcl.left ;
  129. top = rcl.top ;
  130. right = rcl.right ;
  131. bottom = rcl.bottom ;
  132. }
  133. // Initializer -- Initialize the rectangle to a point.
  134. VOID vInit(POINTL& ptl)
  135. {
  136. left = right = ptl.x;
  137. top = bottom = ptl.y;
  138. }
  139. // bEmpty -- Check if the RECTL is empty.
  140. BOOL bEmpty()
  141. {
  142. return((left > right) || (top > bottom));
  143. }
  144. // Operator= -- Initialize the bound to the rectangle.
  145. VOID operator=(RECTL& rcl)
  146. {
  147. left = rcl.left ;
  148. top = rcl.top ;
  149. right = rcl.right ;
  150. bottom = rcl.bottom ;
  151. }
  152. // Operator= -- Initialize the bound to the point.
  153. VOID operator=(POINTL& ptl)
  154. {
  155. left = right = ptl.x;
  156. top = bottom = ptl.y;
  157. }
  158. // Operator+= -- Include a rectangle in the bounds. Only the destination
  159. // may be empty.
  160. VOID operator+=(RECTL& rcl)
  161. {
  162. ASSERTGDI(rcl.left <= rcl.right && rcl.top <= rcl.bottom,
  163. "ERECTL::operator+=: Source rectangle is empty");
  164. if (left > right || top > bottom)
  165. *this = rcl;
  166. else
  167. {
  168. if (rcl.left < left)
  169. left = rcl.left;
  170. if (rcl.top < top)
  171. top = rcl.top;
  172. if (rcl.right > right)
  173. right = rcl.right;
  174. if (rcl.bottom > bottom)
  175. bottom = rcl.bottom;
  176. }
  177. }
  178. // Operator+= -- Include a point in the bounds. The destination may be empty.
  179. VOID operator+=(POINTL& ptl)
  180. {
  181. if (left > right || top > bottom)
  182. {
  183. left = right = ptl.x;
  184. top = bottom = ptl.y;
  185. }
  186. else
  187. {
  188. if (ptl.x < left)
  189. left = ptl.x;
  190. if (ptl.x > right)
  191. right = ptl.x;
  192. if (ptl.y < top)
  193. top = ptl.y;
  194. if (ptl.y > bottom)
  195. bottom = ptl.y;
  196. }
  197. }
  198. // Operator*= -- Intersect two rectangles.
  199. VOID operator*=(RECTL& rcl)
  200. {
  201. left = max(left, rcl.left);
  202. right = min(right, rcl.right);
  203. top = max(top, rcl.top);
  204. bottom = min(bottom,rcl.bottom);
  205. }
  206. // vOrder -- Make the rectangle well ordered.
  207. VOID vOrder()
  208. {
  209. LONG l;
  210. if (left > right)
  211. {
  212. l = left;
  213. left = right;
  214. right = l;
  215. }
  216. if (top > bottom)
  217. {
  218. l = top;
  219. top = bottom;
  220. bottom = l;
  221. }
  222. }
  223. // bContain -- Test if it contains another rectangle
  224. BOOL bContain(RECTL& rcl)
  225. {
  226. return (( left <= rcl.left ) &&
  227. ( right >= rcl.right ) &&
  228. ( top <= rcl.top ) &&
  229. ( bottom >= rcl.bottom));
  230. }
  231. // bNoIntersect -- Return TRUE if the rectangles have no intersection.
  232. // Both rectangles must not be empty.
  233. BOOL bNoIntersect(ERECTL& ercl)
  234. {
  235. #if DBG
  236. if (bEmpty() || ercl.bEmpty())
  237. WARNING("ERECTL::bNoIntersect: rectangle is empty");
  238. #endif
  239. return (( left > ercl.right ) ||
  240. ( right < ercl.left ) ||
  241. ( top > ercl.bottom ) ||
  242. ( bottom < ercl.top ));
  243. }
  244. };
  245. typedef ERECTL *PERECTL;