using System; using Avalonia.Reactive; using Avalonia.VisualTree; namespace Avalonia.Media { /// /// Rotates an . /// public class RotateTransform : Transform { /// /// Defines the property. /// public static readonly StyledProperty AngleProperty = AvaloniaProperty.Register(nameof(Angle)); /// /// Defines the property. /// public static readonly StyledProperty CenterXProperty = AvaloniaProperty.Register(nameof(CenterX)); /// /// Defines the property. /// public static readonly StyledProperty CenterYProperty = AvaloniaProperty.Register(nameof(CenterY)); /// /// Initializes a new instance of the class. /// public RotateTransform() { this.GetObservable(AngleProperty).Subscribe(_ => RaiseChanged()); } /// /// Initializes a new instance of the class. /// /// The angle, in degrees. public RotateTransform(double angle) : this() { Angle = angle; } /// /// Initializes a new instance of the class. /// /// The angle, in degrees. /// The x-coordinate of the center point for the rotation. /// The y-coordinate of the center point for the rotation. public RotateTransform(double angle, double centerX, double centerY) : this() { Angle = angle; CenterX = centerX; CenterY = centerY; } /// /// Gets or sets the angle of rotation, in degrees. /// public double Angle { get => GetValue(AngleProperty); set => SetValue(AngleProperty, value); } /// /// Gets or sets the x-coordinate of the rotation center point. The default is 0. /// public double CenterX { get => GetValue(CenterXProperty); set => SetValue(CenterXProperty, value); } /// /// Gets or sets the y-coordinate of the rotation center point. The default is 0. /// public double CenterY { get => GetValue(CenterYProperty); set => SetValue(CenterYProperty, value); } /// /// Gets the transform's . /// public override Matrix Value => Matrix.CreateTranslation(-CenterX, -CenterY) * Matrix.CreateRotation(Matrix.ToRadians(Angle)) * Matrix.CreateTranslation(CenterX, CenterY); } }