[gimp/wip/animation: 115/197] plug-ins: add a contextual menu on cels to add/delete/duplicate them.



commit b1b6ccfc2bd60d3e69b07a749221c793fa2d08b0
Author: Jehan <jehan girinstud io>
Date:   Wed Dec 7 04:44:44 2016 +0100

    plug-ins: add a contextual menu on cels to add/delete/duplicate them.

 plug-ins/animation-play/Makefile.am                |    2 +
 .../animation-play/core/animation-celanimation.c   |   87 ++++++++++++
 .../animation-play/core/animation-celanimation.h   |    8 +
 plug-ins/animation-play/widgets/animation-menus.c  |  140 ++++++++++++++++++++
 plug-ins/animation-play/widgets/animation-menus.h  |   32 +++++
 plug-ins/animation-play/widgets/animation-xsheet.c |    8 +-
 6 files changed, 276 insertions(+), 1 deletions(-)
---
diff --git a/plug-ins/animation-play/Makefile.am b/plug-ins/animation-play/Makefile.am
index 1a01407..549e05e 100644
--- a/plug-ins/animation-play/Makefile.am
+++ b/plug-ins/animation-play/Makefile.am
@@ -53,6 +53,8 @@ animation_play_SOURCES = \
        core/animation-playback.c               \
        widgets/animation-dialog.h              \
        widgets/animation-dialog.c              \
+       widgets/animation-menus.h               \
+       widgets/animation-menus.c               \
        widgets/animation-storyboard.h  \
        widgets/animation-storyboard.c  \
        widgets/animation-layer-view.h  \
diff --git a/plug-ins/animation-play/core/animation-celanimation.c 
b/plug-ins/animation-play/core/animation-celanimation.c
index 7b6ae85..b860c43 100644
--- a/plug-ins/animation-play/core/animation-celanimation.c
+++ b/plug-ins/animation-play/core/animation-celanimation.c
@@ -531,6 +531,93 @@ animation_cel_animation_set_track_title (AnimationCelAnimation *animation,
     }
 }
 
+gboolean
+animation_cel_animation_cel_delete (AnimationCelAnimation *animation,
+                                    gint                   level,
+                                    gint                   position)
+{
+  Track *track;
+
+  track = g_list_nth_data (animation->priv->tracks, level);
+
+  if (track)
+    {
+      GList *cel = g_list_nth (track->frames, position);
+
+      if (cel)
+        {
+          GList *iter;
+          gint   i;
+
+          g_list_free (cel->data);
+          iter = cel->next;
+          track->frames = g_list_delete_link (track->frames, cel);
+
+          for (i = position; iter; iter = iter->next, i++)
+            {
+              g_signal_emit_by_name (animation, "loading",
+                                     (gdouble) i / ((gdouble) animation->priv->duration - 0.999));
+
+              animation_cel_animation_cache (animation, i);
+            }
+          g_signal_emit_by_name (animation, "loaded");
+
+          return TRUE;
+        }
+    }
+  return FALSE;
+}
+
+gboolean
+animation_cel_animation_cel_add (AnimationCelAnimation *animation,
+                                 gint                   level,
+                                 gint                   position,
+                                 gboolean               dup_previous)
+{
+  Track *track;
+
+  track = g_list_nth_data (animation->priv->tracks, level);
+
+  if (track)
+    {
+      GList *cel;
+      GList *contents = NULL;
+      gint   i = position;
+
+      if (dup_previous && position > 0)
+        {
+          GList *prev_cell;
+
+          i++;
+          prev_cell = g_list_nth (track->frames, position - 1);
+
+          if (prev_cell)
+            contents = g_list_copy (prev_cell->data);
+        }
+      track->frames = g_list_insert (track->frames, contents, position);
+
+      if (g_list_length (track->frames) > animation->priv->duration &&
+          g_list_last (track->frames)->data)
+        animation_cel_animation_set_duration (animation,
+                                              g_list_length (track->frames));
+      cel = g_list_nth (track->frames, i);
+      if (cel)
+        {
+          for (; cel; cel = cel->next, i++)
+            {
+              g_signal_emit_by_name (animation, "loading",
+                                     (gdouble) i / ((gdouble) animation->priv->duration - 0.999));
+
+              animation_cel_animation_cache (animation, i);
+            }
+          g_signal_emit_by_name (animation, "loaded");
+
+          return TRUE;
+        }
+    }
+  return FALSE;
+}
+
 /**** Virtual methods ****/
 
 static gint
diff --git a/plug-ins/animation-play/core/animation-celanimation.h 
b/plug-ins/animation-play/core/animation-celanimation.h
index ee0638a..36205fc 100644
--- a/plug-ins/animation-play/core/animation-celanimation.h
+++ b/plug-ins/animation-play/core/animation-celanimation.h
@@ -82,4 +82,12 @@ void          animation_cel_animation_set_track_title (AnimationCelAnimation *an
 const gchar * animation_cel_animation_get_track_title (AnimationCelAnimation *animation,
                                                        gint                   level);
 
+gboolean      animation_cel_animation_cel_delete      (AnimationCelAnimation *animation,
+                                                       gint                   level,
+                                                       gint                   position);
+gboolean      animation_cel_animation_cel_add         (AnimationCelAnimation *animation,
+                                                       gint                   level,
+                                                       gint                   position,
+                                                       gboolean               dup_previous);
+
 #endif  /*  __ANIMATION_CEL_ANIMATION_H__  */
diff --git a/plug-ins/animation-play/widgets/animation-menus.c 
b/plug-ins/animation-play/widgets/animation-menus.c
new file mode 100644
index 0000000..cb657e1
--- /dev/null
+++ b/plug-ins/animation-play/widgets/animation-menus.c
@@ -0,0 +1,140 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * animation-menus.c
+ * Copyright (C) 2016 Jehan <jehan gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+#include "config.h"
+
+#include <string.h>
+
+#include <libgimp/gimp.h>
+#include <libgimp/gimpui.h>
+
+#include "libgimp/stdplugins-intl.h"
+
+#include "core/animation-celanimation.h"
+#include "core/animation-playback.h"
+
+#include "animation-xsheet.h"
+
+#include "animation-menus.h"
+
+typedef struct
+{
+  AnimationCelAnimation *animation;
+  gint                   level;
+  gint                   position;
+  gboolean               dup_previous;
+}
+CellData;
+
+static void on_delete_cell (GtkMenuItem *menuitem,
+                            gpointer     user_data);
+static void on_add_cell    (GtkMenuItem *menuitem,
+                            gpointer     user_data);
+
+
+static void
+on_add_cell (GtkMenuItem *menuitem,
+             gpointer     user_data)
+{
+  CellData *data = user_data;
+
+  animation_cel_animation_cel_add (data->animation,
+                                   data->level,
+                                   data->position,
+                                   data->dup_previous);
+}
+
+static void
+on_delete_cell (GtkMenuItem *menuitem,
+                gpointer     user_data)
+{
+  CellData *data = user_data;
+
+  animation_cel_animation_cel_delete (data->animation,
+                                      data->level,
+                                      data->position);
+}
+
+void
+animation_menu_cell (AnimationCelAnimation *animation,
+                     GdkEventButton        *event,
+                     gint                   frame,
+                     gint                   track)
+{
+  GtkWidget *menu;
+  GtkWidget *item;
+  CellData  *data;
+
+  menu = gtk_menu_new ();
+
+  /* Duplicate cell. */
+  item = gtk_menu_item_new_with_label (_("Duplicate cel"));
+  data = g_new0 (CellData, 1);
+  data->animation    = animation;
+  data->position     = frame + 1;
+  data->level        = track;
+  data->dup_previous = TRUE;
+  g_signal_connect_data (item, "activate",
+                         G_CALLBACK (on_add_cell), data,
+                         (GClosureNotify) g_free, 0);
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+  gtk_widget_show (item);
+
+  /* Add empty cell. */
+  item = gtk_menu_item_new_with_label (_("Push cels down"));
+  data = g_new0 (CellData, 1);
+  data->animation    = animation;
+  data->position     = frame;
+  data->level        = track;
+  data->dup_previous = FALSE;
+  g_signal_connect_data (item, "activate",
+                         G_CALLBACK (on_add_cell), data,
+                         (GClosureNotify) g_free, 0);
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+  gtk_widget_show (item);
+
+  /* Add empty cell. */
+  item = gtk_menu_item_new_with_label (_("Add empty cel after"));
+  data = g_new0 (CellData, 1);
+  data->animation    = animation;
+  data->position     = frame + 1;
+  data->level        = track;
+  data->dup_previous = FALSE;
+  g_signal_connect_data (item, "activate",
+                         G_CALLBACK (on_add_cell), data,
+                         (GClosureNotify) g_free, 0);
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+  gtk_widget_show (item);
+
+  /* Delete cell. */
+  item = gtk_menu_item_new_with_label (_("Delete cell"));
+  data = g_new0 (CellData, 1);
+  data->animation = animation;
+  data->position  = frame;
+  data->level     = track;
+  g_signal_connect_data (item, "activate",
+                         G_CALLBACK (on_delete_cell), data,
+                         (GClosureNotify) g_free, 0);
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+  gtk_widget_show (item);
+
+  gtk_widget_show (menu);
+  gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
+                  event->button, event->time);
+}
diff --git a/plug-ins/animation-play/widgets/animation-menus.h 
b/plug-ins/animation-play/widgets/animation-menus.h
new file mode 100644
index 0000000..dea7b12
--- /dev/null
+++ b/plug-ins/animation-play/widgets/animation-menus.h
@@ -0,0 +1,32 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * animation-menus.c
+ * Copyright (C) 2016 Jehan <jehan gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ANIMATION_MENUS_H__
+#define __ANIMATION_MENUS_H__
+
+void animation_menu_cell (AnimationCelAnimation *animation,
+                          GdkEventButton        *event,
+                          gint                   frame,
+                          gint                   track);
+
+#endif  /*  __ANIMATION_MENUS_H__  */
+
+
+
diff --git a/plug-ins/animation-play/widgets/animation-xsheet.c 
b/plug-ins/animation-play/widgets/animation-xsheet.c
index 145250b..c5f84bd 100755
--- a/plug-ins/animation-play/widgets/animation-xsheet.c
+++ b/plug-ins/animation-play/widgets/animation-xsheet.c
@@ -33,6 +33,7 @@
 #include "core/animation-celanimation.h"
 
 #include "animation-layer-view.h"
+#include "animation-menus.h"
 
 #include "animation-xsheet.h"
 
@@ -1384,7 +1385,6 @@ animation_xsheet_cel_clicked (GtkWidget       *button,
   /* Left click */
   if (event->button == 1)
     {
-
       if ((! shift && ! ctrl)                                         ||
           (xsheet->priv->selected_track >= 0 &&
            xsheet->priv->selected_track != GPOINTER_TO_INT (track_num)))
@@ -1602,6 +1602,12 @@ animation_xsheet_cel_clicked (GtkWidget       *button,
       xsheet->priv->suite_button = button;
       gtk_widget_show (xsheet->priv->suite_box);
     }
+  else if (event->type == GDK_BUTTON_RELEASE && event->button == 3)
+    {
+      animation_menu_cell (xsheet->priv->animation, event,
+                           GPOINTER_TO_INT (position),
+                           GPOINTER_TO_INT (track_num));
+    }
 
   /* All handled here. */
   return TRUE;


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