aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TEMP/Tango.Graphics2D/VisualBinders/PathBinder.cs
blob: 903d62010859d68b00281479627b4695309b57ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;

namespace Tango.Graphics2D.VisualBinders
{
    public class PathBinder : IVisualBinder
    {
        public void DrawVisual(FrameworkElement element, Drawing2DHost host, DrawingContext context)
        {
            Path path = element as Path;

            var location = host.GetElementLocation(path);
            var size = host.GetElementSize(path);

            Pen pen = null;

            if (path.Stroke != null)
            {
                pen = new Pen(path.Stroke, path.StrokeThickness);
                pen.DashCap = path.StrokeDashCap;
                //TODO: add some stroke features...
            }

            var geo = path.Data.Clone();


            if (path.Stretch == Stretch.Fill)
            {
                TransformGroup group = new TransformGroup();

                TranslateTransform translateTransform = new TranslateTransform();
                translateTransform.X = -geo.Bounds.Left;
                translateTransform.Y = -geo.Bounds.Top;

                ScaleTransform scaleTransform = new ScaleTransform();
                scaleTransform.ScaleX = size.Width / geo.Bounds.Width;
                scaleTransform.ScaleY = size.Height / geo.Bounds.Height;

                group.Children.Add(translateTransform);
                group.Children.Add(scaleTransform);

                context.PushTransform(group);
            }

            context.DrawGeometry(path.Fill, pen, geo);
        }

        public List<DependencyProperty> GetRenderProperties()
        {
            return new List<DependencyProperty>()
            {
                Path.OpacityProperty,
                Path.VisibilityProperty,
                Path.FillProperty,
                Path.StrokeProperty,
                Path.StrokeThicknessProperty,
                Path.StretchProperty
            };
        }
    }
}