Example Non-Blocking EventsThe following program opens twowindows
W1 and W2 . The main loop reads all events,
determines for each event in which of the two windows it occurred
and puts the event back to the event queue. If the event occurred in W1
a point is drawn, for W2 a segment.
#include <LEDA/graphics/window.h> #include <LEDA/geo/point.h> #include <LEDA/geo/segment.h> using namespace leda; int main() { window W1(500,500,"Window 1: points"); W1.display(window::min,window::min); window W2(500,500,"Window 2: segments"); W2.display(window::max,window::min); for (;;) { window* wp; double x,y; int val; if (read_event(wp,val,x,y)!=button_press_event) continue; if (val==MOUSE_BUTTON(3)) break; put_back_event(); if (wp==&W1) {point p; W1 >> p; W1 << p;} if (wp==&W2) {segment s; W2 >> s; W2 << s;} } return 0; } |
See also:Basic Data Types for 2D Geometry Manual Pages: |