Source code of Windows XP (NT5)
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.

302 lines
7.9 KiB

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