diff --git a/Region.C b/Region.C index 7d6eb67..a4a9f45 100644 --- a/Region.C +++ b/Region.C @@ -216,7 +216,15 @@ Region::handle ( int m ) } if ( ox + X >= _track->x() ) - position( ox + X, y() ); + { + int nx = ox + X; + +// nx = _track->snap( this, nx ); + + position( nx, y() ); + + _track->snap( this ); + } if ( Y > y() + h() ) { diff --git a/Track.H b/Track.H index f1fea32..b85fba0 100644 --- a/Track.H +++ b/Track.H @@ -60,9 +60,6 @@ public: void add ( Region *r ) { - - printf( "add" ); - if ( r->track() ) { r->track()->remove_region( r ); @@ -80,6 +77,40 @@ public: r->redraw(); } + /** snap /r/ to nearest edge */ + void + snap ( Region *r ) + { + const int snap_pixels = 10; + + int rx1 = r->x(); + int rx2 = r->x() + r->w(); + + for ( int i = children(); i-- ; ) + { + const Fl_Widget *w = child( i ); + + if ( w == r ) + continue; + + int wx1 = w->x(); + int wx2 = w->x() + w->w(); + + if ( abs( rx1 - wx2 ) < snap_pixels ) + { + rx1 = wx2 - 1; + break; + } + + if ( abs( rx2 - wx1 ) < snap_pixels ) + { + rx1 = (wx1 - r->w()) + 1; + break; + } + } + r->position( rx1, y() ); + } + int handle ( int m ) { switch ( m )