\n","author":{"@type":"Person","name":"Stewart Tunbridge"},"upvoteCount":2,"answerCount":1,"acceptedAnswer":null}}
Reputation: 79
Using Xlib: I'm trying to display a pixmap with a transparent colour (color). That is a colour that will show the background. Currently drawing the pixmap completely opaque using XCopyArea (). How can I make this transparent (to work like XDrawString)?
Thanks
GC pixgc = XCreateGC (XDisplay, pix, 0, NULL);
XSetForeground (XDisplay, pixgc, ColourToXColour (RGB (0xff, 0xFF, 0xff)));
XFillRectangle (XDisplay, pix, pixgc, 0, 0, 32, 32);
XSetForeground (XDisplay, pixgc, ColourToXColour (RGB (0x00, 0x80, 0x80)));
XDrawLine (XDisplay, pix, pixgc, 8, 8, 8 + 16, 8 + 16);
XDrawLine (XDisplay, pix, pixgc, 8, 8 + 16, 8 + 16, 8);
XDrawArc (XDisplay, pix, pixgc, 6, 6, 20, 20, 0, 270 * 64);
XCopyArea (XDisplay, pix, Res->XWindow, DefaultGC (XDisplay, XScreen), 0, 0, 32, 32, 10, 50);
Upvotes: 2
Views: 971
Reputation: 79
Here is one possible solution. I would value better answers if any are possible.
// Mask is Black & White. Areas in Source corresponding White areas in Mask are drawn on Dest
bool CopyArea (Drawable Source, Drawable Dest, Drawable Mask, GC gc, int x, int y, int Width, int Height, int DestX, int DestY)
{
int a, b;
XGCValues gcv;
int func;
Pixmap Mask_;
//
// Clear effected pixels in Dest
XGetGCValues (XDisplay, gc, GCFunction, &gcv);
func = gcv.function;
gcv.function = GXandInverted;
XChangeGC (XDisplay, gc, GCFunction, &gcv);
XCopyArea (XDisplay, Mask, Dest, gc, x, y, Width, Height, DestX, DestY);
// Generate coloured Mask to OR into Dest
Mask_ = XCreatePixmap (XDisplay, Dest, Width, Height, 24); // First make a copy of Mask
gcv.function = GXcopy;
XChangeGC (XDisplay, gc, GCFunction, &gcv);
XCopyArea (XDisplay, Mask, Mask_, gc, x, y, Width, Height, 0, 0);
gcv.function = GXand; // Then colour it to match pixels in Source
XChangeGC (XDisplay, gc, GCFunction, &gcv);
XCopyArea (XDisplay, Source, Mask_, gc, x, y, Width, Height, 0, 0);
// Copy new coloured Mask into Dest
gcv.function = GXor;
XChangeGC (XDisplay, gc, GCFunction, &gcv);
XCopyArea (XDisplay, Mask_, Dest, gc, 0, 0, Width, Height, DestX, DestY);
// Restore gc & free new Mask
gcv.function = func;
XChangeGC (XDisplay, gc, GCFunction, &gcv);
XFreePixmap (XDisplay, Mask_);
}
Upvotes: 1