[gimp/wip/animation: 257/373] plug-ins: better behavior on animation duration change.



commit 84d00ab8dc03f0c411428d4a87997964dc5ff534
Author: Jehan <jehan girinstud io>
Date:   Fri Nov 11 02:41:20 2016 +0100

    plug-ins: better behavior on animation duration change.
    
    When the animation lengthens, if the stop position was the last frame,
    keep it that way. Also fix animation position changing when it is not
    available anymore in the new range.

 .../animation-play/core/animation-celanimation.c   |    2 +
 plug-ins/animation-play/core/animation-playback.c  |   46 +++++++++++++++++++-
 plug-ins/animation-play/widgets/animation-dialog.c |   17 -------
 3 files changed, 46 insertions(+), 19 deletions(-)
---
diff --git a/plug-ins/animation-play/core/animation-celanimation.c 
b/plug-ins/animation-play/core/animation-celanimation.c
index d049c2d..49eea13 100644
--- a/plug-ins/animation-play/core/animation-celanimation.c
+++ b/plug-ins/animation-play/core/animation-celanimation.c
@@ -338,6 +338,8 @@ animation_cel_animation_set_duration (AnimationCelAnimation *animation,
     }
 
   animation->priv->duration = duration;
+  g_signal_emit_by_name (animation, "duration-changed",
+                         duration);
 }
 
 gint
diff --git a/plug-ins/animation-play/core/animation-playback.c 
b/plug-ins/animation-play/core/animation-playback.c
index e2e6321..f40b402 100644
--- a/plug-ins/animation-play/core/animation-playback.c
+++ b/plug-ins/animation-play/core/animation-playback.c
@@ -50,8 +50,9 @@ struct _AnimationPlaybackPrivate
   /* State of the currently loaded playback. */
   gint         position;
   /* Playback can be a subset of frames. */
-  guint        start;
-  guint        stop;
+  gint         start;
+  gint         stop;
+  gboolean     stop_at_end;
 
   guint        timer;
   gint64       start_time;
@@ -74,6 +75,9 @@ static void       animation_playback_get_property           (GObject           *
                                                              GValue            *value,
                                                              GParamSpec        *pspec);
 
+static void       on_duration_changed                       (Animation         *animation,
+                                                             gint               duration,
+                                                             AnimationPlayback *playback);
 static void       on_cache_invalidated                      (Animation         *animation,
                                                              gint               position,
                                                              gint               length,
@@ -409,6 +413,7 @@ animation_playback_set_start (AnimationPlayback *playback,
   if (playback->priv->stop < playback->priv->start)
     {
       playback->priv->stop = duration - 1;
+      playback->priv->stop_at_end = TRUE;
     }
 
   g_signal_emit (playback, animation_playback_signals[RANGE], 0,
@@ -442,15 +447,20 @@ animation_playback_set_stop (AnimationPlayback *playback,
       index >= duration)
     {
       playback->priv->stop = duration - 1;
+      playback->priv->stop_at_end = TRUE;
     }
   else
     {
       playback->priv->stop = index;
+
+      if (index == duration - 1)
+        playback->priv->stop_at_end = TRUE;
     }
   if (playback->priv->stop < playback->priv->start)
     {
       playback->priv->start = 0;
     }
+
   g_signal_emit (playback, animation_playback_signals[RANGE], 0,
                  playback->priv->start, playback->priv->stop);
 
@@ -510,10 +520,13 @@ animation_playback_set_property (GObject      *object,
           playback->priv->position = 0;
           playback->priv->start = 0;
           playback->priv->stop  = animation_get_duration (animation) - 1;
+          playback->priv->stop_at_end = TRUE;
 
           g_signal_emit_by_name (animation, "loaded");
           g_signal_connect (animation, "cache-invalidated",
                             G_CALLBACK (on_cache_invalidated), playback);
+          g_signal_connect (animation, "duration-changed",
+                            G_CALLBACK (on_duration_changed), playback);
 
           /* Once loaded, let's ask render. */
           buffer = animation_get_frame (animation, playback->priv->position);
@@ -552,6 +565,35 @@ animation_playback_get_property (GObject    *object,
 }
 
 static void
+on_duration_changed (Animation         *animation,
+                     gint               duration,
+                     AnimationPlayback *playback)
+{
+  if (! playback->priv->animation)
+    return;
+
+  if (playback->priv->stop >= duration ||
+      playback->priv->stop_at_end)
+    {
+      playback->priv->stop = duration - 1;
+      playback->priv->stop_at_end = TRUE;
+    }
+  if (playback->priv->start >= duration ||
+      playback->priv->start > playback->priv->stop)
+    {
+      playback->priv->start = 0;
+    }
+
+  if (playback->priv->position < playback->priv->start ||
+      playback->priv->position > playback->priv->stop)
+    {
+      playback->priv->position = playback->priv->start;
+    }
+  g_signal_emit (playback, animation_playback_signals[RANGE], 0,
+                 playback->priv->start, playback->priv->stop);
+}
+
+static void
 on_cache_invalidated (Animation         *animation,
                       gint               position,
                       gint               length,
diff --git a/plug-ins/animation-play/widgets/animation-dialog.c 
b/plug-ins/animation-play/widgets/animation-dialog.c
index 35d8f3d..948b41a 100755
--- a/plug-ins/animation-play/widgets/animation-dialog.c
+++ b/plug-ins/animation-play/widgets/animation-dialog.c
@@ -202,9 +202,6 @@ static void        show_loading_progress     (Animation        *animation,
                                               AnimationDialog  *dialog);
 static void        unblock_ui                (Animation        *animation,
                                               AnimationDialog  *dialog);
-static void        duration_changed          (AnimationPlayback *playback,
-                                              gint               duration,
-                                              AnimationDialog   *dialog);
 static void        playback_range_changed    (AnimationPlayback *playback,
                                               gint              playback_start,
                                               gint              playback_stop,
@@ -1095,9 +1092,6 @@ animation_dialog_set_animation (AnimationDialog *dialog,
       g_signal_handlers_disconnect_by_func (priv->animation,
                                             G_CALLBACK (framerate_changed),
                                             dialog);
-      g_signal_handlers_disconnect_by_func (priv->animation,
-                                            G_CALLBACK (duration_changed),
-                                            dialog);
       g_signal_handlers_disconnect_by_func (priv->playback,
                                             G_CALLBACK (playback_range_changed),
                                             dialog);
@@ -1297,9 +1291,6 @@ animation_dialog_set_animation (AnimationDialog *dialog,
   g_signal_connect (priv->animation, "framerate-changed",
                     G_CALLBACK (framerate_changed),
                     dialog);
-  g_signal_connect (priv->animation, "duration-changed",
-                    G_CALLBACK (duration_changed),
-                    dialog);
   g_signal_connect (priv->playback, "range",
                     G_CALLBACK (playback_range_changed),
                     dialog);
@@ -1954,14 +1945,6 @@ unblock_ui (Animation      *animation,
 }
 
 static void
-duration_changed (AnimationPlayback *playback,
-                  gint               duration,
-                  AnimationDialog   *dialog)
-{
-  update_progress (dialog);
-}
-
-static void
 playback_range_changed (AnimationPlayback *playback,
                         gint               playback_start,
                         gint               playback_stop,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]