RotateTransform.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (c) The Perspex Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. namespace Perspex.Media
  5. {
  6. /// <summary>
  7. /// Rotates an <see cref="IVisual"/>.
  8. /// </summary>
  9. public class RotateTransform : Transform
  10. {
  11. /// <summary>
  12. /// Defines the <see cref="Angle"/> property.
  13. /// </summary>
  14. public static readonly StyledProperty<double> AngleProperty =
  15. PerspexProperty.Register<RotateTransform, double>("Angle");
  16. /// <summary>
  17. /// Initializes a new instance of the <see cref="RotateTransform"/> class.
  18. /// </summary>
  19. public RotateTransform()
  20. {
  21. this.GetObservable(AngleProperty).Subscribe(_ => RaiseChanged());
  22. }
  23. /// <summary>
  24. /// Initializes a new instance of the <see cref="RotateTransform"/> class.
  25. /// </summary>
  26. /// <param name="angle">The angle, in degrees.</param>
  27. public RotateTransform(double angle)
  28. : this()
  29. {
  30. Angle = angle;
  31. }
  32. /// <summary>
  33. /// Gets or sets the angle of rotation, in degrees.
  34. /// </summary>
  35. public double Angle
  36. {
  37. get { return GetValue(AngleProperty); }
  38. set { SetValue(AngleProperty, value); }
  39. }
  40. /// <summary>
  41. /// Gets the tranform's <see cref="Matrix"/>.
  42. /// </summary>
  43. public override Matrix Value => Matrix.CreateRotation(Matrix.ToRadians(Angle));
  44. }
  45. }