Author: toshok
Date: 2007-06-09 14:34:50 -0400 (Sat, 09 Jun 2007)
New Revision: 79064

Modified:
   trunk/moon/src/ChangeLog
   trunk/moon/src/animation.cpp
   trunk/moon/src/animation.h
   trunk/moon/src/clock.cpp
   trunk/moon/src/clock.h
   trunk/moon/src/demo.cpp
   trunk/moon/src/runtime.cpp
   trunk/moon/src/value.h
Log:
2007-06-09  Chris Toshok  <[EMAIL PROTECTED]>

        * demo.cpp (main): add in another animation, this one using
        keyframes, that moves a square around in a square, while animating
        its background color the same way as the other rectangles.

        * value.h, runtime.cpp: add in the keyframe types.

        * runtime.cpp (DependencyObject::DependenceyObject): fix a
        valgrind error - we shouldn't be "free"ing Values, since they're
        "new"ed.  Add free_value and use that for the hash table value
        dtor, and delete them correctly.

        * animation.h, animation.cpp: add a lot of the keyframe animation
        stuff.  DoubleAnimationUsingKeyFrames + LinearDoubleKeyFrame is
        the only tested configuration, though.

        * clock.cpp (everywhere): guint64->TimeSpan fixing.
        (TimeUpdated): turns out that not only does the progress go from
        1.0 to 0.0 when reversed, but current_time actually goes backward
        as well.  this has the nice effect of actually simplifying this
        method substantially, since we can always compute progress as
        time/duration.

        * clock.h: typedef TimeSpan to gint64 (switching from guint64
        everywhere), and update the api to use this.



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-06-09 16:58:39 UTC (rev 79063)
+++ trunk/moon/src/ChangeLog    2007-06-09 18:34:50 UTC (rev 79064)
@@ -1,3 +1,30 @@
+2007-06-09  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * demo.cpp (main): add in another animation, this one using
+       keyframes, that moves a square around in a square, while animating
+       its background color the same way as the other rectangles.
+
+       * value.h, runtime.cpp: add in the keyframe types.
+
+       * runtime.cpp (DependencyObject::DependenceyObject): fix a
+       valgrind error - we shouldn't be "free"ing Values, since they're
+       "new"ed.  Add free_value and use that for the hash table value
+       dtor, and delete them correctly.
+
+       * animation.h, animation.cpp: add a lot of the keyframe animation
+       stuff.  DoubleAnimationUsingKeyFrames + LinearDoubleKeyFrame is
+       the only tested configuration, though.
+
+       * clock.cpp (everywhere): guint64->TimeSpan fixing.
+       (TimeUpdated): turns out that not only does the progress go from
+       1.0 to 0.0 when reversed, but current_time actually goes backward
+       as well.  this has the nice effect of actually simplifying this
+       method substantially, since we can always compute progress as
+       time/duration.
+
+       * clock.h: typedef TimeSpan to gint64 (switching from guint64
+       everywhere), and update the api to use this.
+
 2007-06-09  Miguel de Icaza  <[EMAIL PROTECTED]>
 
        * runtime.h (value_color_from_argb): Temporary hack until we

Modified: trunk/moon/src/animation.cpp
===================================================================
--- trunk/moon/src/animation.cpp        2007-06-09 16:58:39 UTC (rev 79063)
+++ trunk/moon/src/animation.cpp        2007-06-09 18:34:50 UTC (rev 79064)
@@ -22,7 +22,7 @@
 {
        clock->events->AddHandler ("CurrentTimeInvalidated", 
update_property_value, this);
 
-       baseValue = targetobj->GetValue (targetprop);
+       baseValue = new Value(*targetobj->GetValue (targetprop));
 }
 
 void
@@ -157,7 +157,7 @@
 }
 
 void
-Storyboard::Seek (/*Timespan*/guint64 timespan)
+Storyboard::Seek (TimeSpan timespan)
 {
        root_clock->Seek (timespan);
 }
@@ -267,8 +267,7 @@
 
        double progress = animationClock->GetCurrentProgress ();
 
-       Value *v = new Value (LERP (start, end, progress));
-       // printf ("Sending %g from=%g to=%g progresss=%g\n", v->u.d, *from, 
*to, progress);
+       Value *v = new Value (LERP (start, end, progress)); // XXX we leak this
        return v;
 }
 
@@ -312,9 +311,7 @@
 
        double progress = animationClock->GetCurrentProgress ();
 
-       Value *v = new Value (LERP (start, end, progress));
-
-       // printf ("Sending %g from=%g to=%g progresss=%g\n", v->u.d, from, to, 
progress);
+       Value *v = new Value (LERP (start, end, progress)); // XXX we leak this
        return v;
 }
 
@@ -394,8 +391,7 @@
 
        double progress = animationClock->GetCurrentProgress ();
 
-       Value *v = new Value (LERP (start, end, progress));
-
+       Value *v = new Value (LERP (start, end, progress)); // XXX we leak this
        return v;
 }
 
@@ -427,12 +423,146 @@
 }
 
 
+DependencyProperty* DoubleKeyFrame::ValueProperty;
+
+DoubleKeyFrame::DoubleKeyFrame ()
+{
+}
+
+
 DependencyProperty* PointKeyFrame::ValueProperty;
 
 PointKeyFrame::PointKeyFrame ()
 {
 }
 
+
+Value*
+LinearDoubleKeyFrame::InterpolateValue (Value *baseValue, double 
keyFrameProgress)
+{
+       double *to = GetValue();
+       /* XXX GetValue can return NULL */
+
+       double start, end;
+
+       start = baseValue->AsDouble();
+       end = *to;
+
+       Value *v = new Value (LERP (start, end, keyFrameProgress));
+
+       return v;
+}
+
+LinearDoubleKeyFrame*
+linear_double_key_frame_new ()
+{
+       return new LinearDoubleKeyFrame ();
+}
+
+
+Value*
+LinearPointKeyFrame::InterpolateValue (Value *baseValue, double 
keyFrameProgress)
+{
+       Point *to = GetValue();
+       /* XXX GetValue can return NULL */
+
+       Point start, end;
+
+       start = *baseValue->AsPoint();
+       end = *to;
+
+       Value *v = new Value (LERP (start, end, keyFrameProgress));
+
+       return v;
+}
+
+LinearPointKeyFrame*
+linear_point_key_frame_new ()
+{
+       return new LinearPointKeyFrame ();
+}
+
+
+
+
+
+DoubleAnimationUsingKeyFrames::DoubleAnimationUsingKeyFrames()
+{
+       key_frames = NULL;
+}
+
+void
+DoubleAnimationUsingKeyFrames::AddKeyFrame (DoubleKeyFrame *frame)
+{
+       key_frames = g_list_append (key_frames, frame);
+}
+
+void
+DoubleAnimationUsingKeyFrames::RemoveKeyFrame (DoubleKeyFrame *frame)
+{
+}
+
+Value*
+DoubleAnimationUsingKeyFrames::GetCurrentValue (Value *defaultOriginValue, 
Value *defaultDestinationValue,
+                                              AnimationClock* animationClock)
+{
+
+       /* current segment info */
+       TimeSpan current_time = animationClock->GetCurrentTime();
+       DoubleKeyFrame *current_keyframe;
+       DoubleKeyFrame *previous_keyframe = NULL;
+       Value *baseValue;
+
+       TimeSpan key_end_time;
+
+       /* figure out what segment to use (this list needs to be sorted) */
+       for (GList *l = key_frames; l; l = l->next) {
+               DoubleKeyFrame *keyframe = (DoubleKeyFrame*)l->data;
+
+               key_end_time = keyframe->GetKeyTime()->GetTimeSpan();
+
+               if (key_end_time >= current_time) {
+                       current_keyframe = keyframe;
+
+                       if (l->prev)
+                               previous_keyframe = 
(DoubleKeyFrame*)l->prev->data;
+
+                       break;
+               }
+
+       }
+
+       TimeSpan key_start_time;
+
+       if (previous_keyframe == NULL) {
+               /* the first keyframe, start at the animation's base value */
+               baseValue = defaultOriginValue;
+               key_start_time = 0;
+       }
+       else {
+               /* start at the previous keyframe's target value */
+               baseValue = new Value(*previous_keyframe->GetValue ());
+               /* XXX DoubleKeyFrame::Value is nullable */
+               key_start_time = previous_keyframe->GetKeyTime()->GetTimeSpan 
();
+       }
+
+       TimeSpan key_duration = key_end_time - key_start_time;
+       double progress = (double)(current_time - key_start_time) / 
key_duration;
+
+       /* get the current value out of that segment */
+       
+       return current_keyframe->InterpolateValue (baseValue, progress);
+}
+
+DoubleAnimationUsingKeyFrames*
+double_animation_using_key_frames_new ()
+{
+       return new DoubleAnimationUsingKeyFrames ();
+}
+
+
+
+
 PointAnimationUsingKeyFrames::PointAnimationUsingKeyFrames()
 {
        key_frames = NULL;
@@ -453,11 +583,12 @@
 PointAnimationUsingKeyFrames::GetCurrentValue (Value *defaultOriginValue, 
Value *defaultDestinationValue,
                                               AnimationClock* animationClock)
 {
+  return NULL;
 #if false
        /* current segment info */
-       PointKeyFrame *current_target;
+       PointKeyFrame *current_keyframe;
        Value *start;
-       guint64/*TimeSpan*/ start_time;
+       TimeSpan segment_start_time;
 
        /* figure out what segment to use (this list needs to be sorted) */
        for (GList *l = key_frames; l; l = l->next) {
@@ -466,15 +597,19 @@
                if (true/*keyframe is the right one*/) {
                        GList *prev = l->prev;
 
-                       current_target = keyframe;
+                       current_keyframe = keyframe;
                        if (prev == NULL) {
                                /* the first keyframe, start at the animation's 
base value */
                                start = defaultOriginValue;
+                               segment_start_time = 0;
                        }
                        else {
+                               PointKeyFrame *prev_frame = 
(PointKeyFrame*)l->data;
+
                                /* start at the previous keyframe's target 
value */
-                               start = keyframe->GetValue ();
+                               start = new Value(*prev_frame->GetValue ()); // 
XXX we leak this
                                /* XXX PointKeyFrame::Value is nullable */
+                               segment_start_time = 
prev_frame->GetKeyTime()->GetTimeSpan ();
                        }
 
                        break;
@@ -483,14 +618,13 @@
 
        /* get the current value out of that segment */
 
-       return current_target->GetCurrentValue (start, NULL, /* XXX */
-                                               animationClock)
+       return current_keyframe->GetCurrentValue (start, NULL, /* XXX */
+                                                 segment_start_time,
+                                                 animationClock);
 #endif
-         return NULL;
 }
 
 
-
 PointAnimationUsingKeyFrames*
 point_animation_using_key_frames_new ()
 {
@@ -499,6 +633,8 @@
 
 
 
+
+
 RepeatBehavior RepeatBehavior::Forever (RepeatBehavior::FOREVER);
 Duration Duration::Automatic (Duration::AUTOMATIC);
 Duration Duration::Forever (Duration::FOREVER);
@@ -510,7 +646,7 @@
 {
        /* Timeline properties */
        Timeline::AutoReverseProperty = DependencyObject::Register 
(Value::TIMELINE, "AutoReverse", new Value (false));
-       Timeline::BeginTimeProperty = DependencyObject::Register 
(Value::TIMELINE, "BeginTime", new Value ((guint64)0));
+       Timeline::BeginTimeProperty = DependencyObject::Register 
(Value::TIMELINE, "BeginTime", new Value ((TimeSpan)0));
        Timeline::DurationProperty = DependencyObject::Register 
(Value::TIMELINE, "Duration", new Value (Duration::Automatic));
        Timeline::RepeatBehaviorProperty = DependencyObject::Register 
(Value::TIMELINE, "RepeatBehavior", new Value (RepeatBehavior ((double)1)));
        //DependencyObject::Register (DependencyObject::TIMELINE, 
"FillBehavior", new Value (0));
@@ -544,6 +680,7 @@
 
        /* KeyFrame properties */
        KeyFrame::KeyTimeProperty = DependencyObject::Register 
(Value::KEYFRAME, "KeyTime", new Value(KeyTime::Uniform));
+       DoubleKeyFrame::ValueProperty = DependencyObject::Register 
(Value::DOUBLEKEYFRAME, "Value", Value::DOUBLE);
        PointKeyFrame::ValueProperty = DependencyObject::Register 
(Value::POINTKEYFRAME, "Value", Value::POINT);
 
        /* KeyFrame animation properties */
@@ -567,3 +704,7 @@
 NULLABLE_GETSET_IMPL (PointAnimation, By, Point, Point)
 NULLABLE_GETSET_IMPL (PointAnimation, To, Point, Point)
 NULLABLE_GETSET_IMPL (PointAnimation, From, Point, Point)
+
+
+NULLABLE_GETSET_IMPL (PointKeyFrame, Value, Point, Point)
+NULLABLE_PRIM_GETSET_IMPL (DoubleKeyFrame, Value, double, Double)

Modified: trunk/moon/src/animation.h
===================================================================
--- trunk/moon/src/animation.h  2007-06-09 16:58:39 UTC (rev 79063)
+++ trunk/moon/src/animation.h  2007-06-09 18:34:50 UTC (rev 79064)
@@ -27,15 +27,15 @@
          : k (PERCENT),
             percent (percent) { }
 
-       KeyTime (guint64/*TimeSpan*/ timeSpan)
+       KeyTime (TimeSpan timeSpan)
          : k (TIMESPAN),
-            timespan (timespan) { }
+            timespan (timeSpan) { }
 
 
        KeyTime (KeyTimeType kind) : k(kind) { }
 
        static KeyTime FromPercent (double percent) { return KeyTime (percent); 
}
-       static KeyTime FromTimeSpan (guint64/*TimeSpan*/ timeSpan) { return 
KeyTime (timeSpan); }
+       static KeyTime FromTimeSpan (TimeSpan timeSpan) { return KeyTime 
(timeSpan); }
 
        static KeyTime Paced;
        static KeyTime Uniform;
@@ -58,12 +58,12 @@
        }
 
        double GetPercent () { return percent; }
-       guint64/*TimeSpan*/ GetTimeSpan () { return timespan; }
+       TimeSpan GetTimeSpan () { return timespan; }
 
   private:
        KeyTimeType k;
        double percent;
-       guint64/*TimeSpan*/ timespan;
+       TimeSpan timespan;
 };
 
 
@@ -146,12 +146,12 @@
 #define NULLABLE_GETSET_IMPL(klass,prop,t,T) \
 void klass::Set##prop (t v) { Set##prop (&v); } \
 void klass::Set##prop (t *pv) { SetNullable##t##Prop (this, 
klass::prop##Property, pv); } \
-t* klass::Get##prop () { Value* v = GetValue (klass::prop##Property);  return 
v ? v->As##T () : NULL; }
+t* klass::Get##prop () { Value* v = this->DependencyObject::GetValue 
(klass::prop##Property);  return v ? v->As##T () : NULL; }
 
 #define NULLABLE_PRIM_GETSET_IMPL(klass,prop,t,T) \
 void klass::Set##prop (t v) { Set##prop (&v); } \
 void klass::Set##prop (t *pv) { SetNullable##t##Prop (this, 
klass::prop##Property, pv); } \
-t* klass::Get##prop () { Value* v = GetValue (klass::prop##Property);  return 
v ? v->AsNullable##T () : NULL; }
+t* klass::Get##prop () { Value* v = this->DependencyObject::GetValue 
(klass::prop##Property);  return v ? v->AsNullable##T () : NULL; }
 
 
 class DoubleAnimation : public Animation/*Timeline*/ {
@@ -226,7 +226,7 @@
 
 
 
-class KeyFrame /* abstract in C# */ : public DependencyObject {
+class KeyFrame : public DependencyObject {
  public:
        KeyFrame ();
        Value::Kind GetObjectType () { return Value::POINTKEYFRAME; };
@@ -235,23 +235,76 @@
        void SetKeyTime (KeyTime keytime);
 
        static DependencyProperty *KeyTimeProperty;
+
+       virtual Value *InterpolateValue (Value *baseValue, double 
keyFrameProgress) = 0;
 };
 
 
 
 
-class PointKeyFrame /* abstract in C# */ : public KeyFrame {
+class DoubleKeyFrame : public KeyFrame {
  public:
+       DoubleKeyFrame ();
+       Value::Kind GetObjectType() { return Value::DOUBLEKEYFRAME; };
+       NULLABLE_GETSET_DECL (Value, double);
+
+       static DependencyProperty *ValueProperty;
+};
+
+
+class PointKeyFrame : public KeyFrame {
+ public:
        PointKeyFrame ();
        Value::Kind GetObjectType () { return Value::POINTKEYFRAME; };
 
+       NULLABLE_GETSET_DECL(Value, Point);
+
        static DependencyProperty *ValueProperty;
 };
 
 
+class LinearDoubleKeyFrame : public DoubleKeyFrame {
+ public:
+       LinearDoubleKeyFrame () { }
+       Value::Kind GetObjectType () { return Value::LINEARDOUBLEKEYFRAME; };
 
-class PointAnimationUsingKeyFrames : PointAnimation {
+       virtual Value *InterpolateValue (Value *baseValue, double 
keyFrameProgress);
+};
+
+LinearDoubleKeyFrame* linear_double_key_frame_new ();
+
+class LinearPointKeyFrame : public PointKeyFrame {
  public:
+       LinearPointKeyFrame () { }
+       Value::Kind GetObjectType () { return Value::LINEARPOINTKEYFRAME; };
+
+       virtual Value *InterpolateValue (Value *baseValue, double 
keyFrameProgress);
+};
+
+LinearPointKeyFrame* linear_point_key_frame_new ();
+
+
+class DoubleAnimationUsingKeyFrames : public DoubleAnimation {
+ public:
+       DoubleAnimationUsingKeyFrames ();
+       Value::Kind GetObjectType () { return 
Value::DOUBLEANIMATIONUSINGKEYFRAMES; };
+
+       void AddKeyFrame (DoubleKeyFrame *frame);
+       void RemoveKeyFrame (DoubleKeyFrame *frame);
+
+       static DependencyProperty *KeyFramesProperty;
+
+       virtual Value *GetCurrentValue (Value *defaultOriginValue, Value 
*defaultDestinationValue,
+                                       AnimationClock* animationClock);
+
+ private:
+       GList *key_frames;
+};
+
+DoubleAnimationUsingKeyFrames* double_animation_using_key_frames_new ();
+
+class PointAnimationUsingKeyFrames : public PointAnimation {
+ public:
        PointAnimationUsingKeyFrames ();
        Value::Kind GetObjectType () { return 
Value::POINTANIMATIONUSINGKEYFRAMES; };
 
@@ -277,7 +330,7 @@
        void Begin ();
        void Pause ();
        void Resume ();
-       void Seek (/*Timespan*/guint64 timespan);
+       void Seek (TimeSpan timespan);
        void Stop ();
 
        static DependencyProperty* TargetNameProperty;

Modified: trunk/moon/src/clock.cpp
===================================================================
--- trunk/moon/src/clock.cpp    2007-06-09 16:58:39 UTC (rev 79063)
+++ trunk/moon/src/clock.cpp    2007-06-09 18:34:50 UTC (rev 79064)
@@ -13,14 +13,14 @@
 
 
 
-static guint64
+static TimeSpan
 get_now ()
 {
         struct timeval tv;
-        guint64 res;
+        TimeSpan res;
 
         if (gettimeofday (&tv, NULL) == 0) {
-                res = (guint64)tv.tv_sec * 1000000 + tv.tv_usec;
+                res = (TimeSpan)tv.tv_sec * 1000000 + tv.tv_usec;
                 return res;
         }
 
@@ -109,83 +109,79 @@
 
        autoreverse = timeline->GetAutoReverse ();
        duration = timeline->GetDuration();
-       completed_iterations = 0.0;
        current_progress = 0.0;
        current_time = 0;
        reversed = false;
        start_time = 0;
+       iter_start = 0;
 }
 
 void
-Clock::TimeUpdated (guint64 parent_clock_time)
+Clock::TimeUpdated (TimeSpan parent_clock_time)
 {
        if ((current_state & (STOPPED | PAUSED)) != 0)
                return;
 
-       current_time = parent_clock_time - start_time;
-       QueueEvent (CURRENT_TIME_INVALIDATED);
-
        if (*duration == Duration::Automatic  /* useful only on clock groups, 
means the clock stops when all child clocks have stopped. */
            || *duration == Duration::Forever /* for Forever duration 
timelines, progress is always 0.0 */) {
                current_progress = 0.0;
        }
        else {
                // we've got a timespan, so our progress will have changed
-               guint64 duration_timespan = duration->GetTimeSpan();
+               TimeSpan duration_timespan = duration->GetTimeSpan();
 
-               double new_progress;
+               current_time = parent_clock_time - iter_start;
+               if (reversed)
+                       current_time = duration_timespan - (current_time - 
duration_timespan);
 
-               new_progress = (double)(current_time - start_time - 
completed_iterations * (autoreverse ? 2 : 1) * duration_timespan) / 
duration_timespan;
+               if (current_time >= duration_timespan) {
+                       // we've hit the end point of the clock's timeline
+                       if (autoreverse) {
+                               /* since autoreverse is true we need
+                                  to turn around and head back to
+                                  0.0 */
+                               reversed = true;
+                               current_time = duration_timespan - 
(current_time - duration_timespan);
+                       }
+                       else {
+                               /* but autoreverse is false. Decrement
+                                  the number of remaining iterations.
 
-               if (new_progress >= 1.0) {
-                       if (reversed) {
-                               reversed = false;
-
-                               /* we were heading from 1.0 to 0.0 and
-                                  passed it.  decrement our
-                                  remaining-iteration count (if we have
-                                  one) */
-                               completed_iterations += 0.5;
-
-                               current_progress = new_progress - 1.0;
-                               guint64 diff = current_time - start_time;
-//                             printf ("current_time=%llu start_time=%llu 
diff=%llu\n", current_time, start_time, diff);
-//                             printf ("completed_iter=%g autoreverse=%d 
duration=%llu\n", completed_iterations, autoreverse, duration_timespan);
-//                             printf ("Assigning=%g\n", current_progress);
-
+                                  If we're done, Stop().  If we're
+                                  not done, force current_time to 0
+                                  so we start counting from there
+                                  again. */
                                if (remaining_iterations > 0)
                                        remaining_iterations --;
 
                                if (remaining_iterations == 0) {
-                                       current_progress = 0.0;
+                                       current_time = duration_timespan;
                                        Stop ();
                                }
-                       }
-                       else {
-                               if (autoreverse) {
-                                       reversed = true;
-                                       completed_iterations += 0.5;
-                                       current_progress = 1.0 - (new_progress 
- 1.0);
-                               }
                                else {
+                                       current_time -= duration_timespan;
+                                       iter_start = parent_clock_time - 
current_time;
+                               }
+                       }
+               }
+               else if (current_time <= 0) {
+                       reversed = false;
+                       current_time = -current_time;
 
-                                       completed_iterations += 1.0;
+                       if (remaining_iterations > 0)
+                               remaining_iterations --;
 
-                                       current_progress = new_progress - 1.0;
-
-                                       if (remaining_iterations > 0)
-                                               remaining_iterations --;
-
-                                       if (remaining_iterations == 0) {
-                                               current_progress = 1.0;
-                                               Stop ();
-                                       }
-                               }
+                       if (remaining_iterations == 0) {
+                               current_time = 0;
+                               Stop ();
                        }
+                       else {
+                               iter_start = parent_clock_time - current_time;
+                       }
                }
-               else {
-                       current_progress = reversed ? 1.0 - new_progress : 
new_progress;
-               }
+
+               current_progress = (double)current_time / duration_timespan;
+               QueueEvent (CURRENT_TIME_INVALIDATED);
        }
 }
 
@@ -211,7 +207,7 @@
        queued_events |= event;
 }
 
-guint64
+TimeSpan
 Clock::GetCurrentTime ()
 {
        return current_time;
@@ -224,10 +220,11 @@
 }
 
 void
-Clock::Begin (guint64 start_time)
+Clock::Begin (TimeSpan start_time)
 {
-       printf ("Starting %llu\n", start_time);
+       printf ("Starting %lld\n", start_time);
        this->start_time = start_time;
+       this->iter_start = start_time;
        current_state = RUNNING; /* should we invalidate the state here? */
        QueueEvent (CURRENT_STATE_INVALIDATED);
 }
@@ -250,7 +247,7 @@
 }
 
 void
-Clock::Seek (/*Timespan*/guint64 timespan)
+Clock::Seek (TimeSpan timespan)
 {
 }
 
@@ -293,7 +290,7 @@
 }
 
 void
-ClockGroup::Begin (guint64 start_time)
+ClockGroup::Begin (TimeSpan start_time)
 {
        this->Clock::Begin (start_time);
 
@@ -303,7 +300,7 @@
 }
 
 void
-ClockGroup::TimeUpdated (guint64 parent_clock_time)
+ClockGroup::TimeUpdated (TimeSpan parent_clock_time)
 {
        /* recompute our current_time */
        this->Clock::TimeUpdated (parent_clock_time);

Modified: trunk/moon/src/clock.h
===================================================================
--- trunk/moon/src/clock.h      2007-06-09 16:58:39 UTC (rev 79063)
+++ trunk/moon/src/clock.h      2007-06-09 18:34:50 UTC (rev 79064)
@@ -6,6 +6,8 @@
 G_BEGIN_DECLS
 
 // misc types
+typedef gint64 TimeSpan;
+
 struct Duration {
  public:
        enum DurationKind {
@@ -14,7 +16,7 @@
                FOREVER
        };
 
-       Duration (guint64/*TimeSpan*/ duration)
+       Duration (TimeSpan duration)
          : k (TIMESPAN),
            timespan (duration) { }
 
@@ -27,7 +29,7 @@
        Duration (DurationKind kind) : k(kind) { };
 
        bool HasTimeSpan () { return k == TIMESPAN; }
-       guint64/*TimeSpan*/ GetTimeSpan() { return timespan; }
+       TimeSpan GetTimeSpan() { return timespan; }
 
        static Duration Automatic;
        static Duration Forever;
@@ -51,11 +53,11 @@
 
 
        // This should live in a TimeSpan class, but oh well.. */
-       static Duration FromSeconds (int seconds) { return (guint64)seconds * 
1000000; }
+       static Duration FromSeconds (int seconds) { return Duration 
((TimeSpan)seconds * 1000000); }
 
        DurationKind k;
  private:
-       guint64/*TimeSpan*/ timespan;
+       TimeSpan timespan;
 };
 
 
@@ -83,7 +85,7 @@
 
        RepeatBehavior (RepeatKind kind) : k(kind) { }
 
-       RepeatBehavior (guint64/*TimeSpan*/ duration)
+       RepeatBehavior (TimeSpan duration)
          : k (DURATION),
            duration (duration)
        {
@@ -109,7 +111,7 @@
        }
 
        double GetCount () { return count; }
-       guint64/*TimeSpan*/ GetDuration() { return duration; }
+       TimeSpan GetDuration() { return duration; }
 
        bool HasCount() { return k == COUNT; }
        bool HasDuration () { return k == DURATION; }
@@ -117,7 +119,7 @@
        RepeatKind k;
   private:
        double count;
-       guint64/*TimeSpan*/ duration;
+       TimeSpan duration;
 };
 
 // our root level time manager (basically the object that registers
@@ -136,7 +138,7 @@
                return _instance;
        }
 
-       static guint64 GetCurrentGlobalTime () { return 
Instance()->current_global_time; }
+       static TimeSpan GetCurrentGlobalTime () { return 
Instance()->current_global_time; }
 
        void AddChild (Clock *clock);
        void RemoveChild (Clock *clock);
@@ -150,7 +152,7 @@
 
        GList *child_clocks; // XXX should we just have a ClockGroup?
 
-       guint64 current_global_time;
+       TimeSpan current_global_time;
        static gboolean tick_timeout (gpointer data);
        gint tick_id;
 };
@@ -191,26 +193,27 @@
 
        virtual void SpeedChanged () { };
 
-       virtual void Begin (guint64 parent_time);
+       virtual void Begin (TimeSpan parent_time);
        void Pause ();
        void Remove ();
        void Resume ();
-       void Seek (guint64/*TimeSpan*/ timespan);
+       void Seek (TimeSpan timespan);
        void SeekAlignedToLastTick ();
        void SkipToFill ();
        void Stop ();
 
        double GetCurrentProgress ();
-       guint64 GetCurrentTime ();
+       TimeSpan GetCurrentTime ();
        Timeline *GetTimeline () { return timeline; }
 
        virtual void RaiseAccumulatedEvents ();
-       virtual void TimeUpdated (guint64 parent_time);
+       virtual void TimeUpdated (TimeSpan parent_time);
 
  protected:
        double current_progress;
-       guint64/*TimeSpan*/ current_time;
-       guint64/*TimeSpan*/ start_time; /* the time we actually started.  used 
for computing CurrentTime */
+       TimeSpan current_time;
+       TimeSpan start_time; /* the time we actually started.  used for 
computing CurrentTime */
+       TimeSpan iter_start; /* the time we started the current iteration */
 
        void QueueEvent (int event);
 
@@ -221,7 +224,6 @@
        bool reversed;  // if we're presently working our way from 1.0 progress 
to 0.0
        bool autoreverse;
        int remaining_iterations;
-       double completed_iterations;
        Duration *duration;
 
        ClockState current_state;
@@ -236,13 +238,13 @@
        ClockGroup (TimelineGroup *timeline);
        Value::Kind GetObjectType () { return Value::CLOCKGROUP; };
 
-       virtual void Begin (guint64 parent_time);
+       virtual void Begin (TimeSpan parent_time);
 
        void AddChild (Clock *clock);
        void RemoveChild (Clock *clock);
 
        virtual void RaiseAccumulatedEvents ();
-       virtual void TimeUpdated (guint64 parent_time);
+       virtual void TimeUpdated (TimeSpan parent_time);
 
        GList *child_clocks;
 

Modified: trunk/moon/src/demo.cpp
===================================================================
--- trunk/moon/src/demo.cpp     2007-06-09 16:58:39 UTC (rev 79063)
+++ trunk/moon/src/demo.cpp     2007-06-09 18:34:50 UTC (rev 79064)
@@ -14,11 +14,11 @@
 
 static UIElement *v;
 static Rectangle *r;
+static Rectangle *square;
 
 static RotateTransform *r_trans;
 static RotateTransform *v_trans;
 static ScaleTransform *s_trans;
-static TranslateTransform *t_trans;
 
 extern NameScope *global_NameScope;
 
@@ -126,8 +126,7 @@
                r_trans = new RotateTransform ();
                v_trans = new RotateTransform ();
                s_trans = new ScaleTransform ();
-               t_trans = new TranslateTransform ();
-               
+
                r = rectangle_new ();
                framework_element_set_width (r, 50.0);
                framework_element_set_height (r, 50.0);
@@ -181,8 +180,11 @@
                panel_child_add (canvas, v2);
 #endif
 
+
                Storyboard *sb = new Storyboard ();
 
+               sb->SetDuration (Duration::FromSeconds(300));
+
                DoubleAnimation *r_anim = new DoubleAnimation ();
                DoubleAnimation *v_anim = new DoubleAnimation ();
                DoubleAnimation *sx_anim = new DoubleAnimation ();
@@ -196,7 +198,7 @@
                c_anim->SetFrom (Color (1.0, 0.0, 0.0, 0.5));
                c_anim->SetTo (Color (0.0, 0.0, 1.0, 0.5));
                c_anim->SetRepeatBehavior (RepeatBehavior::Forever);
-               c_anim->SetDuration (Duration::FromSeconds (5));
+               c_anim->SetDuration (Duration::FromSeconds (2));
                c_anim->SetAutoReverse (true);
                sb->AddChild (c_anim);
                Storyboard::SetTargetName (c_anim, "solid-color-brush");
@@ -243,6 +245,90 @@
                sb->AddChild (sy_anim);
                Storyboard::SetTargetName (sy_anim, "scale-transform");
                Storyboard::SetTargetProperty (sy_anim, "ScaleY");
+
+#define KEYFRAMES 1
+
+#if KEYFRAMES
+               square = rectangle_new ();
+               framework_element_set_width (square, 50.0);
+               framework_element_set_height (square, 50.0);
+               shape_set_stroke_thickness (square, 10.0);
+               square->SetValue (Canvas::LeftProperty, Value (100.0));
+               square->SetValue (Canvas::TopProperty, Value (50.0));
+
+               Transform *square_trans = new TranslateTransform ();
+               square_trans->SetValue (TranslateTransform::XProperty, 
Value(50.0));
+               square_trans->SetValue (TranslateTransform::YProperty, 
Value(50.0));
+
+               item_set_render_transform (square, square_trans);
+               
+               shape_set_stroke (square, scb);
+               panel_child_add (canvas, square);
+
+               global_NameScope->RegisterName ("square-transform", 
square_trans);
+               
+               DoubleAnimationUsingKeyFrames* square_x_anim = new 
DoubleAnimationUsingKeyFrames ();
+               DoubleAnimationUsingKeyFrames* square_y_anim = new 
DoubleAnimationUsingKeyFrames ();
+
+               square_y_anim->SetDuration (Duration::FromSeconds (8));
+               square_y_anim->SetRepeatBehavior (RepeatBehavior::Forever);
+               square_x_anim->SetDuration (Duration::FromSeconds (8));
+               square_x_anim->SetRepeatBehavior (RepeatBehavior::Forever);
+
+               LinearDoubleKeyFrame *frame;
+
+               // the X keyframes for the 4 points of the rectangle
+               frame = new LinearDoubleKeyFrame ();
+               frame->SetValue (100.0);
+               frame->SetKeyTime (KeyTime::FromTimeSpan ((TimeSpan)2 * 
1000000));
+               square_x_anim->AddKeyFrame (frame);
+
+               frame = new LinearDoubleKeyFrame ();
+               frame->SetValue (100.0);
+               frame->SetKeyTime (KeyTime::FromTimeSpan ((TimeSpan)4 * 
1000000));
+               square_x_anim->AddKeyFrame (frame);
+
+               frame = new LinearDoubleKeyFrame ();
+               frame->SetValue (50.0);
+               frame->SetKeyTime (KeyTime::FromTimeSpan ((TimeSpan)6 * 
1000000));
+               square_x_anim->AddKeyFrame (frame);
+
+               frame = new LinearDoubleKeyFrame ();
+               frame->SetValue (50.0);
+               frame->SetKeyTime (KeyTime::FromTimeSpan ((TimeSpan)8 * 
1000000));
+               square_x_anim->AddKeyFrame (frame);
+
+               sb->AddChild (square_x_anim);
+               Storyboard::SetTargetName (square_x_anim, "square-transform");
+               Storyboard::SetTargetProperty (square_x_anim, "X");
+
+               // the Y keyframes for the 4 points of the rectangle
+               frame = new LinearDoubleKeyFrame ();
+               frame->SetValue (50.0);
+               frame->SetKeyTime (KeyTime::FromTimeSpan ((TimeSpan)2 * 
1000000));
+               square_y_anim->AddKeyFrame (frame);
+
+               frame = new LinearDoubleKeyFrame ();
+               frame->SetValue (100.0);
+               frame->SetKeyTime (KeyTime::FromTimeSpan ((TimeSpan)4 * 
1000000));
+               square_y_anim->AddKeyFrame (frame);
+
+               frame = new LinearDoubleKeyFrame ();
+               frame->SetValue (100.0);
+               frame->SetKeyTime (KeyTime::FromTimeSpan ((TimeSpan)6 * 
1000000));
+               square_y_anim->AddKeyFrame (frame);
+
+               frame = new LinearDoubleKeyFrame ();
+               frame->SetValue (50.0);
+               frame->SetKeyTime (KeyTime::FromTimeSpan ((TimeSpan)8 * 
1000000));
+               square_y_anim->AddKeyFrame (frame);
+
+               sb->AddChild (square_y_anim);
+               Storyboard::SetTargetName (square_y_anim, "square-transform");
+               Storyboard::SetTargetProperty (square_y_anim, "Y");
+#endif
+
+
                sb->Begin ();
        }               
        if (do_fps){

Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp  2007-06-09 16:58:39 UTC (rev 79063)
+++ trunk/moon/src/runtime.cpp  2007-06-09 18:34:50 UTC (rev 79064)
@@ -401,8 +401,12 @@
 AS_DEP_SUBCLASS_IMPL(BEGINSTORYBOARD, BeginStoryboard)
 AS_DEP_SUBCLASS_IMPL(EVENTTRIGGER, EventTrigger)
 AS_DEP_SUBCLASS_IMPL(KEYFRAME, KeyFrame)
+AS_DEP_SUBCLASS_IMPL(DOUBLEKEYFRAME, DoubleKeyFrame)
 AS_DEP_SUBCLASS_IMPL(POINTKEYFRAME, PointKeyFrame)
+AS_DEP_SUBCLASS_IMPL(LINEARDOUBLEKEYFRAME, LinearDoubleKeyFrame)
+AS_DEP_SUBCLASS_IMPL(LINEARPOINTKEYFRAME, LinearPointKeyFrame)
 AS_DEP_SUBCLASS_IMPL(POINTANIMATIONUSINGKEYFRAMES, 
PointAnimationUsingKeyFrames)
+AS_DEP_SUBCLASS_IMPL(DOUBLEANIMATIONUSINGKEYFRAMES, 
DoubleAnimationUsingKeyFrames)
 
 AS_DEP_SUBCLASS_IMPL(COLLECTION, Collection)
 AS_DEP_SUBCLASS_IMPL(VISUAL_COLLECTION, VisualCollection)
@@ -1079,9 +1083,16 @@
        return property->default_value;
 }
 
+static void
+free_value (void *v)
+{
+       Value *val = (Value*)v;
+       delete val;
+}
+
 DependencyObject::DependencyObject ()
 {
-       current_values = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, 
free);
+       current_values = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, 
free_value);
        events = new EventObject ();
        this->attached_list = NULL;
 }
@@ -1660,7 +1671,11 @@
        Type::RegisterType ("EventTrigger", Value::EVENTTRIGGER, 
Value::DEPENDENCY_OBJECT);
 
        Type::RegisterType ("KeyFrame", Value::KEYFRAME, 
Value::DEPENDENCY_OBJECT);
+       Type::RegisterType ("DoubleKeyFrame", Value::DOUBLEKEYFRAME, 
Value::KEYFRAME);
        Type::RegisterType ("PointKeyFrame", Value::POINTKEYFRAME, 
Value::KEYFRAME);
+       Type::RegisterType ("LinearDoubleKeyFrame", 
Value::LINEARDOUBLEKEYFRAME, Value::DOUBLEKEYFRAME);
+       Type::RegisterType ("LinearPointKeyFrame", Value::LINEARPOINTKEYFRAME, 
Value::POINTKEYFRAME);
+       Type::RegisterType ("DoubleAnimationUsingKeyFrames", 
Value::DOUBLEANIMATIONUSINGKEYFRAMES, Value::DOUBLEANIMATION);
        Type::RegisterType ("PointAnimationUsingKeyFrames", 
Value::POINTANIMATIONUSINGKEYFRAMES, Value::POINTANIMATION);
 
        // The collections

Modified: trunk/moon/src/value.h
===================================================================
--- trunk/moon/src/value.h      2007-06-09 16:58:39 UTC (rev 79063)
+++ trunk/moon/src/value.h      2007-06-09 18:34:50 UTC (rev 79064)
@@ -27,7 +27,9 @@
 class DependencyObject;
 class DependencyProperty;
 class DoubleAnimation;
+class DoubleAnimationUsingKeyFrames;
 class DoubleArray;
+class DoubleKeyFrame;
 class Ellipse;
 class EllipseGeometry;
 class EventTrigger;
@@ -35,6 +37,8 @@
 class Geometry;
 class GeometryGroup;
 class KeyFrame;
+class LinearDoubleKeyFrame;
+class LinearPointKeyFrame;
 class Line;
 class LineGeometry;
 class LineSegment;
@@ -152,7 +156,11 @@
                BEGINSTORYBOARD,
                EVENTTRIGGER,
                KEYFRAME,
+               DOUBLEKEYFRAME,
                POINTKEYFRAME,
+               LINEARDOUBLEKEYFRAME,
+               LINEARPOINTKEYFRAME,
+               DOUBLEANIMATIONUSINGKEYFRAMES,
                POINTANIMATIONUSINGKEYFRAMES,
 
                // The collections
@@ -292,7 +300,11 @@
        BeginStoryboard*              AsBeginStoryboard ();
        EventTrigger*                 AsEventTrigger ();
        KeyFrame*                     AsKeyFrame ();
+       DoubleKeyFrame*               AsDoubleKeyFrame();
        PointKeyFrame*                AsPointKeyFrame ();
+       LinearDoubleKeyFrame*         AsLinearDoubleKeyFrame ();
+       LinearPointKeyFrame*          AsLinearPointKeyFrame ();
+       DoubleAnimationUsingKeyFrames* AsDoubleAnimationUsingKeyFrames ();
        PointAnimationUsingKeyFrames* AsPointAnimationUsingKeyFrames ();
 
        Collection*                   AsCollection ();

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to