Browse Source

Cache Polygon/Polyline geometry.

pull/387/merge
Steven Kirk 10 years ago
parent
commit
7a8b50de8f
  1. 30
      src/Perspex.Controls/Shapes/Polygon.cs
  2. 26
      src/Perspex.Controls/Shapes/Polyline.cs

30
src/Perspex.Controls/Shapes/Polygon.cs

@ -1,11 +1,7 @@
// Copyright (c) The Perspex Project. All rights reserved. // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Perspex.Media; using Perspex.Media;
namespace Perspex.Controls.Shapes namespace Perspex.Controls.Shapes
@ -15,12 +11,36 @@ namespace Perspex.Controls.Shapes
public static readonly StyledProperty<IList<Point>> PointsProperty = public static readonly StyledProperty<IList<Point>> PointsProperty =
PerspexProperty.Register<Polygon, IList<Point>>("Points"); PerspexProperty.Register<Polygon, IList<Point>>("Points");
private Geometry _geometry;
static Polygon()
{
PointsProperty.Changed.AddClassHandler<Polygon>(x => x.PointsChanged);
}
public override Geometry DefiningGeometry
{
get
{
if (_geometry == null)
{
_geometry = new PolylineGeometry(Points, true);
}
return _geometry;
}
}
public IList<Point> Points public IList<Point> Points
{ {
get { return GetValue(PointsProperty); } get { return GetValue(PointsProperty); }
set { SetValue(PointsProperty, value); } set { SetValue(PointsProperty, value); }
} }
public override Geometry DefiningGeometry => new PolylineGeometry(Points, true); private void PointsChanged(PerspexPropertyChangedEventArgs e)
{
_geometry = null;
InvalidateMeasure();
}
} }
} }

26
src/Perspex.Controls/Shapes/Polyline.cs

@ -1,11 +1,7 @@
// Copyright (c) The Perspex Project. All rights reserved. // Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Perspex.Media; using Perspex.Media;
namespace Perspex.Controls.Shapes namespace Perspex.Controls.Shapes
@ -15,9 +11,25 @@ namespace Perspex.Controls.Shapes
public static readonly StyledProperty<IList<Point>> PointsProperty = public static readonly StyledProperty<IList<Point>> PointsProperty =
PerspexProperty.Register<Polyline, IList<Point>>("Points"); PerspexProperty.Register<Polyline, IList<Point>>("Points");
private Geometry _geometry;
static Polyline() static Polyline()
{ {
StrokeThicknessProperty.OverrideDefaultValue<Polyline>(1); StrokeThicknessProperty.OverrideDefaultValue<Polyline>(1);
PointsProperty.Changed.AddClassHandler<Polyline>(x => x.PointsChanged);
}
public override Geometry DefiningGeometry
{
get
{
if (_geometry == null)
{
_geometry = new PolylineGeometry(Points, false);
}
return _geometry;
}
} }
public IList<Point> Points public IList<Point> Points
@ -26,6 +38,10 @@ namespace Perspex.Controls.Shapes
set { SetValue(PointsProperty, value); } set { SetValue(PointsProperty, value); }
} }
public override Geometry DefiningGeometry => new PolylineGeometry(Points, false); private void PointsChanged(PerspexPropertyChangedEventArgs e)
{
_geometry = null;
InvalidateMeasure();
}
} }
} }

Loading…
Cancel
Save