[easytag/wip/future-gtk: 2/17] Handle UI scale factor in images tree view



commit 5184109a7ca30f52f792bd7324ce25b74625a5f9
Author: David King <amigadave amigadave com>
Date:   Fri Jan 9 18:58:54 2015 +0000

    Handle UI scale factor in images tree view

 README           |    2 +-
 configure.ac     |    4 ++--
 data/tag_area.ui |    4 ++--
 src/tag_area.c   |   41 ++++++++++++++++++++++++++++-------------
 4 files changed, 33 insertions(+), 18 deletions(-)
---
diff --git a/README b/README
index 67448f9..33fa09a 100644
--- a/README
+++ b/README
@@ -58,7 +58,7 @@ Installation
 ### Requirements
 
 * GLib version greater than 2.32.0 (http://www.gtk.org)
-* GTK+ version greater than 3.4.0 (http://www.gtk.org)
+* GTK+ version greater than 3.10.0 (http://www.gtk.org)
 * libid3tag (http://www.underbit.com/products/mad) (if not deactivated by './configure --disable-mp3')
 * id3lib version greater than 3.7.12 (http://id3lib.sourceforge.net) (Recommended: id3lib-3.8.3) (if not 
deactivated by './configure --disable-id3v23')
 * flac (http://flac.sourceforge.net) (if not deactivated by './configure --disable-flac')
diff --git a/configure.ac b/configure.ac
index 29d159a..bb80874 100644
--- a/configure.ac
+++ b/configure.ac
@@ -337,9 +337,9 @@ dnl Check the pkg-config dependencies
 GIO_DEPS="gio-2.0 >= 2.32.0" dnl For g_file_new_tmp()
 AC_SUBST([GLIB_DEPRECATION_FLAGS],
          ["-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"])
-GTK_DEPS="gtk+-3.0 >= 3.4.0"
+GTK_DEPS="gtk+-3.0 >= 3.10.0"
 AC_SUBST([GTK_DEPRECATION_FLAGS],
-         ["-DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_4 -DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_3_4"])
+         ["-DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_10 -DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_3_10"])
 PKG_CHECK_MODULES([EASYTAG], [$GIO_DEPS $GTK_DEPS $OPUS_DEPS $OGG_DEPS $SPEEX_DEPS $FLAC_DEPS $ID3TAG_DEPS 
$TAGLIB_DEPS $WAVPACK_DEPS])
 
 dnl Check for winsock
diff --git a/data/tag_area.ui b/data/tag_area.ui
index f555fd6..6281f8d 100644
--- a/data/tag_area.ui
+++ b/data/tag_area.ui
@@ -7,7 +7,7 @@
     </object>
     <object class="GtkListStore" id="images_model">
         <columns>
-            <column type="GdkPixbuf"/>
+            <column type="CairoSurface"/>
             <column type="gchararray"/>
             <column type="EtPicture"/>
         </columns>
@@ -534,7 +534,7 @@
                                         <child>
                                             <object class="GtkCellRendererPixbuf" 
id="images_thumbnail_renderer"/>
                                             <attributes>
-                                                <attribute name="pixbuf">0</attribute>
+                                                <attribute name="surface">0</attribute>
                                             </attributes>
                                         </child>
                                         <child>
diff --git a/src/tag_area.c b/src/tag_area.c
index 9b6268f..e888bda 100644
--- a/src/tag_area.c
+++ b/src/tag_area.c
@@ -115,7 +115,7 @@ enum
 
 enum /* Columns for picture_entry_view. */
 {
-    PICTURE_COLUMN_PIC,
+    PICTURE_COLUMN_SURFACE,
     PICTURE_COLUMN_TEXT,
     PICTURE_COLUMN_DATA,
     PICTURE_COLUMN_COUNT
@@ -1294,7 +1294,10 @@ PictureEntry_Update (EtTagArea *self,
             if (pixbuf)
             {
                 GtkTreeIter iter1;
+                gint scale_factor;
                 GdkPixbuf *scaled_pixbuf;
+                cairo_surface_t *surface;
+                GdkWindow *view_window;
                 gint scaled_pixbuf_width;
                 gint scaled_pixbuf_height;
                 gchar *pic_info;
@@ -1305,28 +1308,40 @@ PictureEntry_Update (EtTagArea *self,
                 // Keep aspect ratio of the picture
                 pic->width  = gdk_pixbuf_get_width(pixbuf);
                 pic->height = gdk_pixbuf_get_height(pixbuf);
+                /* TODO: Connect to notify:scale-factor and update when the
+                 * scale changes. */
+                scale_factor = gtk_widget_get_scale_factor (priv->picture_entry_view);
+
                 if (pic->width > pic->height)
                 {
-                    scaled_pixbuf_width  = 96;
-                    scaled_pixbuf_height = 96 * pic->height / pic->width;
+                    scaled_pixbuf_width = 96 * scale_factor;
+                    scaled_pixbuf_height = 96 * scale_factor * pic->height
+                                           / pic->width;
                 }else
                 {
-                    scaled_pixbuf_width = 96 * pic->width / pic->height;
-                    scaled_pixbuf_height = 96;
+                    scaled_pixbuf_width = 96 * scale_factor * pic->width
+                                          / pic->height;
+                    scaled_pixbuf_height = 96 * scale_factor;
                 }
 
-                scaled_pixbuf = gdk_pixbuf_scale_simple(pixbuf,
-                                    scaled_pixbuf_width, scaled_pixbuf_height,
-                                    //GDK_INTERP_NEAREST); // Lower quality but better speed
-                                    GDK_INTERP_BILINEAR);
-                g_object_unref(pixbuf);
-
+                scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+                                                         scaled_pixbuf_width,
+                                                         scaled_pixbuf_height,
+                                                         GDK_INTERP_BILINEAR);
+                g_object_unref (pixbuf);
+
+                /* This ties the model to the view, so if the model is to be
+                 * shared in the future, the surface should be per-view. */
+                view_window = gtk_widget_get_window (priv->picture_entry_view);
+                surface = gdk_cairo_surface_create_from_pixbuf (scaled_pixbuf,
+                                                                scale_factor,
+                                                                view_window);
                 pic_info = et_picture_format_info (pic,
                                                    ETCore->ETFileDisplayed->ETFileDescription->TagType);
                 gtk_list_store_insert_with_values (priv->images_model, &iter1,
                                                    G_MAXINT,
-                                                   PICTURE_COLUMN_PIC,
-                                                   scaled_pixbuf,
+                                                   PICTURE_COLUMN_SURFACE,
+                                                   surface,
                                                    PICTURE_COLUMN_TEXT,
                                                    pic_info,
                                                    PICTURE_COLUMN_DATA,


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