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.

307 lines
9.0 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2001, Microsoft Corp. All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. * GdiplusMatrix.h
  8. *
  9. * Abstract:
  10. *
  11. * GDI+ Matrix class
  12. *
  13. \**************************************************************************/
  14. class Matrix : public GdiplusBase
  15. {
  16. public:
  17. friend class Graphics;
  18. friend class GraphicsPath;
  19. friend class TextureBrush;
  20. friend class LinearGradientBrush;
  21. friend class PathGradientBrush;
  22. friend class Pen;
  23. friend class Region;
  24. // Default constructor is set to identity matrix.
  25. Matrix()
  26. {
  27. GpMatrix *matrix = NULL;
  28. lastResult = DllExports::GdipCreateMatrix(&matrix);
  29. SetNativeMatrix(matrix);
  30. }
  31. Matrix(IN REAL m11,
  32. IN REAL m12,
  33. IN REAL m21,
  34. IN REAL m22,
  35. IN REAL dx,
  36. IN REAL dy)
  37. {
  38. GpMatrix *matrix = NULL;
  39. lastResult = DllExports::GdipCreateMatrix2(m11, m12, m21, m22,
  40. dx, dy, &matrix);
  41. SetNativeMatrix(matrix);
  42. }
  43. Matrix(IN const RectF& rect,
  44. IN const PointF* dstplg)
  45. {
  46. GpMatrix *matrix = NULL;
  47. lastResult = DllExports::GdipCreateMatrix3(&rect,
  48. dstplg,
  49. &matrix);
  50. SetNativeMatrix(matrix);
  51. }
  52. Matrix(IN const Rect& rect,
  53. IN const Point* dstplg)
  54. {
  55. GpMatrix *matrix = NULL;
  56. lastResult = DllExports::GdipCreateMatrix3I(&rect,
  57. dstplg,
  58. &matrix);
  59. SetNativeMatrix(matrix);
  60. }
  61. ~Matrix()
  62. {
  63. DllExports::GdipDeleteMatrix(nativeMatrix);
  64. }
  65. Matrix *Clone() const
  66. {
  67. GpMatrix *cloneMatrix = NULL;
  68. SetStatus(DllExports::GdipCloneMatrix(nativeMatrix,
  69. &cloneMatrix));
  70. if (lastResult != Ok)
  71. return NULL;
  72. return new Matrix(cloneMatrix);
  73. }
  74. Status GetElements(OUT REAL *m) const
  75. {
  76. return SetStatus(DllExports::GdipGetMatrixElements(nativeMatrix, m));
  77. }
  78. Status SetElements(IN REAL m11,
  79. IN REAL m12,
  80. IN REAL m21,
  81. IN REAL m22,
  82. IN REAL dx,
  83. IN REAL dy)
  84. {
  85. return SetStatus(DllExports::GdipSetMatrixElements(nativeMatrix,
  86. m11, m12, m21, m22, dx, dy));
  87. }
  88. REAL OffsetX() const
  89. {
  90. REAL elements[6];
  91. if (GetElements(&elements[0]) == Ok)
  92. return elements[4];
  93. else
  94. return 0.0f;
  95. }
  96. REAL OffsetY() const
  97. {
  98. REAL elements[6];
  99. if (GetElements(&elements[0]) == Ok)
  100. return elements[5];
  101. else
  102. return 0.0f;
  103. }
  104. Status Reset()
  105. {
  106. // set identity matrix elements
  107. return SetStatus(DllExports::GdipSetMatrixElements(nativeMatrix,
  108. 1.0, 0.0, 0.0, 1.0, 0.0, 0.0));
  109. }
  110. Status Multiply(IN const Matrix *matrix,
  111. IN MatrixOrder order = MatrixOrderPrepend)
  112. {
  113. return SetStatus(DllExports::GdipMultiplyMatrix(nativeMatrix,
  114. matrix->nativeMatrix,
  115. order));
  116. }
  117. Status Translate(IN REAL offsetX,
  118. IN REAL offsetY,
  119. IN MatrixOrder order = MatrixOrderPrepend)
  120. {
  121. return SetStatus(DllExports::GdipTranslateMatrix(nativeMatrix, offsetX,
  122. offsetY, order));
  123. }
  124. Status Scale(IN REAL scaleX,
  125. IN REAL scaleY,
  126. IN MatrixOrder order = MatrixOrderPrepend)
  127. {
  128. return SetStatus(DllExports::GdipScaleMatrix(nativeMatrix, scaleX,
  129. scaleY, order));
  130. }
  131. Status Rotate(IN REAL angle,
  132. IN MatrixOrder order = MatrixOrderPrepend)
  133. {
  134. return SetStatus(DllExports::GdipRotateMatrix(nativeMatrix, angle,
  135. order));
  136. }
  137. Status RotateAt(IN REAL angle,
  138. IN const PointF& center,
  139. IN MatrixOrder order = MatrixOrderPrepend)
  140. {
  141. if(order == MatrixOrderPrepend)
  142. {
  143. SetStatus(DllExports::GdipTranslateMatrix(nativeMatrix, center.X,
  144. center.Y, order));
  145. SetStatus(DllExports::GdipRotateMatrix(nativeMatrix, angle,
  146. order));
  147. return SetStatus(DllExports::GdipTranslateMatrix(nativeMatrix,
  148. -center.X,
  149. -center.Y,
  150. order));
  151. }
  152. else
  153. {
  154. SetStatus(DllExports::GdipTranslateMatrix(nativeMatrix,
  155. - center.X,
  156. - center.Y,
  157. order));
  158. SetStatus(DllExports::GdipRotateMatrix(nativeMatrix, angle,
  159. order));
  160. return SetStatus(DllExports::GdipTranslateMatrix(nativeMatrix,
  161. center.X,
  162. center.Y,
  163. order));
  164. }
  165. }
  166. Status Shear(IN REAL shearX,
  167. IN REAL shearY,
  168. IN MatrixOrder order = MatrixOrderPrepend)
  169. {
  170. return SetStatus(DllExports::GdipShearMatrix(nativeMatrix, shearX,
  171. shearY, order));
  172. }
  173. Status Invert()
  174. {
  175. return SetStatus(DllExports::GdipInvertMatrix(nativeMatrix));
  176. }
  177. // float version
  178. Status TransformPoints(IN OUT PointF* pts,
  179. IN INT count = 1) const
  180. {
  181. return SetStatus(DllExports::GdipTransformMatrixPoints(nativeMatrix,
  182. pts, count));
  183. }
  184. Status TransformPoints(IN OUT Point* pts,
  185. IN INT count = 1) const
  186. {
  187. return SetStatus(DllExports::GdipTransformMatrixPointsI(nativeMatrix,
  188. pts,
  189. count));
  190. }
  191. Status TransformVectors(IN OUT PointF* pts,
  192. IN INT count = 1) const
  193. {
  194. return SetStatus(DllExports::GdipVectorTransformMatrixPoints(
  195. nativeMatrix, pts, count));
  196. }
  197. Status TransformVectors(IN OUT Point* pts,
  198. IN INT count = 1) const
  199. {
  200. return SetStatus(DllExports::GdipVectorTransformMatrixPointsI(
  201. nativeMatrix,
  202. pts,
  203. count));
  204. }
  205. BOOL IsInvertible() const
  206. {
  207. BOOL result = FALSE;
  208. SetStatus(DllExports::GdipIsMatrixInvertible(nativeMatrix, &result));
  209. return result;
  210. }
  211. BOOL IsIdentity() const
  212. {
  213. BOOL result = FALSE;
  214. SetStatus(DllExports::GdipIsMatrixIdentity(nativeMatrix, &result));
  215. return result;
  216. }
  217. BOOL Equals(IN const Matrix *matrix) const
  218. {
  219. BOOL result = FALSE;
  220. SetStatus(DllExports::GdipIsMatrixEqual(nativeMatrix,
  221. matrix->nativeMatrix,
  222. &result));
  223. return result;
  224. }
  225. Status GetLastStatus() const
  226. {
  227. Status lastStatus = lastResult;
  228. lastResult = Ok;
  229. return lastStatus;
  230. }
  231. private:
  232. Matrix(const Matrix &);
  233. Matrix& operator=(const Matrix &);
  234. protected:
  235. Matrix(GpMatrix *nativeMatrix)
  236. {
  237. lastResult = Ok;
  238. SetNativeMatrix(nativeMatrix);
  239. }
  240. VOID SetNativeMatrix(GpMatrix *nativeMatrix)
  241. {
  242. this->nativeMatrix = nativeMatrix;
  243. }
  244. Status SetStatus(Status status) const
  245. {
  246. if (status != Ok)
  247. return (lastResult = status);
  248. else
  249. return status;
  250. }
  251. protected:
  252. GpMatrix *nativeMatrix;
  253. mutable Status lastResult;
  254. };