[gimp/wip/animation: 268/373] plug-ins: scroll to storyboard panel corresponding to playback position.



commit 261cf51ed5c21b3c6db5f251f2a607838dda4eaf
Author: Jehan <jehan girinstud io>
Date:   Sun Nov 13 22:44:37 2016 +0100

    plug-ins: scroll to storyboard panel corresponding to playback position.
    
    The code used in AnimationXSheet moved to `utils` so that I could reuse
    it for any scrolled window. Thus I made the storyboard a native scrolled
    window.

 plug-ins/animation-play/animation-utils.c          |   42 ++++++++++++++++++
 plug-ins/animation-play/animation-utils.h          |   34 ++++++++------
 plug-ins/animation-play/widgets/animation-dialog.c |   22 +++++-----
 .../animation-play/widgets/animation-storyboard.c  |   34 +++++++++++----
 .../animation-play/widgets/animation-storyboard.h  |    4 +-
 plug-ins/animation-play/widgets/animation-xsheet.c |   46 ++------------------
 6 files changed, 103 insertions(+), 79 deletions(-)
---
diff --git a/plug-ins/animation-play/animation-utils.c b/plug-ins/animation-play/animation-utils.c
index 67b6a91..9692181 100755
--- a/plug-ins/animation-play/animation-utils.c
+++ b/plug-ins/animation-play/animation-utils.c
@@ -233,3 +233,45 @@ normal_blend (gint        width,
 
   return buffer;
 }
+
+void
+show_scrolled_child (GtkScrolledWindow *window,
+                     GtkWidget         *child)
+{
+  GtkWidget     *contents = gtk_bin_get_child (GTK_BIN (window));
+  GtkAdjustment *hadj;
+  GtkAdjustment *vadj;
+  GtkAllocation  window_allocation;
+  GtkAllocation  child_allocation;
+  gint           x;
+  gint           y;
+  gint           x_xsheet;
+  gint           y_xsheet;
+
+  hadj = gtk_scrolled_window_get_vadjustment (window);
+  vadj = gtk_scrolled_window_get_vadjustment (window);
+
+  /* Handling both contents with native scroll abilities, and
+     contents added with a viewport. */
+  if (GTK_IS_VIEWPORT (contents))
+    contents = gtk_bin_get_child (GTK_BIN (contents));
+
+  gtk_widget_translate_coordinates (child, GTK_WIDGET (window),
+                                    0, 0, &x_xsheet, &y_xsheet);
+  gtk_widget_translate_coordinates (child, contents,
+                                    0, 0, &x, &y);
+
+  gtk_widget_get_allocation (child, &child_allocation);
+  gtk_widget_get_allocation (GTK_WIDGET (window),
+                             &window_allocation);
+
+  /* Scroll only if the widget is not already visible. */
+  if (x_xsheet < 0 || x_xsheet + child_allocation.width > window_allocation.width)
+    {
+      gtk_adjustment_set_value (hadj, x);
+    }
+  if (y_xsheet < 0 || y_xsheet + child_allocation.height > window_allocation.height)
+    {
+      gtk_adjustment_set_value (vadj, y);
+    }
+}
diff --git a/plug-ins/animation-play/animation-utils.h b/plug-ins/animation-play/animation-utils.h
index bb5a34f..704bd40 100755
--- a/plug-ins/animation-play/animation-utils.h
+++ b/plug-ins/animation-play/animation-utils.h
@@ -21,6 +21,8 @@
 #ifndef __ANIMATION_UTILS_H__
 #define __ANIMATION_UTILS_H__
 
+#include <gtk/gtk.h>
+
 #define PLUG_IN_PROC       "plug-in-animationplay"
 #define PLUG_IN_BINARY     "animation-play"
 #define PLUG_IN_ROLE       "gimp-animation-playback"
@@ -28,21 +30,23 @@
 #define MAX_FRAMERATE      300.0
 #define DEFAULT_FRAMERATE  24.0
 
-void         total_alpha_preview (guchar     *drawing_data,
-                                  guint       drawing_width,
-                                  guint       drawing_height);
-
-GeglBuffer * normal_blend        (gint        width,
-                                  gint        height,
-                                  GeglBuffer *backdrop,
-                                  gdouble     backdrop_scale_ratio,
-                                  gint        backdrop_offset_x,
-                                  gint        backdrop_offset_y,
-                                  GeglBuffer *source,
-                                  gdouble     source_scale_ratio,
-                                  gint        source_offset_x,
-                                  gint        source_offset_y);
-
+void         total_alpha_preview (guchar            *drawing_data,
+                                  guint              drawing_width,
+                                  guint              drawing_height);
+
+GeglBuffer * normal_blend        (gint               width,
+                                  gint               height,
+                                  GeglBuffer        *backdrop,
+                                  gdouble            backdrop_scale_ratio,
+                                  gint               backdrop_offset_x,
+                                  gint               backdrop_offset_y,
+                                  GeglBuffer        *source,
+                                  gdouble            source_scale_ratio,
+                                  gint               source_offset_x,
+                                  gint               source_offset_y);
+
+void         show_scrolled_child (GtkScrolledWindow *window,
+                                  GtkWidget         *child);
 #endif  /*  __ANIMATION_UTILS_H__  */
 
 
diff --git a/plug-ins/animation-play/widgets/animation-dialog.c 
b/plug-ins/animation-play/widgets/animation-dialog.c
index 261a77c..a41d3f7 100755
--- a/plug-ins/animation-play/widgets/animation-dialog.c
+++ b/plug-ins/animation-play/widgets/animation-dialog.c
@@ -1161,7 +1161,6 @@ animation_dialog_set_animation (AnimationDialog *dialog,
                                 Animation       *animation)
 {
   AnimationDialogPrivate *priv = GET_PRIVATE (dialog);
-  GtkWidget              *scrolled_win;
   GtkWidget              *frame;
   gchar                  *text;
   gdouble                 fps;
@@ -1300,23 +1299,17 @@ animation_dialog_set_animation (AnimationDialog *dialog,
     gtk_notebook_remove_page (GTK_NOTEBOOK (priv->right_notebook), 0);
   priv->layer_list = NULL;
 
-  scrolled_win = gtk_scrolled_window_new (NULL, NULL);
-  gtk_notebook_prepend_page (GTK_NOTEBOOK (priv->right_notebook),
-                             scrolled_win, NULL);
-  gtk_widget_show (scrolled_win);
-
   if (ANIMATION_IS_ANIMATIC (animation))
     {
       GtkWidget *storyboard;
 
-      gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (priv->right_notebook),
-                                       scrolled_win, _("Storyboard"));
-
       /* The Storyboard view. */
       storyboard = animation_storyboard_new (ANIMATION_ANIMATIC (animation),
                                              priv->playback);
-      gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win),
-                                             storyboard);
+      gtk_notebook_prepend_page (GTK_NOTEBOOK (priv->right_notebook),
+                                 storyboard, NULL);
+      gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (priv->right_notebook),
+                                       storyboard, _("Storyboard"));
       gtk_widget_show (storyboard);
 
       /* The animation type box. */
@@ -1324,6 +1317,13 @@ animation_dialog_set_animation (AnimationDialog *dialog,
     }
   else
     {
+      GtkWidget *scrolled_win;
+
+      scrolled_win = gtk_scrolled_window_new (NULL, NULL);
+      gtk_notebook_prepend_page (GTK_NOTEBOOK (priv->right_notebook),
+                                 scrolled_win, NULL);
+      gtk_widget_show (scrolled_win);
+
       gtk_notebook_set_tab_label_text (GTK_NOTEBOOK (priv->right_notebook),
                                        scrolled_win, _("Layers"));
 
diff --git a/plug-ins/animation-play/widgets/animation-storyboard.c 
b/plug-ins/animation-play/widgets/animation-storyboard.c
index 3d38e40..286906d 100644
--- a/plug-ins/animation-play/widgets/animation-storyboard.c
+++ b/plug-ins/animation-play/widgets/animation-storyboard.c
@@ -27,6 +27,8 @@
 
 #include "libgimp/stdplugins-intl.h"
 
+#include "animation-utils.h"
+
 #include "core/animation-animatic.h"
 #include "core/animation-playback.h"
 
@@ -85,7 +87,7 @@ static void animation_storyboard_disposal_toggled      (GtkToggleButton     *but
 static void animation_storyboard_button_clicked        (GtkWidget           *widget,
                                                         AnimationStoryboard *storyboard);
 
-G_DEFINE_TYPE (AnimationStoryboard, animation_storyboard, GTK_TYPE_TABLE)
+G_DEFINE_TYPE (AnimationStoryboard, animation_storyboard, GTK_TYPE_SCROLLED_WINDOW)
 
 #define parent_class animation_storyboard_parent_class
 
@@ -120,8 +122,6 @@ animation_storyboard_init (AnimationStoryboard *view)
   view->priv = G_TYPE_INSTANCE_GET_PRIVATE (view,
                                             ANIMATION_TYPE_STORYBOARD,
                                             AnimationStoryboardPrivate);
-
-  gtk_table_set_homogeneous (GTK_TABLE (view), TRUE);
 }
 
 /**** Public Functions ****/
@@ -144,6 +144,7 @@ animation_storyboard_new (AnimationAnimatic *animation,
                              NULL);
   storyboard = ANIMATION_STORYBOARD (layer_view);
   storyboard->priv->playback = playback;
+
   return layer_view;
 }
 
@@ -153,10 +154,19 @@ static void
 animation_storyboard_constructed (GObject *object)
 {
   AnimationStoryboard *view = ANIMATION_STORYBOARD (object);
+  GtkWidget           *layout;
 
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view),
+                                  GTK_POLICY_AUTOMATIC,
+                                  GTK_POLICY_AUTOMATIC);
+
+  layout = gtk_table_new (1, 1, FALSE);
+  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (view),
+                                         layout);
   g_signal_connect (view->priv->animation, "loaded",
                     (GCallback) animation_storyboard_load,
                     view);
+  gtk_widget_show (layout);
 }
 
 static void
@@ -235,6 +245,7 @@ animation_storyboard_load (Animation           *animation,
                            AnimationStoryboard *view)
 {
   AnimationAnimatic *animatic = ANIMATION_ANIMATIC (animation);
+  GtkWidget         *layout;
   gint              *layers;
   gint32             image_id;
   gint               n_images;
@@ -244,8 +255,12 @@ animation_storyboard_load (Animation           *animation,
   image_id = gimp_image_duplicate (image_id);
   gimp_image_undo_disable (image_id);
 
+  /* The actual layout is the grand-child. */
+  layout = gtk_bin_get_child (GTK_BIN (view));
+  layout = gtk_bin_get_child (GTK_BIN (layout));
+
   /* Cleaning previous loads. */
-  gtk_container_foreach (GTK_CONTAINER (view),
+  gtk_container_foreach (GTK_CONTAINER (layout),
                          (GtkCallback) gtk_widget_destroy,
                          NULL);
   if (view->priv->panel_buttons)
@@ -268,7 +283,7 @@ animation_storyboard_load (Animation           *animation,
   layers = gimp_image_get_layers (image_id,
                                   &n_images);
 
-  gtk_table_resize (GTK_TABLE (view),
+  gtk_table_resize (GTK_TABLE (layout),
                     5 * n_images,
                     9);
 
@@ -288,7 +303,7 @@ animation_storyboard_load (Animation           *animation,
                                 0.5, 0.5);
       gtk_button_set_relief (GTK_BUTTON (panel_button),
                              GTK_RELIEF_NONE);
-      gtk_table_attach (GTK_TABLE (view),
+      gtk_table_attach (GTK_TABLE (layout),
                         panel_button, 0, 4,
                         5 * panel_num,
                         5 * (panel_num + 1),
@@ -321,7 +336,7 @@ animation_storyboard_load (Animation           *animation,
       comment = gtk_text_view_new ();
       g_object_set_data (G_OBJECT (comment), "panel-num",
                          GINT_TO_POINTER (panel_num));
-      gtk_table_attach (GTK_TABLE (view),
+      gtk_table_attach (GTK_TABLE (layout),
                         comment, 5, 9,
                         5 * panel_num,
                         5 * (panel_num + 1),
@@ -371,7 +386,7 @@ animation_storyboard_load (Animation           *animation,
       /* Allowing non-numeric text to type "ms" or "s". */
       gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (duration), FALSE);
 
-      gtk_table_attach (GTK_TABLE (view),
+      gtk_table_attach (GTK_TABLE (layout),
                         duration, 4, 5,
                         5 * panel_num + 1,
                         5 * panel_num + 2,
@@ -393,7 +408,7 @@ animation_storyboard_load (Animation           *animation,
                                             GTK_ICON_SIZE_MENU);
       gtk_container_add (GTK_CONTAINER (disposal), image);
       gtk_widget_show (image);
-      gtk_table_attach (GTK_TABLE (view),
+      gtk_table_attach (GTK_TABLE (layout),
                         disposal, 4, 5,
                         5 * panel_num + 2,
                         5 * panel_num + 3,
@@ -440,6 +455,7 @@ animation_storyboard_rendered (AnimationPlayback   *playback,
                             view->priv->current_panel);
   gtk_button_set_relief (GTK_BUTTON (button),
                          GTK_RELIEF_NORMAL);
+  show_scrolled_child (GTK_SCROLLED_WINDOW (view), button);
 }
 
 static void
diff --git a/plug-ins/animation-play/widgets/animation-storyboard.h 
b/plug-ins/animation-play/widgets/animation-storyboard.h
index cb7452b..9d3b1ad 100644
--- a/plug-ins/animation-play/widgets/animation-storyboard.h
+++ b/plug-ins/animation-play/widgets/animation-storyboard.h
@@ -34,14 +34,14 @@ typedef struct _AnimationStoryboardPrivate AnimationStoryboardPrivate;
 
 struct _AnimationStoryboard
 {
-  GtkTable          parent_instance;
+  GtkScrolledWindow           parent_instance;
 
   AnimationStoryboardPrivate *priv;
 };
 
 struct _AnimationStoryboardClass
 {
-  GtkTableClass     parent_class;
+  GtkScrolledWindowClass      parent_class;
 };
 
 GType       animation_storyboard_get_type (void) G_GNUC_CONST;
diff --git a/plug-ins/animation-play/widgets/animation-xsheet.c 
b/plug-ins/animation-play/widgets/animation-xsheet.c
index 9870bb3..95e65cf 100755
--- a/plug-ins/animation-play/widgets/animation-xsheet.c
+++ b/plug-ins/animation-play/widgets/animation-xsheet.c
@@ -25,9 +25,12 @@
 
 #include <libgimp/gimp.h>
 
+#include "animation-utils.h"
+
 #include "core/animation.h"
 #include "core/animation-playback.h"
 #include "core/animation-celanimation.h"
+
 #include "animation-layer-view.h"
 
 #include "animation-xsheet.h"
@@ -124,8 +127,6 @@ static void     on_track_right_clicked               (GtkToolButton   *toolbutto
 static void     animation_xsheet_rename_cel          (AnimationXSheet *xsheet,
                                                       GtkWidget       *cel,
                                                       gboolean         recursively);
-static void     animation_xsheet_show_child          (AnimationXSheet *xsheet,
-                                                      GtkWidget       *child);
 
 G_DEFINE_TYPE (AnimationXSheet, animation_xsheet, GTK_TYPE_SCROLLED_WINDOW)
 
@@ -209,7 +210,6 @@ animation_xsheet_constructed (GObject *object)
                                          xsheet->priv->track_layout);
   gtk_table_set_row_spacings (GTK_TABLE (xsheet->priv->track_layout), 0);
   gtk_table_set_col_spacings (GTK_TABLE (xsheet->priv->track_layout), 0);
-
   gtk_widget_show (xsheet->priv->track_layout);
 
   /* Tie the layer view to the xsheet. */
@@ -863,7 +863,7 @@ on_animation_rendered (AnimationPlayback *playback,
                                 TRUE);
   xsheet->priv->active_pos_button = button;
 
-  animation_xsheet_show_child (xsheet, button);
+  show_scrolled_child (GTK_SCROLLED_WINDOW (xsheet), button);
 }
 
 static gboolean
@@ -1247,41 +1247,3 @@ animation_xsheet_rename_cel (AnimationXSheet *xsheet,
         }
     }
 }
-
-static void
-animation_xsheet_show_child (AnimationXSheet *xsheet,
-                             GtkWidget       *child)
-{
-  GtkScrolledWindow *window = GTK_SCROLLED_WINDOW (xsheet);
-  GtkAdjustment     *hadj;
-  GtkAdjustment     *vadj;
-  GtkAllocation      xsheet_allocation;
-  GtkAllocation      child_allocation;
-  gint               x;
-  gint               y;
-  gint               x_xsheet;
-  gint               y_xsheet;
-
-  hadj = gtk_scrolled_window_get_vadjustment (window);
-  vadj = gtk_scrolled_window_get_vadjustment (window);
-
-  gtk_widget_translate_coordinates (child, GTK_WIDGET (xsheet),
-                                    0, 0, &x_xsheet, &y_xsheet);
-  gtk_widget_translate_coordinates (child,
-                                    xsheet->priv->track_layout,
-                                    0, 0, &x, &y);
-
-  gtk_widget_get_allocation (child, &child_allocation);
-  gtk_widget_get_allocation (GTK_WIDGET (xsheet),
-                             &xsheet_allocation);
-
-  /* Scroll only if the widget is not already visible. */
-  if (x_xsheet < 0 || x_xsheet + child_allocation.width > xsheet_allocation.width)
-    {
-      gtk_adjustment_set_value (hadj, x);
-    }
-  if (y_xsheet < 0 || y_xsheet + child_allocation.height > xsheet_allocation.height)
-    {
-      gtk_adjustment_set_value (vadj, y);
-    }
-}


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