[gimp/wip/animation: 262/373] plug-ins: add track deletion button.



commit 78660dc73f1edc5a26e23c182abba2c3d8ccc25c
Author: Jehan <jehan girinstud io>
Date:   Sun Nov 13 04:36:37 2016 +0100

    plug-ins: add track deletion button.
    
    The UI is quite ugly with all these buttons. I will revise it later.

 .../animation-play/core/animation-celanimation.c   |   33 +++++++++++++++++-
 plug-ins/animation-play/widgets/animation-xsheet.c |   37 ++++++++++++++++++++
 2 files changed, 69 insertions(+), 1 deletions(-)
---
diff --git a/plug-ins/animation-play/core/animation-celanimation.c 
b/plug-ins/animation-play/core/animation-celanimation.c
index 3e79048..385146b 100644
--- a/plug-ins/animation-play/core/animation-celanimation.c
+++ b/plug-ins/animation-play/core/animation-celanimation.c
@@ -449,7 +449,38 @@ gboolean
 animation_cel_animation_level_delete (AnimationCelAnimation *animation,
                                       gint                   level)
 {
-  /* XXX no implementation yet. */
+  gint   tracks_n = g_list_length (animation->priv->tracks);
+  GList *item;
+  GList *iter;
+  Track *track;
+  gint   i;
+
+  g_return_val_if_fail (level >= 0 && level < tracks_n, FALSE);
+
+  /* Do not remove when there is only a single level. */
+  if (tracks_n > 1)
+    {
+      item = g_list_nth (animation->priv->tracks, level);
+      track = item->data;
+      animation_cel_animation_clean_track (track);
+      animation->priv->tracks = g_list_delete_link (animation->priv->tracks, item);
+
+      iter  = track->frames;
+      for (i = 0; iter; iter = iter->next, i++)
+        {
+          g_signal_emit_by_name (animation, "loading",
+                                 (gdouble) i / ((gdouble) animation->priv->duration - 0.999));
+
+          if (GPOINTER_TO_INT (iter->data))
+            {
+              /* Only cache if the track had contents for this frame. */
+              animation_cel_animation_cache (animation, i);
+            }
+        }
+      g_signal_emit_by_name (animation, "loaded");
+
+      return TRUE;
+    }
   return FALSE;
 }
 
diff --git a/plug-ins/animation-play/widgets/animation-xsheet.c 
b/plug-ins/animation-play/widgets/animation-xsheet.c
index 308baf8..9870bb3 100755
--- a/plug-ins/animation-play/widgets/animation-xsheet.c
+++ b/plug-ins/animation-play/widgets/animation-xsheet.c
@@ -114,6 +114,8 @@ static gboolean animation_xsheet_comment_keypress    (GtkWidget       *entry,
 
 static void     on_track_add_clicked                 (GtkToolButton   *button,
                                                       AnimationXSheet *xsheet);
+static void     on_track_delete_clicked              (GtkToolButton   *button,
+                                                      AnimationXSheet *xsheet);
 static void     on_track_left_clicked                (GtkToolButton   *toolbutton,
                                                       AnimationXSheet *xsheet);
 static void     on_track_right_clicked               (GtkToolButton   *toolbutton,
@@ -531,6 +533,27 @@ animation_xsheet_reset_layout (AnimationXSheet *xsheet)
                           GTK_TOOL_ITEM (item), -1);
       gtk_widget_show (GTK_WIDGET (item));
 
+      image = gtk_image_new_from_icon_name ("edit-delete",
+                                            GTK_ICON_SIZE_SMALL_TOOLBAR);
+      item = gtk_tool_button_new (image, NULL);
+      g_object_set_data (G_OBJECT (item), "track-num",
+                         GINT_TO_POINTER (j));
+      g_signal_connect (item, "clicked",
+                        G_CALLBACK (on_track_delete_clicked),
+                        xsheet);
+      gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
+                          GTK_TOOL_ITEM (item), -1);
+      gtk_widget_show (image);
+      gtk_widget_show (GTK_WIDGET (item));
+
+      item = gtk_separator_tool_item_new ();
+      gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (item),
+                                        FALSE);
+      gtk_tool_item_set_expand (GTK_TOOL_ITEM (item), TRUE);
+      gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
+                          GTK_TOOL_ITEM (item), -1);
+      gtk_widget_show (GTK_WIDGET (item));
+
       image = gtk_image_new_from_icon_name ("gimp-menu-right",
                                             GTK_ICON_SIZE_SMALL_TOOLBAR);
       item = gtk_tool_button_new (image, NULL);
@@ -1093,6 +1116,20 @@ on_track_add_clicked (GtkToolButton   *button,
 }
 
 static void
+on_track_delete_clicked (GtkToolButton   *button,
+                         AnimationXSheet *xsheet)
+{
+  gpointer     track_num;
+
+  track_num = g_object_get_data (G_OBJECT (button), "track-num");
+  if (animation_cel_animation_level_delete (xsheet->priv->animation,
+                                            GPOINTER_TO_INT (track_num)))
+    {
+      animation_xsheet_reset_layout (xsheet);
+    }
+}
+
+static void
 on_track_left_clicked (GtkToolButton   *button,
                        AnimationXSheet *xsheet)
 {


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