[gimp/wip/animation: 92/145] plug-ins: double-click on animation's frame position updates the...



commit 7d42a5c213beec92ea324468165a88aa1df25b18
Author: Jehan <jehan girinstud io>
Date:   Tue Jan 24 21:48:37 2017 +0100

    plug-ins: double-click on animation's frame position updates the...
    
    ... image view in GIMP.

 plug-ins/animation-play/animation-utils.c          |   33 ++++++++++++++
 plug-ins/animation-play/animation-utils.h          |    5 ++
 .../animation-play/core/animation-celanimation.c   |   46 ++++++++++++++++++++
 plug-ins/animation-play/core/animation.c           |    8 +++
 plug-ins/animation-play/core/animation.h           |    6 +++
 plug-ins/animation-play/widgets/animation-xsheet.c |   27 ++++++++----
 6 files changed, 116 insertions(+), 9 deletions(-)
---
diff --git a/plug-ins/animation-play/animation-utils.c b/plug-ins/animation-play/animation-utils.c
index 9692181..b04d411 100755
--- a/plug-ins/animation-play/animation-utils.c
+++ b/plug-ins/animation-play/animation-utils.c
@@ -275,3 +275,36 @@ show_scrolled_child (GtkScrolledWindow *window,
       gtk_adjustment_set_value (vadj, y);
     }
 }
+
+void
+hide_item (gint     item,
+           gboolean recursive)
+{
+  gimp_item_set_visible (item, FALSE);
+
+  if (recursive && gimp_item_is_group (item))
+    {
+      gint32 *children;
+      gint32  n_children;
+      gint    i;
+
+      children = gimp_item_get_children (item, &n_children);
+
+      for (i = 0; i < n_children; i++)
+        {
+          hide_item (children[i], TRUE);
+        }
+    }
+}
+
+void
+show_item (gint item)
+{
+  gint32 parent;
+
+  gimp_item_set_visible (item, TRUE);
+  parent = gimp_item_get_parent (item);
+
+  if (parent > 0)
+    show_item (parent);
+}
diff --git a/plug-ins/animation-play/animation-utils.h b/plug-ins/animation-play/animation-utils.h
index 704bd40..d77cd9b 100755
--- a/plug-ins/animation-play/animation-utils.h
+++ b/plug-ins/animation-play/animation-utils.h
@@ -47,6 +47,11 @@ GeglBuffer * normal_blend        (gint               width,
 
 void         show_scrolled_child (GtkScrolledWindow *window,
                                   GtkWidget         *child);
+
+void         hide_item           (gint               item,
+                                  gboolean           recursive);
+void         show_item           (gint               item);
+
 #endif  /*  __ANIMATION_UTILS_H__  */
 
 
diff --git a/plug-ins/animation-play/core/animation-celanimation.c 
b/plug-ins/animation-play/core/animation-celanimation.c
index 0d0f55d..7603aca 100644
--- a/plug-ins/animation-play/core/animation-celanimation.c
+++ b/plug-ins/animation-play/core/animation-celanimation.c
@@ -133,6 +133,9 @@ static gboolean     animation_cel_animation_deserialize    (Animation         *a
                                                             const gchar       *xml,
                                                             GError           **error);
 
+static void         animation_cel_animation_update_paint_view (Animation      *animation,
+                                                               gint            position);
+
 /* XML parsing */
 
 static void      animation_cel_animation_start_element     (GMarkupParseContext *context,
@@ -190,6 +193,8 @@ animation_cel_animation_class_init (AnimationCelAnimationClass *klass)
   anim_class->serialize      = animation_cel_animation_serialize;
   anim_class->deserialize    = animation_cel_animation_deserialize;
 
+  anim_class->update_paint_view = animation_cel_animation_update_paint_view;
+
   g_type_class_add_private (klass, sizeof (AnimationCelAnimationPrivate));
 }
 
@@ -958,6 +963,47 @@ animation_cel_animation_deserialize (Animation    *animation,
 }
 
 static void
+animation_cel_animation_update_paint_view (Animation *animation,
+                                           gint       position)
+{
+  AnimationCelAnimation *cel_animation;
+  Cache                 *cache;
+  gint                  *layers;
+  gint                   num_layers;
+  gint32                 image_id;
+  gint                   i;
+
+  image_id = animation_get_image_id (animation);
+
+  /* Hide all layers. */
+  layers = gimp_image_get_layers (image_id, &num_layers);
+  for (i = 0; i < num_layers; i++)
+    {
+      hide_item (layers[i], TRUE);
+    }
+
+  /* Show layers */
+  cel_animation = ANIMATION_CEL_ANIMATION (animation);
+
+  cache = g_list_nth_data (cel_animation->priv->cache,
+                           position);
+  if (cache)
+    {
+      gint i;
+
+      for (i = 0; i < cache->n_sources; i++)
+        {
+          gint tattoo = cache->composition[i].tattoo;
+          gint layer;
+
+          layer = gimp_image_get_layer_by_tattoo (image_id, tattoo);
+
+          show_item (layer);
+        }
+    }
+}
+
+static void
 animation_cel_animation_start_element (GMarkupParseContext  *context,
                                        const gchar          *element_name,
                                        const gchar         **attribute_names,
diff --git a/plug-ins/animation-play/core/animation.c b/plug-ins/animation-play/core/animation.c
index 72be739..4b6bfc4 100644
--- a/plug-ins/animation-play/core/animation.c
+++ b/plug-ins/animation-play/core/animation.c
@@ -481,6 +481,14 @@ animation_loaded (Animation *animation)
   return priv->loaded;
 }
 
+void
+animation_update_paint_view (Animation *animation,
+                             gint       position)
+{
+  ANIMATION_GET_CLASS (animation)->update_paint_view (animation, position);
+  gimp_displays_flush ();
+}
+
 /************ Private Functions ****************/
 
 static void
diff --git a/plug-ins/animation-play/core/animation.h b/plug-ins/animation-play/core/animation.h
index 5cfc62a..03a01c4 100644
--- a/plug-ins/animation-play/core/animation.h
+++ b/plug-ins/animation-play/core/animation.h
@@ -73,6 +73,9 @@ struct _AnimationClass
   gboolean     (*deserialize)        (Animation    *animation,
                                       const gchar  *xml,
                                       GError      **error);
+
+  void         (*update_paint_view)  (Animation    *animation,
+                                      gint          position);
 };
 
 GType         animation_get_type (void);
@@ -106,4 +109,7 @@ gdouble       animation_get_framerate      (Animation   *animation);
 
 gboolean      animation_loaded             (Animation   *animation);
 
+void          animation_update_paint_view  (Animation   *animation,
+                                            gint         position);
+
 #endif  /*  __ANIMATION_H__  */
diff --git a/plug-ins/animation-play/widgets/animation-xsheet.c 
b/plug-ins/animation-play/widgets/animation-xsheet.c
index a591625..e9f0aba 100755
--- a/plug-ins/animation-play/widgets/animation-xsheet.c
+++ b/plug-ins/animation-play/widgets/animation-xsheet.c
@@ -1502,18 +1502,27 @@ animation_xsheet_frame_clicked (GtkWidget       *button,
 
   position = g_object_get_data (G_OBJECT (button), "frame-position");
 
-  animation_playback_jump (xsheet->priv->playback,
-                           GPOINTER_TO_INT (position));
-  if (xsheet->priv->active_pos_button)
+  if (event->type == GDK_BUTTON_PRESS)
     {
-      GtkToggleButton *active_button;
+      /* Single click: jump to the position. */
+      animation_playback_jump (xsheet->priv->playback,
+                               GPOINTER_TO_INT (position));
+      if (xsheet->priv->active_pos_button)
+        {
+          GtkToggleButton *active_button;
 
-      active_button = GTK_TOGGLE_BUTTON (xsheet->priv->active_pos_button);
-      gtk_toggle_button_set_active (active_button, FALSE);
+          active_button = GTK_TOGGLE_BUTTON (xsheet->priv->active_pos_button);
+          gtk_toggle_button_set_active (active_button, FALSE);
+        }
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+      xsheet->priv->active_pos_button = button;
+    }
+  else if (event->type == GDK_2BUTTON_PRESS)
+    {
+      /* Double click: update GIMP view. */
+      animation_update_paint_view (ANIMATION (xsheet->priv->animation),
+                                   GPOINTER_TO_INT (position));
     }
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
-                                TRUE);
-  xsheet->priv->active_pos_button = button;
 
   /* All handled here. */
   return TRUE;


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