[gnome-photos/gnome-3-18] utils: Scale the emblems for HiDpi displays
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/gnome-3-18] utils: Scale the emblems for HiDpi displays
- Date: Sun, 8 Nov 2015 17:48:38 +0000 (UTC)
commit 3235a44bc21d1aa4ed898c708362bb69871ae527
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Nov 3 20:37:26 2015 +0100
utils: Scale the emblems for HiDpi displays
src/photos-base-item.c | 13 +++++++------
src/photos-utils.c | 19 +++++++++++++------
src/photos-utils.h | 2 +-
3 files changed, 21 insertions(+), 13 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 2a5e7fd..bab9db9 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -184,13 +184,13 @@ photos_base_item_create_placeholder_icon (const gchar *icon_name)
static GIcon *
-photos_base_item_create_symbolic_emblem (const gchar *name)
+photos_base_item_create_symbolic_emblem (const gchar *name, gint scale)
{
GIcon *pix;
gint size;
- size = photos_utils_get_icon_size ();
- pix = photos_utils_create_symbolic_icon (name, size);
+ size = photos_utils_get_icon_size_unscaled ();
+ pix = photos_utils_create_symbolic_icon_for_scale (name, size, scale);
if (pix == NULL)
pix = g_themed_icon_new (name);
@@ -214,11 +214,14 @@ photos_base_item_check_effects_and_update_info (PhotosBaseItem *self)
if (priv->original_icon == NULL)
goto out;
+ app = g_application_get_default ();
+ scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app));
+
emblemed_pixbuf = g_object_ref (priv->original_icon);
if (priv->favorite)
{
- pix = photos_base_item_create_symbolic_emblem (PHOTOS_ICON_FAVORITE);
+ pix = photos_base_item_create_symbolic_emblem (PHOTOS_ICON_FAVORITE, scale);
emblem_icons = g_list_prepend (emblem_icons, pix);
}
@@ -291,8 +294,6 @@ photos_base_item_check_effects_and_update_info (PhotosBaseItem *self)
else
thumbnailed_pixbuf = g_object_ref (emblemed_pixbuf);
- app = g_application_get_default ();
- scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app));
windows = gtk_application_get_windows (GTK_APPLICATION (app));
if (windows != NULL)
window = gtk_widget_get_window (GTK_WIDGET (windows->data));
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 6541b7f..d477817 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -237,7 +237,7 @@ photos_utils_create_pixbuf_from_node (GeglNode *node)
GIcon *
-photos_utils_create_symbolic_icon (const gchar *name, gint base_size)
+photos_utils_create_symbolic_icon_for_scale (const gchar *name, gint base_size, gint scale)
{
GIcon *icon;
GIcon *ret_val = NULL;
@@ -246,6 +246,7 @@ photos_utils_create_symbolic_icon (const gchar *name, gint base_size)
GtkIconTheme *theme;
GtkStyleContext *style;
GtkWidgetPath *path;
+ cairo_surface_t *icon_surface = NULL;
cairo_surface_t *surface;
cairo_t *cr;
gchar *symbolic_name;
@@ -254,11 +255,14 @@ photos_utils_create_symbolic_icon (const gchar *name, gint base_size)
gint emblem_pos;
gint emblem_size;
gint total_size;
+ gint total_size_scaled;
total_size = base_size / 2;
+ total_size_scaled = total_size * scale;
emblem_size = bg_size - emblem_margin * 2;
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, total_size, total_size);
+ surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, total_size_scaled, total_size_scaled);
+ cairo_surface_set_device_scale (surface, (gdouble) scale, (gdouble) scale);
cr = cairo_create (surface);
style = gtk_style_context_new ();
@@ -277,7 +281,7 @@ photos_utils_create_symbolic_icon (const gchar *name, gint base_size)
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);
+ info = gtk_icon_theme_lookup_by_gicon_for_scale (theme, icon, emblem_size, scale,
GTK_ICON_LOOKUP_FORCE_SIZE);
g_object_unref (icon);
if (info == NULL)
@@ -289,14 +293,17 @@ photos_utils_create_symbolic_icon (const gchar *name, gint base_size)
if (pixbuf == NULL)
goto out;
- emblem_pos = total_size - emblem_size - emblem_margin;
- gtk_render_icon (style, cr, pixbuf, emblem_pos, emblem_pos);
+ icon_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
g_object_unref (pixbuf);
- ret_val = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, total_size, total_size));
+ emblem_pos = total_size - emblem_size - emblem_margin;
+ gtk_render_icon_surface (style, cr, icon_surface, emblem_pos, emblem_pos);
+
+ ret_val = G_ICON (gdk_pixbuf_get_from_surface (surface, 0, 0, total_size_scaled, total_size_scaled));
out:
g_object_unref (style);
+ cairo_surface_destroy (icon_surface);
cairo_surface_destroy (surface);
cairo_destroy (cr);
diff --git a/src/photos-utils.h b/src/photos-utils.h
index 94896e4..72e3c65 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -57,7 +57,7 @@ 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);
+GIcon *photos_utils_create_symbolic_icon_for_scale (const gchar *name, gint base_size, gint scale);
gboolean photos_utils_create_thumbnail (GFile *file, GCancellable *cancellable, GError
**error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]