[gnome-documents] all: style symbolic emblems like in the mockups



commit c3a8667502c998bc29fbc67c6c409e9218e3a4e6
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Sep 12 10:31:38 2011 -0400

    all: style symbolic emblems like in the mockups
    
    Render white symbolic icons over a dark blue background as in the
    Documents mockup by Jakub.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=658826

 data/gtk-style.css |    9 ++++++-
 src/documents.js   |   16 +----------
 src/lib/gd-utils.c |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/lib/gd-utils.h |    3 ++
 4 files changed, 85 insertions(+), 15 deletions(-)
---
diff --git a/data/gtk-style.css b/data/gtk-style.css
index f04502d..6b1aa61 100644
--- a/data/gtk-style.css
+++ b/data/gtk-style.css
@@ -3,4 +3,11 @@
 #ViewLoadMore {
     border-image-width: 0 2 2 2;
     border-width: 0 1 1 1;
-}
\ No newline at end of file
+}
+
+.documents-icon-bg {
+    background-color: #3465a4;
+    border-radius: 4;
+
+    color: #ffffff;
+}
diff --git a/src/documents.js b/src/documents.js
index 7955afc..54ae50b 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -168,22 +168,10 @@ DocCommon.prototype = {
     },
 
     _createSymbolicEmblem: function(name) {
-        let symbolicName = name + '-symbolic';
-        let icon = new Gio.ThemedIcon({ name: symbolicName });
+        let pix = Gd.create_symbolic_icon(name, Utils.getIconSize());
 
-        let theme = Gtk.IconTheme.get_default();
-        let info = theme.lookup_by_gicon(icon, 64, Gtk.IconLookupFlags.FORCE_SIZE);
-
-        let rgba = new Gdk.RGBA();
-        rgba.parse("#3465a4");
-
-        let pix = null;
-
-        try {
-            pix = info.load_symbolic(rgba, null, null, null, null)[0];
-        } catch (e) {
+        if (!pix)
             pix = new Gio.ThemedIcon({ name: name });
-        }
 
         return pix;
     },
diff --git a/src/lib/gd-utils.c b/src/lib/gd-utils.c
index 7898ca2..3573d04 100644
--- a/src/lib/gd-utils.c
+++ b/src/lib/gd-utils.c
@@ -450,3 +450,75 @@ gd_time_val_from_iso8601 (const gchar *string,
 {
   return g_time_val_from_iso8601 (string, timeval);
 }
+
+#define _BG_MIN_SIZE 20
+#define _EMBLEM_MIN_SIZE 8
+
+/**
+ * gd_create_symbolic_icon:
+ * @name:
+ *
+ * Returns: (transfer full):
+ */
+GIcon *
+gd_create_symbolic_icon (const gchar *name,
+                         gint base_size)
+{
+  gchar *symbolic_name;
+  GIcon *icon, *retval = NULL;
+  cairo_surface_t *surface;
+  cairo_t *cr;
+  GtkStyleContext *style;
+  GtkWidgetPath *path;
+  GdkPixbuf *pixbuf;
+  GtkIconTheme *theme;
+  GtkIconInfo *info;
+  gint bg_size;
+  gint emblem_size;
+  gint total_size;
+
+  total_size = base_size / 2;
+  bg_size = MAX (total_size / 2, _BG_MIN_SIZE);
+  emblem_size = MAX (bg_size - 8, _EMBLEM_MIN_SIZE);
+
+  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, total_size, total_size);
+  cr = cairo_create (surface);
+
+  style = gtk_style_context_new ();
+
+  path = gtk_widget_path_new ();
+  gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);
+  gtk_style_context_set_path (style, path);
+  gtk_widget_path_unref (path);
+
+  gtk_style_context_add_class (style, "documents-icon-bg");
+
+  gtk_render_background (style, cr, (total_size - bg_size) / 2, (total_size - bg_size) / 2, bg_size, bg_size);
+
+  symbolic_name = g_strconcat (name, "-symbolic", NULL);
+  icon = g_themed_icon_new (symbolic_name);
+
+  theme = gtk_icon_theme_get_default();
+  info = gtk_icon_theme_lookup_by_gicon (theme, icon, emblem_size,
+                                         GTK_ICON_LOOKUP_FORCE_SIZE);
+  pixbuf = gtk_icon_info_load_symbolic_for_context (info, style, NULL, NULL);
+
+  gtk_icon_info_free (info);
+  g_object_unref (icon);
+  g_free (symbolic_name);
+
+  if (pixbuf == NULL)
+    goto out;
+
+  gtk_render_icon (style, cr, pixbuf, (total_size - emblem_size) / 2,  (total_size - emblem_size) / 2);
+  g_object_unref (pixbuf);
+
+  retval = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, total_size, total_size));
+
+ out:
+  g_object_unref (style);
+  cairo_surface_destroy (surface);
+  cairo_destroy (cr);
+
+  return retval;
+}
diff --git a/src/lib/gd-utils.h b/src/lib/gd-utils.h
index 67304e0..282700b 100644
--- a/src/lib/gd-utils.h
+++ b/src/lib/gd-utils.h
@@ -69,5 +69,8 @@ char *gd_filename_strip_extension (const char * filename_with_extension);
 gboolean gd_time_val_from_iso8601 (const gchar *string,
                                    GTimeVal *timeval);
 
+GIcon *gd_create_symbolic_icon (const gchar *name,
+                                gint base_size);
+
 #endif /* __GD_UTILS_H__ */
                                   



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