当前位置: 首页>>代码示例>>C#>>正文


C# Direct2D.D2dBrush类代码示例

本文整理汇总了C#中Sce.Atf.Direct2D.D2dBrush的典型用法代码示例。如果您正苦于以下问题:C# D2dBrush类的具体用法?C# D2dBrush怎么用?C# D2dBrush使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


D2dBrush类属于Sce.Atf.Direct2D命名空间,在下文中一共展示了D2dBrush类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawVerticalScaleGrid

        /// <summary>
        /// Draws grid lines corresponding to a vertical scale</summary>
        /// <param name="g">The Direct2D graphics object</param>
        /// <param name="transform">Graph (world) to window's client (screen) transform</param>
        /// <param name="graphRect">Graph rectangle</param>
        /// <param name="majorSpacing">Scale's major spacing</param>
        /// <param name="lineBrush">Grid line brush</param>
        public static void DrawVerticalScaleGrid(
            this D2dGraphics g,
            Matrix transform,
            RectangleF graphRect,
            int majorSpacing,
            D2dBrush lineBrush)
        {
            double xScale = transform.Elements[0];
            RectangleF clientRect = Transform(transform, graphRect);

            double min = Math.Min(graphRect.Left, graphRect.Right);
            double max = Math.Max(graphRect.Left, graphRect.Right);
            double tickAnchor = CalculateTickAnchor(min, max);
            double step = CalculateStep(min, max, Math.Abs(clientRect.Right - clientRect.Left), majorSpacing, 0.0);
            if (step > 0)
            {
                double offset = tickAnchor - min;
                offset = offset - MathUtil.Remainder(offset, step) + step;
                for (double x = tickAnchor - offset; x <= max; x += step)
                {
                    double cx = (x - graphRect.Left) * xScale + clientRect.Left;
                    g.DrawLine((float)cx, clientRect.Top, (float)cx, clientRect.Bottom, lineBrush);
                }
            }
        }
开发者ID:Joxx0r,项目名称:ATF,代码行数:32,代码来源:D2dUtil.cs

示例2: DrawExpander

 /// <summary>
 /// Draws a tree-control style expander, which looks like a square with
 /// a dash (expanded) or a cross (unexpanded)</summary>
 /// <param name="g">The Direct2D graphics object</param>
 /// <param name="x">X coordinate of expander top left corner</param>
 /// <param name="y">Y coordinate of expander top left corner</param>
 /// <param name="size">Size of expander, in pixels</param>
 /// <param name="brush">Brush</param>
 /// <param name="expanded">Whether or not expander should appear "expanded"</param>
 public static void DrawExpander(this D2dGraphics g, float x, float y, float size, D2dBrush brush, bool expanded)
 {
     s_expanderPoints[0] = new PointF(x, y + size);
     if (expanded)
     {                
         s_expanderPoints[1] = new PointF(x + size, y + size);
         s_expanderPoints[2] = new PointF(x + size, y);
         g.FillPolygon(s_expanderPoints, brush);
     }
     else
     {                
         s_expanderPoints[1] = new PointF(x + size, y + size / 2);
         s_expanderPoints[2] = new PointF(x, y);
         g.DrawPolygon(s_expanderPoints, brush, 1.0f);
     }
 }
开发者ID:sbambach,项目名称:ATF,代码行数:25,代码来源:D2dUtil.cs

示例3: DrawEyeIcon

        /// <summary>
        /// Draws the eye icon</summary>
        /// <param name="g">The D2dGraphics graphics object</param>
        /// <param name="rect">The rectangle to fit the eye icon in</param>
        /// <param name="pen">The pen used to draw the icon</param>
        /// <param name="strokeWidth">Width of the stroke</param>
        public static void DrawEyeIcon(this D2dGraphics g, RectangleF rect, D2dBrush pen, float strokeWidth)
        {
            float delta = rect.Width / 3;
            var p1 = new PointF(rect.X, rect.Y + rect.Height / 2);
            var p2 = new PointF(p1.X + delta, rect.Y);
            var p3 = new PointF(p1.X + 2 * delta, rect.Y);
            var p4 = new PointF(rect.X + rect.Width, rect.Y + rect.Height / 2);
            g.DrawBezier(p1, p2, p3, p4, pen, strokeWidth);// top lid
            p2 = new PointF(p2.X, rect.Y + rect.Height);
            p3 = new PointF(p3.X, rect.Y + rect.Height);
            g.DrawBezier(p1, p2, p3, p4, pen, strokeWidth); //bottom lid

            var irisCenter = new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
            float irisRadius = 0.2f * Math.Min(rect.Width, rect.Height);
            var irisRect = new RectangleF(irisCenter.X - irisRadius, irisCenter.Y - irisRadius, 2 * irisRadius, 2 * irisRadius);
            g.DrawEllipse(irisRect, pen, strokeWidth * 1.8f);
        }
开发者ID:sbambach,项目名称:ATF,代码行数:23,代码来源:D2dUtil.cs

示例4: DrawExpander

        /// <summary>
        /// Draws a tree-control style expander, which looks like a square with
        /// a dash (expanded) or a cross (unexpanded)</summary>
        /// <param name="g">The Direct2D graphics object</param>
        /// <param name="x">X coordinate of expander top left corner</param>
        /// <param name="y">Y coordinate of expander top left corner</param>
        /// <param name="size">Size of expander, in pixels</param>
        /// <param name="brush">Brush</param>
        /// <param name="expanded">Whether or not expander should appear "expanded"</param>
        public static void DrawExpander(this D2dGraphics g, float x, float y, float size, D2dBrush brush, bool expanded)
        {
            s_expanderPoints[0] = new PointF(x, y + size);
            if (expanded)
            {                
                s_expanderPoints[1] = new PointF(x + size, y + size);
                s_expanderPoints[2] = new PointF(x + size, y);
                g.FillPolygon(s_expanderPoints, brush);
            }
            else
            {                
                s_expanderPoints[1] = new PointF(x + size, y + size / 2);
                s_expanderPoints[2] = new PointF(x, y);
                g.DrawPolygon(s_expanderPoints, brush, 1.0f);
            }

            //g.DrawRectangle(new RectangleF(x, y, size, size), brush);           
            //float lineLength = size - 4;
            //float center = size / 2;
            //g.DrawLine(x + 2, y + center, x + 2 + lineLength, y + center, brush);
            //if (!expanded)
            //    g.DrawLine(x + center, y + 2, x + center, y + 2 + lineLength, brush);
        }
开发者ID:Joxx0r,项目名称:ATF,代码行数:32,代码来源:D2dUtil.cs

示例5: FillRectangle

 /// <summary>
 /// Paints the interior of the specified rectangle</summary>
 /// <param name="rect">Rectangle to paint, in pixels</param>
 /// <param name="brush">The brush used to paint the rectangle's interior</param>
 public void FillRectangle(RectangleF rect, D2dBrush brush)
 {
     m_renderTarget.FillRectangle(rect.ToSharpDX(), brush.NativeBrush);
 }
开发者ID:sbambach,项目名称:ATF,代码行数:8,代码来源:D2dGraphics.cs

示例6: FillOpacityMask

 /// <summary>
 /// Draws a solid rectangle with the specified brush while using the alpha channel of the given
 /// bitmap to control the opacity of each pixel.</summary>
 /// <param name="opacityMask">The opacity mask to apply to the brush. The alpha value of
 /// each pixel in the region specified by sourceRectangle is multiplied with the alpha value
 /// of the brush after the brush has been mapped to the area defined by destinationRectangle.</param>
 /// <param name="brush">The brush used to paint the region of the render target specified by destinationRectangle.</param>
 /// <param name="destRect">The region of the render target to paint, in device-independent pixels.</param>
 /// <param name="sourceRect">The region of the bitmap to use as the opacity mask, in device-independent pixels.</param>
 public void FillOpacityMask(D2dBitmap opacityMask, D2dBrush brush, RectangleF destRect, RectangleF sourceRect)
 {
     m_renderTarget.FillOpacityMask(opacityMask.NativeBitmap, brush.NativeBrush,
                                    OpacityMaskContent.Graphics,
                                    destRect.ToSharpDX(), sourceRect.ToSharpDX());
 }
开发者ID:sbambach,项目名称:ATF,代码行数:15,代码来源:D2dGraphics.cs

示例7: FillPolygon

        /// <summary>
        /// Fills the interior of a polygon defined by given points</summary>
        /// <param name="points">Array of PointF structures that represent the vertices of
        /// the polygon to fill</param>
        /// <param name="brush">Brush that determines the characteristics of the fill</param>
        public void FillPolygon(IEnumerable<PointF> points, D2dBrush brush)
        {
            var iter = points.GetEnumerator();
            if (!iter.MoveNext()) return;

            using (var geom = new PathGeometry(D2dFactory.NativeFactory))
            {
                var sink = geom.Open();
                var pt1 = iter.Current;
                sink.BeginFigure(pt1.ToSharpDX(), FigureBegin.Filled);
                while (iter.MoveNext())
                {
                    sink.AddLine(iter.Current.ToSharpDX());
                }
                sink.EndFigure(FigureEnd.Closed);
                sink.Close();
                sink.Dispose();

                m_renderTarget.FillGeometry(geom, brush.NativeBrush);
            }
        }
开发者ID:sbambach,项目名称:ATF,代码行数:26,代码来源:D2dGraphics.cs

示例8: DrawEllipse

 /// <summary>
 /// Draws the outline of the specified ellipse</summary>
 /// <param name="rect">The rectangle, in pixels, that encloses the ellipse to paint</param>
 /// <param name="brush">The brush used to paint the ellipse's outline</param>
 /// <param name="strokeWidth">The thickness of the ellipse's stroke. The stroke is centered on the ellipse's outline.</param>
 /// <param name="strokeStyle">The style of stroke to apply to the ellipse's outline or null to draw a solid line</param>
 public void DrawEllipse(RectangleF rect, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null)
 {
     var tmpEllipse = new Ellipse();
     tmpEllipse.RadiusX = rect.Width * 0.5f;
     tmpEllipse.RadiusY = rect.Height * 0.5f;
     tmpEllipse.Point = new Vector2(rect.X + tmpEllipse.RadiusX, rect.Y + tmpEllipse.RadiusY);
     m_renderTarget.DrawEllipse(tmpEllipse, brush.NativeBrush, strokeWidth,
         strokeStyle != null ? strokeStyle.NativeStrokeStyle : null);
 }
开发者ID:sbambach,项目名称:ATF,代码行数:15,代码来源:D2dGraphics.cs

示例9: FillEllipse

 /// <summary>
 /// Paints the interior of the specified ellipse</summary>
 /// <param name="ellipse">The position and radius, in pixels, of the ellipse to paint</param>
 /// <param name="brush">The brush used to paint the interior of the ellipse</param>
 public void FillEllipse(D2dEllipse ellipse, D2dBrush brush)
 {
     m_renderTarget.FillEllipse(ellipse.ToSharpDX(), brush.NativeBrush);
 }
开发者ID:sbambach,项目名称:ATF,代码行数:8,代码来源:D2dGraphics.cs

示例10: DrawArc

        /// <summary>
        /// Draws an arc representing a portion of an ellipse specified by a D2dEllipse</summary>
        /// <param name="ellipse">Ellipse to draw</param>
        /// <param name="brush">The brush used to paint the arc's outline</param>
        /// <param name="startAngle">Starting angle in degrees measured clockwise from the x-axis 
        /// to the starting point of the arc</param>
        /// <param name="sweepAngle">Sweep angle in degrees measured clockwise from the startAngle 
        /// parameter to ending point of the arc</param>
        /// <param name="strokeWidth">The thickness of the ellipse's stroke. The stroke is centered 
        /// on the ellipse's outline.</param>
        /// <param name="strokeStyle">The style of stroke to apply to the arc's outline or null to draw a solid line</param>
        public void DrawArc(D2dEllipse ellipse, D2dBrush brush, float startAngle, float sweepAngle, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null)
        {
            // compute steps
            float step = Tessellation / m_scale.X;
            float angle1 = startAngle * ToRadian;
            float angle2 = (startAngle + sweepAngle) * ToRadian;
            if (angle1 > angle2)
            {
                float temp = angle1;
                angle1 = angle2;
                angle2 = temp;
            }

            float cx = ellipse.Center.X;
            float cy = ellipse.Center.Y;

            var v1 = new Vec2F();
            v1.X = ellipse.RadiusX * (float)Math.Cos(angle1);
            v1.Y = ellipse.RadiusY * (float)Math.Sin(angle1);

            var v2 = new Vec2F();
            v2.X = ellipse.RadiusX * (float)Math.Cos(angle2);
            v2.Y = ellipse.RadiusY * (float)Math.Sin(angle2);

            float arcLen = (v2 - v1).Length; // approx arc len.
            float numSegs = arcLen / step;
            float dtheta = (angle2 - angle1) / numSegs;

            m_tempPoints.Clear();
            for (float theta = angle1; theta < angle2; theta += dtheta)
            {
                var pt = new PointF();
                pt.X = cx + ellipse.RadiusX * (float)Math.Cos(theta);
                pt.Y = cy + ellipse.RadiusY * (float)Math.Sin(theta);
                m_tempPoints.Add(pt);
            }
            DrawLines(m_tempPoints, brush, strokeWidth, strokeStyle);
        }
开发者ID:sbambach,项目名称:ATF,代码行数:49,代码来源:D2dGraphics.cs

示例11: DrawHorizontalScale

        /// <summary>
        /// Draws a horizontal chart scale</summary>
        /// <param name="g">The Direct2D graphics object</param>
        /// <param name="transform">Graph (world) to window's client (screen) transform</param>
        /// <param name="graphRect">Graph rectangle</param>
        /// <param name="top">Whether or not the scale should be aligned along the top of the rectangle</param>
        /// <param name="majorSpacing">Spacing, in pixels, between major tick marks</param>
        /// <param name="minimumGraphStep">Minimum spacing, in graph (world) space, between ticks.
        /// For example, 1.0 would limit ticks to being drawn on whole integers.</param>
        /// <param name="lineBrush">Scale line pen</param>
        /// <param name="textFormat">Text format</param>
        /// <param name="textBrush">Text brush</param>
        public static void DrawHorizontalScale(
            this D2dGraphics g,
            Matrix transform,
            RectangleF graphRect,
            bool top,
            int majorSpacing,
            float minimumGraphStep,
            D2dBrush lineBrush,
            D2dTextFormat textFormat,
            D2dBrush textBrush)
        {
            double xScale = transform.Elements[0];
            RectangleF clientRect = Transform(transform, graphRect);

            double tickEnd, majorTickStart, minorTickStart, textStart;

            if (top)
            {
                tickEnd = clientRect.Top + 1;
                majorTickStart = tickEnd + 12;
                minorTickStart = tickEnd + 6;
                textStart = tickEnd + 8;
            }
            else
            {
                tickEnd = clientRect.Bottom - 1;
                majorTickStart = tickEnd - 12;
                minorTickStart = tickEnd - 6;
                textStart = tickEnd - 19;
            }

            double min = Math.Min(graphRect.Left, graphRect.Right);
            double max = Math.Max(graphRect.Left, graphRect.Right);

            double tickAnchor = CalculateTickAnchor(min, max);
            double majorGraphStep = CalculateStep(
                min, max, Math.Abs(clientRect.Right - clientRect.Left), majorSpacing, minimumGraphStep);
            int numMinorTicks = CalculateNumMinorTicks(majorGraphStep, minimumGraphStep, 5);
            double cMinorStep = (majorGraphStep / numMinorTicks) * xScale;
            if (majorGraphStep > 0)
            {
                double offset = tickAnchor - min;
                offset = offset - MathUtil.Remainder(offset, majorGraphStep);

                // draw leading minor ticks
                double cmx;
                cmx = ((tickAnchor - (offset + majorGraphStep)) - min) * xScale + clientRect.Left + cMinorStep;
                for (int i = 0; i < numMinorTicks - 1 && cmx < clientRect.Right; i++)
                {
                    // cull minor ticks outside of the view
                    if (cmx > clientRect.Left)
                    {
                        g.DrawLine((float)cmx, (float)minorTickStart, (float)cmx, (float)tickEnd, lineBrush);
                    }
                    cmx += cMinorStep;
                }

                for (double x = tickAnchor - offset; x < max; x += majorGraphStep)
                {
                    double cx = (x - min) * xScale + clientRect.Left;
                    g.DrawLine((float)cx, (float)majorTickStart, (float)cx, (float)tickEnd, lineBrush);
                    string xString = String.Format("{0:G8}", Math.Round(x, 6));
                    SizeF textSize = g.MeasureText(xString, textFormat);
                    var textRect = new RectangleF(new PointF((float)cx + 1, (float)textStart), textSize);
                    g.DrawText(xString, textFormat, textRect, textBrush);

                    // draw minor ticks
                    cmx = cx + cMinorStep;
                    for (int i = 0; i < numMinorTicks - 1 && cmx < clientRect.Right; i++)
                    {
                        g.DrawLine((float)cmx, (float)minorTickStart, (float)cmx, (float)tickEnd, lineBrush);
                        cmx += cMinorStep;
                    }
                }
            }
        }
开发者ID:Joxx0r,项目名称:ATF,代码行数:88,代码来源:D2dUtil.cs

示例12: DrawRoundedRectangle

 /// <summary>
 ///  Draws the outline of the specified rounded rectangle</summary>
 /// <param name="roundedRect">The dimensions of the rounded rectangle to draw, in pixels</param>
 /// <param name="brush">The brush used to paint the rounded rectangle's outline</param>
 /// <param name="strokeWidth">The width of the rounded rectangle's stroke. The stroke is centered on the
 /// rounded rectangle's outline.</param>
 /// <param name="strokeStyle">The style of the rounded rectangle's stroke, or null to paint a solid stroke</param>
 public void DrawRoundedRectangle(D2dRoundedRect roundedRect, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null)
 {
     m_renderTarget.DrawRoundedRectangle(roundedRect.ToSharpDX(), brush.NativeBrush, strokeWidth,
         strokeStyle != null ? strokeStyle.NativeStrokeStyle : null);
 }
开发者ID:sbambach,项目名称:ATF,代码行数:12,代码来源:D2dGraphics.cs

示例13: DrawText

 /// <summary>
 /// Draws the specified text using the format information provided at the specified location</summary>
 /// <param name="text">The text string to draw</param>
 /// <param name="textFormat">The text format object to use</param>
 /// <param name="upperLeft">Upper left corner of the text</param>
 /// <param name="brush">The brush to use to draw the text</param>
 public void DrawText(string text, D2dTextFormat textFormat, PointF upperLeft, D2dBrush brush)
 {
     var rtsize = Size;
     using (var layout
         = new SharpDX.DirectWrite.TextLayout(D2dFactory.NativeDwFactory,
             text, textFormat.NativeTextFormat, rtsize.Width, rtsize.Height))
     {
         layout.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading;
         layout.ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Near;
         if (textFormat.Underlined)
             layout.SetUnderline(true,new SharpDX.DirectWrite.TextRange(0, text.Length));
         if (textFormat.Strikeout)
             layout.SetStrikethrough(true,new SharpDX.DirectWrite.TextRange(0, text.Length));
         m_renderTarget.DrawTextLayout(upperLeft.ToSharpDX(),
             layout,
             brush.NativeBrush,
             (DrawTextOptions)textFormat.DrawTextOptions);
     }
 }
开发者ID:sbambach,项目名称:ATF,代码行数:25,代码来源:D2dGraphics.cs

示例14: DrawLines

        /// <summary>
        /// Draws a series of line segments that connect an array of System.Drawing.PointF</summary>
        /// <param name="points">Array of PointF that represent the points to connect</param>
        /// <param name="brush">The brush used to paint the line's stroke</param>
        /// <param name="strokeWidth">A value greater than or equal to 0.0f that specifies the width of the stroke</param>
        /// <param name="strokeStyle">The style of stroke to paint, or NULL to paint a solid line</param>
        public void DrawLines(IEnumerable<PointF> points, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null)
        {
            var iter = points.GetEnumerator();
            if (!iter.MoveNext()) return;

            var transparent = brush.Opacity < 1.0f;
            if (!transparent)
            {
                var sbrush = brush as D2dSolidColorBrush;
                if (sbrush != null)
                    transparent = sbrush.Color.A < 255;
            }

            var nstroke = (strokeStyle ?? s_strokeStyle).NativeStrokeStyle;

            if (transparent)
            {
                using (var geom = new PathGeometry(D2dFactory.NativeFactory))
                {
                    var sink = geom.Open();
                    var pt1 = iter.Current;
                    sink.BeginFigure(pt1.ToSharpDX(), FigureBegin.Hollow);
                    while (iter.MoveNext())
                    {
                        sink.AddLine(iter.Current.ToSharpDX());
                    }
                    sink.EndFigure(FigureEnd.Open);
                    sink.Close();
                    sink.Dispose();

                    m_renderTarget.DrawGeometry(geom, brush.NativeBrush, strokeWidth, nstroke);
                }
            }
            else
            {
                var nbrush = brush.NativeBrush;
                var pt1 = iter.Current;
                while (iter.MoveNext())
                {
                    var pt2 = iter.Current;
                    m_renderTarget.DrawLine(pt1.ToSharpDX(), pt2.ToSharpDX(), nbrush,
                            strokeWidth, nstroke);
                    pt1 = pt2;
                }
            }
        }
开发者ID:sbambach,项目名称:ATF,代码行数:52,代码来源:D2dGraphics.cs

示例15: DrawPolygon

        /// <summary>
        /// Draws a polygon defined by an array of PointF structures</summary>
        /// <param name="points">Array of System.Drawing.PointF structures 
        /// that represent the vertices of the polygon</param>
        /// <param name="brush">The brush used to paint the polygon's stroke</param>
        /// <param name="strokeWidth">A value greater than or equal to 0.0f that specifies the width of the stroke</param>
        /// <param name="strokeStyle">The style of stroke to paint, or NULL to paint a solid line</param>
        public void DrawPolygon(IEnumerable<PointF> points, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null)
        {
            var iter = points.GetEnumerator();
            if (!iter.MoveNext()) return;

            using (var geom = new PathGeometry(D2dFactory.NativeFactory))
            {
                var sink = geom.Open();
                var pt1 = iter.Current;
                sink.BeginFigure(pt1.ToSharpDX(), FigureBegin.Hollow);
                while (iter.MoveNext())
                {
                    sink.AddLine(iter.Current.ToSharpDX());
                }
                sink.EndFigure(FigureEnd.Closed);
                sink.Close();
                sink.Dispose();

                m_renderTarget.DrawGeometry(geom, brush.NativeBrush, strokeWidth,
                    strokeStyle != null ? strokeStyle.NativeStrokeStyle : null);
            }
        }
开发者ID:sbambach,项目名称:ATF,代码行数:29,代码来源:D2dGraphics.cs


注:本文中的Sce.Atf.Direct2D.D2dBrush类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。