|
19 | 19 | */ |
20 | 20 |
|
21 | 21 | public class Notifications.MaskedImage : Granite.Bin { |
22 | | - private const int ICON_SIZE = 48; |
23 | | - |
24 | 22 | public Gdk.Pixbuf pixbuf { get; construct; } |
25 | 23 |
|
| 24 | + private const int ICON_SIZE = 40; |
| 25 | + |
26 | 26 | public MaskedImage (Gdk.Pixbuf pixbuf) { |
27 | 27 | Object (pixbuf: pixbuf); |
28 | 28 | } |
29 | 29 |
|
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"); |
36 | 32 | } |
37 | 33 |
|
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 | + }; |
54 | 39 |
|
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; |
57 | 44 |
|
58 | | - return Gdk.pixbuf_get_from_surface (surface, 0, 0, mask_size, mask_size); |
| 45 | + child = image; |
59 | 46 | } |
60 | 47 | } |
0 commit comments