Skip to content

Commit cee7548

Browse files
committed
Fix masked image
1 parent 851f1c1 commit cee7548

File tree

2 files changed

+18
-27
lines changed

2 files changed

+18
-27
lines changed

data/application.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ window,
6464
animation: urgent 1.25s ease-in-out;
6565
}
6666

67+
masked-image {
68+
margin: 5px 4px 3px;
69+
}
70+
6771
@keyframes urgent {
6872
0% { -gtk-icon-transform: scale(1) rotate(0deg); }
6973
10% { -gtk-icon-transform: scale(0.8) rotate(30deg); }

src/Widgets/MaskedImage.vala

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,29 @@
1919
*/
2020

2121
public class Notifications.MaskedImage : Granite.Bin {
22-
private const int ICON_SIZE = 48;
23-
2422
public Gdk.Pixbuf pixbuf { get; construct; }
2523

24+
private const int ICON_SIZE = 40;
25+
2626
public MaskedImage (Gdk.Pixbuf pixbuf) {
2727
Object (pixbuf: pixbuf);
2828
}
2929

30-
construct {
31-
var image = new Gtk.Image ();
32-
image.gicon = mask_pixbuf (pixbuf, scale_factor);
33-
image.pixel_size = ICON_SIZE;
34-
35-
child = image;
30+
class construct {
31+
set_css_name ("masked-image");
3632
}
3733

38-
private static Gdk.Pixbuf? mask_pixbuf (Gdk.Pixbuf pixbuf, int scale) {
39-
var size = ICON_SIZE * scale;
40-
var mask_offset = 4 * scale;
41-
var mask_size_offset = mask_offset * 2;
42-
var mask_size = ICON_SIZE * scale;
43-
var offset_x = mask_offset;
44-
var offset_y = mask_offset + scale;
45-
size = size - mask_size_offset;
46-
47-
var input = pixbuf.scale_simple (size, size, Gdk.InterpType.BILINEAR);
48-
var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, mask_size, mask_size);
49-
var cr = new Cairo.Context (surface);
50-
51-
// FIXME: Do it in CSS
52-
// Granite.Drawing.Utilities.cairo_rounded_rectangle (cr, offset_x, offset_y, size, size, mask_offset);
53-
// cr.clip ();
34+
construct {
35+
var image = new Gtk.Image () {
36+
paintable = Gdk.Texture.for_pixbuf (pixbuf),
37+
pixel_size = ICON_SIZE
38+
};
5439

55-
Gdk.cairo_set_source_pixbuf (cr, input, offset_x, offset_y);
56-
cr.paint ();
40+
add_css_class (Granite.STYLE_CLASS_CARD);
41+
add_css_class (Granite.STYLE_CLASS_CHECKERBOARD);
42+
add_css_class (Granite.STYLE_CLASS_ROUNDED);
43+
overflow = HIDDEN;
5744

58-
return Gdk.pixbuf_get_from_surface (surface, 0, 0, mask_size, mask_size);
45+
child = image;
5946
}
6047
}

0 commit comments

Comments
 (0)