[gnome-photos/wip/abono/star-on-left] base-item: Move favorite icon on bottom left



commit d9850d5394f12d4298b192ce6bd84ca282396af3
Author: Alessandro Bono <shadow openaliasbox org>
Date:   Tue Oct 27 20:58:03 2015 +0100

    base-item: Move favorite icon on bottom left
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733311

 src/photos-base-item.c |  125 +++++++++++++++++++----------------------------
 src/photos-utils.c     |   68 --------------------------
 src/photos-utils.h     |    2 -
 3 files changed, 51 insertions(+), 144 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 1ae667c..b282d5a 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -50,6 +50,9 @@
 #include "photos-single-item-job.h"
 #include "photos-utils.h"
 
+const GdkRGBA SMALL_EMBLEM_COLOR = { 1.0, 1.0, 1.0, 1.0 };
+const int SMALL_EMBLEM_SIZE = 16;
+const int EMBLEM_PADDING = 8;
 
 struct _PhotosBaseItemPrivate
 {
@@ -108,6 +111,7 @@ enum
 static guint signals[LAST_SIGNAL] = { 0 };
 
 static void photos_base_item_filterable_iface_init (PhotosFilterableInterface *iface);
+static GdkPixbuf * photos_base_item_add_emblem_icon (PhotosBaseItem *self, GdkPixbuf *pixbuf, const gchar 
*icon_name, GtkCornerType corner_type);
 
 
 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (PhotosBaseItem, photos_base_item, G_TYPE_OBJECT,
@@ -183,27 +187,11 @@ photos_base_item_create_placeholder_icon (const gchar *icon_name)
 }
 
 
-static GIcon *
-photos_base_item_create_symbolic_emblem (const gchar *name)
-{
-  GIcon *pix;
-  gint size;
-
-  size = photos_utils_get_icon_size ();
-  pix = photos_utils_create_symbolic_icon (name, size);
-  if (pix == NULL)
-    pix = g_themed_icon_new (name);
-
-  return pix;
-}
-
-
 static void
 photos_base_item_check_effects_and_update_info (PhotosBaseItem *self)
 {
   PhotosBaseItemPrivate *priv = self->priv;
   GApplication *app;
-  GIcon *pix;
   GList *emblem_icons = NULL;
   GList *windows;
   GdkPixbuf *emblemed_pixbuf = NULL;
@@ -215,65 +203,8 @@ photos_base_item_check_effects_and_update_info (PhotosBaseItem *self)
     goto out;
 
   emblemed_pixbuf = g_object_ref (priv->original_icon);
-
   if (priv->favorite)
-    {
-      pix = photos_base_item_create_symbolic_emblem (PHOTOS_ICON_FAVORITE);
-      emblem_icons = g_list_prepend (emblem_icons, pix);
-    }
-
-  if (g_list_length (emblem_icons) > 0)
-    {
-      GIcon *emblemed_icon;
-      GList *l;
-      GtkIconInfo *icon_info;
-      GtkIconTheme *theme;
-      gint height;
-      gint size;
-      gint width;
-
-      emblem_icons = g_list_reverse (emblem_icons);
-      emblemed_icon = g_emblemed_icon_new (G_ICON (priv->original_icon), NULL);
-      for (l = emblem_icons; l != NULL; l = g_list_next (l))
-        {
-          GEmblem *emblem;
-          GIcon *emblem_icon = G_ICON (l->data);
-
-          emblem = g_emblem_new (emblem_icon);
-          g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon), emblem);
-          g_object_unref (emblem);
-        }
-
-      theme = gtk_icon_theme_get_default ();
-
-      width = gdk_pixbuf_get_width (priv->original_icon);
-      height = gdk_pixbuf_get_height (priv->original_icon);
-      size = (width > height) ? width : height;
-
-      icon_info = gtk_icon_theme_lookup_by_gicon (theme, emblemed_icon, size, GTK_ICON_LOOKUP_FORCE_SIZE);
-
-      if (icon_info != NULL)
-        {
-          GError *error = NULL;
-          GdkPixbuf *tmp;
-
-          tmp = gtk_icon_info_load_icon (icon_info, &error);
-          if (error != NULL)
-            {
-              g_warning ("Unable to render the emblem: %s", error->message);
-              g_error_free (error);
-            }
-          else
-            {
-              g_object_unref (emblemed_pixbuf);
-              emblemed_pixbuf = tmp;
-            }
-
-          g_object_unref (icon_info);
-        }
-
-      g_object_unref (emblemed_icon);
-    }
+      emblemed_pixbuf = photos_base_item_add_emblem_icon(self, emblemed_pixbuf, 
PHOTOS_ICON_FAVORITE_SYMBOLIC, GTK_CORNER_BOTTOM_LEFT);
 
   g_clear_pointer (&priv->surface, (GDestroyNotify) cairo_surface_destroy);
 
@@ -307,6 +238,52 @@ photos_base_item_check_effects_and_update_info (PhotosBaseItem *self)
   g_list_free_full (emblem_icons, g_object_unref);
 }
 
+static GdkPixbuf *
+photos_base_item_add_emblem_icon (PhotosBaseItem *self, GdkPixbuf *pixbuf, const gchar *icon_name, 
GtkCornerType corner_type)
+{
+  GError *error = NULL;
+  GdkPixbuf *emblem = NULL;
+  GdkPixbuf *emblemed = NULL;
+  GtkIconTheme *theme;
+  GtkIconInfo *icon_info;
+  gint offset_x;
+  gint offset_y;
+
+  theme = gtk_icon_theme_get_default ();
+
+  icon_info = gtk_icon_theme_lookup_icon (theme, icon_name, SMALL_EMBLEM_SIZE, GTK_ICON_LOOKUP_FORCE_SIZE);
+
+  if (icon_info == NULL)
+    {
+      g_warning ("Unable to find icon %s", icon_name);
+      return pixbuf;
+    }
+
+  emblem = gtk_icon_info_load_symbolic (icon_info, &SMALL_EMBLEM_COLOR, NULL, NULL, NULL, NULL, &error);
+  if (error != NULL)
+    {
+      g_warning ("Unable to render the emblem: %s", error->message);
+      g_error_free (error);
+      return pixbuf;
+    }
+  g_object_unref (icon_info);
+
+  if (corner_type == GTK_CORNER_TOP_RIGHT || corner_type == GTK_CORNER_BOTTOM_RIGHT)
+    offset_x = gdk_pixbuf_get_width (pixbuf) - gdk_pixbuf_get_width (emblem) - EMBLEM_PADDING;
+  else
+    offset_x = EMBLEM_PADDING;
+
+  if (corner_type == GTK_CORNER_BOTTOM_LEFT || corner_type == GTK_CORNER_BOTTOM_RIGHT)
+    offset_y = gdk_pixbuf_get_height (pixbuf) - gdk_pixbuf_get_height (emblem) - EMBLEM_PADDING;
+  else
+    offset_y = EMBLEM_PADDING;
+
+  emblemed = gdk_pixbuf_copy (pixbuf);
+  gdk_pixbuf_composite (emblem, emblemed, offset_x, offset_y, SMALL_EMBLEM_SIZE, SMALL_EMBLEM_SIZE, 
offset_x, offset_y, 1.0, 1.0, GDK_INTERP_BILINEAR, 255);
+
+  g_object_unref (pixbuf);
+  return emblemed;
+}
 
 static void
 photos_base_item_set_original_icon (PhotosBaseItem *self, GdkPixbuf *icon)
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 99f9ef1..af4e3ae 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -236,74 +236,6 @@ photos_utils_create_pixbuf_from_node (GeglNode *node)
 }
 
 
-GIcon *
-photos_utils_create_symbolic_icon (const gchar *name, gint base_size)
-{
-  GIcon *icon;
-  GIcon *ret_val = NULL;
-  GdkPixbuf *pixbuf;
-  GtkIconInfo *info;
-  GtkIconTheme *theme;
-  GtkStyleContext *style;
-  GtkWidgetPath *path;
-  cairo_surface_t *surface;
-  cairo_t *cr;
-  gchar *symbolic_name;
-  const gint bg_size = 24;
-  const gint emblem_margin = 4;
-  gint emblem_pos;
-  gint emblem_size;
-  gint total_size;
-
-  total_size = base_size / 2;
-  emblem_size = bg_size - emblem_margin * 2;
-
-  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, "photos-icon-bg");
-
-  gtk_render_background (style, cr, total_size - bg_size, total_size - bg_size, bg_size, bg_size);
-
-  symbolic_name = g_strconcat (name, "-symbolic", NULL);
-  icon = g_themed_icon_new_with_default_fallbacks (symbolic_name);
-  g_free (symbolic_name);
-
-  theme = gtk_icon_theme_get_default();
-  info = gtk_icon_theme_lookup_by_gicon (theme, icon, emblem_size, GTK_ICON_LOOKUP_FORCE_SIZE);
-  g_object_unref (icon);
-
-  if (info == NULL)
-    goto out;
-
-  pixbuf = gtk_icon_info_load_symbolic_for_context (info, style, NULL, NULL);
-  g_object_unref (info);
-
-  if (pixbuf == NULL)
-    goto out;
-
-  emblem_pos = total_size - emblem_size - emblem_margin;
-  gtk_render_icon (style, cr, pixbuf, emblem_pos, emblem_pos);
-  g_object_unref (pixbuf);
-
-  ret_val = 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 ret_val;
-}
-
-
 gboolean
 photos_utils_create_thumbnail (GFile *file, GCancellable *cancellable, GError **error)
 {
diff --git a/src/photos-utils.h b/src/photos-utils.h
index 76bb932..14ec3ca 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -57,8 +57,6 @@ GIcon           *photos_utils_create_collection_icon      (gint base_size, GList
 
 GdkPixbuf       *photos_utils_create_pixbuf_from_node     (GeglNode *node);
 
-GIcon           *photos_utils_create_symbolic_icon        (const gchar *name, gint base_size);
-
 gboolean         photos_utils_create_thumbnail            (GFile *file, GCancellable *cancellable, GError 
**error);
 
 GIcon           *photos_utils_get_icon_from_cursor        (TrackerSparqlCursor *cursor);


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