Add option for magnetic snapping.

This commit is contained in:
Jonathan Moore Liles 2008-04-27 13:56:20 -05:00
parent 96051065db
commit 193c24bd37
4 changed files with 31 additions and 20 deletions

View File

@ -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 <Sequence_Widget*>::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 <Sequence_Widget*>::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;
}
}
}

View File

@ -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
}
}

View File

@ -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;

View File

@ -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;