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

模拟服务器

开发平台:

C/C++

  1. /**************************************************************************
  2. * Copyright (c) 1998-2001, Microsoft Corp.  All Rights Reserved.
  3. *
  4. * Module Name:
  5. *
  6. *   GdiplusPen.h
  7. *
  8. * Abstract:
  9. *
  10. *   GDI+ Pen class
  11. *
  12. **************************************************************************/
  13. #ifndef _GDIPLUSPEN_H
  14. #define _GDIPLUSPEN_H
  15. //--------------------------------------------------------------------------
  16. // Pen class
  17. //--------------------------------------------------------------------------
  18. class Pen : public GdiplusBase
  19. {
  20. public:
  21.     friend class GraphicsPath;
  22.     friend class Graphics;
  23.     Pen(IN const Color& color, 
  24.         IN REAL width = 1.0f)
  25.     {
  26.         Unit unit = UnitWorld;
  27.         nativePen = NULL;
  28.         lastResult = DllExports::GdipCreatePen1(color.GetValue(),
  29.                                     width, unit, &nativePen);
  30.     }
  31.     Pen(IN const Brush* brush, 
  32.         IN REAL width = 1.0f)
  33.     {
  34.         Unit unit = UnitWorld;
  35.         nativePen = NULL;
  36.         lastResult = DllExports::GdipCreatePen2(brush->nativeBrush,
  37.                                     width, unit, &nativePen);
  38.     }
  39.     ~Pen()
  40.     {
  41.         DllExports::GdipDeletePen(nativePen);
  42.     }
  43.     Pen* Clone() const
  44.     {
  45.         GpPen *clonePen = NULL;
  46.         lastResult = DllExports::GdipClonePen(nativePen, &clonePen);
  47.    
  48.         return new Pen(clonePen, lastResult);
  49.     }
  50.     Status SetWidth(IN REAL width)
  51.     {
  52.         return SetStatus(DllExports::GdipSetPenWidth(nativePen, width));
  53.     }
  54.     REAL GetWidth() const
  55.     {
  56.         REAL width;
  57.         SetStatus(DllExports::GdipGetPenWidth(nativePen, &width));
  58.         
  59.         return width;
  60.     }
  61.     
  62.     // Set/get line caps: start, end, and dash
  63.     // Line cap and join APIs by using LineCap and LineJoin enums.
  64.     Status SetLineCap(IN LineCap startCap, 
  65.                       IN LineCap endCap, 
  66.                       IN DashCap dashCap)
  67.     {
  68.         return SetStatus(DllExports::GdipSetPenLineCap197819(nativePen, 
  69.                                    startCap, endCap, dashCap));
  70.     }
  71.     Status SetStartCap(IN LineCap startCap)
  72.     {
  73.         return SetStatus(DllExports::GdipSetPenStartCap(nativePen, startCap));
  74.     }
  75.     Status SetEndCap(IN LineCap endCap)
  76.     {
  77.         return SetStatus(DllExports::GdipSetPenEndCap(nativePen, endCap));
  78.     }
  79.     Status SetDashCap(IN DashCap dashCap)
  80.     {
  81.         return SetStatus(DllExports::GdipSetPenDashCap197819(nativePen,
  82.                                    dashCap));
  83.     }
  84.     LineCap GetStartCap() const
  85.     {
  86.         LineCap startCap;
  87.         SetStatus(DllExports::GdipGetPenStartCap(nativePen, &startCap));
  88.         
  89.         return startCap;
  90.     }
  91.     LineCap GetEndCap() const
  92.     {
  93.         LineCap endCap;
  94.         SetStatus(DllExports::GdipGetPenEndCap(nativePen, &endCap));
  95.         return endCap;
  96.     }
  97.     DashCap GetDashCap() const
  98.     {
  99.         DashCap dashCap;
  100.         SetStatus(DllExports::GdipGetPenDashCap197819(nativePen,
  101.                             &dashCap));
  102.         return dashCap;
  103.     }
  104.     Status SetLineJoin(IN LineJoin lineJoin)
  105.     {
  106.         return SetStatus(DllExports::GdipSetPenLineJoin(nativePen, lineJoin));
  107.     }
  108.     LineJoin GetLineJoin() const
  109.     {
  110.         LineJoin lineJoin;
  111.         
  112.         SetStatus(DllExports::GdipGetPenLineJoin(nativePen, &lineJoin));
  113.         
  114.         return lineJoin;
  115.     }
  116.     Status SetCustomStartCap(IN const CustomLineCap* customCap)
  117.     {
  118.         GpCustomLineCap* nativeCap = NULL;
  119.         if(customCap)
  120.             nativeCap = customCap->nativeCap;
  121.         return SetStatus(DllExports::GdipSetPenCustomStartCap(nativePen, 
  122.                                                               nativeCap));
  123.     }
  124.     Status GetCustomStartCap(OUT CustomLineCap* customCap) const
  125.     {
  126.         if(!customCap)
  127.             return SetStatus(InvalidParameter);
  128.         return SetStatus(DllExports::GdipGetPenCustomStartCap(nativePen, 
  129.                                                     &(customCap->nativeCap)));
  130.     }
  131.     Status SetCustomEndCap(IN const CustomLineCap* customCap)
  132.     {
  133.         GpCustomLineCap* nativeCap = NULL;
  134.         if(customCap)
  135.             nativeCap = customCap->nativeCap;
  136.         return SetStatus(DllExports::GdipSetPenCustomEndCap(nativePen, 
  137.                                                             nativeCap));
  138.     }
  139.     Status GetCustomEndCap(OUT CustomLineCap* customCap) const
  140.     {
  141.         if(!customCap)
  142.             return SetStatus(InvalidParameter);
  143.         return SetStatus(DllExports::GdipGetPenCustomEndCap(nativePen, 
  144.                                                     &(customCap->nativeCap)));
  145.     }
  146.     Status SetMiterLimit(IN REAL miterLimit)
  147.     {
  148.         return SetStatus(DllExports::GdipSetPenMiterLimit(nativePen, 
  149.                                                     miterLimit));
  150.     }
  151.     REAL GetMiterLimit() const
  152.     {
  153.         REAL miterLimit;
  154.         SetStatus(DllExports::GdipGetPenMiterLimit(nativePen, &miterLimit));
  155.         return miterLimit;
  156.     }
  157.     Status SetAlignment(IN PenAlignment penAlignment)
  158.     {
  159.         return SetStatus(DllExports::GdipSetPenMode(nativePen, penAlignment));
  160.     }
  161.     PenAlignment GetAlignment() const
  162.     {
  163.         PenAlignment penAlignment;
  164.         
  165.         SetStatus(DllExports::GdipGetPenMode(nativePen, &penAlignment));
  166.         
  167.         return penAlignment;
  168.     }
  169.     
  170.     Status SetTransform(IN const Matrix* matrix)
  171.     {
  172.         return SetStatus(DllExports::GdipSetPenTransform(nativePen, 
  173.                                                        matrix->nativeMatrix));
  174.     }
  175.     Status GetTransform(OUT Matrix* matrix) const
  176.     {
  177.         return SetStatus(DllExports::GdipGetPenTransform(nativePen, 
  178.                                                          matrix->nativeMatrix));
  179.     }
  180.     Status ResetTransform()
  181.     {
  182.         return SetStatus(DllExports::GdipResetPenTransform(nativePen));
  183.     }
  184.     Status MultiplyTransform(IN const Matrix* matrix,
  185.                              IN MatrixOrder order = MatrixOrderPrepend)
  186.     {
  187.         return SetStatus(DllExports::GdipMultiplyPenTransform(nativePen,
  188.                                                          matrix->nativeMatrix,
  189.                                                          order));
  190.     }
  191.     Status TranslateTransform(IN REAL dx, 
  192.                               IN REAL dy,
  193.                               IN MatrixOrder order = MatrixOrderPrepend)
  194.     {
  195.         return SetStatus(DllExports::GdipTranslatePenTransform(nativePen,
  196.                                                                dx, 
  197.                                                                dy, 
  198.                                                                order));
  199.     }
  200.     Status ScaleTransform(IN REAL sx, 
  201.                           IN REAL sy,
  202.                           IN MatrixOrder order = MatrixOrderPrepend)
  203.     {
  204.         return SetStatus(DllExports::GdipScalePenTransform(nativePen,
  205.                                                            sx, 
  206.                                                            sy, 
  207.                                                            order));
  208.     }
  209.     Status RotateTransform(IN REAL angle, 
  210.                            IN MatrixOrder order = MatrixOrderPrepend)
  211.     {
  212.         return SetStatus(DllExports::GdipRotatePenTransform(nativePen,
  213.                                                             angle, 
  214.                                                             order));
  215.     }
  216.     PenType GetPenType() const
  217.     {
  218.        PenType type;
  219.        SetStatus(DllExports::GdipGetPenFillType(nativePen, &type));
  220.        return type;
  221.     }
  222.     Status SetColor(IN const Color& color)
  223.     {
  224.         return SetStatus(DllExports::GdipSetPenColor(nativePen,
  225.                                                      color.GetValue()));
  226.     }
  227.     Status SetBrush(IN const Brush* brush)
  228.     {
  229.         return SetStatus(DllExports::GdipSetPenBrushFill(nativePen, 
  230.                                        brush->nativeBrush));
  231.     }
  232.     Status GetColor(OUT Color* color) const
  233.     {
  234.         if (color == NULL) 
  235.         {
  236.             return SetStatus(InvalidParameter);
  237.         }
  238.         
  239.         PenType type = GetPenType();
  240.         if (type != PenTypeSolidColor) 
  241.         {
  242.             return WrongState;
  243.         }
  244.         
  245.         ARGB argb;
  246.         
  247.         SetStatus(DllExports::GdipGetPenColor(nativePen,
  248.                                               &argb));
  249.         if (lastResult == Ok)
  250.         {
  251.             color->SetValue(argb);
  252.         }
  253.         
  254.         return lastResult;
  255.     }
  256.     Brush* GetBrush() const
  257.     {
  258.        PenType type = GetPenType();
  259.        Brush* brush = NULL;
  260.        switch(type)
  261.        {
  262.        case PenTypeSolidColor:
  263.            brush = new SolidBrush();
  264.            break;
  265.        case PenTypeHatchFill:
  266.            brush = new HatchBrush();
  267.            break;
  268.        case PenTypeTextureFill:
  269.            brush = new TextureBrush();
  270.            break;
  271.        case PenTypePathGradient:
  272.            brush = new Brush();
  273.            break;
  274.        case PenTypeLinearGradient:
  275.            brush = new LinearGradientBrush();
  276.            break;
  277.        default:
  278.            break;
  279.        }
  280.        if(brush)
  281.        {
  282.            GpBrush* nativeBrush;
  283.            SetStatus(DllExports::GdipGetPenBrushFill(nativePen, 
  284.                                                      &nativeBrush));
  285.            brush->SetNativeBrush(nativeBrush);
  286.        }
  287.        return brush;
  288.     }
  289.     DashStyle GetDashStyle() const
  290.     {
  291.         DashStyle dashStyle;
  292.         SetStatus(DllExports::GdipGetPenDashStyle(nativePen, &dashStyle));
  293.         return dashStyle;
  294.     }
  295.     Status SetDashStyle(IN DashStyle dashStyle)
  296.     {
  297.         return SetStatus(DllExports::GdipSetPenDashStyle(nativePen, 
  298.                                                          dashStyle));
  299.     }
  300.     REAL GetDashOffset() const
  301.     {
  302.         REAL dashOffset;
  303.         SetStatus(DllExports::GdipGetPenDashOffset(nativePen, &dashOffset));
  304.         return dashOffset;
  305.     }
  306.     Status SetDashOffset(IN REAL dashOffset)
  307.     {
  308.         return SetStatus(DllExports::GdipSetPenDashOffset(nativePen, 
  309.                                                           dashOffset));
  310.     }
  311.     
  312.     Status SetDashPattern(IN const REAL* dashArray, IN INT count)
  313.     {
  314.         return SetStatus(DllExports::GdipSetPenDashArray(nativePen,
  315.                                                          dashArray, 
  316.                                                          count));
  317.     }
  318.     
  319.     INT GetDashPatternCount() const
  320.     {
  321.         INT count = 0;
  322.         
  323.         SetStatus(DllExports::GdipGetPenDashCount(nativePen, &count));
  324.         
  325.         return count;
  326.     }
  327.     Status GetDashPattern(OUT REAL* dashArray, 
  328.                           IN INT count) const
  329.     {
  330.         if (dashArray == NULL || count <= 0)
  331.             return SetStatus(InvalidParameter); 
  332.         
  333.         return SetStatus(DllExports::GdipGetPenDashArray(nativePen, 
  334.                                                          dashArray, 
  335.                                                          count));
  336.     }
  337.     Status SetCompoundArray(IN const REAL* compoundArray,
  338.                             IN INT count)
  339.     {
  340.         return SetStatus(DllExports::GdipSetPenCompoundArray(nativePen, 
  341.                                                              compoundArray,
  342.                                                              count));
  343.     }
  344.     INT GetCompoundArrayCount() const
  345.     {
  346.         INT count = 0;
  347.         
  348.         SetStatus(DllExports::GdipGetPenCompoundCount(nativePen, &count));
  349.         
  350.         return count;
  351.     }
  352.     Status GetCompoundArray(OUT REAL* compoundArray, 
  353.                             IN INT count) const
  354.     {
  355.         if (compoundArray == NULL || count <= 0)
  356.             return SetStatus(InvalidParameter); 
  357.         
  358.         return SetStatus(DllExports::GdipGetPenCompoundArray(nativePen, 
  359.                                                              compoundArray, 
  360.                                                              count));
  361.     }
  362.     Status GetLastStatus() const
  363.     {
  364.         Status lastStatus = lastResult;
  365.         lastResult = Ok;
  366.         return lastStatus;
  367.     }
  368. private:
  369.     Pen(const Pen &);
  370.     Pen& operator=(const Pen &);
  371. protected:
  372.     Pen(GpPen* nativePen, Status status)
  373.     {
  374.         lastResult = status;
  375.         SetNativePen(nativePen);
  376.     }
  377.     VOID SetNativePen(GpPen* nativePen)
  378.     {
  379.         this->nativePen = nativePen;
  380.     }
  381.     
  382.     Status SetStatus(Status status) const
  383.     {
  384.         if (status != Ok)
  385.             return (lastResult = status);
  386.         else 
  387.             return status;
  388.     }
  389. protected:
  390.     GpPen* nativePen;
  391.     mutable Status lastResult;
  392. };
  393. #endif