… | |
… | |
2 | #include "rxvt.h" |
2 | #include "rxvt.h" |
3 | |
3 | |
4 | #if HAVE_IMG |
4 | #if HAVE_IMG |
5 | |
5 | |
6 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) |
6 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) |
7 | : s(screen), w(width), h(height), format(format) |
7 | : s(screen), w(width), h(height), format(format), shared(false) |
8 | { |
8 | { |
9 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
9 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
10 | } |
10 | } |
11 | |
11 | |
12 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
12 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
13 | : s(screen), pm(pixmap), w(width), h(height), format(format) |
13 | : s(screen), pm(pixmap), w(width), h(height), format(format), shared(false) |
14 | { |
14 | { |
|
|
15 | } |
|
|
16 | |
|
|
17 | rxvt_img * |
|
|
18 | rxvt_img::new_from_file (rxvt_screen *s, const char *filename) |
|
|
19 | { |
|
|
20 | GError *err; |
|
|
21 | GdkPixbuf *pb = gdk_pixbuf_new_from_file (filename, &err); |
|
|
22 | |
|
|
23 | if (!pb) |
|
|
24 | return 0; |
|
|
25 | |
|
|
26 | int w = gdk_pixbuf_get_width (pb); |
|
|
27 | int h = gdk_pixbuf_get_height (pb); |
|
|
28 | |
|
|
29 | rxvt_img *img = new rxvt_img ( |
|
|
30 | s, |
|
|
31 | XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), |
|
|
32 | gdk_pixbuf_get_width (pb), |
|
|
33 | gdk_pixbuf_get_height (pb) |
|
|
34 | ); |
|
|
35 | |
|
|
36 | img->render (pb, 0, 0, w, h, 0, 0); |
|
|
37 | |
|
|
38 | return img; |
15 | } |
39 | } |
16 | |
40 | |
17 | rxvt_img::~rxvt_img () |
41 | rxvt_img::~rxvt_img () |
18 | { |
42 | { |
19 | if (pm) |
43 | if (!shared) |
20 | XFreePixmap (s->display->dpy, pm); |
44 | XFreePixmap (s->display->dpy, pm); |
21 | } |
45 | } |
22 | |
46 | |
23 | void |
47 | void |
24 | rxvt_img::fill (const rxvt_color &c) |
48 | rxvt_img::fill (const rxvt_color &c) |