[gnome-boxes] collection-view: Favorite emblem to bottom left



commit 8fd7955dea4f3bd694bc0c3d53d0a8d120ff3f8b
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Tue Jun 23 10:12:43 2015 +0200

    collection-view: Favorite emblem to bottom left
    
    This moves the "favorites" emblem to the bottom left corner of the
    thumbnails and draws it smaller.
    
    This is needed to comply to GNOME's HIG and to make sure the "favorites"
    emblem don't conflict with the item's selection checkbox.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=745757

 src/collection-view.vala |   55 ++++++++++++++++++++++++++++++----------------
 1 files changed, 36 insertions(+), 19 deletions(-)
---
diff --git a/src/collection-view.vala b/src/collection-view.vala
index abcc628..c9afde5 100644
--- a/src/collection-view.vala
+++ b/src/collection-view.vala
@@ -37,6 +37,13 @@ private class Boxes.CollectionView: Gd.MainView, Boxes.UI {
     private Boxes.ActionsPopover context_popover;
     private GLib.List<CollectionItem> hidden_items;
 
+    private const Gtk.CornerType[] right_corners = { Gtk.CornerType.TOP_RIGHT, Gtk.CornerType.BOTTOM_RIGHT };
+    private const Gtk.CornerType[] bottom_corners = { Gtk.CornerType.BOTTOM_LEFT, 
Gtk.CornerType.BOTTOM_RIGHT };
+
+    public const Gdk.RGBA SMALL_EMBLEM_COLOR = { 1.0, 1.0, 1.0, 1.0 };
+    public const int SMALL_EMBLEM_SIZE = 16;
+    public const int EMBLEM_PADDING = 8;
+
     construct {
         category = new Category (_("New and Recent"), Category.Kind.NEW);
         hidden_items = new GLib.List<CollectionItem> ();
@@ -67,7 +74,6 @@ private class Boxes.CollectionView: Gd.MainView, Boxes.UI {
 
     private void update_screenshot (Gtk.TreeIter iter) {
         CollectionItem item;
-        GLib.Icon[] emblem_icons = {};
 
         store.get (iter, ModelColumns.ITEM, out item);
         Machine machine = item as Machine;
@@ -75,29 +81,40 @@ private class Boxes.CollectionView: Gd.MainView, Boxes.UI {
         var pixbuf = machine.pixbuf;
 
         if ("favorite" in machine.config.categories)
-            emblem_icons += create_symbolic_emblem ("emblem-favorite");
-
-        if (emblem_icons.length > 0) {
-            var emblemed_icon = new GLib.EmblemedIcon (pixbuf, null);
-            foreach (var emblem_icon in emblem_icons)
-                emblemed_icon.add_emblem (new GLib.Emblem (emblem_icon));
-
-            var theme = Gtk.IconTheme.get_default ();
-
-            try {
-                var size = int.max (pixbuf.width, pixbuf.height);
-                var icon_info = theme.lookup_by_gicon (emblemed_icon, size,
-                                                       Gtk.IconLookupFlags.FORCE_SIZE);
-                pixbuf = icon_info.load_icon ();
-            } catch (GLib.Error error) {
-                warning ("Unable to render the emblem: " + error.message);
-            }
-        }
+            pixbuf = add_emblem_icon (pixbuf, "emblem-favorite-symbolic", Gtk.CornerType.BOTTOM_LEFT);
 
         store.set (iter, ModelColumns.SCREENSHOT, pixbuf);
         queue_draw ();
     }
 
+    private Gdk.Pixbuf add_emblem_icon (Gdk.Pixbuf pixbuf, string icon_name, Gtk.CornerType corner_type) {
+        Gdk.Pixbuf? emblem = null;
+
+        var theme = Gtk.IconTheme.get_default ();
+        try {
+            var icon_info = theme.lookup_icon (icon_name, SMALL_EMBLEM_SIZE, Gtk.IconLookupFlags.FORCE_SIZE);
+            emblem = icon_info.load_symbolic (SMALL_EMBLEM_COLOR);
+        } catch (GLib.Error error) {
+            warning (@"Unable to get icon '$icon_name': $(error.message)");
+            return pixbuf;
+        }
+
+        if (emblem == null)
+            return pixbuf;
+
+        var offset_x = corner_type in right_corners ? pixbuf.width - emblem.width - EMBLEM_PADDING :
+                                                      EMBLEM_PADDING;
+
+        var offset_y = corner_type in bottom_corners ? pixbuf.height - emblem.height - EMBLEM_PADDING :
+                                                       EMBLEM_PADDING;
+
+        var emblemed = pixbuf.copy ();
+        emblem.composite (emblemed, offset_x, offset_y, SMALL_EMBLEM_SIZE, SMALL_EMBLEM_SIZE,
+                          offset_x, offset_y, 1.0, 1.0, Gdk.InterpType.BILINEAR, 255);
+
+        return emblemed;
+    }
+
     private Gtk.TreeIter append (string title,
                                  string? info,
                                  CollectionItem item) {


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