Author: toshok
Date: 2007-06-04 17:00:37 -0400 (Mon, 04 Jun 2007)
New Revision: 78596
Added:
trunk/moon/src/animation.cpp
trunk/moon/src/animation.h
Modified:
trunk/moon/src/ChangeLog
Log:
* animation.h, animation.cpp: initial pass at some of the
animation stuff. doesn't build yet.
2007-06-04 Chris Toshok <[EMAIL PROTECTED]>
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-04 20:51:49 UTC (rev 78595)
+++ trunk/moon/src/ChangeLog 2007-06-04 21:00:37 UTC (rev 78596)
@@ -1,5 +1,10 @@
2007-06-04 Chris Toshok <[EMAIL PROTECTED]>
+ * animation.h, animation.cpp: initial pass at some of the
+ animation stuff. doesn't build yet.
+
+2007-06-04 Chris Toshok <[EMAIL PROTECTED]>
+
* runtime.cpp, runtime.h: add EventObject, a c++ only base class
for managing events.
Added: trunk/moon/src/animation.cpp
===================================================================
--- trunk/moon/src/animation.cpp 2007-06-04 20:51:49 UTC (rev 78595)
+++ trunk/moon/src/animation.cpp 2007-06-04 21:00:37 UTC (rev 78596)
@@ -0,0 +1,284 @@
+#include <config.h>
+#include <string.h>
+#include <gtk/gtk.h>
+#include <malloc.h>
+#include <glib.h>
+#include <stdlib.h>
+
+//#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+//#endif
+
+#include "anim.h"
+
+/*
+ * Magic number to convert a time which is relative to
+ * Jan 1, 1970 into a value which is relative to Jan 1, 0001.
+ */
+#define EPOCH_ADJUST ((guint64)62135596800LL)
+
+static gint64
+get_now ()
+{
+ struct timeval tv;
+ gint64 res;
+
+ if (gettimeofday (&tv, NULL) == 0) {
+ res = (((gint64)tv.tv_sec + EPOCH_ADJUST)* 1000000 +
tv.tv_usec)*10;
+ return res;
+ }
+
+ // XXX error
+ return 0;
+}
+
+
+
+
+Clock::Clock (Timeline *tl)
+ : timeline (tl), parent_clock (NULL), child_clocks (NULL)
+{
+}
+
+Clock::Clock (Timeline *tl, Clock *clock)
+ : timeline (tl), parent_clock (clock), child_clocks (NULL)
+{
+ parent_clock->child_clocks = g_list_prepend (parent_clock->child_clocks,
clock);
+}
+
+void
+Clock::Begin ()
+{
+ if (parent_clock != NULL) {
+ /* XXX error */
+ return;
+ }
+
+ start_time = get_now();
+ tick_id = gtk_timeout_add (50 /* something suitably small */,
Clock::StaticTick, this);
+
+ for (GList *l = child_clocks; l; l = l->next) {
+ ((Clock*)l->data)->Begin();
+ }
+}
+
+gboolean
+Clock::StaticTick (gpointer data)
+{
+ ((Clock*)data)->Tick ();
+ return true;
+}
+
+void
+Clock::Tick ()
+{
+ for (GList *l = child_clocks; l; l = l->next) {
+ ((Clock*)l->data)->Tick();
+ }
+}
+
+void
+Clock::Pause ()
+{
+ if (parent_clock != NULL) {
+ /* XXX error */
+ return;
+ }
+
+ g_source_remove (tick_id);
+}
+
+void
+Clock::Remove ()
+{
+}
+
+void
+Clock::Resume ()
+{
+ if (parent_clock != NULL) {
+ /* XXX error */
+ return;
+ }
+
+ tick_id = gtk_timeout_add (50 /* something suitably small */,
Clock::StaticTick, this);
+}
+
+void
+Clock::Seek (/*Timespan*/gint64 timespan)
+{
+ if (parent_clock != NULL) {
+ /* XXX error */
+ return;
+ }
+
+}
+
+void
+Clock::SeekAlignedToLastTick ()
+{
+ if (parent_clock != NULL) {
+ /* XXX error */
+ return;
+ }
+
+}
+
+void
+Clock::SkipToFill ()
+{
+ if (parent_clock != NULL) {
+ /* XXX error */
+ return;
+ }
+
+}
+
+void
+Clock::Stop ()
+{
+ if (parent_clock != NULL) {
+ /* XXX error */
+ return;
+ }
+
+ g_source_remove (tick_id);
+}
+
+double
+Clock::GetCurrentProgress ()
+{
+ gint64/*TimeSpan*/ current_time = GetCurrentTime ();
+ gint64 duration = do_get_value (timeline, "Timeline.Duration");
+
+ return (double)current_time / duration;
+}
+
+gint64
+Clock::GetCurrentTime ()
+{
+ return get_now () - start_time;
+}
+
+
+
+
+/* timeline group */
+
+TimelineGroup::TimelineGroup ()
+ : child_timelines (NULL)
+{
+}
+
+void
+TimelineGroup::AddChild (Timeline *child)
+{
+ child_timelines = g_list_prepend (child_timelines, child);
+
+ if (child->clock)
+ delete child->clock;
+
+ child->clock = new Clock (child, this->clock);
+}
+
+void
+TimelineGroup::RemoveChild (Timeline *child)
+{
+ /* nada for now */
+}
+
+void
+timeline_group_add_child (TimelineGroup *group, Timeline *child)
+{
+ group->AddChild (child);
+}
+
+void
+timeline_group_remove_child (TimelineGroup *group, Timeline *child)
+{
+ group->RemoveChild (child);
+}
+
+
+/* storyboard */
+
+Storyboard::Storyboard ()
+{
+}
+
+void
+Storyboard::Begin ()
+{
+ clock->Begin ();
+}
+
+void
+Storyboard::Pause ()
+{
+ clock->Pause ();
+}
+
+void
+Storyboard::Resume ()
+{
+ clock->Resume ();
+}
+
+void
+Storyboard::Seek (/*Timespan*/gint64 timespan)
+{
+ clock->Seek (timespan);
+}
+
+void
+Storyboard::Stop ()
+{
+ clock->Stop ();
+}
+
+
+void
+storyboard_begin (Storyboard *sb)
+{
+ sb->Begin ();
+}
+
+void
+storyboard_pause (Storyboard *sb)
+{
+ sb->Pause ();
+}
+
+void
+storyboard_resume (Storyboard *sb)
+{
+ sb->Resume ();
+}
+
+void
+storyboard_seek (Storyboard *sb, /*Timespan*/gint64 timespan)
+{
+ sb->Seek (timespan);
+}
+
+void
+storyboard_stop (Storyboard *sb)
+{
+ sb->Stop ();
+}
+
+void
+storyboard_child_set_target_property (Storyboard *sb,
+ DependencyObject *o,
+ char *targetProperty)
+{
+ do_set_value (o, "Storyboard.targetProperty", targetProperty);
+}
+
+void
+storyboard_child_set_target_name (Storyboard *sb,
+ DependencyObject *o,
+ char *targetName)
+{
+ do_set_value (o, "Storyboard.targetName", targetName);
+}
Added: trunk/moon/src/animation.h
===================================================================
--- trunk/moon/src/animation.h 2007-06-04 20:51:49 UTC (rev 78595)
+++ trunk/moon/src/animation.h 2007-06-04 21:00:37 UTC (rev 78596)
@@ -0,0 +1,140 @@
+#include "runtime.h"
+
+G_BEGIN_DECLS
+
+class Timeline;
+class DependencyObject;
+
+/* this merges WPF's Clock and ClockController */
+class Clock {
+ public:
+ Clock (Timeline *timeline);
+ Clock (Timeline *timeline, Clock *clock);
+
+ void Begin ();
+ void Pause ();
+ void Remove ();
+ void Resume ();
+ void Seek (gint64/*TimeSpan*/ timespan);
+ void SeekAlignedToLastTick ();
+ void SkipToFill ();
+ void Stop ();
+
+ double GetCurrentProgress ();
+ gint64 GetCurrentTime ();
+
+ static long current_global_time;
+
+
+ Clock *parent_clock;
+ GList *child_clocks;
+
+ gint tick_id;
+ void Tick ();
+ static gboolean StaticTick (gpointer data);
+
+
+ Timeline *timeline;
+ gint64/*TimeSpan*/ start_time; /* the time we actually started. used for
computing CurrentTime */
+};
+
+class Timeline /*: public DependencyObject */ {
+ public:
+ Timeline () { }
+
+ /* we use these dependency properties:
+ bool AutoReverse
+ TimeSpan? BeginTime
+ Duration Duration
+ FillBehavior FillBehavior
+ RepeatBehavior RepeatBehavior
+ double SpeedRatio
+ */
+
+ Clock *clock;
+};
+
+class Animation : Timeline {
+};
+
+class TimelineGroup : public Timeline {
+ public:
+ TimelineGroup ();
+
+ /* we use these dependency properties:
+ Timeline Children - XXX shouldn't that be TimelineCollection?
+ */
+ void AddChild (Timeline *child);
+ void RemoveChild (Timeline *child);
+
+ GList *child_timelines;
+};
+
+void timeline_group_add_child (TimelineGroup *group, Timeline *child);
+void timeline_group_remove_child (TimelineGroup *group, Timeline *child);
+
+
+class ParallelTimeline : public TimelineGroup {
+ public:
+ ParallelTimeline () { }
+};
+
+
+class Storyboard : public ParallelTimeline {
+ public:
+ Storyboard ();
+
+ void Begin ();
+ void Pause ();
+ void Resume ();
+ void Seek (/*Timespan*/gint64 timespan);
+ void Stop ();
+
+ /* we use these attached properties for our children
+ string targetProperty
+ string targetName
+ */
+
+ // XXX event Completed
+
+ private:
+ gboolean Tick ();
+ static gboolean storyboard_tick (gpointer data);
+};
+
+void storyboard_begin (Storyboard *sb);
+void storyboard_pause (Storyboard *sb);
+void storyboard_resume (Storyboard *sb);
+void storyboard_seek (Storyboard *sb, /*Timespan*/gint64 timespan);
+void storyboard_stop (Storyboard *sb);
+
+void storyboard_child_set_target_property (Storyboard *sb,
+ DependencyObject *o,
+ char *targetProperty);
+
+void storyboard_child_set_target_name (Storyboard *sb,
+ DependencyObject *o,
+ char *targetName);
+
+class DoubleAnimation : public Animation {
+ public:
+
+ DoubleAnimation () { }
+
+ /* these are dependency properties:
+ double? By
+ double? From
+ double? To
+ */
+};
+
+void double_animation_set_by (DoubleAnimation *da, double by);
+double double_animation_get_by (DoubleAnimation *da);
+
+void double_animation_set_from (DoubleAnimation *da, double from);
+double double_animation_get_from (DoubleAnimation *da);
+
+void double_animation_set_to (DoubleAnimation *da, double to);
+double double_animation_get_to (DoubleAnimation *da);
+
+G_END_DECLS
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches