Algorithmic Solutions > LEDA > LEDA Guide > Windows and Panels > Events > Example Blocking Events

Example Blocking Events

The following program implements a click and drag routine for the definition of rectangles. It generates and displays a window W. It uses the (blocking) operation W.read_mouse() to get the first corner of the rectangle. The rectangle is drawn by dragging the mouse. The opposite corner of the rectangle is the point where the left mouse button is released. This event is catched by the (blocking) operation W.read_event(). The program is 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>

using namespace leda;

int main() 
{
  window W(450,500,"Event Demo");
  W.display();

  W.start_buffering();
  for (;;) {
    //read the first corner p of the rectangle
    //terminate if the right button was pressed
    point p;
    if (W.read_mouse(p)==MOUSE_BUTTON(3)) break;

    //draw rectangle from p to current position 
    //while button down
    int val;
    double x, y;
    char* win_buf=W.get_window_pixrect();
    while (W.read_event(val,x,y)!=button_release_event) {
      point q(x,y);
      W.put_pixrect(win_buf);
      W.draw_box(p,q,yellow);
      W.draw_rectangle(p,q,black);
      W.flush_buffer();
    }
			
    W.del_pixrect(win_buf);
  }
  W.stop_buffering();

  W.screenshot("blocking_events");

  return 0;
}    

See also:

Events

Windows and Panels

Mouse Input


Manual Pages:

Manual Page Windows




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