From 193c24bd3744a08e65ef5963d4f5466fe3570498 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sun, 27 Apr 2008 13:56:20 -0500 Subject: [PATCH] Add option for magnetic snapping. --- Timeline/Sequence.C | 40 ++++++++++++++++++++++------------------ Timeline/TLE.fl | 9 +++++++-- Timeline/Timeline.C | 1 + Timeline/Timeline.H | 1 + 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/Timeline/Sequence.C b/Timeline/Sequence.C index 1eccfb4..2cba111 100644 --- a/Timeline/Sequence.C +++ b/Timeline/Sequence.C @@ -299,36 +299,40 @@ Sequence::snap ( Sequence_Widget *r ) { const int snap_pixels = 10; - const int rx1 = r->x(); - const int rx2 = r->x() + r->w(); - - - for ( list ::iterator i = _widgets.begin(); i != _widgets.end(); i++ ) + if ( Timeline::snap_magnetic ) { - const Sequence_Widget *w = (*i); - if ( w == r ) - continue; + const int rx1 = r->x(); + const int rx2 = r->x() + r->w(); - const int wx1 = w->x(); - const int wx2 = w->x() + w->w(); - if ( abs( rx1 - wx2 ) < snap_pixels ) + for ( list ::iterator i = _widgets.begin(); i != _widgets.end(); i++ ) { - r->offset( w->offset() + w->length() + 1 ); + const Sequence_Widget *w = (*i); + + if ( w == r ) + continue; + + const int wx1 = w->x(); + const int wx2 = w->x() + w->w(); + + if ( abs( rx1 - wx2 ) < snap_pixels ) + { + r->offset( w->offset() + w->length() + 1 ); // printf( "snap: %lu | %lu\n", w->offset() + w->length(), r->offset() ); - goto done; - } + goto done; + } - if ( abs( rx2 - wx1 ) < snap_pixels ) - { - r->offset( ( w->offset() - r->length() ) - 1 ); + if ( abs( rx2 - wx1 ) < snap_pixels ) + { + r->offset( ( w->offset() - r->length() ) - 1 ); // printf( "snap: %lu | %lu\n", r->offset() + r->length(), w->offset() ); - goto done; + goto done; + } } } diff --git a/Timeline/TLE.fl b/Timeline/TLE.fl index 7af5e7a..1a2c107 100644 --- a/Timeline/TLE.fl +++ b/Timeline/TLE.fl @@ -244,7 +244,7 @@ exit( 0 );} xywh {0 0 74 25} } { Submenu {} { - label {&Snap} open + label {&Snap to} open xywh {0 0 74 25} } { MenuItem {} { @@ -263,6 +263,11 @@ exit( 0 );} xywh {20 20 40 25} type Radio } } + MenuItem {} { + label {Magnetic snap} + callback {Timeline::snap_magnetic = menu_picked_value( o );} selected + xywh {10 10 40 25} type Toggle value 1 + } Submenu {} { label {Capture Format} open xywh {0 0 74 25} @@ -411,7 +416,7 @@ Fl::scheme( Fl::scheme() );} Fl::background( 220, 220, 220 ); Fl::foreground( 0, 0, 0 ); -Fl::scheme( Fl::scheme() );} selected +Fl::scheme( Fl::scheme() );} xywh {20 20 40 25} type Radio } } diff --git a/Timeline/Timeline.C b/Timeline/Timeline.C index e6e1f8d..26a38ef 100644 --- a/Timeline/Timeline.C +++ b/Timeline/Timeline.C @@ -33,6 +33,7 @@ bool Timeline::draw_with_measure_lines = true; Timeline::snap_e Timeline::snap_to = Bars; +bool Timeline::snap_magnetic = true; const float UPDATE_FREQ = 0.02f; diff --git a/Timeline/Timeline.H b/Timeline/Timeline.H index 1e8176f..e3577ef 100644 --- a/Timeline/Timeline.H +++ b/Timeline/Timeline.H @@ -115,6 +115,7 @@ public: static bool draw_with_measure_lines; static snap_e snap_to; + static bool snap_magnetic; Tempo_Sequence *tempo_track; Time_Sequence *time_track;