Clip Regions
Clipping regions are used to restrict the effect of a drawing
operation to a restricted area of a window.
Definition and Resetting
The following operations can be used to define clipping regions
void W.set_clip_rectangle(double x0, double y0, double x1, double y1);
void W.set_clip_ellipse(double x0, double y0, double r1, double r2);
The following operation resets the clipping area to the entire drawing
section of the window
void W.reset_clipping();
|
#include <LEDA/graphics/window.h>
#include <LEDA/geo/point.h>
#include <LEDA/geo/circle.h>
#include <LEDA/graphics/pixmaps/leda_icon.xpm>
using namespace leda;
void draw_pix_circle(window& W, const circle& C, char* prect)
{
point p=C.center();
double x=p.xcoord(),y=p.ycoord(),r=C.radius();
W.draw_disc(C,black);
W.set_clip_ellipse(x,y,r,r); //sets clipping region
W.center_pixrect(x,y,prect); //places pixrect with center at x,y
W.reset_clipping(); //restores the clipping region to
//entire drawing area of W
}
int main()
{
window W(400,400,"Clipping a Pixmap");
W.display();
char* leda_pix=W.create_pixrect(leda_icon);
circle c;
while (W>>c) draw_pix_circle(W,c,leda_pix);
W.del_pixrect(leda_pix);
W.screenshot("clipping");
return 0;
}
|