Algorithmic Solutions > LEDA > LEDA Guide > Windows and Panels > Events > Example Putting Back Events

Example Putting Back Events

The following program partitions the drawing area window W into four quadrants..In the upper left part, points can be drawn, in the upper right part polygons, in the lower left part segments, and in the lower right part circles.The kind of object drawn is defined by the position of the first mouse click. push_back_event() is used to push the first mouse click back into the event queue and make it available as the first event for the following basic input operation. The window is cleared with the middle mouse button and the program can be terminated with the right mouse button.

On the right there is a screenshot of the program. Clicking on the picture shows the window in original size.

Picture of Convex Hull
#include <LEDA/graphics/window.h>
#include <LEDA/geo/point.h>
#include <LEDA/geo/segment.h>
#include <LEDA/geo/polygon.h>
#include <LEDA/geo/circle.h>

using namespace leda;

int main()
{
  window W(400,400,"Putback Event Demo");
  W.init(-100,+100,-100);
  W.display(window::center,window::center);

  //partition the drawing area in four quadrants
  W.draw_hline(0); 
  W.draw_vline(0);

  point p;segment s;polygon pol;circle c;
  for (;;) {		
    //wait for the first click
    double x,y;
    int but=W.read_mouse(x,y);
			
    //middle button erases the window
    if (but==MOUSE_BUTTON(2)) {
      W.clear();
      W.draw_hline(0);
      W.draw_vline(0);
      continue;
    }
			
    //right button terminates program
    if (but==MOUSE_BUTTON(3)) break;
			
    //put mouse click back to the event queue
    put_back_event();
			
    //and distinguish cases according to its position
    if (x<0) {
      if (y>0) {
        if (W>>p) W.draw_point(p,red); 
      }
      else if (W>>s) W.draw_segment(s,green);
    }
    else { 
      if (y>0) {
        if (W>>pol) W.draw_polygon(pol,blue);
      }
      else if (W>>c) W.draw_circle(c,orange);
    }
  }

  W.screenshot("putback");
	
  return 0;
}  

See also:

Events

Windows and Panels

Mouse Input

Input and Output Operators

Example Non-Blocking Events


Manual Pages:

Manual Page Windows




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