/// <inheritdoc /> public void DrawLine(Point point1, Point point2, IPaint paint) { var dashPattern = new DoubleCollection(); if (paint.DashPattern != null && paint.DashPattern.Length == 4) { dashPattern = new DoubleCollection() { paint.DashPattern[0], paint.DashPattern[1], paint.DashPattern[2], paint.DashPattern[3], }; } Canvas.Children.Add(new Line { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, X1 = point1.X, X2 = point2.X, Y1 = point1.Y, Y2 = point2.Y, Fill = new SolidColorBrush(paint.Fill.ToSystemColor()), Stroke = new SolidColorBrush(paint.Stroke.ToSystemColor()), StrokeThickness = paint.StrokeThickness, StrokeDashArray = dashPattern, Opacity = paint.Opacity }); }
/// <inheritdoc /> public void DrawEllipse(Point location, float radius, IPaint paint) { var x = location.X - radius; var y = location.Y - radius; Canvas.Children.Add(new Ellipse { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(x, y, 0, 0), Width = radius * 2, Height = radius * 2, Fill = new SolidColorBrush(paint.Fill.ToSystemColor()), Stroke = new SolidColorBrush(paint.Stroke.ToSystemColor()), StrokeThickness = paint.StrokeThickness, Opacity = paint.Opacity }); }
/// <inheritdoc /> public void DrawRectangle(Point location, Size size, IPaint paint, float cornerRadius = 0) { if (size.Width < 0 || size.Height < 0) { return; } Canvas.Children.Add(new Border { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(location.X, location.Y, 0, 0), Width = size.Width, Height = size.Height, Background = new SolidColorBrush(paint.Fill.ToSystemColor()), BorderBrush = new SolidColorBrush(paint.Stroke.ToSystemColor()), BorderThickness = new Thickness(paint.StrokeThickness), CornerRadius = new CornerRadius(cornerRadius), Opacity = paint.Opacity }); }
/// <inheritdoc /> public void DrawText(Point location, string text, ITextPaint paint) { var textBlock = new TextBlock { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Text = text, Foreground = new SolidColorBrush(paint.Fill.ToSystemColor()), FontSize = paint.TextStyle.FontSize, FontFamily = new FontFamily(paint.TextStyle.FontFamily), Margin = new Thickness(location.X, location.Y, 0, 0), TextAlignment = paint.TextStyle.Alignment.ToSystemTextAlignment(), Opacity = paint.Opacity }; textBlock.Measure(new global::System.Windows.Size(double.PositiveInfinity, double.PositiveInfinity)); textBlock.Arrange(new Rect(0, 0, textBlock.DesiredSize.Width, textBlock.DesiredSize.Height)); textBlock.Margin = new Thickness(location.X, location.Y - textBlock.ActualHeight, 0, 0); Canvas.Children.Add(textBlock); }