diff --git a/samples/RenderDemo/Controls/LineBoundsDemoControl.cs b/samples/RenderDemo/Controls/LineBoundsDemoControl.cs index 6030eae47b..0e0b3d6142 100644 --- a/samples/RenderDemo/Controls/LineBoundsDemoControl.cs +++ b/samples/RenderDemo/Controls/LineBoundsDemoControl.cs @@ -9,24 +9,34 @@ namespace RenderDemo.Controls { public class LineBoundsDemoControl : Control { - private double angle = Math.PI / 8; + static LineBoundsDemoControl() + { + AffectsRender(AngleProperty); + } - public static double CalculateOppSide(double angle, double hyp) + public LineBoundsDemoControl() { - return Math.Sin(angle) * hyp; + var timer = new DispatcherTimer(); + timer.Interval = TimeSpan.FromSeconds(1 / 60); + timer.Tick += (sender, e) => Angle += Math.PI / 360; + timer.Start(); } - public static double CalculateAdjSide(double angle, double hyp) + public static readonly StyledProperty AngleProperty = + AvaloniaProperty.Register(nameof(Angle)); + + public double Angle { - return Math.Cos(angle) * hyp; + get => GetValue(AngleProperty); + set => SetValue(AngleProperty, value); } public override void Render(DrawingContext drawingContext) { var lineLength = Math.Sqrt((100 * 100) + (100 * 100)); - var diffX = CalculateAdjSide(angle, lineLength); - var diffY = CalculateOppSide(angle, lineLength); + var diffX = LineBoundsHelper.CalculateAdjSide(Angle, lineLength); + var diffY = LineBoundsHelper.CalculateOppSide(Angle, lineLength); var p1 = new Point(200, 200); @@ -38,9 +48,6 @@ namespace RenderDemo.Controls drawingContext.DrawLine(pen, p1, p2); drawingContext.DrawRectangle(boundPen, LineBoundsHelper.CalculateBounds(p1, p2, pen)); - - angle += Math.PI / 360; - Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Background); } } } diff --git a/samples/RenderDemo/RenderDemo.csproj b/samples/RenderDemo/RenderDemo.csproj index ce33f42143..0d7d62e177 100644 --- a/samples/RenderDemo/RenderDemo.csproj +++ b/samples/RenderDemo/RenderDemo.csproj @@ -3,6 +3,9 @@ Exe netcoreapp3.1 + + + diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/LineBoundsHelper.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/LineBoundsHelper.cs index 4b5527ce6f..56d218e398 100644 --- a/src/Avalonia.Visuals/Rendering/SceneGraph/LineBoundsHelper.cs +++ b/src/Avalonia.Visuals/Rendering/SceneGraph/LineBoundsHelper.cs @@ -3,7 +3,7 @@ using Avalonia.Media; namespace Avalonia.Rendering.SceneGraph { - public static class LineBoundsHelper + internal static class LineBoundsHelper { private static double CalculateAngle(Point p1, Point p2) { @@ -13,12 +13,12 @@ namespace Avalonia.Rendering.SceneGraph return Math.Atan2(yDiff, xDiff); } - private static double CalculateOppSide(double angle, double hyp) + internal static double CalculateOppSide(double angle, double hyp) { return Math.Sin(angle) * hyp; } - private static double CalculateAdjSide(double angle, double hyp) + internal static double CalculateAdjSide(double angle, double hyp) { return Math.Cos(angle) * hyp; }