class move_handler : public handler {
public:
move_handler( canvas* cv ) : c(cv) { dragging = 0; }
void press( event& e ) { // if overlapping start dragging
x = e.x(); y = e.y();
id = c->overlapping(x, y);
if (id) dragging = 1;
}
void motion( event& e ) { // if dragging move
if (dragging) {
id.move( e.x() - x, e.y() - y );
x = e.x(); y = e.y();
}
}
void release( event& ) { dragging = 0; } // stop dragging
protected:
canvas* c; int dragging; item id; int x,y;
};