GdiPlusPen.h
上传用户:jinlangri
上传日期:2022-07-17
资源大小:10774k
文件大小:13k
源码类别:

GDI/图象编程

开发平台:

Visual C++

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