Skip to content

Commit

Permalink
ScaleTransform Added
Browse files Browse the repository at this point in the history
  • Loading branch information
donandren committed Mar 9, 2016
1 parent d36aae9 commit 454d1b7
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/Perspex.SceneGraph/Media/ScaleTransform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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.

using System;

namespace Perspex.Media
{
/// <summary>
/// Scale an <see cref="IVisual"/>.
/// </summary>
public class ScaleTransform : Transform
{
/// <summary>
/// Defines the <see cref="ScaleX"/> property.
/// </summary>
public static readonly StyledProperty<double> ScaleXProperty =
PerspexProperty.Register<ScaleTransform, double>(nameof(ScaleX), 1);

/// <summary>
/// Defines the <see cref="ScaleY"/> property.
/// </summary>
public static readonly StyledProperty<double> ScaleYProperty =
PerspexProperty.Register<ScaleTransform, double>(nameof(ScaleY), 1);

/// <summary>
/// Initializes a new instance of the <see cref="ScaleTransform"/> class.
/// </summary>
public ScaleTransform()
{
this.GetObservable(ScaleXProperty).Subscribe(_ => RaiseChanged());
this.GetObservable(ScaleYProperty).Subscribe(_ => RaiseChanged());
}

/// <summary>
/// Initializes a new instance of the <see cref="ScaleTransform"/> class.
/// </summary>
/// <param name="scaleX">ScaleX</param>
/// <param name="scaleY">ScaleY</param>
public ScaleTransform(double scaleX, double scaleY)
: this()
{
ScaleX = scaleX;
ScaleY = scaleY;
}

/// <summary>
/// Gets or sets the ScaleX property.
/// </summary>
public double ScaleX
{
get { return GetValue(ScaleXProperty); }
set { SetValue(ScaleXProperty, value); }
}

/// <summary>
/// Gets or sets the ScaleY property.
/// </summary>
public double ScaleY
{
get { return GetValue(ScaleYProperty); }
set { SetValue(ScaleYProperty, value); }
}

/// <summary>
/// Gets the tranform's <see cref="Matrix"/>.
/// </summary>
public override Matrix Value => Matrix.CreateScale(ScaleX, ScaleY);
}
}
1 change: 1 addition & 0 deletions src/Perspex.SceneGraph/Perspex.SceneGraph.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Compile Include="Media\LinearGradientBrush.cs" />
<Compile Include="Media\MediaExtensions.cs" />
<Compile Include="Media\PenLineCap.cs" />
<Compile Include="Media\ScaleTransform.cs" />
<Compile Include="Media\TextAlignment.cs" />
<Compile Include="Media\FontWeight.cs" />
<Compile Include="Media\FontStyle.cs" />
Expand Down

0 comments on commit 454d1b7

Please sign in to comment.