Author: toshok
Date: 2007-12-05 18:16:49 -0500 (Wed, 05 Dec 2007)
New Revision: 90783

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
Log:
2007-12-05  Chris Toshok  <[EMAIL PROTECTED]>

        * animation.cpp, animation.h: a couple of fixes.  Move away from
        watching the clock state in AnimationStorage and resetting the
        property value there.  instead, just override Clock::Stop in
        AnimationClock and call ResetPropertyValue on the storage.

        Also, when a storyboard's clock group is stopped, free it and
        remove it from the parent clock's list of children.  This should
        keep us from growing the number of clocks over time for
        storyboards which don't have Begin() called again (the only
        circumstance under which we destroy the clock).

        * clock.cpp, clock.h: handle the case where a clock can be started
        and then stopped before the next clock tick.  This happens when
        you move the mouse very quickly over the thumbnails in pageturn.



Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog    2007-12-05 23:03:05 UTC (rev 90782)
+++ trunk/moon/src/ChangeLog    2007-12-05 23:16:49 UTC (rev 90783)
@@ -1,3 +1,9 @@
+2007-12-05  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * clock.cpp, clock.h: handle the case where a clock can be started
+       and then stopped before the next clock tick.  This happens when
+       you move the mouse very quickly over the thumbnails in pageturn.
+
 2007-12-05  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * geometry.cpp: Fix crash when EllipseGeometry is used for clipping

Modified: trunk/moon/src/animation.cpp
===================================================================
--- trunk/moon/src/animation.cpp        2007-12-05 23:03:05 UTC (rev 90782)
+++ trunk/moon/src/animation.cpp        2007-12-05 23:16:49 UTC (rev 90783)
@@ -37,10 +37,10 @@
   
 {
        clock->AddHandler (clock->CurrentTimeInvalidatedEvent, 
update_property_value, this);
-       clock->AddHandler (clock->CurrentStateInvalidatedEvent, 
reset_property_value, this);
        targetobj->AddHandler (EventObject::DestroyedEvent, 
target_object_destroyed, this);
 
        baseValue = new Value(*targetobj->GetValue (targetprop));
+       printf ("basevalue %p.%s is %f\n", targetobj, targetprop->name, 
baseValue->AsDouble());
 }
 
 void
@@ -77,19 +77,14 @@
 }
 
 void
-AnimationStorage::reset_property_value (EventObject *, gpointer, gpointer 
closure)
-{
-       ((AnimationStorage*)closure)->ResetPropertyValue ();
-}
-
-void
 AnimationStorage::ResetPropertyValue ()
 {
        if (targetobj == NULL)
                return;
 
-       if (clock->GetClockState() == Clock::Stopped)
-               targetobj->SetValue (targetprop, *baseValue);
+       targetobj->SetValue (targetprop, *baseValue);
+       if (baseValue->GetKind() == Type::DOUBLE)
+               printf ("resetting %p.%s to %f\n", targetobj, targetprop->name, 
baseValue->AsDouble());
 }
 
 AnimationStorage::~AnimationStorage ()
@@ -99,7 +94,6 @@
        
        if (clock != NULL) {
                clock->RemoveHandler (clock->CurrentTimeInvalidatedEvent, 
update_property_value, this);
-               clock->RemoveHandler (clock->CurrentStateInvalidatedEvent, 
reset_property_value, this);
        }
        
        if (targetobj != NULL) {
@@ -126,6 +120,13 @@
        return timeline->GetCurrentValue (defaultOriginValue, 
defaultDestinationValue, this);
 }
 
+void
+AnimationClock::Stop ()
+{
+       if (storage)
+               storage->ResetPropertyValue ();
+}
+
 AnimationClock::~AnimationClock ()
 {
        if (storage)
@@ -136,8 +137,8 @@
 Animation/*Timeline*/::AllocateClock()
 {
        Clock *clock = new AnimationClock (this);
-       char *name = g_strdup_printf ("AnimationClock for %s, targetobj = %s, 
targetprop = %s", GetTypeName(),
-                                     Storyboard::GetTargetName (this), 
Storyboard::GetTargetProperty (this));
+       char *name = g_strdup_printf ("AnimationClock for %s, targetobj = 
%p/%s, targetprop = %s", GetTypeName(),
+                                     FindName 
(Storyboard::GetTargetName(this)), Storyboard::GetTargetName (this), 
Storyboard::GetTargetProperty (this));
        clock->SetValue (DependencyObject::NameProperty, name);
        g_free (name);
        return clock;
@@ -234,6 +235,25 @@
 }
 
 void
+Storyboard::TeardownClockGroup ()
+{
+       if (root_clock) {
+               ClockGroup *group = root_clock->GetParent();
+               if (group)
+                       group->RemoveChild (root_clock);
+               root_clock->unref ();
+               root_clock = NULL;
+       }
+}
+
+void
+Storyboard::teardown_clockgroup (EventObject *sender, gpointer calldata, 
gpointer closure)
+{
+       Storyboard *sb = (Storyboard *)closure;
+       sb->TeardownClockGroup ();
+}
+
+void
 Storyboard::Begin ()
 {
        ClockGroup *group = NULL;
@@ -252,10 +272,12 @@
           easier than making Begin work again with the existing clock
           hierarchy */
        if (root_clock) {
-               group = root_clock->GetParent();
-               group->RemoveChild (root_clock);
-               root_clock->unref ();
-               root_clock = NULL;
+               if (root_clock->GetClockState() != Clock::Stopped) {
+                       root_clock->RemoveHandler (root_clock->CompletedEvent, 
teardown_clockgroup, this);
+                       root_clock->Stop();
+               }
+
+               TeardownClockGroup ();
        }
 #endif
 
@@ -276,6 +298,7 @@
        root_clock->SetValue (DependencyObject::NameProperty, name);
        g_free (name);
        root_clock->AddHandler (root_clock->CompletedEvent, invoke_completed, 
this);
+       root_clock->AddHandler (root_clock->CompletedEvent, 
teardown_clockgroup, this);
 
        // walk the clock tree hooking up the correct properties and
        // creating AnimationStorage's for AnimationClocks.
@@ -413,11 +436,7 @@
        if (root_clock) {
                //printf ("Clock %p (ref=%d)\n", root_clock, 
root_clock->refcount);
                Stop ();
-               if (root_clock->GetParent())
-                       root_clock->GetParent()->RemoveChild (root_clock);
-               //printf ("Unrefing Clock %p (ref=%d)\n", root_clock, 
root_clock->refcount);
-               root_clock->unref ();
-               root_clock = NULL;
+               TeardownClockGroup ();
        }
 }
 

Modified: trunk/moon/src/animation.h
===================================================================
--- trunk/moon/src/animation.h  2007-12-05 23:03:05 UTC (rev 90782)
+++ trunk/moon/src/animation.h  2007-12-05 23:16:49 UTC (rev 90783)
@@ -119,6 +119,8 @@
                          DependencyObject *targetobj, DependencyProperty 
*targetprop);
        ~AnimationStorage ();
        
+       void ResetPropertyValue ();
+
  private:
        void TargetObjectDestroyed ();
        static void target_object_destroyed (EventObject *sender, gpointer 
calldata, gpointer data);
@@ -126,9 +128,6 @@
        void UpdatePropertyValue ();
        static void update_property_value (EventObject *sender, gpointer 
calldata, gpointer data);
 
-       void ResetPropertyValue ();
-       static void reset_property_value (EventObject *sender, gpointer 
calldata, gpointer data);
-
        AnimationClock *clock;
        Animation/*Timeline*/* timeline;
        DependencyObject *targetobj;
@@ -152,6 +151,8 @@
 
        void HookupStorage (DependencyObject *targetobj, DependencyProperty 
*targetprop);
 
+       virtual void Stop ();
+
  private:
        Animation/*Timeline*/ *timeline;
        AnimationStorage *storage;
@@ -559,6 +560,9 @@
        gboolean Tick ();
        static gboolean storyboard_tick (gpointer data);
        static void invoke_completed (EventObject *sender, gpointer calldata, 
gpointer data);
+
+       void TeardownClockGroup ();
+       static void teardown_clockgroup (EventObject *sender, gpointer 
calldata, gpointer data);
 };
 
 /* @ContentProperty="Storyboard" */

Modified: trunk/moon/src/clock.cpp
===================================================================
--- trunk/moon/src/clock.cpp    2007-12-05 23:03:05 UTC (rev 90782)
+++ trunk/moon/src/clock.cpp    2007-12-05 23:16:49 UTC (rev 90783)
@@ -538,7 +538,7 @@
                ClockGroup *cg = (ClockGroup*)clock;
                level += 2;
                for (GList *l = cg->child_clocks; l; l = l->next) {
-                       if (((Clock*)l->data)->GetClockState () != 
Clock::Stopped)
+//                     if (((Clock*)l->data)->GetClockState () != 
Clock::Stopped)
                                output_clock ((Clock*)l->data, level);
                }
        }
@@ -551,7 +551,7 @@
        printf ("============================\n");
 
        for (GList *l = child_clocks; l; l = l->next) {
-               if (((Clock*)l->data)->GetClockState () != Clock::Filling)
+//             if (((Clock*)l->data)->GetClockState () != Clock::Filling)
                        output_clock ((Clock*)l->data, 2);
        }
 }
@@ -582,6 +582,7 @@
     queued_events (0),
     forward (true)
 {
+       was_stopped = false;
        begin_time = -1;
 
        if (timeline->HasBeginTime ())
@@ -810,6 +811,7 @@
 {
        seeking = false;
        has_started = false;
+       was_stopped = false;
        is_paused = false;
        forward = true;
 
@@ -941,6 +943,7 @@
        printf ("stopping clock %p after this tick\n", this);
 #endif
        SetClockState (Clock::Stopped);
+       was_stopped = true;
 }
 
 
@@ -1040,7 +1043,7 @@
                if (c->GetClockState() != Clock::Stopped) {
                        c->Tick ();
                }
-               else if (!c->GetHasStarted() && c->GetBeginTime () <= 
current_time) {
+               else if (!c->GetHasStarted() && !c->GetWasStopped() && 
c->GetBeginTime () <= current_time) {
                        c->Begin ();
                }
        }

Modified: trunk/moon/src/clock.h
===================================================================
--- trunk/moon/src/clock.h      2007-12-05 23:03:05 UTC (rev 90782)
+++ trunk/moon/src/clock.h      2007-12-05 23:16:49 UTC (rev 90783)
@@ -339,6 +339,7 @@
        Duration    GetNaturalDuration () { return natural_duration; }
        bool        GetIsPaused ()        { return is_paused; }
        bool        GetHasStarted ()      { return has_started; }
+       bool        GetWasStopped ()      { return was_stopped; }
        void        ClearHasStarted ()    { has_started = false; }
        bool        GetIsReversed ()      { return !forward; }
        TimeSpan    GetBeginTime ()       { return begin_time; }
@@ -424,6 +425,7 @@
 
        bool is_paused;
        bool has_started;
+       bool was_stopped;
        Timeline *timeline;
        int queued_events;
 

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

Reply via email to