-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
PathFigure.cs
143 lines (116 loc) · 4.6 KB
/
PathFigure.cs
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#nullable disable
using System;
using System.Collections.Specialized;
using System.ComponentModel;
using Microsoft.Maui.Graphics;
namespace Microsoft.Maui.Controls.Shapes
{
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/PathFigure.xml" path="Type[@FullName='Microsoft.Maui.Controls.Shapes.PathFigure']/Docs/*" />
[ContentProperty("Segments")]
public sealed class PathFigure : BindableObject, IAnimatable
{
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/PathFigure.xml" path="//Member[@MemberName='.ctor']/Docs/*" />
public PathFigure()
{
Segments = new PathSegmentCollection();
}
/// <summary>Bindable property for <see cref="Segments"/>.</summary>
public static readonly BindableProperty SegmentsProperty =
BindableProperty.Create(nameof(Segments), typeof(PathSegmentCollection), typeof(PathFigure), null,
propertyChanged: OnPathSegmentCollectionChanged);
static void OnPathSegmentCollectionChanged(BindableObject bindable, object oldValue, object newValue)
{
(bindable as PathFigure)?.UpdatePathSegmentCollection(oldValue as PathSegmentCollection, newValue as PathSegmentCollection);
}
/// <summary>Bindable property for <see cref="StartPoint"/>.</summary>
public static readonly BindableProperty StartPointProperty =
BindableProperty.Create(nameof(StartPoint), typeof(Point), typeof(PathFigure), new Point(0, 0));
/// <summary>Bindable property for <see cref="IsClosed"/>.</summary>
public static readonly BindableProperty IsClosedProperty =
BindableProperty.Create(nameof(IsClosed), typeof(bool), typeof(PathFigure), false);
/// <summary>Bindable property for <see cref="IsFilled"/>.</summary>
public static readonly BindableProperty IsFilledProperty =
BindableProperty.Create(nameof(IsFilled), typeof(bool), typeof(PathFigure), true);
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/PathFigure.xml" path="//Member[@MemberName='Segments']/Docs/*" />
public PathSegmentCollection Segments
{
set { SetValue(SegmentsProperty, value); }
get { return (PathSegmentCollection)GetValue(SegmentsProperty); }
}
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/PathFigure.xml" path="//Member[@MemberName='StartPoint']/Docs/*" />
public Point StartPoint
{
set { SetValue(StartPointProperty, value); }
get { return (Point)GetValue(StartPointProperty); }
}
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/PathFigure.xml" path="//Member[@MemberName='IsClosed']/Docs/*" />
public bool IsClosed
{
set { SetValue(IsClosedProperty, value); }
get { return (bool)GetValue(IsClosedProperty); }
}
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/PathFigure.xml" path="//Member[@MemberName='IsFilled']/Docs/*" />
public bool IsFilled
{
set { SetValue(IsFilledProperty, value); }
get { return (bool)GetValue(IsFilledProperty); }
}
internal event EventHandler InvalidatePathSegmentRequested;
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/PathFigure.xml" path="//Member[@MemberName='BatchBegin']/Docs/*" />
public void BatchBegin()
{
}
/// <include file="../../../docs/Microsoft.Maui.Controls.Shapes/PathFigure.xml" path="//Member[@MemberName='BatchCommit']/Docs/*" />
public void BatchCommit()
{
}
void UpdatePathSegmentCollection(PathSegmentCollection oldCollection, PathSegmentCollection newCollection)
{
if (oldCollection != null)
{
oldCollection.CollectionChanged -= OnPathSegmentCollectionChanged;
foreach (var oldPathSegment in oldCollection)
{
oldPathSegment.PropertyChanged -= OnPathSegmentPropertyChanged;
}
}
if (newCollection == null)
return;
newCollection.CollectionChanged += OnPathSegmentCollectionChanged;
foreach (var newPathSegment in newCollection)
{
newPathSegment.PropertyChanged += OnPathSegmentPropertyChanged;
}
}
void OnPathSegmentCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.OldItems != null)
{
foreach (var oldItem in e.OldItems)
{
if (!(oldItem is PathSegment oldPathSegment))
continue;
oldPathSegment.PropertyChanged -= OnPathSegmentPropertyChanged;
}
}
if (e.NewItems != null)
{
foreach (var newItem in e.NewItems)
{
if (!(newItem is PathSegment newPathSegment))
continue;
newPathSegment.PropertyChanged += OnPathSegmentPropertyChanged;
}
}
Invalidate();
}
void OnPathSegmentPropertyChanged(object sender, PropertyChangedEventArgs e)
{
Invalidate();
}
void Invalidate()
{
InvalidatePathSegmentRequested?.Invoke(this, EventArgs.Empty);
}
}
}