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.

283 lines
9.0 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: draweng.hxx
  3. *
  4. * Internal helper functions for GDI draw calls.
  5. *
  6. * Created: 19-Nov-1990
  7. * Author: J. Andrew Goossen [andrewgo]
  8. *
  9. * Copyright (c) 1990-1999 Microsoft Corporation
  10. *
  11. \**************************************************************************/
  12. // This constant defines how many fractional device units to expand
  13. // an ellipse if it will be filled, so that it looks better according
  14. // to our fill conventions:
  15. #define GROW_ELLIPSE_SIZE 4
  16. // Some internal DrawEng structures:
  17. enum PARTIALARC
  18. {
  19. PARTIALARCTYPE_CONTINUE,
  20. PARTIALARCTYPE_MOVETO,
  21. PARTIALARCTYPE_LINETO
  22. };
  23. // Arctan constants:
  24. #define NEGATE_X 0x01
  25. #define NEGATE_Y 0x02
  26. #define SWITCH_X_AND_Y 0x04
  27. #define OCTANT_0 0
  28. #define OCTANT_1 (SWITCH_X_AND_Y)
  29. #define OCTANT_2 (NEGATE_X | SWITCH_X_AND_Y)
  30. #define OCTANT_3 (NEGATE_X)
  31. #define OCTANT_4 (NEGATE_X | NEGATE_Y)
  32. #define OCTANT_5 (NEGATE_X | NEGATE_Y | SWITCH_X_AND_Y)
  33. #define OCTANT_6 (NEGATE_Y | SWITCH_X_AND_Y)
  34. #define OCTANT_7 (NEGATE_Y)
  35. // The following fraction is for determing the control point
  36. // placements for approximating a quarter-ellipse by a Bezier curve,
  37. // given the vector that describes the side of the bounding box.
  38. //
  39. // It is is the fraction over 2^32 which for the vector of the bound box
  40. // pointing towards the origin, describes the placement of the corresponding
  41. // control point on that vector. This value is equal to
  42. // (4 cos(45)) / (3 cos(45) + 1):
  43. #define QUADRANT_TAU 1922922357L
  44. /******************************Public*Routine******************************\
  45. * VOID vEllipseControlsOut(pvec, pvecResult, peq)
  46. *
  47. * For a quarter portion of an ellipse, this function, given a vector
  48. * pointing away from the origin of the ellipse that describes the
  49. * boundbox, returns the vector that describes the placement of the
  50. * corresponding control point on that vector.
  51. *
  52. * History:
  53. * 4-Apr-1992 -by- J. Andrew Goossen [andrewgo]
  54. * Wrote it.
  55. \**************************************************************************/
  56. inline VOID vEllipseControlsOut(
  57. VECTORFX* pvec, // Input vector
  58. VECTORFX* pvecResult, // Output vector
  59. LONGLONG* peq) // Temporary EQUAD. If it's declared here,
  60. // compiler pops function out-line
  61. {
  62. *peq = Int32x32To64(pvec->x, QUADRANT_TAU);
  63. pvecResult->x = pvec->x - (LONG) (*peq >> 32);
  64. *peq = Int32x32To64(pvec->y, QUADRANT_TAU);
  65. pvecResult->y = pvec->y - (LONG) (*peq >> 32);
  66. }
  67. /******************************Public*Routine******************************\
  68. * VOID vEllipseControlsIn(pvec, pvecResult, peq)
  69. *
  70. * For a quarter portion of an ellipse, this function, given a vector
  71. * pointing towards the origin of the ellipse that describes the
  72. * boundbox, returns the vector that describes the placement of the
  73. * corresponding control point on that vector.
  74. *
  75. * History:
  76. * 4-Apr-1992 -by- J. Andrew Goossen [andrewgo]
  77. * Wrote it.
  78. \**************************************************************************/
  79. inline VOID vEllipseControlsIn(
  80. VECTORFX* pvec, // Input vector
  81. VECTORFX* pvecResult, // Output vector
  82. LONGLONG* peq) // Temporary EQUAD. If it's declared here,
  83. // compiler pops function out-line
  84. {
  85. *peq = Int32x32To64(pvec->x, QUADRANT_TAU);
  86. pvecResult->x = (LONG) (*peq>>32);
  87. *peq = Int32x32To64(pvec->y, QUADRANT_TAU);
  88. pvecResult->y = (LONG) (*peq >> 32);
  89. }
  90. /************************************Class*********************************\
  91. * class EAPOINTL
  92. *
  93. * EPOINTL class without any constructors, so that it can be used in
  94. * an array. (Compiler mucks up with static constructors.)
  95. *
  96. * History:
  97. * 9-Oct-1991 -by- J. Andrew Goossen [andrewgo]
  98. * Wrote it.
  99. \**************************************************************************/
  100. class EAPOINTL : public _POINTL
  101. {
  102. public:
  103. VOID operator=(POINTL& ptl)
  104. {
  105. x = ptl.x;
  106. y = ptl.y;
  107. }
  108. VOID operator+=(POINTL& ptl)
  109. {
  110. x += ptl.x;
  111. y += ptl.y;
  112. }
  113. VOID operator-=(POINTL& ptl)
  114. {
  115. x -= ptl.x;
  116. y -= ptl.y;
  117. }
  118. };
  119. /************************************Class*********************************\
  120. * class EBOX
  121. *
  122. * Object defining the bounding box for figures requiring one. Useful
  123. * for providing a consistent object defining the bound box for the
  124. * various uses of the APIs requiring it.
  125. *
  126. * Arcs must be constructed in device coordinates because the 'snapping'
  127. * of the control points to the grid can only be done in device space.
  128. * As such, the bounding box goes through the World-to-Device linear
  129. * transform and will become a parallelogram.
  130. *
  131. * Figures requiring a bounding box must be drawn in the same direction
  132. * and starting at the same part of the figure, independent of the current
  133. * Page-to-Device transform and the ordering of the rectangle given by
  134. * the User. When the World-to-Page transform is identity, figures must
  135. * be drawn in a counter-clockwise direction for compatiblity with Old
  136. * Windows.
  137. *
  138. * As such, the 'rcl' describing the bound box must be well-ordered so
  139. * that (yTop, xLeft) is the upper-left corner of the box in device
  140. * coordinates when the World-to-Page transform is indentity (i.e., the
  141. * ordering is depedent of the Page-to-Device transform).
  142. *
  143. * 'rcl' doesn't have to be well-ordered for the Create-region APIs
  144. * because it doesn't matter where the figure starts and in what direction
  145. * it is drawn when it is converted to a region.
  146. *
  147. * Public interface:
  148. *
  149. * EBOX(dco, rcl, pla, bFillEllipse)
  150. * // Constructor when PS_INSIDEFRAME and lower-right
  151. * // exclusion has to be done (uses WORLD_TO_DEVICE
  152. * // DC transform on the 'rcl')
  153. * EBOX(xfo, rcl) // Constructor when PS_INSIDEFRAME and lower-right
  154. * // exclusion don't have to be done
  155. * EBOX(ercl, bFillEllipse)
  156. * // Constructor for Create-region APIs
  157. * ptlXform(ptef) // Transforms a point constructed on the unit circle
  158. * // centered at the origin to the ellipse described
  159. * // by the bounding box
  160. * bEmpty() // TRUE when no figure will be drawn
  161. *
  162. * Public members:
  163. *
  164. * rclWorld // Original rectangle expressed in world
  165. * // coordinates that defines the box.
  166. * ptlA // Half the vector defining the "horizontal" axis
  167. * // of the ellipse (in device coordinates)
  168. * ptlB // Half the vector defining the "vertical" axis
  169. * // of the ellipse (in device coordinates)
  170. * eptlOrigin // Center of box (in device coordinates). Note that
  171. * // it is rounded and so the figure may be 1/16th of
  172. * // a pel off.
  173. * aptl // Points defining corners of the box (in device
  174. * // coordinates)
  175. *
  176. * 1-------------0
  177. * | |
  178. * | |
  179. * ^ | o <- eptlOrigin
  180. * | | |
  181. * B | |
  182. * | 2-------------3
  183. *
  184. * ---A--->
  185. *
  186. * History:
  187. * 19-Nov-1990 -by- J. Andrew Goossen [andrewgo]
  188. * Wrote it.
  189. \**************************************************************************/
  190. class EBOX /* ebox */
  191. {
  192. private:
  193. BOOL bIsEmpty;
  194. BOOL bIsFillInsideFrame;
  195. public:
  196. EAPOINTL aeptl[4];
  197. EAPOINTL eptlOrigin;
  198. EAPOINTL eptlA;
  199. EAPOINTL eptlB;
  200. RECTL rclWorld;
  201. EBOX(ERECTL& ercl, BOOL bFillEllipse = FALSE);
  202. EBOX(EXFORMOBJ& xfo, RECTL& rcl);
  203. EBOX(DCOBJ& dco, RECTL& rcl, PLINEATTRS pla, BOOL bFillEllipse = FALSE);
  204. POINTL ptlXform(EPOINTFL& ptef);
  205. BOOL bEmpty() { return(bIsEmpty); }
  206. BOOL bFillInsideFrame() { return(bIsFillInsideFrame); }
  207. };
  208. // Prototypes:
  209. BOOL bPartialArc
  210. (
  211. PARTIALARC paType,
  212. EPATHOBJ& epo,
  213. EBOX& ebox,
  214. EPOINTFL& eptefStart,
  215. LONG lStartQuadrant,
  216. EFLOAT& efStartAngle,
  217. EPOINTFL& eptefEnd,
  218. LONG lEndQuadrant,
  219. EFLOAT& efEndAngle,
  220. LONG lQuadrants
  221. );
  222. BOOL bEllipse
  223. (
  224. EPATHOBJ& epo,
  225. EBOX& ebox
  226. );
  227. BOOL bRoundRect
  228. (
  229. EPATHOBJ& epo,
  230. EBOX& ebox,
  231. LONG dx,
  232. LONG dy
  233. );
  234. BOOL bPolyPolygon
  235. (
  236. EPATHOBJ& epo,
  237. EXFORMOBJ& xfo,
  238. PPOINTL pptl,
  239. PLONG pcptl,
  240. ULONG ccptl,
  241. LONG cMaxPoints
  242. );
  243. BOOL GreRectBlt
  244. (
  245. DCOBJ& dco,
  246. ERECTL* percl
  247. );
  248. VOID vArctan
  249. (
  250. EFLOAT x,
  251. EFLOAT y,
  252. EFLOAT& efTheta,
  253. LONG& lQuadrant
  254. );