简体   繁体   中英

How can I limit the surface in which Xlib graphics primitives draw?

I think that's what clip are used for but I can't find any example to do this. I need to:

  • Limit the region by setting a new clipmask (altering the GC)
  • Draw
  • Set the GC back to its previous state

You can do it by using XSetClipRectangles() referenced here and XSetClipMask() referenced here

So:

Display dpy; //This is your display, we'll assume it is a valid Display
GC gc; //This is your GC, we'll assume it is a valid GC
XRectangle recs[]; //This is an array containing the clipping regions you want.
int recs_n; //This is the number of rectangles in the 'recs' array.

XSetClipRectangles(dpy, gc, 0, 0, recs, recs_n, Unsorted); //Enable clipping
drawMyClippedGraphics(); //Call to whatever you want to use for drawing
XSetClipMask(dpy, gc, None); //Restore the GC

For further information type man functionName in your terminal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM