Browse Source

Added simple animation.

pull/16/head
Steven Kirk 12 years ago
parent
commit
6d45c57dbb
  1. 1
      Perspex.Controls/Presenters/ScrollContentPresenter.cs
  2. 12
      Perspex.Controls/Window.cs
  3. 5
      Perspex.SceneGraph/IVisual.cs
  4. 4
      Perspex.SceneGraph/Media/ITransform.cs
  5. 4
      Perspex.SceneGraph/Media/MatrixTransform.cs
  6. 4
      Perspex.SceneGraph/Media/RotateTransform.cs
  7. 12
      Perspex.SceneGraph/Media/Transform.cs
  8. 39
      Perspex.SceneGraph/Visual.cs
  9. 43
      TestApplication/Program.cs
  10. 2
      Windows/Perspex.Direct2D1/Renderer.cs
  11. 2
      Windows/Perspex.Win32/WindowImpl.cs

1
Perspex.Controls/Presenters/ScrollContentPresenter.cs

@ -31,6 +31,7 @@ namespace Perspex.Controls.Presenters
static ScrollContentPresenter() static ScrollContentPresenter()
{ {
ClipToBoundsProperty.OverrideDefaultValue(typeof(ScrollContentPresenter), true);
Control.AffectsArrange(OffsetProperty); Control.AffectsArrange(OffsetProperty);
} }

12
Perspex.Controls/Window.cs

@ -164,7 +164,9 @@ namespace Perspex.Controls
private void HandleRenderNeeded() private void HandleRenderNeeded()
{ {
this.dispatcher.InvokeAsync(this.RenderVisualTree, DispatcherPriority.Render); this.dispatcher.InvokeAsync(
() => this.impl.Invalidate(new Rect(this.ClientSize)),
DispatcherPriority.Render);
} }
private void HandlePaint(Rect rect, IPlatformHandle handle) private void HandlePaint(Rect rect, IPlatformHandle handle)
@ -186,13 +188,5 @@ namespace Perspex.Controls
this.LayoutManager.ExecuteLayoutPass(); this.LayoutManager.ExecuteLayoutPass();
this.impl.Invalidate(new Rect(this.ClientSize)); this.impl.Invalidate(new Rect(this.ClientSize));
} }
private void RenderVisualTree()
{
if (!this.LayoutManager.LayoutQueued)
{
this.impl.Invalidate(new Rect(this.ClientSize));
}
}
} }
} }

5
Perspex.SceneGraph/IVisual.cs

@ -28,6 +28,11 @@ namespace Perspex
/// <returns></returns> /// <returns></returns>
Rect Bounds { get; } Rect Bounds { get; }
/// <summary>
/// Gets a value indicating whether the scene graph node should be clipped to its bounds.
/// </summary>
bool ClipToBounds { get; }
/// <summary> /// <summary>
/// Gets a value indicating whether this scene graph node is visible. /// Gets a value indicating whether this scene graph node is visible.
/// </summary> /// </summary>

4
Perspex.SceneGraph/Media/ITransform.cs

@ -6,8 +6,12 @@
namespace Perspex.Media namespace Perspex.Media
{ {
using System;
public interface ITransform public interface ITransform
{ {
event EventHandler Changed;
Matrix Value { get; } Matrix Value { get; }
} }
} }

4
Perspex.SceneGraph/Media/MatrixTransform.cs

@ -6,6 +6,8 @@
namespace Perspex.Media namespace Perspex.Media
{ {
using System;
public class MatrixTransform : Transform public class MatrixTransform : Transform
{ {
public static readonly PerspexProperty<Matrix> MatrixProperty = public static readonly PerspexProperty<Matrix> MatrixProperty =
@ -13,9 +15,11 @@ namespace Perspex.Media
public MatrixTransform() public MatrixTransform()
{ {
this.GetObservable(MatrixProperty).Subscribe(_ => this.RaiseChanged());
} }
public MatrixTransform(Matrix matrix) public MatrixTransform(Matrix matrix)
: this()
{ {
this.Matrix = matrix; this.Matrix = matrix;
} }

4
Perspex.SceneGraph/Media/RotateTransform.cs

@ -6,6 +6,8 @@
namespace Perspex.Media namespace Perspex.Media
{ {
using System;
public class RotateTransform : Transform public class RotateTransform : Transform
{ {
public static readonly PerspexProperty<double> AngleProperty = public static readonly PerspexProperty<double> AngleProperty =
@ -13,9 +15,11 @@ namespace Perspex.Media
public RotateTransform() public RotateTransform()
{ {
this.GetObservable(AngleProperty).Subscribe(_ => this.RaiseChanged());
} }
public RotateTransform(double angle) public RotateTransform(double angle)
: this()
{ {
this.Angle = angle; this.Angle = angle;
} }

12
Perspex.SceneGraph/Media/Transform.cs

@ -6,8 +6,20 @@
namespace Perspex.Media namespace Perspex.Media
{ {
using System;
public abstract class Transform : PerspexObject, ITransform public abstract class Transform : PerspexObject, ITransform
{ {
public event EventHandler Changed;
public abstract Matrix Value { get; } public abstract Matrix Value { get; }
protected void RaiseChanged()
{
if (this.Changed != null)
{
this.Changed(this, EventArgs.Empty);
}
}
} }
} }

39
Perspex.SceneGraph/Visual.cs

@ -10,12 +10,16 @@ namespace Perspex
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
using System.Reactive.Linq;
using Perspex.Media; using Perspex.Media;
using Perspex.Rendering; using Perspex.Rendering;
using Splat; using Splat;
public class Visual : PerspexObject, IVisual public class Visual : PerspexObject, IVisual
{ {
public static readonly PerspexProperty<bool> ClipToBoundsProperty =
PerspexProperty.Register<Visual, bool>("ClipToBounds");
public static readonly PerspexProperty<bool> IsVisibleProperty = public static readonly PerspexProperty<bool> IsVisibleProperty =
PerspexProperty.Register<Visual, bool>("IsVisible", true); PerspexProperty.Register<Visual, bool>("IsVisible", true);
@ -37,6 +41,7 @@ namespace Perspex
static Visual() static Visual()
{ {
AffectsRender(IsVisibleProperty); AffectsRender(IsVisibleProperty);
RenderTransformProperty.Changed.Subscribe(RenderTransformChanged);
} }
public Visual() public Visual()
@ -45,6 +50,12 @@ namespace Perspex
this.visualChildren.CollectionChanged += this.VisualChildrenChanged; this.visualChildren.CollectionChanged += this.VisualChildrenChanged;
} }
public bool ClipToBounds
{
get { return this.GetValue(ClipToBoundsProperty); }
set { this.SetValue(ClipToBoundsProperty, value); }
}
public bool IsVisible public bool IsVisible
{ {
get { return this.GetValue(IsVisibleProperty); } get { return this.GetValue(IsVisibleProperty); }
@ -197,6 +208,34 @@ namespace Perspex
return result; return result;
} }
private static void RenderTransformChanged(PerspexPropertyChangedEventArgs e)
{
var sender = e.Sender as Visual;
if (sender != null)
{
var oldValue = e.OldValue as ITransform;
var newValue = e.NewValue as ITransform;
if (oldValue != null)
{
oldValue.Changed -= sender.RenderTransformChanged;
}
if (newValue != null)
{
newValue.Changed += sender.RenderTransformChanged;
}
sender.InvalidateVisual();
}
}
private void RenderTransformChanged(object sender, EventArgs e)
{
this.InvalidateVisual();
}
private void SetVisualParent(Visual value) private void SetVisualParent(Visual value)
{ {
if (this.visualParent != value) if (this.visualParent != value)

43
TestApplication/Program.cs

@ -1,7 +1,9 @@
using System.Reactive.Linq; using System;
using System.Reactive.Linq;
using Perspex; using Perspex;
using Perspex.Controls; using Perspex.Controls;
using Perspex.Controls.Primitives; using Perspex.Controls.Primitives;
using Perspex.Controls.Shapes;
using Perspex.Diagnostics; using Perspex.Diagnostics;
using Perspex.Layout; using Perspex.Layout;
using Perspex.Media; using Perspex.Media;
@ -132,6 +134,7 @@ namespace TestApplication
ListsTab(), ListsTab(),
SlidersTab(), SlidersTab(),
LayoutTab(), LayoutTab(),
AnimationsTab(),
} }
}, },
new TextBlock new TextBlock
@ -430,5 +433,43 @@ namespace TestApplication
} }
}; };
} }
private static TabItem AnimationsTab()
{
Rectangle rect1;
var result = new TabItem
{
Header = "Animations",
Content = new Grid
{
ColumnDefinitions = new ColumnDefinitions
{
new ColumnDefinition(1, GridUnitType.Star),
},
Children = new Controls
{
(rect1 = new Rectangle
{
Width = 100,
Height = 100,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Fill = Brushes.Crimson,
RenderTransform = new RotateTransform(),
}),
},
},
};
Observable.Interval(TimeSpan.FromMilliseconds(10))
.Subscribe(x =>
{
((RotateTransform)rect1.RenderTransform).Angle = x;
});
return result;
}
} }
} }

2
Windows/Perspex.Direct2D1/Renderer.cs

@ -133,7 +133,7 @@ namespace Perspex.Direct2D1
transform *= Matrix.Translation(visual.Bounds.Position); transform *= Matrix.Translation(visual.Bounds.Position);
using (context.PushClip(visual.Bounds)) using (visual.ClipToBounds ? context.PushClip(visual.Bounds) : null)
using (context.PushTransform(transform)) using (context.PushTransform(transform))
{ {
visual.Render(context); visual.Render(context);

2
Windows/Perspex.Win32/WindowImpl.cs

@ -103,8 +103,6 @@ namespace Perspex.Win32
lpszClassName = this.className, lpszClassName = this.className,
}; };
System.Diagnostics.Debug.WriteLine("Registered class " + this.className);
ushort atom = UnmanagedMethods.RegisterClassEx(ref wndClassEx); ushort atom = UnmanagedMethods.RegisterClassEx(ref wndClassEx);
if (atom == 0) if (atom == 0)

Loading…
Cancel
Save