Timeline: Allow drag and drop moving of tracks.

This commit is contained in:
Jonathan Moore Liles 2013-05-22 23:50:10 -07:00
parent 0552a9a7cf
commit b664d0ed04
3 changed files with 42 additions and 4 deletions

View File

@ -1619,6 +1619,16 @@ Timeline::handle_scroll ( int m )
return 0; return 0;
} }
Track *
Timeline::event_inside ( void )
{
for ( int i = tracks->children(); i--; )
if ( Fl::event_inside( tracks->child(i) ) )
return (Track*)tracks->child(i);
return NULL;
}
int int
Timeline::handle ( int m ) Timeline::handle ( int m )
{ {
@ -1901,6 +1911,14 @@ Timeline::add_track ( Track *track )
} }
void
Timeline::insert_track ( Track *track, Track *before )
{
tracks->insert( *track, before );
tracks->redraw();
}
void void
Timeline::insert_track ( Track *track, int n ) Timeline::insert_track ( Track *track, int n )
{ {

View File

@ -140,8 +140,12 @@ class Timeline : public Fl_Single_Window, public RWLock
void apply_track_order ( void ); void apply_track_order ( void );
void insert_track ( Track *track, int n ); void insert_track ( Track *track, int n );
public: public:
void insert_track ( Track *track, Track *before );
Track * event_inside ( void );
/* called when widgets are moved etc */ /* called when widgets are moved etc */
void damage_sequence ( void ); void damage_sequence ( void );

View File

@ -1041,6 +1041,7 @@ Track::handle ( int m )
/* if ( m != FL_NO_EVENT ) */ /* if ( m != FL_NO_EVENT ) */
/* DMESSAGE( "%s", event_name( m ) ); */ /* DMESSAGE( "%s", event_name( m ) ); */
static Fl_Widget *dragging = NULL;
switch ( m ) switch ( m )
{ {
@ -1087,7 +1088,12 @@ Track::handle ( int m )
} }
case FL_PUSH: case FL_PUSH:
{ {
if ( Fl::event_inside( ((Track_Header*)child(0))->output_connector_handle ) ) if ( Fl::event_button1() && Fl::event_inside( ((Track_Header*)child(0))->color_box ) )
{
dragging = this;
return 1;
}
if ( Fl::event_button1() && Fl::event_inside( ((Track_Header*)child(0))->output_connector_handle ) )
return 1; return 1;
Logger log( this ); Logger log( this );
@ -1123,6 +1129,15 @@ Track::handle ( int m )
Fl::selection_owner(0); Fl::selection_owner(0);
} }
return 1; return 1;
case FL_RELEASE:
if ( dragging == this )
{
dragging = NULL;
timeline->insert_track( this, timeline->event_inside() );
return 1;
}
return 0;
break;
case FL_DND_RELEASE: case FL_DND_RELEASE:
receptive_to_drop = 0; receptive_to_drop = 0;
redraw(); redraw();
@ -1234,8 +1249,9 @@ Track::handle ( int m )
return 1; return 1;
} }
else else
return 0; {
return 1;
}
} }
default: default:
return Fl_Group::handle( m ); return Fl_Group::handle( m );