Esempio n. 1
0
 /// <summary>
 /// Draws the outline of a rectangle.
 /// </summary>
 /// <param name="pen">The pen.</param>
 /// <param name="rect">The rectangle bounds.</param>
 /// <param name="cornerRadius">The corner radius.</param>
 public void DrawRectange(Pen pen, Rect rect, float cornerRadius)
 {
     using (var brush = pen.Brush.ToDirect2D(this.renderTarget))
     using (var d2dStroke = pen.ToDirect2DStrokeStyle(this.renderTarget))
     {
         this.renderTarget.DrawRoundedRectangle(
             new RoundedRectangle { Rect = rect.ToDirect2D(), RadiusX = cornerRadius, RadiusY = cornerRadius },
             brush,
             (float)pen.Thickness,
             d2dStroke);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Draws a line.
 /// </summary>
 /// <param name="pen">The stroke pen.</param>
 /// <param name="p1">The first point of the line.</param>
 /// <param name="p2">The second point of the line.</param>
 public void DrawLine(Pen pen, Perspex.Point p1, Perspex.Point p2)
 {
     if (pen != null)
     {
         using (var d2dBrush = pen.Brush.ToDirect2D(this.renderTarget))
         using (var d2dStroke = pen.ToDirect2DStrokeStyle(this.renderTarget))
         {
             this.renderTarget.DrawLine(
                 p1.ToSharpDX(),
                 p2.ToSharpDX(),
                 d2dBrush,
                 (float)pen.Thickness,
                 d2dStroke);
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Draws the outline of a rectangle.
 /// </summary>
 /// <param name="pen">The pen.</param>
 /// <param name="rect">The rectangle bounds.</param>
 /// <param name="cornerRadius">The corner radius.</param>
 public void DrawRectangle(Pen pen, Rect rect, float cornerRadius)
 {
     using (var brush = CreateBrush(pen.Brush, rect.Size))
     using (var d2dStroke = pen.ToDirect2DStrokeStyle(_renderTarget))
     {
         if (brush.PlatformBrush != null)
         {
             if (cornerRadius == 0)
             {
                 _renderTarget.DrawRectangle(
                     rect.ToDirect2D(),
                     brush.PlatformBrush,
                     (float)pen.Thickness,
                     d2dStroke);
             }
             else
             {
                 _renderTarget.DrawRoundedRectangle(
                     new RoundedRectangle { Rect = rect.ToDirect2D(), RadiusX = cornerRadius, RadiusY = cornerRadius },
                     brush.PlatformBrush,
                     (float)pen.Thickness,
                     d2dStroke);
             }
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Draws a line.
        /// </summary>
        /// <param name="pen">The stroke pen.</param>
        /// <param name="p1">The first point of the line.</param>
        /// <param name="p2">The second point of the line.</param>
        public void DrawLine(Pen pen, Point p1, Point p2)
        {
            if (pen != null)
            {
                var size = new Rect(p1, p2).Size;

                using (var d2dBrush = CreateBrush(pen.Brush, size))
                using (var d2dStroke = pen.ToDirect2DStrokeStyle(_renderTarget))
                {
                    if (d2dBrush.PlatformBrush != null)
                    {
                        _renderTarget.DrawLine(
                            p1.ToSharpDX(),
                            p2.ToSharpDX(),
                            d2dBrush.PlatformBrush,
                            (float)pen.Thickness,
                            d2dStroke);
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Draws a geometry.
        /// </summary>
        /// <param name="brush">The fill brush.</param>
        /// <param name="pen">The stroke pen.</param>
        /// <param name="geometry">The geometry.</param>
        public void DrawGeometry(Perspex.Media.Brush brush, Pen pen, Perspex.Media.Geometry geometry)
        {
            if (brush != null)
            {
                using (var d2dBrush = CreateBrush(brush, geometry.Bounds.Size))
                {
                    if (d2dBrush.PlatformBrush != null)
                    {
                        var impl = (GeometryImpl)geometry.PlatformImpl;
                        _renderTarget.FillGeometry(impl.Geometry, d2dBrush.PlatformBrush);
                    }
                }
            }

            if (pen != null)
            {
                using (var d2dBrush = CreateBrush(pen.Brush, geometry.GetRenderBounds(pen.Thickness).Size))
                using (var d2dStroke = pen.ToDirect2DStrokeStyle(_renderTarget))
                {
                    if (d2dBrush.PlatformBrush != null)
                    {
                        var impl = (GeometryImpl)geometry.PlatformImpl;
                        _renderTarget.DrawGeometry(impl.Geometry, d2dBrush.PlatformBrush, (float)pen.Thickness, d2dStroke);
                    }
                }
            }
        }