c - draw icon with transparency in xlib and cairo -
now i've got icons want draw them correctly. @ moment i'm using cairo draw these images on window. have mask , icon pixmap.
cairo_surface_t *image; cairo_surface_t *imask; cairo_surface_t *surface; cairo_t *csurface; surface = cairo_xlib_surface_create(display, d, defaultvisual(display, screen), 400, 400); csurface = cairo_create(surface); pixmap icon; pixmap mask; //xwm stuff ... if(icon != 0) { get_pixmap_geometry(display, icon, &width, &height, &depth); image = cairo_xlib_surface_create(display, icon, defaultvisual(display, screen), width, height); cairo_set_source_surface(csurface, image, 0, 0); //how apply mask? //i tried cairo_set_operator(csurface, cairo_operator_source); cairo_paint(csurface); }
but icons not have transparencies. i've found no example solve cairo on internet. there complicated way it's badly documented doesn't me @ all. have link or example how restore original icon transparencies? thank in advance.
here example awesome "turns" icon cairo surface: https://github.com/awesomewm/awesome/blob/430f4fab15bb101b4af9fadbebb9a9bfa47ba9de/objects/client.c#l1501
this uses xcb instead of xlib, should manage still understand this. part handles mask begins in line 1538. basically, new cairo surface created , cairo context set it. source surface icon , mask applied via cairo_mask_surface
("use alpha channel of cairo surface mask of drawing operation"). can copy part code don't have draw icons temporary surface.
tl;dr: answer //how apply mask?
is: use cairo_mask_surface()
instead of cairo_paint()
.
Comments
Post a Comment