clipping - Xwindows
This is a discussion on clipping - Xwindows ; Hello all,
is there a possibility to intersect a pixmap and a rectangle area?
I want to display a *xpm pixmap, but only the part that lies
within a given rectangle. The region outsite the rectangle may
not be touched.
...
-
clipping
Hello all,
is there a possibility to intersect a pixmap and a rectangle area?
I want to display a *xpm pixmap, but only the part that lies
within a given rectangle. The region outsite the rectangle may
not be touched.
So far the display of the xpm-pixmap is done as follows (simpified):
ret = XpmCreatePixmapFromXpmImage(di, rootwin, p_xpmimage,
&pix, &shapepix, &attributes);
if(shapepix != 0)
{
/* set clipping to shapepix, so only those pixels will be copied */
/* which are really set
*/
XSetClipMask(di, gc, shapepix);
/* ??? now I would like to reduce the clipmask to smaler area */
/* ??? but how can I do that
*/
XSetClipOrigin(di, gc, x, y);
}
else
return;
/* now copy the pixmap to the window */
XCopyArea(di, pix, wdw, gc, src_x, src_y, w, h, dest_x, dest_y);
Thank you for any help
Dieter
-
Re: clipping
In comp.windows.x, Dieter Müller
wrote
on 24 Nov 2006 05:23:04 -0800
<1164374583.886922.112570@j44g2000cwa.googlegroups. com>:
> Hello all,
>
> is there a possibility to intersect a pixmap and a rectangle area?
> I want to display a *xpm pixmap, but only the part that lies
> within a given rectangle. The region outsite the rectangle may
> not be touched.
>
> So far the display of the xpm-pixmap is done as follows (simpified):
>
> ret = XpmCreatePixmapFromXpmImage(di, rootwin, p_xpmimage,
> &pix, &shapepix, &attributes);
>
> if(shapepix != 0)
> {
> /* set clipping to shapepix, so only those pixels will be copied */
> /* which are really set
> */
> XSetClipMask(di, gc, shapepix);
>
> /* ??? now I would like to reduce the clipmask to smaler area */
> /* ??? but how can I do that
> */
>
> XSetClipOrigin(di, gc, x, y);
> }
> else
> return;
>
> /* now copy the pixmap to the window */
> XCopyArea(di, pix, wdw, gc, src_x, src_y, w, h, dest_x, dest_y);
>
>
> Thank you for any help
>
> Dieter
>
The simplest method I can think of is something along the lines of the
following.
// create a new GC for scratchwork
GC gc2 = XCreateGC(di, shapepix, 0, 0);
// and a pixmap (I'm assuming 1 plane here)
Pixmap scratch = XCreatePixmap(di, shapepix, pixmap_w, pixmap_h, 1);
// blask it to all zeroes
XSetForeground(gc2, 0);
XFillRectangle(di, scratch, 0,0,pixmap_w, pixmap_h)
// draw the mask for the mask (yeah, I know :-) )
XSetForeground(gc2, 1);
XFillRectangle(di, scratch, x,y,w,h);
// now and the mask with the rectangle
XSetFunction(gc2, GxAnd);
XCopyArea(di, pixmap, scratch, gc2, 0,0,pixmap_w, pixmap_h, 0,0);
// and here's your mask; apply it to the original GC
XSetClipMask(di, gc, scratch);
Straightforward but a little ugly.
Since you're using XCopyArea anyway, a simpler solution might be to
shrink the rectangle into which you're copying.
--
#191, ewill3@earthlink.net
Windows Vista. It'll Fix Everything(tm).
--
Posted via a free Usenet account from http://www.teranews.com
-
Re: clipping
Thank you for your answer,
that was exactly what I was looking for. Quick, a little bit dirty, but
it works!
Thanks
Dieter
-
Re: clipping
"Dieter Müller" wrote in message
news:1164374583.886922.112570@j44g2000cwa.googlegr oups.com...
> Hello all,
>
> is there a possibility to intersect a pixmap and a rectangle area?
> I want to display a *xpm pixmap, but only the part that lies
> within a given rectangle. The region outsite the rectangle may
> not be touched.
>
> So far the display of the xpm-pixmap is done as follows (simpified):
>
> ret = XpmCreatePixmapFromXpmImage(di, rootwin, p_xpmimage,
> &pix, &shapepix, &attributes);
>
> if(shapepix != 0)
> {
> /* set clipping to shapepix, so only those pixels will be copied */
> /* which are really set
> */
> XSetClipMask(di, gc, shapepix);
>
> /* ??? now I would like to reduce the clipmask to smaler area */
> /* ??? but how can I do that
> */
>
> XSetClipOrigin(di, gc, x, y);
> }
> else
> return;
>
> /* now copy the pixmap to the window */
> XCopyArea(di, pix, wdw, gc, src_x, src_y, w, h, dest_x, dest_y);
>
>
> Thank you for any help
>
> Dieter
>
Instead of setting the clip mask, just determine the intersection of
the pixmap and the target rectangle, and adjust the parameters in the
call to XCopyArea.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project