GdiPlusMatrix.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:9k
源码类别:

模拟服务器

开发平台:

C/C++

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