[geary/wip/732065-icons] Get the rest of the icon issues
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/732065-icons] Get the rest of the icon issues
- Date: Fri, 3 Oct 2014 21:07:38 +0000 (UTC)
commit 3c76075bc7267fb86f7f47b06a031fc5f29df64c
Author: Jim Nelson <jim yorba org>
Date: Fri Oct 3 14:07:15 2014 -0700
Get the rest of the icon issues
src/client/components/icon-factory.vala | 25 +++++++++++++++++++++++--
src/client/components/pill-toolbar.vala | 17 +++++++++++++----
2 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/src/client/components/icon-factory.vala b/src/client/components/icon-factory.vala
index c1478be..a387795 100644
--- a/src/client/components/icon-factory.vala
+++ b/src/client/components/icon-factory.vala
@@ -123,6 +123,27 @@ public class IconFactory {
icon_theme.lookup_icon("document-symbolic", size, flags);
}
+ private Gdk.Pixbuf aspect_scale_down_pixbuf(Gdk.Pixbuf pixbuf, int size) {
+ if (pixbuf.width <= size && pixbuf.height <= size)
+ return pixbuf;
+
+ int scaled_width, scaled_height;
+ if (pixbuf.width >= pixbuf.height) {
+ double aspect = (double) size / (double) pixbuf.width;
+ scaled_width = size;
+ scaled_height = (int) Math.round((double) pixbuf.height * aspect);
+ } else {
+ double aspect = (double) size / (double) pixbuf.height;
+ scaled_width = (int) Math.round((double) pixbuf.width * aspect);
+ scaled_height = size;
+ }
+
+ debug("scale pixbuf: %dx%d size:%d => %dx%d", pixbuf.width, pixbuf.height, size,
+ scaled_width, scaled_height);
+
+ return pixbuf.scale_simple(scaled_width, scaled_height, Gdk.InterpType.BILINEAR);
+ }
+
public Gdk.Pixbuf? load_symbolic(string icon_name, int size, Gtk.StyleContext style,
Gtk.IconLookupFlags flags = 0) {
Gtk.IconInfo? icon_info = icon_theme.lookup_icon(icon_name, size, flags);
@@ -130,7 +151,7 @@ public class IconFactory {
// Attempt to load as a symbolic icon.
if (icon_info != null) {
try {
- return icon_info.load_symbolic_for_context(style);
+ return aspect_scale_down_pixbuf(icon_info.load_symbolic_for_context(style), size);
} catch (Error e) {
message("Couldn't load icon: %s", e.message);
}
@@ -151,7 +172,7 @@ public class IconFactory {
// Attempt to load as a symbolic icon.
if (icon_info != null) {
try {
- return icon_info.load_symbolic(color);
+ return aspect_scale_down_pixbuf(icon_info.load_symbolic(color), size);
} catch (Error e) {
warning("Couldn't load icon: %s", e.message);
}
diff --git a/src/client/components/pill-toolbar.vala b/src/client/components/pill-toolbar.vala
index 1c9a1a9..f5ea032 100644
--- a/src/client/components/pill-toolbar.vala
+++ b/src/client/components/pill-toolbar.vala
@@ -39,12 +39,21 @@ public interface PillBar : Gtk.Container {
b.tooltip_text = b.related_action.tooltip;
b.related_action.notify["tooltip"].connect(() => { b.tooltip_text = b.related_action.tooltip; });
+ // Load icon by name with this fallback order: specified icon name, the action's icon name,
+ // the action's stock ID ... although stock IDs are being deprecated, that's how we specify
+ // the icon in the GtkActionEntry (also being deprecated) and GTK+ 3.14 doesn't support that
+ // any longer
+ string? icon_to_load = icon_name ?? b.related_action.icon_name;
+ if (icon_to_load == null)
+ icon_to_load = b.related_action.stock_id;
+
// set pixel size to force GTK+ to load our images from our installed directory, not the theme
// directory
- Gtk.Image image = new Gtk.Image.from_icon_name(icon_name != null ? icon_name :
- b.related_action.icon_name, Gtk.IconSize.MENU);
- image.set_pixel_size(16);
- b.image = image;
+ if (icon_to_load != null) {
+ Gtk.Image image = new Gtk.Image.from_icon_name(icon_to_load, Gtk.IconSize.MENU);
+ image.set_pixel_size(16);
+ b.image = image;
+ }
// Unity buttons are a bit tight
#if ENABLE_UNITY
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]