public void Render(SKCanvas canvas, IGeometryVisual gemoetry, double scale)
        {
            var circle = gemoetry as ICircle;

            if (circle == null || !circle.IsValid)
            {
                return;
            }
            using (var paint = new SKPaint())
            {
                // Draw Circle
                paint.Color       = circle.Color.ToSkiaColor();
                paint.IsAntialias = true;
                paint.IsStroke    = true;
                paint.StrokeWidth = (float)(circle.Size * scale);
                canvas.DrawCircle((float)(circle.Start.X * scale), (float)(circle.Start.Y * scale), (float)(circle.Radius * scale), paint);
                // Fill Circle
                if (!circle.IsFilled)
                {
                    return;
                }
                paint.Color    = circle.Color.ToFillColor().ToSkiaColor();
                paint.IsStroke = false;
                canvas.DrawCircle((float)(circle.Start.X * scale), (float)(circle.Start.Y * scale), (float)(circle.Radius * scale), paint);
            }
        }
Esempio n. 2
0
        public void Render(SKCanvas canvas, IGeometryVisual geometry, double scale)
        {
            var moist = geometry as IMoist;

            if (moist == null || !moist.IsValid)
            {
                return;
            }
            using (var paint = new SKPaint())
            {
                // Setup common paint parameters
                paint.Color       = moist.ToolSettings.SelectedColor.ToSkiaColor();
                paint.IsAntialias = true;
                paint.IsStroke    = false;
                var text = moist.ToolSettings.SelectedText;
                if (string.IsNullOrEmpty(text))
                {
                    paint.StrokeWidth = (float)(moist.Size * scale);
                    paint.StrokeCap   = SKStrokeCap.Round;
                    canvas.DrawPoint((float)(moist.Point.X * scale), (float)(moist.Point.Y * scale), paint);
                }
                else
                {
                    paint.TextSize = (float)(moist.Size * scale);
                    // Get the path of the text to calibrate the touch point to the middle of the text area
                    var originalTextPath = paint.GetTextPath(text, (float)(moist.Point.X * scale), (float)(moist.Point.Y * scale));
                    // Set the mid of the text area to the touch point
                    var calibratedX = originalTextPath.Bounds.Left - originalTextPath.Bounds.Width / 2;
                    var calibratedY = originalTextPath.Bounds.Bottom + originalTextPath.Bounds.Height / 2;

                    // Set the right text color
                    var textColor = Converter.ContrastColor(moist.ToolSettings.SelectedColor);
                    // Get the path of the calibrated text area and add some padding to the rect
                    var calibratedTextPath = paint.GetTextPath(text, calibratedX, calibratedY);
                    // Rect parameters
                    float left;
                    float top;
                    float right;
                    float bottom;
                    float cornerRadius;

                    var textSizeDependentPadding = paint.TextSize / 4;
                    left         = calibratedTextPath.Bounds.Left - textSizeDependentPadding;
                    top          = calibratedTextPath.Bounds.Top - textSizeDependentPadding;
                    right        = calibratedTextPath.Bounds.Right + textSizeDependentPadding;
                    bottom       = calibratedTextPath.Bounds.Bottom + textSizeDependentPadding;
                    cornerRadius = paint.TextSize / 2;

                    var rect = new SKRect(left, top, right, bottom);
                    // Draw background rect
                    canvas.DrawRoundRect(rect, cornerRadius, cornerRadius, paint);
                    // Draw text
                    paint.Color = textColor.ToSkiaColor();
                    canvas.DrawText(text, calibratedX, calibratedY, paint);
                    // Draw the background border in same color as text
                    paint.IsStroke = true;
                    canvas.DrawRoundRect(rect, cornerRadius, cornerRadius, paint);
                }
            }
        }
Esempio n. 3
0
        public void Render(SKCanvas canvas, IGeometryVisual geometry, double scale)
        {
            var oval = geometry as IOval;

            if (oval == null || !oval.IsValid)
            {
                return;
            }
            using (var paint = new SKPaint())
            {
                // Draw Oval
                paint.Color       = oval.ToolSettings.SelectedColor.ToSkiaColor();
                paint.IsAntialias = true;
                paint.IsStroke    = true;
                paint.StrokeWidth = (float)(oval.Size * scale);
                canvas.DrawOval((float)(oval.Start.X * scale), (float)(oval.Start.Y * scale), (float)(oval.End.X - oval.Start.X) * (float)scale, (float)(oval.End.Y - oval.Start.Y) * (float)scale, paint);
                // Fill Oval
                paint.Color    = oval.ToolSettings.SelectedColor.ToFillColor().ToSkiaColor();
                paint.IsStroke = false;
                if (oval.IsFilled)
                {
                    canvas.DrawOval((float)(oval.Start.X * scale), (float)(oval.Start.Y * scale), (float)(oval.End.X - oval.Start.X) * (float)scale, (float)(oval.End.Y - oval.Start.Y) * (float)scale, paint);
                }
                if (oval.IsStenciled)
                {
                    using (var shader = ShaderFactory.Line(oval.ToolSettings.SelectedColor.ToSkiaColor()))
                    {
                        paint.Shader = shader;
                    }
                    canvas.DrawOval((float)(oval.Start.X * scale), (float)(oval.Start.Y * scale), (float)(oval.End.X - oval.Start.X) * (float)scale, (float)(oval.End.Y - oval.Start.Y) * (float)scale, paint);
                }
            }
        }
        public void Render(SKCanvas canvas, IGeometryVisual gemoetry, double scale)
        {
            var rect = gemoetry as IRectangle;

            if (rect == null || !rect.IsValid)
            {
                return;
            }
            using (var paint = new SKPaint())
            {
                // Draw Rect
                paint.Color       = rect.Color.ToSkiaColor();
                paint.IsAntialias = true;
                paint.IsStroke    = true;
                paint.StrokeWidth = (float)(rect.Size * scale);
                canvas.DrawRect(Helper.Converter.ToSKRect(rect.Start, rect.End, scale), paint);
                // Fill Rect
                if (!rect.IsFilled)
                {
                    return;
                }
                paint.Color    = rect.Color.ToFillColor().ToSkiaColor();
                paint.IsStroke = false;
                canvas.DrawRect(Helper.Converter.ToSKRect(rect.Start, rect.End, scale), paint);
            }
        }
Esempio n. 5
0
        public void Render(SKCanvas canvas, IGeometryVisual gemoetry, double scale)
        {
            var rect = gemoetry as IRectangle;

            if (rect == null || !rect.IsValid)
            {
                return;
            }
            using (var paint = new SKPaint())
            {
                // Draw Rect
                paint.Color       = rect.ToolSettings.SelectedColor.ToSkiaColor();
                paint.IsAntialias = true;
                paint.IsStroke    = true;
                paint.StrokeWidth = (float)(rect.Size * scale);
                canvas.DrawRect(Helper.Converter.ToSKRect(rect.Start, rect.End, scale), paint);
                // Fill and or stencil rect
                paint.Color    = rect.ToolSettings.SelectedColor.ToFillColor().ToSkiaColor();
                paint.IsStroke = false;
                if (rect.IsFilled)
                {
                    canvas.DrawRect(Helper.Converter.ToSKRect(rect.Start, rect.End, scale), paint);
                }
                if (rect.IsStenciled)
                {
                    using (var shader = ShaderFactory.Line(rect.ToolSettings.SelectedColor.ToSkiaColor()))
                    {
                        paint.Shader = shader;
                    }
                    canvas.DrawRect(Helper.Converter.ToSKRect(rect.Start, rect.End, scale), paint);
                }
            }
        }
Esempio n. 6
0
        public void Render(SKCanvas canvas, IGeometryVisual geometry, double scale)
        {
            var oval = geometry as IOval;

            if (oval == null || !oval.IsValid)
            {
                return;
            }
            using (var paint = new SKPaint())
            {
                // Draw Oval
                paint.Color       = oval.Color.ToSkiaColor();
                paint.IsAntialias = true;
                paint.IsStroke    = true;
                paint.StrokeWidth = (float)(oval.Size * scale);
                canvas.DrawOval((float)(oval.Start.X * scale), (float)(oval.Start.Y * scale), (float)(oval.End.X - oval.Start.X) * (float)scale, (float)(oval.End.Y - oval.Start.Y) * (float)scale, paint);
                // Fill Oval
                if (!oval.IsFilled)
                {
                    return;
                }
                paint.Color    = oval.Color.ToFillColor().ToSkiaColor();
                paint.IsStroke = false;
                canvas.DrawOval((float)(oval.Start.X * scale), (float)(oval.Start.Y * scale), (float)(oval.End.X - oval.Start.X) * (float)scale, (float)(oval.End.Y - oval.Start.Y) * (float)scale, paint);
            }
        }
Esempio n. 7
0
        public void Render(SKCanvas canvas, IGeometryVisual gemoetry, double scale)
        {
            var circle = gemoetry as ICircle;

            if (circle == null || !circle.IsValid)
            {
                return;
            }
            using (var paint = new SKPaint())
            {
                // Draw Circle
                paint.Color       = circle.ToolSettings.SelectedColor.ToSkiaColor();
                paint.IsAntialias = true;
                paint.IsStroke    = true;
                paint.StrokeWidth = (float)(circle.Size * scale);
                canvas.DrawCircle((float)(circle.Start.X * scale), (float)(circle.Start.Y * scale), (float)(circle.Radius * scale), paint);
                // Fill Circle
                paint.Color    = circle.ToolSettings.SelectedColor.ToFillColor().ToSkiaColor();
                paint.IsStroke = false;
                if (circle.IsFilled)
                {
                    canvas.DrawCircle((float)(circle.Start.X * scale), (float)(circle.Start.Y * scale), (float)(circle.Radius * scale), paint);
                }
                if (circle.IsStenciled)
                {
                    using (var shader = ShaderFactory.Line(circle.ToolSettings.SelectedColor.ToSkiaColor()))
                    {
                        paint.Shader = shader;
                    }
                    canvas.DrawCircle((float)(circle.Start.X * scale), (float)(circle.Start.Y * scale), (float)(circle.Radius * scale), paint);
                }
            }
        }
Esempio n. 8
0
        public void Render(SKCanvas canvas, IGeometryVisual gemoetry, double scale)
        {
            var stroke = gemoetry as IStroke;

            if (stroke == null || !stroke.IsValid)
            {
                return;
            }
            using (var paint = new SKPaint())
            {
                paint.IsStroke    = true;
                paint.StrokeCap   = SKStrokeCap.Round;
                paint.StrokeWidth = (float)(stroke.Size * scale);
                paint.IsAntialias = true;
                paint.Color       = stroke.ToolSettings.SelectedColor.ToSkiaColor();

                var points = stroke.Points.Select(arg => Helper.Converter.ToSKPoint(arg, scale)).ToArray();
                // Draw HighLight or Stroke
                if (stroke.HighLight)
                {
                    paint.StrokeCap = SKStrokeCap.Butt;
                    if (stroke.IsStenciled)
                    {
                        using (var shader = ShaderFactory.Line(stroke.ToolSettings.SelectedColor.ToSkiaColor()))
                        {
                            paint.Shader = shader;
                        }
                    }
                    paint.Color = stroke.ToolSettings.SelectedColor.ToFillColor().ToSkiaColor();
                    canvas.DrawPointsInPath(paint, points);
                    return;
                }
                else
                {
                    canvas.DrawPoints(SKPointMode.Polygon, points, paint);
                }
                if (!points.Any())
                {
                    return;
                }
                paint.Color    = stroke.ToolSettings.SelectedColor.ToFillColor().ToSkiaColor();
                paint.IsStroke = false;
                if (stroke.IsFilled)
                {
                    canvas.DrawPointsInPath(paint, points);
                }
                if (stroke.IsStenciled)
                {
                    using (var shader = ShaderFactory.Line(stroke.ToolSettings.SelectedColor.ToSkiaColor()))
                    {
                        paint.Shader = shader;
                    }
                    canvas.DrawPointsInPath(paint, points);
                }
            }
        }
Esempio n. 9
0
        public static void Render(SKCanvas canvas, IGeometryVisual geometry, double scale = 1.0)
        {
            if (!geometry.IsValid)
            {
                return;
            }
            var renderer = _renderers.FirstOrDefault(arg => arg.GeometryType.GetTypeInfo().IsAssignableFrom(geometry.GetType().GetTypeInfo()));

            renderer?.Render(canvas, geometry, scale);
        }
Esempio n. 10
0
 public static void CopyTo(this IGeometryVisual self, IGeometryVisual copy)
 {
     if (copy == null)
     {
         return;
     }
     copy.IsFilled     = self.IsFilled;
     copy.IsStenciled  = self.IsStenciled;
     copy.MaxSize      = self.MaxSize;
     copy.MinSize      = self.MinSize;
     copy.Size         = self.Size;
     copy.ToolSettings = self.ToolSettings;
 }
Esempio n. 11
0
        public void Render(SKCanvas canvas, IGeometryVisual gemoetry, double scale)
        {
            var text = gemoetry as IText;

            if (text == null || !text.IsValid)
            {
                return;
            }

            using (var paint = new SKPaint())
            {
                // Setup common paint parameters
                paint.IsAntialias = true;
                paint.IsStroke    = false;
                paint.TextSize    = (float)(text.Size * scale);
                paint.Color       = text.Color.ToSkiaColor();

                // Get the path of the text to calibrate the touch point to the middle of the text area
                var originalTextPath = paint.GetTextPath(text.Value, (float)(text.Point.X * scale), (float)(text.Point.Y * scale));
                // Set the mid of the text area to the touch point
                var calibratedX = originalTextPath.Bounds.Left - originalTextPath.Bounds.Width / 2;
                var calibratedY = originalTextPath.Bounds.Bottom + originalTextPath.Bounds.Height / 2;

                if (text.IsFilled)
                {
                    // Set the right text color
                    var textColor = Converter.ContrastColor(text.Color);

                    var calibratedTextPath = paint.GetTextPath(text.Value, calibratedX, calibratedY);
                    // Get the path of the calibrated text area and add some padding to the rect
                    var left   = calibratedTextPath.Bounds.Left - Padding;
                    var top    = calibratedTextPath.Bounds.Top - Padding;
                    var right  = calibratedTextPath.Bounds.Right + Padding;
                    var bottom = calibratedTextPath.Bounds.Bottom + Padding;
                    var rect   = new SKRect(left, top, right, bottom);
                    // Draw background rect
                    canvas.DrawRect(rect, paint);
                    // Draw text
                    paint.Color = textColor.ToSkiaColor();
                    canvas.DrawText(text.Value, calibratedX, calibratedY, paint);
                    // Draw the background border in same color as text
                    paint.IsStroke = true;
                    canvas.DrawRect(rect, paint);
                }
                else
                {
                    // Draw Text
                    canvas.DrawText(text.Value, calibratedX, calibratedY, paint);
                }
            }
        }
Esempio n. 12
0
        public void Render(SKCanvas canvas, IGeometryVisual geometry, double scale)
        {
            var oval = geometry as IOval;

            using (var paint = new SKPaint()) {
                paint.Color       = oval.Color.ToSkiaColor();
                paint.IsAntialias = true;
                paint.IsStroke    = true;
                paint.StrokeWidth = (float)(oval.Size * scale);

                canvas.DrawOval((float)(oval.Start.X * scale), (float)(oval.Start.Y * scale),
                                (float)(oval.End.X - oval.Start.X) * (float)scale, (float)(oval.End.Y - oval.Start.Y) * (float)scale, paint);
            }
        }
Esempio n. 13
0
        public void Render(SKCanvas canvas, IGeometryVisual gemoetry, double scale)
        {
            var stroke = gemoetry as IStroke;

            if (stroke == null || !stroke.IsValid)
            {
                return;
            }
            using (var paint = new SKPaint())
            {
                // Draw Stroke
                paint.IsStroke    = true;
                paint.StrokeCap   = SKStrokeCap.Round;
                paint.StrokeWidth = (float)(stroke.Size * scale);
                paint.IsAntialias = true;
                paint.Color       = stroke.Color.ToSkiaColor();
                if (stroke.HighLight)
                {
                    paint.BlendMode = SKBlendMode.Darken;                                   //TODO: Maybe use filters, paint.ColorFilter = SKColorFilter.CreateLighting()
                }
                var points = stroke.Points.Select(arg => Helper.Converter.ToSKPoint(arg, scale)).ToArray();
                canvas.DrawPoints(SKPointMode.Polygon, points, paint);
                // Fill Stroke
                if (!stroke.IsFilled)
                {
                    return;
                }
                if (!points.Any())
                {
                    return;
                }
                paint.Color    = stroke.Color.ToFillColor().ToSkiaColor();
                paint.IsStroke = false;
                var path = new SKPath();
                foreach (var skPoint in points)
                {
                    if (!path.Points.Any())
                    {
                        path.MoveTo(skPoint);
                    }
                    path.LineTo(skPoint);
                }
                canvas.DrawPath(path, paint);
            }
        }
Esempio n. 14
0
        public void Render(SKCanvas canvas, IGeometryVisual gemoetry, double scale)
        {
            var mark = gemoetry as IMark;

            if (mark == null || !mark.IsValid)
            {
                return;
            }
            using (var paint = new SKPaint())
            {
                paint.Color       = mark.ToolSettings.SelectedColor.ToSkiaColor();
                paint.IsAntialias = true;
                paint.IsStroke    = false;
                paint.StrokeWidth = (float)(mark.Size * scale);
                paint.StrokeCap   = SKStrokeCap.Round;
                canvas.DrawPoint((float)(mark.Point.X * scale), (float)(mark.Point.Y * scale), paint);
                //TODO: Maybe fix real fill
            }
        }
Esempio n. 15
0
        public void Render(SKCanvas canvas, IGeometryVisual geometry, double scale = 1)
        {
            var ruler = geometry as IRuler;

            if (ruler == null || !ruler.IsValid)
            {
                return;
            }
            using (var paint = new SKPaint())
            {
                paint.IsStroke    = true;
                paint.StrokeCap   = SKStrokeCap.Round;
                paint.StrokeWidth = (float)(ruler.Size * scale);
                paint.IsAntialias = true;
                var start = Converter.ToSKPoint(ruler.Start, scale);
                var stop  = Converter.ToSKPoint(ruler.End, scale);
                paint.Color = ruler.ToolSettings.SelectedColor.ToSkiaColor();
                var x1 = start.X;
                var y1 = start.Y;
                var x2 = stop.X;
                var y2 = stop.Y;

                canvas.DrawLine(x1, y1, x2, y2, paint);
                var angle = Math.Atan2(y2 - y1, x2 - x1);
                var x3    = (float)(x1 - TickLength * Math.Cos(angle - Math.PI / 2));
                var y3    = (float)(y1 - TickLength * Math.Sin(angle - Math.PI / 2));
                var x4    = (float)(x1 - TickLength * Math.Cos(angle + Math.PI / 2));
                var y4    = (float)(y1 - TickLength * Math.Sin(angle + Math.PI / 2));

                var x5 = (float)(x2 - TickLength * Math.Cos(angle - Math.PI / 2));
                var y5 = (float)(y2 - TickLength * Math.Sin(angle - Math.PI / 2));
                var x6 = (float)(x2 - TickLength * Math.Cos(angle + Math.PI / 2));
                var y6 = (float)(y2 - TickLength * Math.Sin(angle + Math.PI / 2));

                canvas.DrawLine(x1, y1, x3, y3, paint);
                canvas.DrawLine(x1, y1, x4, y4, paint);

                canvas.DrawLine(x2, y2, x5, y5, paint);
                canvas.DrawLine(x2, y2, x6, y6, paint);
            }
        }
Esempio n. 16
0
        private const float L2  = 20;        // Length of the arrow lines

        public void Render(SKCanvas canvas, IGeometryVisual gemoetry, double scale)
        {
            var arrow = gemoetry as IArrow;

            if (arrow == null || !arrow.IsValid)
            {
                return;
            }
            using (var paint = new SKPaint())
            {
                // Paint parameters
                paint.IsStroke    = true;
                paint.StrokeCap   = SKStrokeCap.Round;
                paint.StrokeWidth = (float)(arrow.Size * scale);
                paint.IsAntialias = true;
                paint.Color       = arrow.ToolSettings.SelectedColor.ToSkiaColor();
                // Line points
                var startPoint = arrow.Start.ToSkiaPoint(scale);
                var endPoint   = arrow.End.ToSkiaPoint(scale);
                var x1         = startPoint.X;
                var y1         = startPoint.Y;
                var x2         = endPoint.X;
                var y2         = endPoint.Y;
                // Calculate the arrow points
                var l1 = (float)Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
                var x3 = (float)(x2 + L2 / l1 * ((x1 - x2) * Math.Cos(Angle) + (y1 - y2) * Math.Sin(Angle)));
                var y3 = (float)(y2 + L2 / l1 * ((y1 - y2) * Math.Cos(Angle) - (x1 - x2) * Math.Sin(Angle)));
                var x4 = (float)(x2 + L2 / l1 * ((x1 - x2) * Math.Cos(Angle) - (y1 - y2) * Math.Sin(Angle)));
                var y4 = (float)(y2 + L2 / l1 * ((y1 - y2) * Math.Cos(Angle) + (x1 - x2) * Math.Sin(Angle)));
                // Draw line
                canvas.DrawLine(x1, y1, x2, y2, paint);
                // Draw arrow lines
                canvas.DrawLine(x2, y2, x3, y3, paint);
                canvas.DrawLine(x2, y2, x4, y4, paint);
            }
        }
Esempio n. 17
0
 public Ruler(IGeometryVisual v)
 {
     v.CopyTo(this);
 }
Esempio n. 18
0
 public Mark(IGeometryVisual src) : this(src.Color, src.Size, src.IsFilled)
 {
 }
Esempio n. 19
0
 public Rectangle(IGeometryVisual src) : this()
 {
     src.CopyTo(this);
 }
Esempio n. 20
0
 public Circle(IGeometryVisual src) : this()
 {
     src.CopyTo(this);
 }
Esempio n. 21
0
 public Oval(IGeometryVisual o) : base()
 {
     Color = o.Color;
     Size  = o.Size;
 }
Esempio n. 22
0
 public Rectangle(IGeometryVisual src) : this(src.Color, src.Size, src.IsFilled)
 {
 }
Esempio n. 23
0
 public AddGeometryMessage(IGeometryVisual g)
 {
     Geometry = g;
 }
Esempio n. 24
0
 public Arrow(IGeometryVisual src) : this()
 {
     src.CopyTo(this);
 }
Esempio n. 25
0
        public ITool ToolForGeometry(IGeometryVisual geometry)
        {
            var tools = Tools.Where((arg) => arg.Geometry.GetType() == geometry.GetType());

            return(tools.FirstOrDefault());
        }
Esempio n. 26
0
 public Mark(IGeometryVisual src) : this()
 {
     src.CopyTo(this);
 }
Esempio n. 27
0
 public Text(IGeometryVisual src) : this()
 {
     src.CopyTo(this);
 }
Esempio n. 28
0
 public Oval(IGeometryVisual src) : this()
 {
     src.CopyTo(this);
 }
Esempio n. 29
0
 public Stroke(IGeometryVisual src) : this()
 {
     src.CopyTo(this);
 }