Merge lp:~tintou/granite/avatar-pixbuf-hidpi into lp:~elementary-pantheon/granite/granite

Proposed by Corentin Noël
Status: Merged
Approved by: Danielle Foré
Approved revision: 1030
Merged at revision: 1030
Proposed branch: lp:~tintou/granite/avatar-pixbuf-hidpi
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 74 lines (+17/-9)
1 file modified
lib/Widgets/Avatar.vala (+17/-9)
To merge this branch: bzr merge lp:~tintou/granite/avatar-pixbuf-hidpi
Reviewer Review Type Date Requested Status
Danielle Foré Approve
Review via email: mp+316155@code.launchpad.net

Commit message

avatar: allow HiDPI Pixbufs (X times bigger raw images or icons specifically rendered for @X size)

Description of the change

This is the proper patch allowing HiDPI Pixbufs (X times bigger raw images or icons specifically rendered for @X size)

To post a comment you must log in.
1030. By Corentin Noël

Allow HiDPI pixbufs

Revision history for this message
Danielle Foré (danrabbit) wrote :

As far as I can tell this does as advertised and doesn't affect 1x

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/Widgets/Avatar.vala'
2--- lib/Widgets/Avatar.vala 2016-12-31 19:48:54 +0000
3+++ lib/Widgets/Avatar.vala 2017-02-01 19:34:50 +0000
4@@ -55,7 +55,8 @@
5 */
6 public Avatar.from_file (string filepath, int icon_size) {
7 try {
8- pixbuf = new Gdk.Pixbuf.from_file_at_scale (filepath, icon_size, icon_size, true);
9+ var size = icon_size * get_style_context ().get_scale ();
10+ pixbuf = new Gdk.Pixbuf.from_file_at_size (filepath, size, size);
11 } catch (Error e) {
12 show_default (icon_size);
13 }
14@@ -74,7 +75,8 @@
15 valign = Gtk.Align.CENTER;
16 halign = Gtk.Align.CENTER;
17 visible_window = false;
18- get_style_context ().add_class (DEFAULT_STYLE);
19+ var style_context = get_style_context ();
20+ style_context.add_class (DEFAULT_STYLE);
21
22 notify["pixbuf"].connect (refresh_size_request);
23 }
24@@ -85,7 +87,8 @@
25
26 private void refresh_size_request () {
27 if (pixbuf != null) {
28- set_size_request (pixbuf.width + EXTRA_MARGIN * 2, pixbuf.height + EXTRA_MARGIN * 2);
29+ var scale_factor = get_style_context ().get_scale ();
30+ set_size_request (pixbuf.width / scale_factor + EXTRA_MARGIN * 2, pixbuf.height / scale_factor + EXTRA_MARGIN * 2);
31 draw_theme_background = true;
32 } else {
33 set_size_request (0, 0);
34@@ -102,7 +105,7 @@
35 public void show_default (int icon_size) {
36 Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default ();
37 try {
38- pixbuf = icon_theme.load_icon (DEFAULT_ICON, icon_size, 0);
39+ pixbuf = icon_theme.load_icon_for_scale (DEFAULT_ICON, icon_size, get_style_context ().get_scale (), 0);
40 } catch (Error e) {
41 stderr.printf ("Error setting default avatar icon: %s ", e.message);
42 }
43@@ -118,21 +121,26 @@
44 unowned Gtk.StyleContext style_context = get_style_context ();
45 var width = get_allocated_width () - EXTRA_MARGIN * 2;
46 var height = get_allocated_height () - EXTRA_MARGIN * 2;
47+ var scale_factor = style_context.get_scale ();
48
49 if (draw_theme_background) {
50- var border_radius = style_context.get_property (Gtk.STYLE_PROPERTY_BORDER_RADIUS, Gtk.StateFlags.NORMAL).get_int ();
51+ var border_radius = style_context.get_property (Gtk.STYLE_PROPERTY_BORDER_RADIUS, style_context.get_state ()).get_int ();
52 var crop_radius = int.min (width / 2, border_radius * width / 100);
53
54 Granite.Drawing.Utilities.cairo_rounded_rectangle (cr, EXTRA_MARGIN, EXTRA_MARGIN, width, height, crop_radius);
55- Gdk.cairo_set_source_pixbuf (cr, pixbuf, EXTRA_MARGIN, EXTRA_MARGIN);
56+ cr.save ();
57+ cr.scale (1.0 / scale_factor, 1.0 / scale_factor);
58+ Gdk.cairo_set_source_pixbuf (cr, pixbuf, EXTRA_MARGIN * scale_factor, EXTRA_MARGIN * scale_factor);
59 cr.fill_preserve ();
60+ cr.restore ();
61 style_context.render_background (cr, EXTRA_MARGIN, EXTRA_MARGIN, width, height);
62 style_context.render_frame (cr, EXTRA_MARGIN, EXTRA_MARGIN, width, height);
63
64 } else {
65- Granite.Drawing.Utilities.cairo_rounded_rectangle (cr, EXTRA_MARGIN, EXTRA_MARGIN, width, height, 0);
66- Gdk.cairo_set_source_pixbuf (cr, pixbuf, EXTRA_MARGIN, EXTRA_MARGIN);
67- cr.fill_preserve ();
68+ cr.save ();
69+ cr.scale (1.0 / scale_factor, 1.0 / scale_factor);
70+ style_context.render_icon (cr, pixbuf, EXTRA_MARGIN, EXTRA_MARGIN);
71+ cr.restore ();
72 }
73
74 return Gdk.EVENT_STOP;

Subscribers

People subscribed via source and target branches