Browse Source

Added page slide transition.

pull/58/head
Steven Kirk 11 years ago
parent
commit
560707bfe2
  1. 14
      Perspex-Mono.sln
  2. 6
      Perspex.Controls/Deck.cs
  3. 11
      Perspex.Controls/Presenters/DeckPresenter.cs
  4. 4
      Perspex.Controls/TabControl.cs
  5. 9
      Perspex.SceneGraph/Animation/CrossFade.cs
  6. 6
      Perspex.SceneGraph/Animation/IPageTransition.cs
  7. 78
      Perspex.SceneGraph/Animation/PageSlide.cs
  8. 49
      Perspex.SceneGraph/Media/TranslateTransform.cs
  9. 6
      Perspex.SceneGraph/Perspex.SceneGraph.csproj
  10. 18
      TestApplication/Program.cs

14
Perspex-Mono.sln

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22609.0
VisualStudioVersion = 14.0.22823.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Base", "Perspex.Base\Perspex.Base.csproj", "{B09B78D8-9B26-48B0-9149-D64A2F120F3F}"
EndProject
@ -53,7 +53,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{596AF7
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Cairo.RenderTests", "Tests\Perspex.RenderTests\Perspex.Cairo.RenderTests.csproj", "{DABFD304-D6A4-4752-8123-C2CCF7AC7831}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Perspex.Cairo.RenderTests", "Tests\Perspex.RenderTests\Perspex.Cairo.RenderTests.csproj", "{E106CF37-4066-4615-B684-172A6D30B058}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -141,10 +141,10 @@ Global
{D211E587-D8BC-45B9-95A4-F297C8FA5200}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D211E587-D8BC-45B9-95A4-F297C8FA5200}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D211E587-D8BC-45B9-95A4-F297C8FA5200}.Release|Any CPU.Build.0 = Release|Any CPU
{DABFD304-D6A4-4752-8123-C2CCF7AC7831}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DABFD304-D6A4-4752-8123-C2CCF7AC7831}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DABFD304-D6A4-4752-8123-C2CCF7AC7831}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DABFD304-D6A4-4752-8123-C2CCF7AC7831}.Release|Any CPU.Build.0 = Release|Any CPU
{E106CF37-4066-4615-B684-172A6D30B058}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E106CF37-4066-4615-B684-172A6D30B058}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E106CF37-4066-4615-B684-172A6D30B058}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E106CF37-4066-4615-B684-172A6D30B058}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -158,6 +158,6 @@ Global
{2905FF23-53FB-45E6-AA49-6AF47A172056} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
{415E048E-4611-4815-9CF2-D774E29079AC} = {2BAFBE53-7FA4-4BB9-976F-9AFCC4F9847D}
{DB070A10-BF39-4752-8456-86E9D5928478} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
{DABFD304-D6A4-4752-8123-C2CCF7AC7831} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
{E106CF37-4066-4615-B684-172A6D30B058} = {C5A00AC3-B34C-4564-9BDD-2DA473EF4D8B}
EndGlobalSection
EndGlobal

6
Perspex.Controls/Deck.cs

@ -18,8 +18,8 @@ namespace Perspex.Controls
/// </summary>
public class Deck : SelectingItemsControl
{
public static readonly PerspexProperty<IVisibilityTransition> TransitionProperty =
PerspexProperty.Register<Deck, IVisibilityTransition>("Transition");
public static readonly PerspexProperty<IPageTransition> TransitionProperty =
PerspexProperty.Register<Deck, IPageTransition>("Transition");
private static readonly ItemsPanelTemplate PanelTemplate =
new ItemsPanelTemplate(() => new Panel());
@ -29,7 +29,7 @@ namespace Perspex.Controls
ItemsPanelProperty.OverrideDefaultValue(typeof(Deck), PanelTemplate);
}
public IVisibilityTransition Transition
public IPageTransition Transition
{
get { return this.GetValue(TransitionProperty); }
set { this.SetValue(TransitionProperty, value); }

11
Perspex.Controls/Presenters/DeckPresenter.cs

@ -9,6 +9,7 @@ namespace Perspex.Controls.Presenters
using Perspex.Animation;
using Perspex.Controls.Generators;
using Perspex.Controls.Primitives;
using Perspex.Controls.Utils;
using Perspex.Input;
using Perspex.Styling;
using System;
@ -29,7 +30,7 @@ namespace Perspex.Controls.Presenters
public static readonly PerspexProperty<object> SelectedItemProperty =
SelectingItemsControl.SelectedItemProperty.AddOwner<DeckPresenter>();
public static readonly PerspexProperty<IVisibilityTransition> TransitionProperty =
public static readonly PerspexProperty<IPageTransition> TransitionProperty =
Deck.TransitionProperty.AddOwner<DeckPresenter>();
private bool createdPanel;
@ -69,7 +70,7 @@ namespace Perspex.Controls.Presenters
private set;
}
public IVisibilityTransition Transition
public IPageTransition Transition
{
get { return this.GetValue(TransitionProperty); }
set { this.SetValue(TransitionProperty, value); }
@ -125,21 +126,25 @@ namespace Perspex.Controls.Presenters
var generator = this.GetGenerator();
Control from = null;
Control to = null;
int fromIndex = -1;
int toIndex = -1;
if (value.Item1 != null)
{
from = generator.GetContainerForItem(value.Item1);
fromIndex = this.Items.IndexOf(value.Item1);
}
if (value.Item2 != null)
{
to = generator.Generate(new[] { value.Item2 }).Single();
this.Panel.Children.Add(to);
toIndex = this.Items.IndexOf(value.Item2);
}
if (this.Transition != null)
{
await this.Transition.Start(from, to);
await this.Transition.Start(from, to, fromIndex < toIndex);
}
if (from != null)

4
Perspex.Controls/TabControl.cs

@ -25,7 +25,7 @@ namespace Perspex.Controls
public static readonly PerspexProperty<TabItem> SelectedTabProperty =
PerspexProperty.Register<TabControl, TabItem>("SelectedTab");
public static readonly PerspexProperty<IVisibilityTransition> TransitionProperty =
public static readonly PerspexProperty<IPageTransition> TransitionProperty =
Deck.TransitionProperty.AddOwner<TabControl>();
private PerspexReadOnlyListView<ILogical> logicalChildren =
@ -60,7 +60,7 @@ namespace Perspex.Controls
set { this.SetValue(SelectedTabProperty, value); }
}
public IVisibilityTransition Transition
public IPageTransition Transition
{
get { return this.GetValue(TransitionProperty); }
set { this.SetValue(TransitionProperty, value); }

9
Perspex.SceneGraph/Animation/CrossFadeTransition.cs → Perspex.SceneGraph/Animation/CrossFade.cs

@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
// <copyright file="CrossFadeTransition.cs" company="Steven Kirk">
// <copyright file="CrossFade.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
@ -8,20 +8,19 @@ namespace Perspex.Animation
{
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
public class CrossFadeTransition : IVisibilityTransition
public class CrossFade : IPageTransition
{
public CrossFadeTransition(TimeSpan duration)
public CrossFade(TimeSpan duration)
{
this.Duration = duration;
}
public TimeSpan Duration { get; }
public async Task Start(Visual from, Visual to)
public async Task Start(Visual from, Visual to, bool forward)
{
var tasks = new List<Task>();

6
Perspex.SceneGraph/Animation/IVisibilityTransition.cs → Perspex.SceneGraph/Animation/IPageTransition.cs

@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
// <copyright file="IVisibilityTransition.cs" company="Steven Kirk">
// <copyright file="IPageTransition.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
@ -8,8 +8,8 @@ namespace Perspex.Animation
{
using System.Threading.Tasks;
public interface IVisibilityTransition
public interface IPageTransition
{
Task Start(Visual from, Visual to);
Task Start(Visual from, Visual to, bool forward);
}
}

78
Perspex.SceneGraph/Animation/PageSlide.cs

@ -0,0 +1,78 @@
// -----------------------------------------------------------------------
// <copyright file="PageSlide.cs" company="Steven Kirk">
// Copyright 2015 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Animation
{
using Perspex.Media;
using Perspex.VisualTree;
using System;
using System.Collections.Generic;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
public class PageSlide : IPageTransition
{
public PageSlide(TimeSpan duration)
{
this.Duration = duration;
}
public TimeSpan Duration { get; }
public async Task Start(Visual from, Visual to, bool forward)
{
var tasks = new List<Task>();
var parent = GetVisualParent(from, to);
var distance = parent.Bounds.Width;
if (from != null)
{
var transform = new TranslateTransform();
from.RenderTransform = transform;
tasks.Add(Animate.Property(
transform,
TranslateTransform.XProperty,
0,
forward ? -distance : distance,
LinearEasing.For<double>(),
this.Duration).ToTask());
}
if (to != null)
{
var transform = new TranslateTransform();
to.RenderTransform = transform;
tasks.Add(Animate.Property(
transform,
TranslateTransform.XProperty,
forward ? distance : -distance,
0,
LinearEasing.For<double>(),
this.Duration).ToTask());
}
await Task.WhenAll(tasks.ToArray());
if (from != null)
{
from.IsVisible = false;
}
}
private static IVisual GetVisualParent(IVisual from, IVisual to)
{
var p1 = (from ?? to).VisualParent;
var p2 = (to ?? from).VisualParent;
if (p1 != null && p2 != null && p1 != p2)
{
throw new ArgumentException("Controls for PageSlide must have same parent.");
}
return p1;
}
}
}

49
Perspex.SceneGraph/Media/TranslateTransform.cs

@ -0,0 +1,49 @@
// -----------------------------------------------------------------------
// <copyright file="MatrixTransform.cs" company="Steven Kirk">
// Copyright 2013 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Media
{
using System;
public class TranslateTransform : Transform
{
public static readonly PerspexProperty<double> XProperty =
PerspexProperty.Register<TranslateTransform, double>("X");
public static readonly PerspexProperty<double> YProperty =
PerspexProperty.Register<TranslateTransform, double>("Y");
public TranslateTransform()
{
this.GetObservable(XProperty).Subscribe(_ => this.RaiseChanged());
this.GetObservable(YProperty).Subscribe(_ => this.RaiseChanged());
}
public TranslateTransform(double x, double y)
: this()
{
this.X = x;
this.Y = y;
}
public double X
{
get { return this.GetValue(XProperty); }
set { this.SetValue(XProperty, value); }
}
public double Y
{
get { return this.GetValue(YProperty); }
set { this.SetValue(YProperty, value); }
}
public override Matrix Value
{
get { return Matrix.Translation(this.X, this.Y); }
}
}
}

6
Perspex.SceneGraph/Perspex.SceneGraph.csproj

@ -45,8 +45,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Animation\CrossFadeTransition.cs" />
<Compile Include="Animation\IVisibilityTransition.cs" />
<Compile Include="Animation\PageSlide.cs" />
<Compile Include="Animation\CrossFade.cs" />
<Compile Include="Animation\IPageTransition.cs" />
<Compile Include="ILogical.cs" />
<Compile Include="Media\Brush.cs" />
<Compile Include="Media\Brushes.cs" />
@ -63,6 +64,7 @@
<Compile Include="Media\Imaging\Bitmap.cs" />
<Compile Include="Media\Imaging\IBitmap.cs" />
<Compile Include="Media\Imaging\RenderTargetBitmap.cs" />
<Compile Include="Media\TranslateTransform.cs" />
<Compile Include="Media\PathMarkupParser.cs" />
<Compile Include="Media\Pen.cs" />
<Compile Include="Media\EllipseGeometry.cs" />

18
TestApplication/Program.cs

@ -155,7 +155,7 @@ namespace TestApplication
LayoutTab(),
AnimationsTab(),
},
Transition = new CrossFadeTransition(TimeSpan.FromSeconds(0.25)),
Transition = new PageSlide(TimeSpan.FromSeconds(0.25)),
[Grid.ColumnSpanProperty] = 2,
},
(fps = new TextBlock
@ -178,14 +178,14 @@ namespace TestApplication
DevTools.Attach(window);
//var renderer = ((IRenderRoot)window).Renderer;
//var last = renderer.RenderCount;
//DispatcherTimer.Run(() =>
//{
// fps.Text = "FPS: " + (renderer.RenderCount - last);
// last = renderer.RenderCount;
// return true;
//}, TimeSpan.FromSeconds(1));
var renderer = ((IRenderRoot)window).Renderer;
var last = renderer.RenderCount;
DispatcherTimer.Run(() =>
{
fps.Text = "FPS: " + (renderer.RenderCount - last);
last = renderer.RenderCount;
return true;
}, TimeSpan.FromSeconds(1));
window.Show();
Application.Current.Run(window);

Loading…
Cancel
Save