Algorithmic Solutions > LEDA > LEDA Guide > Windows and Panels > Clip Regions

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();

Example

The following program generates a window W and creates a pixrect from the xpm data file <LEDA/pixmaps/leda_icon.xpm>. It uses the Input Operator >> to get a circle C and draws the pixrect inside C using the function draw_pix_circle().

On the right you see a screenshot from the program. Clicking on the picture shows the window in original size.

Example of Convex Hull
#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;
}

See also:

Drawing Operations

Windows and Panels

Basic Data Types for 2D Geometry

Pixrects (Pixmaps)

Input and Output Operators


Manual Pages:

Manual Page Windows




Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH