[gthumb] animations: allow to pause and view the next frame



commit 08ed16a3436edd45c385a7923e624bac6af2340a
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Jan 2 14:33:18 2016 +0100

    animations: allow to pause and view the next frame

 extensions/image_viewer/actions.c               |   37 ++++++++++++++
 extensions/image_viewer/actions.h               |    2 +
 extensions/image_viewer/gth-image-viewer-page.c |   58 +++++++++++++++++++----
 gthumb/gth-browser.c                            |    3 +-
 4 files changed, 89 insertions(+), 11 deletions(-)
---
diff --git a/extensions/image_viewer/actions.c b/extensions/image_viewer/actions.c
index 53dbddb..d0c4703 100644
--- a/extensions/image_viewer/actions.c
+++ b/extensions/image_viewer/actions.c
@@ -195,3 +195,40 @@ gth_browser_activate_image_zoom  (GSimpleAction    *action,
        else if (strcmp (state, "300") == 0)
                gth_image_viewer_set_zoom (image_viewer, 3.0);
 }
+
+
+void
+gth_browser_activate_toggle_animation (GSimpleAction   *action,
+                                      GVariant         *state,
+                                      gpointer          user_data)
+{
+       GthBrowser     *browser = user_data;
+       GthViewerPage  *viewer_page;
+       GthImageViewer *image_viewer;
+
+       g_simple_action_set_state (action, state);
+
+       viewer_page = gth_browser_get_viewer_page (browser);
+       image_viewer = GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE 
(viewer_page)));
+
+       if (gth_image_viewer_is_playing_animation (image_viewer))
+               gth_image_viewer_stop_animation (image_viewer);
+       else
+               gth_image_viewer_start_animation (image_viewer);
+       gth_viewer_page_update_sensitivity (viewer_page);
+}
+
+
+void
+gth_browser_activate_step_animation (GSimpleAction     *action,
+                                    GVariant           *state,
+                                    gpointer            user_data)
+{
+       GthBrowser     *browser = user_data;
+       GthViewerPage  *viewer_page;
+       GthImageViewer *image_viewer;
+
+       viewer_page = gth_browser_get_viewer_page (browser);
+       image_viewer = GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE 
(viewer_page)));
+       gth_image_viewer_step_animation (image_viewer);
+}
diff --git a/extensions/image_viewer/actions.h b/extensions/image_viewer/actions.h
index ea6c2d9..9ed216f 100644
--- a/extensions/image_viewer/actions.h
+++ b/extensions/image_viewer/actions.h
@@ -37,5 +37,7 @@ DEF_ACTION_CALLBACK (gth_browser_activate_copy_image)
 DEF_ACTION_CALLBACK (gth_browser_activate_paste_image)
 DEF_ACTION_CALLBACK (gth_browser_activate_apply_icc_profile)
 DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom)
+DEF_ACTION_CALLBACK (gth_browser_activate_toggle_animation)
+DEF_ACTION_CALLBACK (gth_browser_activate_step_animation)
 
 #endif /* ACTIONS_H */
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index 061cf69..a88769d 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -30,11 +30,13 @@
 
 #define UPDATE_QUALITY_DELAY 200
 #define UPDATE_VISIBILITY_DELAY 100
-#define N_HEADER_BAR_BUTTONS 4
+#define N_HEADER_BAR_BUTTONS 6
 #define HIDE_OVERVIEW_TIMEOUT 2 /* in seconds */
 #define OVERLAY_MARGIN 10
 #define ZOOM_BUTTON 2
 #define APPLY_ICC_PROFILE_BUTTON 3
+#define TOGGLE_ANIMATION_BUTTON 4
+#define STEP_ANIMATION_BUTTON 5
 #undef ALWAYS_LOAD_ORIGINAL_SIZE
 
 
@@ -61,6 +63,8 @@ static const GActionEntry actions[] = {
        { "copy-image", gth_browser_activate_copy_image },
        { "paste-image", gth_browser_activate_paste_image },
        { "apply-icc-profile", toggle_action_activated, NULL, "true", gth_browser_activate_apply_icc_profile 
},
+       { "toggle-animation", toggle_action_activated, NULL, "true", gth_browser_activate_toggle_animation },
+       { "step-animation", gth_browser_activate_step_animation },
        { "image-zoom", gth_browser_activate_image_zoom, "s", "''", NULL },
 };
 
@@ -959,6 +963,21 @@ gth_image_viewer_page_real_activate (GthViewerPage *base,
                                                                  "win.apply-icc-profile",
                                                                  NULL);
 
+       self->priv->buttons[TOGGLE_ANIMATION_BUTTON] =
+                       gth_browser_add_header_bar_toggle_button (browser,
+                                                                 GTH_BROWSER_HEADER_SECTION_VIEWER_COMMANDS,
+                                                                 "media-playback-start-symbolic",
+                                                                 _("Play"),
+                                                                 "win.toggle-animation",
+                                                                 NULL);
+       self->priv->buttons[STEP_ANIMATION_BUTTON] =
+                       gth_browser_add_header_bar_button (browser,
+                                                          GTH_BROWSER_HEADER_SECTION_VIEWER_COMMANDS,
+                                                          "media-skip-forward-symbolic",
+                                                          _("Next frame"),
+                                                          "win.step-animation",
+                                                          NULL);
+
        gth_window_add_accelerators (GTH_WINDOW (browser), accelerators, G_N_ELEMENTS (accelerators));
 
        self->priv->preloader = gth_browser_get_image_preloader (browser);
@@ -1338,6 +1357,7 @@ gth_image_viewer_page_real_update_sensitivity (GthViewerPage *base)
 {
        GthImageViewerPage *self;
        GthImage           *image;
+       gboolean            is_animation;
 
        self = (GthImageViewerPage*) base;
 
@@ -1348,6 +1368,11 @@ gth_image_viewer_page_real_update_sensitivity (GthViewerPage *base)
        gtk_widget_set_visible (self->priv->buttons[APPLY_ICC_PROFILE_BUTTON], (image != NULL) && 
(gth_image_get_icc_profile (image) != NULL));
        gth_window_enable_action (GTH_WINDOW (self->priv->browser), "apply-icc-profile", (image != NULL) && 
(gth_image_get_icc_profile (image) != NULL));
 
+       is_animation = gth_image_viewer_is_animation (GTH_IMAGE_VIEWER (self->priv->viewer));
+       gtk_widget_set_visible (self->priv->buttons[TOGGLE_ANIMATION_BUTTON], is_animation);
+       gtk_widget_set_visible (self->priv->buttons[STEP_ANIMATION_BUTTON], is_animation);
+       gth_window_enable_action (GTH_WINDOW (self->priv->browser), "step-animation", ! 
gth_image_viewer_is_playing_animation (GTH_IMAGE_VIEWER (self->priv->viewer)));
+
        _gth_image_viewer_page_update_paste_command_sensitivity (self, NULL);
 
        update_zoom_info (self);
@@ -2062,15 +2087,28 @@ gth_image_viewer_page_get_original (GthImageViewerPage   *self,
                                                  gth_image_viewer_page_get_original);
        data->cancellable = (cancellable != NULL) ? g_object_ref (cancellable) : g_cancellable_new ();
 
-       _gth_image_preloader_init_preloader (self);
-       gth_image_preloader_load (self->priv->preloader,
-                                 self->priv->image_changed ? GTH_MODIFIED_IMAGE : self->priv->file_data,
-                                 GTH_ORIGINAL_SIZE,
-                                 data->cancellable,
-                                 original_image_ready_cb,
-                                 data,
-                                 GTH_NO_PRELOADERS,
-                                 NULL);
+       if (gth_image_viewer_is_animation (GTH_IMAGE_VIEWER (self->priv->viewer))) {
+               GthImage *image;
+
+               image = gth_image_new_for_surface (gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER 
(self->priv->viewer)));
+               g_simple_async_result_set_op_res_gpointer (data->result,
+                                                          image,
+                                                          (GDestroyNotify) g_object_unref);
+               g_simple_async_result_complete_in_idle (data->result);
+
+               get_original_data_free (data);
+       }
+       else {
+               _gth_image_preloader_init_preloader (self);
+               gth_image_preloader_load (self->priv->preloader,
+                                         self->priv->image_changed ? GTH_MODIFIED_IMAGE : 
self->priv->file_data,
+                                         GTH_ORIGINAL_SIZE,
+                                         data->cancellable,
+                                         original_image_ready_cb,
+                                         data,
+                                         GTH_NO_PRELOADERS,
+                                         NULL);
+       }
 }
 
 
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index ea574d2..1a59546 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -4408,7 +4408,7 @@ gth_browser_init (GthBrowser *browser)
                gboolean separated_buttons;
 
                separated_buttons = ((i == GTH_BROWSER_HEADER_SECTION_BROWSER_TOOLS)
-                                    || (i == GTH_BROWSER_HEADER_SECTION_VIEWER_OTHER_COMMANDS)
+                                    /*|| (i == GTH_BROWSER_HEADER_SECTION_VIEWER_OTHER_COMMANDS)*/
                                     /*|| (i == GTH_BROWSER_HEADER_SECTION_VIEWER_SIDEBAR)*/
                                     || (i == GTH_BROWSER_HEADER_SECTION_VIEWER_OTHER_VIEW)
                                     /*|| (i == GTH_BROWSER_HEADER_SECTION_VIEWER_EDIT)*/
@@ -4438,6 +4438,7 @@ gth_browser_init (GthBrowser *browser)
                gtk_widget_set_margin_left 
(browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_VIEWER_VIEW], GTH_BROWSER_HEADER_BAR_BIG_MARGIN);
                gtk_widget_set_margin_left 
(browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_VIEWER_OTHER_VIEW], 
GTH_BROWSER_HEADER_BAR_BIG_MARGIN);
                gtk_widget_set_margin_left 
(browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_VIEWER_COMMANDS], 
GTH_BROWSER_HEADER_BAR_BIG_MARGIN);
+               gtk_widget_set_margin_left 
(browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_VIEWER_OTHER_COMMANDS], 
GTH_BROWSER_HEADER_BAR_BIG_MARGIN);
                gtk_widget_set_margin_left 
(browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_EDITOR_VIEW], GTH_BROWSER_HEADER_BAR_BIG_MARGIN);
                gtk_widget_set_margin_right 
(browser->priv->header_sections[GTH_BROWSER_HEADER_SECTION_EDITOR_COMMANDS], 
GTH_BROWSER_HEADER_BAR_BIG_MARGIN);
 


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