24 changed files with 502 additions and 14 deletions
@ -0,0 +1,48 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="Animatable.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Animation |
|||
{ |
|||
using System.Linq; |
|||
using System.Reactive.Linq; |
|||
using Perspex.Input; |
|||
|
|||
public class Animatable : InputElement |
|||
{ |
|||
private PropertyTransitions propertyTransitions; |
|||
|
|||
public PropertyTransitions PropertyTransitions |
|||
{ |
|||
get |
|||
{ |
|||
if (this.propertyTransitions == null) |
|||
{ |
|||
this.propertyTransitions = new PropertyTransitions(); |
|||
} |
|||
|
|||
return this.propertyTransitions; |
|||
} |
|||
|
|||
set |
|||
{ |
|||
this.propertyTransitions = value; |
|||
} |
|||
} |
|||
|
|||
protected override void OnPropertyChanged(PerspexPropertyChangedEventArgs e) |
|||
{ |
|||
if (e.Priority != BindingPriority.Animation && this.propertyTransitions != null) |
|||
{ |
|||
var match = this.propertyTransitions.FirstOrDefault(x => x.Property == e.Property); |
|||
|
|||
if (match != null) |
|||
{ |
|||
Animate.Property(this, e.Property, e.OldValue, e.NewValue, match.Easing, match.Duration); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="Animate.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Animation |
|||
{ |
|||
using System; |
|||
using System.Linq; |
|||
using System.Reactive.Linq; |
|||
using Perspex.Input; |
|||
using Perspex.Threading; |
|||
|
|||
public static class Animate |
|||
{ |
|||
private const int FramesPerSecond = 30; |
|||
|
|||
private static readonly TimeSpan Tick = TimeSpan.FromSeconds(1.0 / FramesPerSecond); |
|||
|
|||
public static IDisposable Property( |
|||
PerspexObject target, |
|||
PerspexProperty property, |
|||
object start, |
|||
object finish, |
|||
IEasing easing, |
|||
TimeSpan duration, |
|||
double repeats = 1) |
|||
{ |
|||
var startTime = Environment.TickCount; |
|||
var runningTime = (double)duration.TotalMilliseconds; |
|||
var endTime = Environment.TickCount + (runningTime * repeats); |
|||
|
|||
var o = Observable.Interval(Tick, PerspexScheduler.Instance) |
|||
.Select(_ => Environment.TickCount) |
|||
.TakeWhile(tick => tick < endTime) |
|||
.Select(tick => easing.Ease((tick - startTime) / runningTime, start, finish)) |
|||
.StartWith(start) |
|||
.Concat(Observable.Return(finish)); |
|||
|
|||
return target.Bind(property, o, BindingPriority.Animation); |
|||
} |
|||
|
|||
public static IDisposable Property<T>( |
|||
PerspexObject target, |
|||
PerspexProperty<T> property, |
|||
T start, |
|||
T finish, |
|||
IEasing easing, |
|||
TimeSpan duration) |
|||
{ |
|||
return Property(target, (PerspexProperty)property, start, finish, easing, duration); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="PropertyTransition.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Animation |
|||
{ |
|||
using System; |
|||
|
|||
public static class AnimationExtensions |
|||
{ |
|||
public static PropertyTransition Transition<T>(this PerspexProperty<T> property, int milliseconds) |
|||
{ |
|||
return Transition(property, TimeSpan.FromMilliseconds(milliseconds)); |
|||
} |
|||
|
|||
public static PropertyTransition Transition<T>(this PerspexProperty<T> property, TimeSpan duration) |
|||
{ |
|||
return new PropertyTransition |
|||
{ |
|||
Property = property, |
|||
Duration = duration, |
|||
Easing = LinearEasing.For<T>(), |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="PropertyTransition.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Animation |
|||
{ |
|||
public interface IEasing |
|||
{ |
|||
object Ease(double progress, object start, object finish); |
|||
} |
|||
|
|||
public interface IEasing<T> : IEasing |
|||
{ |
|||
T Ease(double progress, T start, T finish); |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="PropertyTransition.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Animation |
|||
{ |
|||
using System; |
|||
|
|||
public class LinearDoubleEasing : IEasing<double> |
|||
{ |
|||
public double Ease(double progress, double start, double finish) |
|||
{ |
|||
return ((finish - start) * progress) + start; |
|||
} |
|||
|
|||
public object Ease(double progress, object start, object finish) |
|||
{ |
|||
return this.Ease(progress, (double)start, (double)finish); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="PropertyTransition.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Animation |
|||
{ |
|||
using System; |
|||
|
|||
public static class LinearEasing |
|||
{ |
|||
public static LinearDoubleEasing For<T>() |
|||
{ |
|||
if (typeof(T) == typeof(double)) |
|||
{ |
|||
return new LinearDoubleEasing(); |
|||
} |
|||
else |
|||
{ |
|||
throw new NotSupportedException(string.Format( |
|||
"Don't know how to create a LinearEasing for type '{0}'.", |
|||
typeof(T).FullName)); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,99 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
|||
<PropertyGroup> |
|||
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{D211E587-D8BC-45B9-95A4-F297C8FA5200}</ProjectGuid> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>Perspex.Animation</RootNamespace> |
|||
<AssemblyName>Perspex.Animation</AssemblyName> |
|||
<DefaultLanguage>en-US</DefaultLanguage> |
|||
<FileAlignment>512</FileAlignment> |
|||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|||
<TargetFrameworkProfile>Profile7</TargetFrameworkProfile> |
|||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<!-- A reference to the entire .NET Framework is automatically included --> |
|||
<ProjectReference Include="..\Perspex.Base\Perspex.Base.csproj"> |
|||
<Project>{b09b78d8-9b26-48b0-9149-d64a2f120f3f}</Project> |
|||
<Name>Perspex.Base</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Input\Perspex.Input.csproj"> |
|||
<Project>{62024b2d-53eb-4638-b26b-85eeaa54866e}</Project> |
|||
<Name>Perspex.Input</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Interactivity\Perspex.Interactivity.csproj"> |
|||
<Project>{6b0ed19d-a08b-461c-a9d9-a9ee40b0c06b}</Project> |
|||
<Name>Perspex.Interactivity</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Layout\Perspex.Layout.csproj"> |
|||
<Project>{42472427-4774-4c81-8aff-9f27b8e31721}</Project> |
|||
<Name>Perspex.Layout</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.SceneGraph\Perspex.SceneGraph.csproj"> |
|||
<Project>{eb582467-6abb-43a1-b052-e981ba910e3a}</Project> |
|||
<Name>Perspex.SceneGraph</Name> |
|||
</ProjectReference> |
|||
<ProjectReference Include="..\Perspex.Styling\Perspex.Styling.csproj"> |
|||
<Project>{f1baa01a-f176-4c6a-b39d-5b40bb1b148f}</Project> |
|||
<Name>Perspex.Styling</Name> |
|||
</ProjectReference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Compile Include="Animate.cs" /> |
|||
<Compile Include="Animatable.cs" /> |
|||
<Compile Include="AnimationExtensions.cs" /> |
|||
<Compile Include="LinearEasing.cs" /> |
|||
<Compile Include="LinearDoubleEasing.cs" /> |
|||
<Compile Include="IEasing.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
<Compile Include="PropertyTransitions.cs" /> |
|||
<Compile Include="PropertyTransition.cs" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<Reference Include="System.Reactive.Core"> |
|||
<HintPath>..\packages\Rx-Core.2.2.5\lib\portable-windows8+net45+wp8\System.Reactive.Core.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System.Reactive.Interfaces"> |
|||
<HintPath>..\packages\Rx-Interfaces.2.2.5\lib\portable-windows8+net45+wp8\System.Reactive.Interfaces.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System.Reactive.Linq"> |
|||
<HintPath>..\packages\Rx-Linq.2.2.5\lib\portable-windows8+net45+wp8\System.Reactive.Linq.dll</HintPath> |
|||
</Reference> |
|||
<Reference Include="System.Reactive.PlatformServices"> |
|||
<HintPath>..\packages\Rx-PlatformServices.2.2.5\lib\portable-windows8+net45+wp8\System.Reactive.PlatformServices.dll</HintPath> |
|||
</Reference> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<None Include="packages.config" /> |
|||
</ItemGroup> |
|||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,30 @@ |
|||
using System.Resources; |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyTitle("Perspex.Animation")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("Perspex.Animation")] |
|||
[assembly: AssemblyCopyright("Copyright © 2014")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
[assembly: NeutralResourcesLanguage("en")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
@ -0,0 +1,19 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="PropertyTransition.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Animation |
|||
{ |
|||
using System; |
|||
|
|||
public class PropertyTransition |
|||
{ |
|||
public PerspexProperty Property { get; set; } |
|||
|
|||
public TimeSpan Duration { get; set; } |
|||
|
|||
public IEasing Easing { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="PropertyTransitions.cs" company="Steven Kirk">
|
|||
// Copyright 2014 MIT Licence. See licence.md for more information.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace Perspex.Animation |
|||
{ |
|||
public class PropertyTransitions : PerspexList<PropertyTransition> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="Rx-Core" version="2.2.5" targetFramework="portable-net45+win" /> |
|||
<package id="Rx-Interfaces" version="2.2.5" targetFramework="portable-net45+win" /> |
|||
<package id="Rx-Linq" version="2.2.5" targetFramework="portable-net45+win" /> |
|||
<package id="Rx-Main" version="2.2.5" targetFramework="portable-net45+win" /> |
|||
<package id="Rx-PlatformServices" version="2.2.5" targetFramework="portable-net45+win" /> |
|||
</packages> |
|||
Loading…
Reference in new issue