Refactored shape data property
This commit is contained in:
Родитель
f0ade6fe3b
Коммит
87e2e3e81f
|
@ -49,15 +49,10 @@ namespace SpiroNet
|
|||
public bool IsTagged { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The generated Path data.
|
||||
/// Try to generate Path shape data from Points using path bezier context implementation.
|
||||
/// </summary>
|
||||
public string Data { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Generate Path shape data using path bezier context implementation.
|
||||
/// </summary>
|
||||
/// <returns>True when Data was generated successfully.</returns>
|
||||
public bool UpdateData()
|
||||
/// <returns>True when output data was generated successfully.</returns>
|
||||
public bool TryGetData(out string data)
|
||||
{
|
||||
var points = this.Points.ToArray();
|
||||
var bc = new PathBezierContext();
|
||||
|
@ -66,9 +61,9 @@ namespace SpiroNet
|
|||
{
|
||||
var success = Spiro.TaggedSpiroCPsToBezier0(points, bc);
|
||||
if (success)
|
||||
this.Data = bc.ToString();
|
||||
data = bc.ToString();
|
||||
else
|
||||
this.Data = string.Empty;
|
||||
data = null;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
@ -76,9 +71,9 @@ namespace SpiroNet
|
|||
{
|
||||
var success = Spiro.SpiroCPsToBezier0(points, points.Length, this.IsClosed, bc);
|
||||
if (success)
|
||||
this.Data = bc.ToString();
|
||||
data = bc.ToString();
|
||||
else
|
||||
this.Data = string.Empty;
|
||||
data = null;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace SpiroNet.Wpf
|
|||
public class SpiroCanvas : Canvas
|
||||
{
|
||||
public IList<PathShape> Shapes { get; set; }
|
||||
public IDictionary<PathShape, string> Data { get; set; }
|
||||
|
||||
private Brush _geometryBrush;
|
||||
private Brush _geometryPenBrush;
|
||||
|
@ -78,15 +79,15 @@ namespace SpiroNet.Wpf
|
|||
if (shape == null)
|
||||
return;
|
||||
|
||||
if (!string.IsNullOrEmpty(shape.Data))
|
||||
string data;
|
||||
if (Data.TryGetValue(shape, out data) && !string.IsNullOrEmpty(data))
|
||||
{
|
||||
var geometry = Geometry.Parse(shape.Data);
|
||||
var geometry = Geometry.Parse(data);
|
||||
dc.DrawGeometry(shape.IsClosed ? _geometryBrush : null, _geometryPen, geometry);
|
||||
}
|
||||
|
||||
if (shape.Points == null)
|
||||
return;
|
||||
|
||||
if (shape.Points != null)
|
||||
{
|
||||
foreach (var point in shape.Points)
|
||||
{
|
||||
dc.DrawEllipse(_pointBrush, null, new Point(point.X, point.Y), 4.0, 4.0);
|
||||
|
@ -94,3 +95,4 @@ namespace SpiroNet.Wpf
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче