Browse Source

Added SkewTransform and the corresponding skew function in Matrix class.

pull/1446/head
Jumar Macato 9 years ago
parent
commit
e9c4c238f1
  1. 14
      src/Avalonia.Visuals/Matrix.cs
  2. 69
      src/Avalonia.Visuals/Media/SkewTransform.cs

14
src/Avalonia.Visuals/Matrix.cs

@ -150,6 +150,19 @@ namespace Avalonia
return new Matrix(cos, sin, -sin, cos, 0, 0);
}
/// <summary>
/// Creates a skew matrix from the given axis skew angles in radians.
/// </summary>
/// <param name="xAngle">The amount of skew along the X-axis, in radians.</param>
/// <param name="yAngle">The amount of skew along the Y-axis, in radians.</param>
/// <returns>A rotation matrix.</returns>
public static Matrix CreateSkew(double xAngle, double yAngle)
{
double tanX = Math.Tan(xAngle);
double tanY = Math.Tan(yAngle);
return new Matrix(1.0, tanX, tanY, 1.0, 0.0, 0.0);
}
/// <summary>
/// Creates a scale matrix from the given X and Y components.
/// </summary>
@ -215,7 +228,6 @@ namespace Avalonia
return (_m11 * _m22) - (_m12 * _m21);
}
/// <summary>
/// Returns a boolean indicating whether the matrix is equal to the other given matrix.
/// </summary>

69
src/Avalonia.Visuals/Media/SkewTransform.cs

@ -0,0 +1,69 @@
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using Avalonia.VisualTree;
namespace Avalonia.Media
{
/// <summary>
/// Skews an <see cref="IVisual"/>.
/// </summary>
public class SkewTransform : Transform
{
/// <summary>
/// Defines the <see cref="AngleX"/> property.
/// </summary>
public static readonly StyledProperty<double> AngleXProperty =
AvaloniaProperty.Register<SkewTransform, double>(nameof(AngleX));
/// <summary>
/// Defines the <see cref="AngleY"/> property.
/// </summary>
public static readonly StyledProperty<double> AngleYProperty =
AvaloniaProperty.Register<SkewTransform, double>(nameof(AngleY));
/// <summary>
/// Initializes a new instance of the <see cref="SkewTransform"/> class.
/// </summary>
public SkewTransform()
{
this.GetObservable(AngleXProperty).Subscribe(_ => RaiseChanged());
this.GetObservable(AngleYProperty).Subscribe(_ => RaiseChanged());
}
/// <summary>
/// Initializes a new instance of the <see cref="SkewTransform"/> class.
/// </summary>
/// <param name="angleX">The skew angle of X-axis, in degrees.</param>
/// <param name="angleY">The skew angle of Y-axis, in degrees.</param>
public SkewTransform(double angleX, double angleY) : this()
{
AngleX = angleX;
AngleY = angleY;
}
/// <summary>
/// Gets or sets the AngleX property.
/// </summary>
public double AngleX
{
get { return GetValue(AngleXProperty); }
set { SetValue(AngleXProperty, value); }
}
/// <summary>
/// Gets or sets the AngleY property.
/// </summary>
public double AngleY
{
get { return GetValue(AngleYProperty); }
set { SetValue(AngleYProperty, value); }
}
/// <summary>
/// Gets the tranform's <see cref="Matrix"/>.
/// </summary>
public override Matrix Value => Matrix.CreateSkew(Matrix.ToRadians(AngleX), Matrix.ToRadians(AngleY));
}
}
Loading…
Cancel
Save