[gthumb] video viewer: show the zoom factor in the statusbar



commit 24895899dc5b2178c7f6b6701ce171bdf7fc2d94
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Feb 13 17:53:01 2020 +0100

    video viewer: show the zoom factor in the statusbar

 extensions/gstreamer_tools/gth-media-viewer-page.c | 54 ++++++++++++++++++++++
 1 file changed, 54 insertions(+)
---
diff --git a/extensions/gstreamer_tools/gth-media-viewer-page.c 
b/extensions/gstreamer_tools/gth-media-viewer-page.c
index 292d7704..e3f9e97d 100644
--- a/extensions/gstreamer_tools/gth-media-viewer-page.c
+++ b/extensions/gstreamer_tools/gth-media-viewer-page.c
@@ -56,6 +56,8 @@ struct _GthMediaViewerPagePrivate {
        gint64          duration;
        int             video_fps_n;
        int             video_fps_d;
+       int             video_width;
+       int             video_height;
        gboolean        has_video;
        gboolean        has_audio;
        gulong          update_progress_id;
@@ -170,6 +172,52 @@ video_area_unrealize_cb (GtkWidget *widget,
 }
 
 
+static void
+update_zoom_info (GthMediaViewerPage *self)
+{
+       GtkAllocation  allocation;
+       double         view_width;
+       double         view_height;
+       int            zoom;
+       char          *text;
+
+       if (! self->priv->has_video) {
+               gth_statusbar_set_secondary_text (GTH_STATUSBAR (gth_browser_get_statusbar 
(self->priv->browser)), "");
+               return;
+       }
+
+       gtk_widget_get_allocation (self->priv->video_area, &allocation);
+
+       view_width = allocation.width;
+       view_height = (((double) self->priv->video_height / self->priv->video_width) * view_width);
+       if (view_height > allocation.height) {
+               view_height = allocation.height;
+               view_width = (((double) self->priv->video_width / self->priv->video_height) * view_height);
+       }
+
+       if (self->priv->video_width > 0)
+               zoom = (int) round ((double) view_width / self->priv->video_width * 100);
+       else if (self->priv->video_height > 0)
+               zoom = (int) round ((double) view_height / self->priv->video_height * 100);
+       else
+               zoom = 100;
+       text = g_strdup_printf ("  %d%%  ", zoom);
+       gth_statusbar_set_secondary_text (GTH_STATUSBAR (gth_browser_get_statusbar (self->priv->browser)), 
text);
+
+       g_free (text);
+}
+
+
+static void
+video_area_size_allocate_cb (GtkWidget    *widget,
+                            GdkRectangle *allocation,
+                            gpointer      user_data)
+{
+       GthMediaViewerPage *self = user_data;
+       update_zoom_info (self);
+}
+
+
 static gboolean
 video_area_draw_cb (GtkWidget *widget,
                    cairo_t   *cr,
@@ -662,6 +710,8 @@ update_stream_info (GthMediaViewerPage *self)
                                        g_file_info_set_attribute_int32 (self->priv->updated_info, 
"frame::width", video_width);
                                        g_file_info_set_attribute_int32 (self->priv->updated_info, 
"frame::height", video_height);
                                        self->priv->has_video = TRUE;
+                                       self->priv->video_width = video_width;
+                                       self->priv->video_height = video_height;
                                }
 
                                gst_caps_unref (caps);
@@ -826,6 +876,10 @@ create_playbin (GthMediaViewerPage *self)
                          "unrealize",
                          G_CALLBACK (video_area_unrealize_cb),
                          self);
+       g_signal_connect (G_OBJECT (self->priv->video_area),
+                         "size-allocate",
+                         G_CALLBACK (video_area_size_allocate_cb),
+                         self);
 
        gtk_stack_add_named (GTK_STACK (self->priv->area_box), self->priv->video_area, "video-area");
        gtk_widget_show (self->priv->video_area);


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