Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

310 řádky
8.3 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2000, 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 - 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, offsetY, order));
  122. }
  123. Status Scale(IN REAL scaleX,
  124. IN REAL scaleY,
  125. IN MatrixOrder order = MatrixOrderPrepend)
  126. {
  127. return SetStatus(DllExports::GdipScaleMatrix(nativeMatrix, scaleX, scaleY, order));
  128. }
  129. Status Rotate(IN REAL angle,
  130. IN MatrixOrder order = MatrixOrderPrepend)
  131. {
  132. return SetStatus(DllExports::GdipRotateMatrix(nativeMatrix, angle, order));
  133. }
  134. Status RotateAt(IN REAL angle,
  135. IN const PointF& center,
  136. IN MatrixOrder order = MatrixOrderPrepend)
  137. {
  138. if(order == MatrixOrderPrepend)
  139. {
  140. SetStatus(DllExports::GdipTranslateMatrix(nativeMatrix, center.X, center.Y, order));
  141. SetStatus(DllExports::GdipRotateMatrix(nativeMatrix, angle, order));
  142. return SetStatus(DllExports::GdipTranslateMatrix(nativeMatrix, - center.X, - center.Y, order));
  143. }
  144. else
  145. {
  146. SetStatus(DllExports::GdipTranslateMatrix(nativeMatrix, - center.X, - center.Y, order));
  147. SetStatus(DllExports::GdipRotateMatrix(nativeMatrix, angle, order));
  148. return SetStatus(DllExports::GdipTranslateMatrix(nativeMatrix, center.X, center.Y, order));
  149. }
  150. }
  151. Status Shear(IN REAL shearX,
  152. IN REAL shearY,
  153. IN MatrixOrder order = MatrixOrderPrepend)
  154. {
  155. return SetStatus(DllExports::GdipShearMatrix(nativeMatrix, shearX, shearY, order));
  156. }
  157. Status Invert()
  158. {
  159. return SetStatus(DllExports::GdipInvertMatrix(nativeMatrix));
  160. }
  161. // float version
  162. Status TransformPoints(IN OUT PointF* pts,
  163. IN INT count = 1) const
  164. {
  165. return SetStatus(DllExports::GdipTransformMatrixPoints(nativeMatrix, pts, count));
  166. }
  167. Status TransformPoints(IN OUT Point* pts,
  168. IN INT count = 1) const
  169. {
  170. return SetStatus(DllExports::GdipTransformMatrixPointsI(nativeMatrix,
  171. pts,
  172. count));
  173. }
  174. Status TransformVectors(IN OUT PointF* pts,
  175. IN INT count = 1) const
  176. {
  177. return SetStatus(DllExports::GdipVectorTransformMatrixPoints(nativeMatrix, pts, count));
  178. }
  179. Status TransformVectors(IN OUT Point* pts,
  180. IN INT count = 1) const
  181. {
  182. return SetStatus(DllExports::GdipVectorTransformMatrixPointsI(nativeMatrix,
  183. pts,
  184. count));
  185. }
  186. BOOL IsInvertible() const
  187. {
  188. BOOL result = FALSE;
  189. SetStatus(DllExports::GdipIsMatrixInvertible(nativeMatrix, &result));
  190. return result;
  191. }
  192. BOOL IsIdentity() const
  193. {
  194. BOOL result = FALSE;
  195. SetStatus(DllExports::GdipIsMatrixIdentity(nativeMatrix, &result));
  196. return result;
  197. }
  198. BOOL Equals(IN const Matrix *matrix) const
  199. {
  200. BOOL result = FALSE;
  201. SetStatus(DllExports::GdipIsMatrixEqual(nativeMatrix,
  202. matrix->nativeMatrix, &result));
  203. return result;
  204. }
  205. Status GetLastStatus() const
  206. {
  207. Status lastStatus = lastResult;
  208. lastResult = Ok;
  209. return lastStatus;
  210. }
  211. protected:
  212. #ifdef DCR_USE_NEW_250932
  213. private:
  214. Matrix(const Matrix &);
  215. Matrix& operator=(const Matrix &);
  216. protected:
  217. #else
  218. Matrix(const Matrix& matrix)
  219. {
  220. matrix;
  221. SetStatus(NotImplemented);
  222. SetNativeMatrix(NULL);
  223. }
  224. Matrix& operator=(const Matrix& matrix)
  225. {
  226. matrix;
  227. SetStatus(NotImplemented);
  228. return *this;
  229. }
  230. #endif
  231. Matrix(GpMatrix *nativeMatrix)
  232. {
  233. lastResult = Ok;
  234. SetNativeMatrix(nativeMatrix);
  235. }
  236. VOID SetNativeMatrix(GpMatrix *nativeMatrix)
  237. {
  238. this->nativeMatrix = nativeMatrix;
  239. }
  240. Status SetStatus(Status status) const
  241. {
  242. if (status != Ok)
  243. return (lastResult = status);
  244. else
  245. return status;
  246. }
  247. protected:
  248. GpMatrix *nativeMatrix;
  249. mutable Status lastResult;
  250. };