Author: alanmc
Date: 2007-07-31 16:31:02 -0400 (Tue, 31 Jul 2007)
New Revision: 83143
Modified:
trunk/lunareclipse/ChangeLog
trunk/lunareclipse/Controller/MoonlightController.cs
trunk/lunareclipse/Controls/TimeLine/AnimationTimeline.cs
trunk/lunareclipse/LunarEclipse.mdp
trunk/lunareclipse/Model/Draw/RecordDraw.cs
trunk/lunareclipse/View/MainWindow.cs
Log:
* Model/Draw/RecordDraw.cs, Controller/MoonlightController.cs,
Controls/TimeLine/AnimationTimeline.cs, LunarEclipse.mdp,
View/MainWindow.cs: Initial commit of the complete recordingdraw,
so you can record animations
Modified: trunk/lunareclipse/ChangeLog
===================================================================
--- trunk/lunareclipse/ChangeLog 2007-07-31 20:30:22 UTC (rev 83142)
+++ trunk/lunareclipse/ChangeLog 2007-07-31 20:31:02 UTC (rev 83143)
@@ -1,5 +1,12 @@
2007-07-31 Alan McGovern <[EMAIL PROTECTED]>
+ * Model/Draw/RecordDraw.cs, Controller/MoonlightController.cs,
+ Controls/TimeLine/AnimationTimeline.cs, LunarEclipse.mdp,
+ View/MainWindow.cs: Initial commit of the complete recordingdraw,
+ so you can record animations
+
+2007-07-31 Alan McGovern <[EMAIL PROTECTED]>
+
* Serialization/ReflectionHelper.cs: Quick hack to generate the
property path for XAML
Modified: trunk/lunareclipse/Controller/MoonlightController.cs
===================================================================
--- trunk/lunareclipse/Controller/MoonlightController.cs 2007-07-31
20:30:22 UTC (rev 83142)
+++ trunk/lunareclipse/Controller/MoonlightController.cs 2007-07-31
20:31:02 UTC (rev 83143)
@@ -26,6 +26,7 @@
private GtkSilver moonlight;
private DrawBase current;
private Serializer serializer;
+ private AnimationTimeline timeline;
internal Canvas Canvas
{
@@ -46,6 +47,11 @@
current.Prepare();
}
}
+
+ public AnimationTimeline Timeline
+ {
+ get { return timeline; }
+ }
public UndoEngine UndoEngine
{
@@ -60,10 +66,11 @@
undo.Undo();
}
- public MoonlightController(GtkSilver moonlight, IPropertyGroup
properties)
+ public MoonlightController(GtkSilver moonlight, AnimationTimeline
timeline, IPropertyGroup properties)
{
this.moonlight = moonlight;
this.properties = properties;
+ this.timeline = timeline;
moonlight.Canvas.MouseLeftButtonDown += new
MouseEventHandler(MouseLeftDown);
moonlight.Canvas.MouseMove += new MouseEventHandler(MouseMove);
moonlight.Canvas.MouseLeftButtonUp += new
MouseEventHandler(MouseLeftUp);
Modified: trunk/lunareclipse/Controls/TimeLine/AnimationTimeline.cs
===================================================================
--- trunk/lunareclipse/Controls/TimeLine/AnimationTimeline.cs 2007-07-31
20:30:22 UTC (rev 83142)
+++ trunk/lunareclipse/Controls/TimeLine/AnimationTimeline.cs 2007-07-31
20:31:02 UTC (rev 83143)
@@ -33,7 +33,12 @@
private List<IMarker> divisionMarkers;
private List<TextBlock> divisionTextblocks;
+ public TimeSpan CurrentPosition
+ {
+ get { return this.marker.Time; }
+ }
+
public AnimationTimeline(int width, int height)
:base (width, height)
{
Modified: trunk/lunareclipse/LunarEclipse.mdp
===================================================================
--- trunk/lunareclipse/LunarEclipse.mdp 2007-07-31 20:30:22 UTC (rev 83142)
+++ trunk/lunareclipse/LunarEclipse.mdp 2007-07-31 20:31:02 UTC (rev 83143)
@@ -16,7 +16,6 @@
<Contents>
<File name="./AssemblyInfo.cs" subtype="Code" buildaction="Compile" />
<File name="./Controller/MoonlightController.cs" subtype="Code"
buildaction="Compile" />
- <File name="./Controller/Recorder.cs" subtype="Code" buildaction="Compile"
/>
<File name="./Controller/Toolbox.cs" subtype="Code" buildaction="Compile"
/>
<File name="./Controller/UndoEngine.cs" subtype="Code"
buildaction="Compile" />
<File name="./Controller/UndoActions/UndoActionBase.cs" subtype="Code"
buildaction="Compile" />
@@ -70,6 +69,7 @@
<ProjectReference type="Gac" localcopy="False" refto="System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<ProjectReference type="Gac" localcopy="False" refto="System.Xml,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<ProjectReference type="Gac" localcopy="True" refto="agclr,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <ProjectReference type="Gac" localcopy="True" refto="gtk-sharp,
Version=2.8.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
</References>
<DeploymentInformation target="" script="" strategy="File">
<excludeFiles />
Modified: trunk/lunareclipse/Model/Draw/RecordDraw.cs
===================================================================
--- trunk/lunareclipse/Model/Draw/RecordDraw.cs 2007-07-31 20:30:22 UTC (rev
83142)
+++ trunk/lunareclipse/Model/Draw/RecordDraw.cs 2007-07-31 20:31:02 UTC (rev
83143)
@@ -8,46 +8,145 @@
using System.Windows.Media;
using System.Windows.Media.Animation;
using LunarEclipse.Controller;
+using System.Windows.Controls;
+using System.Windows;
namespace LunarEclipse.Model
{
public class RecordDraw : Selector
{
- private Storyboard storyBoard;
-
+ private bool prepared;
+ private static int nameCounter;
+ private Storyboard storyboard;
+
public RecordDraw(MoonlightController controller)
: base(controller)
{
- ChangedHeight += new
EventHandler<PropertyChangedEventArgs>(HeightChanged);
- ChangedLeft += new
EventHandler<PropertyChangedEventArgs>(LeftChanged);
- ChangedRotation += new
EventHandler<PropertyChangedEventArgs>(RotationChanged);
- ChangedTop += new
EventHandler<PropertyChangedEventArgs>(TopChanged);
- ChangedWidth += new
EventHandler<PropertyChangedEventArgs>(WidthChanged);
+ ChangedHeight += new
EventHandler<PropertyChangedEventArgs>(PropertyChanged);
+ ChangedLeft += new
EventHandler<PropertyChangedEventArgs>(PropertyChanged);
+ ChangedRotation += new
EventHandler<PropertyChangedEventArgs>(PropertyChanged);
+ ChangedTop += new
EventHandler<PropertyChangedEventArgs>(PropertyChanged);
+ ChangedWidth += new
EventHandler<PropertyChangedEventArgs>(PropertyChanged);
}
+ internal override void Prepare ()
+ {
+ base.Prepare();
+ if(!prepared)
+ {
+ prepared = true;
+ storyboard = new Storyboard();
+ storyboard.Completed += new
EventHandler(Completed);
+ Controller.Canvas.Resources.Add(storyboard);
+ }
+ }
- private void HeightChanged(object sender,
PropertyChangedEventArgs e)
+ public override bool CanUndo {
+ get { return false; }
+ }
+
+ internal override void Cleanup ()
{
-
+ base.Cleanup();
+ //Controller.Canvas.Resources.Remove(storyboard);
}
+
- private void LeftChanged(object sender,
PropertyChangedEventArgs e)
+ private void Completed(object sender, EventArgs e)
{
-
+ Console.WriteLine("**** Done ****");
}
+
+ public void Play()
+ {
+ PrintKeyframes();
+ Seek(TimeSpan.Zero);
+ storyboard.Begin();
+ }
- private void RotationChanged(object sender,
PropertyChangedEventArgs e)
+ // This just prints all the keyframes out for each of the
timelines so i
+ // can visually see them as the serializer isn't working 100%
for this
+ // scenario.
+ private void PrintKeyframes()
{
-
+ foreach(DoubleAnimationUsingKeyFrames line in
this.storyboard.Children)
+ {
+
Console.Write(line.GetValue(Storyboard.TargetPropertyProperty));
+ Console.Write('\t');
+
Console.Write(line.GetValue(Storyboard.TargetNameProperty));
+ Console.WriteLine();
+ foreach(LinearDoubleKeyFrame kf in
line.KeyFrames)
+ {
+ Console.Write(kf.KeyTime);
+ Console.Write('\t');
+ Console.Write(kf.Value);
+ Console.WriteLine();
+ }
+ }
}
- private void TopChanged(object sender, PropertyChangedEventArgs
e)
+ public void Seek(TimeSpan time)
{
+ storyboard.Seek(time);
+ }
+
+ public void Stop()
+ {
+ storyboard.Stop();
+ }
+
+ private void PropertyChanged(object sender,
PropertyChangedEventArgs e)
+ {
+ LinearDoubleKeyFrame keyframe = null;
+ // Make sure the 'name' of the shape isn't null. This
is a hack for the moment.
+ if(string.IsNullOrEmpty(e.Target.Name))
+
e.Target.SetValue<string>(DependencyObject.NameProperty,
(nameCounter++).ToString());
+
+ // Get a timeline: either an existing one or a new one
+ DoubleAnimationUsingKeyFrames timeline =
GetTimeline(e.Target, e.Property);
+
+ // For each of the keyframes, if any of them have
exactly the same time
+ // as the current time, we select that keyframe and
update it's value
+ foreach(LinearDoubleKeyFrame kf in timeline.KeyFrames)
+ if(kf.KeyTime ==
Controller.Timeline.CurrentPosition)
+ keyframe = kf;
+
+ // Otherwise we just create a new keyframe for this time
+ if(keyframe == null)
+ {
+ keyframe = new LinearDoubleKeyFrame();
+ keyframe.KeyTime =
Controller.Timeline.CurrentPosition;
+ timeline.KeyFrames.Add(keyframe);
+ }
+
+ // Update the keyframes value
+ keyframe.Value = (double)e.NewValue;
}
- private void WidthChanged(object sender,
PropertyChangedEventArgs e)
+ private DoubleAnimationUsingKeyFrames
GetTimeline(DependencyObject target, DependencyProperty property)
{
+ DoubleAnimationUsingKeyFrames animation;
+ // If there is already a timeline for this target item
+ // which is altering the same property, return that
timeline
+ foreach(Timeline t in storyboard.Children)
+ {
+
if(!target.Name.Equals(t.GetValue(Storyboard.TargetNameProperty)))
+ continue;
+
+ if(!ReflectionHelper.GetFullPath(target,
property).Equals(t.GetValue(Storyboard.TargetPropertyProperty)))
+ continue;
+
+ return (DoubleAnimationUsingKeyFrames)t;
+ }
+
+ // There was no pre-existing timeline, so create a new
one
+ animation = new DoubleAnimationUsingKeyFrames();
+ animation.BeginTime = TimeSpan.Zero;
+
animation.SetValue<object>(Storyboard.TargetNameProperty, target.Name);
+
animation.SetValue<object>(Storyboard.TargetPropertyProperty,
ReflectionHelper.GetFullPath(target, property));
+ storyboard.Children.Add(animation);
+ return animation;
}
}
}
Modified: trunk/lunareclipse/View/MainWindow.cs
===================================================================
--- trunk/lunareclipse/View/MainWindow.cs 2007-07-31 20:30:22 UTC (rev
83142)
+++ trunk/lunareclipse/View/MainWindow.cs 2007-07-31 20:31:02 UTC (rev
83143)
@@ -26,6 +26,8 @@
Button undo;
Button redo;
Notebook book;
+ AnimationTimeline timeline;
+ Box animationWidgets;
public MainWindow (): base (Gtk.WindowType.Toplevel)
{
@@ -38,18 +40,19 @@
GtkSilver moonlight = new GtkSilver(800, 600);
moonlight.Attach(c);
moonlight.Show ();
-
+ timeline = new AnimationTimeline(800, 70);
mainContainer = new HBox ();
Widget toolbox = InitialiseWidgets ();
toolbox.ShowAll ();
mainContainer.Add (toolbox);
+ animationWidgets = InitialiseAnimationWidgets();
+ mainContainer.Add(animationWidgets);
VBox vbox = new VBox();
vbox.PackStart(moonlight);
- vbox.PackEnd(new AnimationTimeline(800, 70));
+ vbox.PackEnd(timeline);
vbox.ShowAll();
mainContainer.Add (vbox);
-
Widget propertyPane = new Properties ();
propertyPane.Show ();
mainContainer.Add (propertyPane);
@@ -74,11 +77,46 @@
book.Show ();
Add (book);
- controller = new MoonlightController (moonlight, properties);
+ controller = new MoonlightController (moonlight, timeline,
properties);
HookEvents(true);
Show ();
}
+ private Box InitialiseAnimationWidgets()
+ {
+ Box box = new VBox();
+ Button b = new Button("Start");
+
+ b.Clicked += delegate (object sender, EventArgs e) {
+ Button button = (Button)sender;
+
+ if(button.Label == "Start")
+ {
+ this.controller.Current.Cleanup();
+ this.controller.Current.Prepare();
+ }
+ };
+ box.Add(b);
+
+ b = new Button("Play");
+ b.Clicked += delegate (object sender, EventArgs e) {
+ RecordDraw animation =
(RecordDraw)controller.Current;
+ if(b.Label == "Play")
+ {
+ Console.WriteLine("Playing");
+ animation.Seek(TimeSpan.Zero);
+ animation.Play();
+ }
+ else if(b.Label == "Stop");
+ {
+ animation.Stop();
+ }
+
+ b.Label = b.Label == "Play" ? "Stop" : "Play";
+ };
+ box.Add(b);
+ return box;
+ }
private void HookEvents(bool hook)
{
@@ -166,6 +204,13 @@
Console.WriteLine("Draw is: " +
controller.Current.GetType().Name);
};
widgets.Add(b);
+
+ b = new Button("Record");
+ b.Clicked += delegate {
+ controller.Current = new RecordDraw(controller);
+ this.animationWidgets.ShowAll();
+ };
+ widgets.Add(b);
undo = new Button("Undo");
undo.Sensitive = false;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches