Overhaul timeline event handling.

This commit is contained in:
Jonathan Moore Liles 2008-05-25 21:22:52 -05:00
parent 0525433a41
commit 0e1ac2563d
6 changed files with 115 additions and 139 deletions

View File

@ -198,21 +198,10 @@ Audio_Region::handle ( int m )
static bool copied = false; static bool copied = false;
static nframes_t os; static nframes_t os;
if ( ! active_r() )
return 0;
// int X = Fl::event_x() - _track->x();
int X = Fl::event_x(); int X = Fl::event_x();
int Y = Fl::event_y(); int Y = Fl::event_y();
int ret;
if ( m != FL_RELEASE && Sequence_Region::handle( m ) )
return 1;
Logger _log( this ); Logger _log( this );
//log_r->start();
switch ( m ) switch ( m )
{ {
@ -251,36 +240,26 @@ Audio_Region::handle ( int m )
case FL_PUSH: case FL_PUSH:
{ {
/* splitting */ /* splitting */
if ( Fl::event_shift() && ! Fl::event_ctrl() ) if ( Fl::test_shortcut( FL_BUTTON2 | FL_SHIFT ) )
{ {
switch ( Fl::event_button() ) /* split */
if ( ! copied )
{ {
case 2: Loggable::block_start();
{
/* split */
if ( ! copied )
{
Loggable::block_start();
Audio_Region *copy = new Audio_Region( *this ); Audio_Region *copy = new Audio_Region( *this );
trim( RIGHT, X ); trim( RIGHT, X );
copy->trim( LEFT, X ); copy->trim( LEFT, X );
sequence()->add( copy ); sequence()->add( copy );
log_end(); log_end();
Loggable::block_end(); Loggable::block_end();
return 0;
}
}
default:
return 0;
break;
} }
return 1; return 0;
} }
else else
{ {
@ -289,22 +268,9 @@ Audio_Region::handle ( int m )
/* for panning */ /* for panning */
os = _r->offset; os = _r->offset;
/* normalization and selection */ if ( Fl::test_shortcut( FL_BUTTON2 | FL_CTRL ) && ! Fl::event_shift() )
if ( Fl::event_button2() )
{ {
if ( Fl::event_ctrl() ) normalize();
normalize();
else
{
if ( Sequence_Widget::current() == this )
{
if ( selected() )
deselect();
else
select();
}
}
redraw(); redraw();
return 1; return 1;
} }
@ -346,11 +312,12 @@ Audio_Region::handle ( int m )
redraw(); redraw();
} }
return 0; return 1;
} }
else else
return Sequence_Region::handle( m ); return Sequence_Region::handle( m );
} }
break; break;
} }
case FL_RELEASE: case FL_RELEASE:
@ -362,32 +329,29 @@ Audio_Region::handle ( int m )
return 1; return 1;
} }
case FL_DRAG: case FL_DRAG:
if ( ! _drag ) if ( ! _drag )
{ {
begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) ); begin_drag( Drag( x() - X, y() - Y, x_to_offset( X ) ) );
_log.hold(); _log.hold();
} }
if ( Fl::event_button1() )
if ( Fl::test_shortcut( FL_BUTTON1 | FL_SHIFT | FL_CTRL ) )
{ {
if ( Fl::event_state() & ( FL_SHIFT | FL_CTRL ) ) /* panning */
{ int d = (ox + X) - x();
/* panning */ long td = timeline->x_to_ts( d );
int d = (ox + X) - x();
long td = timeline->x_to_ts( d );
if ( td > 0 && os < (nframes_t)td ) if ( td > 0 && os < (nframes_t)td )
_r->offset = 0; _r->offset = 0;
else else
_r->offset = os - td; _r->offset = os - td;
sequence()->redraw(); redraw();
return 1; return 1;
}
} }
ret = Sequence_Region::handle( m ); return Sequence_Region::handle( m );
return ret | 1;
default: default:
return Sequence_Region::handle( m ); return Sequence_Region::handle( m );
break; break;

View File

@ -280,20 +280,21 @@ Sequence::snap ( Sequence_Widget *r )
int int
Sequence::handle ( int m ) Sequence::handle ( int m )
{ {
switch ( m ) switch ( m )
{ {
case FL_FOCUS: case FL_FOCUS:
case FL_UNFOCUS: case FL_UNFOCUS:
return 1;
case FL_LEAVE: case FL_LEAVE:
// DMESSAGE( "leave" );
fl_cursor( FL_CURSOR_DEFAULT ); fl_cursor( FL_CURSOR_DEFAULT );
return 1; return 1;
case FL_DND_DRAG: case FL_DND_DRAG:
return 1; return 1;
case FL_ENTER: case FL_ENTER:
// DMESSAGE( "enter" );
if ( Sequence_Widget::pushed() ) if ( Sequence_Widget::pushed() )
{ {
if ( Sequence_Widget::pushed()->sequence()->class_name() == class_name() ) if ( Sequence_Widget::pushed()->sequence()->class_name() == class_name() )
{ {
/* accept objects dragged from other sequences of this type */ /* accept objects dragged from other sequences of this type */
@ -306,7 +307,8 @@ Sequence::handle ( int m )
fl_cursor( (Fl_Cursor)1 ); fl_cursor( (Fl_Cursor)1 );
} }
else else
fl_cursor( cursor() ); if ( ! event_widget() )
fl_cursor( cursor() );
return 1; return 1;
case FL_DND_ENTER: case FL_DND_ENTER:
@ -337,16 +339,18 @@ Sequence::handle ( int m )
{ {
int retval = r->dispatch( m ); int retval = r->dispatch( m );
if ( retval && m == FL_PUSH ) if ( retval )
{ {
take_focus(); if ( m == FL_PUSH )
{
take_focus();
Sequence_Widget::pushed( r ); Sequence_Widget::pushed( r );
}
else if ( m == FL_RELEASE )
Sequence_Widget::pushed( NULL );
} }
if ( retval && m == FL_RELEASE )
Sequence_Widget::pushed( NULL );
Loggable::block_start(); Loggable::block_start();
while ( _delete_queue.size() ) while ( _delete_queue.size() )
@ -355,7 +359,6 @@ Sequence::handle ( int m )
Sequence_Widget *t = _delete_queue.front(); Sequence_Widget *t = _delete_queue.front();
_delete_queue.pop(); _delete_queue.pop();
if ( Sequence_Widget::pushed() == t ) if ( Sequence_Widget::pushed() == t )
Sequence_Widget::pushed( NULL ); Sequence_Widget::pushed( NULL );
if ( Sequence_Widget::belowmouse() == t ) if ( Sequence_Widget::belowmouse() == t )

View File

@ -136,17 +136,10 @@ Sequence_Region::handle ( int m )
static bool copied = false; static bool copied = false;
/* if ( ! active_r() ) */
/* return 0; */
// int X = Fl::event_x() - _track->x();
int X = Fl::event_x(); int X = Fl::event_x();
int Y = Fl::event_y(); int Y = Fl::event_y();
int ret;
Logger _log( this ); Logger _log( this );
//log_r->offset();
switch ( m ) switch ( m )
{ {
@ -188,14 +181,14 @@ Sequence_Region::handle ( int m )
redraw(); redraw();
return 1; return 1;
} }
else if ( Fl::test_shortcut( FL_CTRL + FL_BUTTON1 ) ) else if ( Fl::test_shortcut( FL_CTRL + FL_BUTTON1 ) && ! Fl::event_shift() )
{ {
/* duplication */ /* duplication */
fl_cursor( FL_CURSOR_MOVE );
return 1; return 1;
} }
else else
return Sequence_Widget::handle( m ); return Sequence_Widget::handle( m );
break;
} }
case FL_RELEASE: case FL_RELEASE:
{ {
@ -216,7 +209,8 @@ Sequence_Region::handle ( int m )
} }
/* trimming */ /* trimming */
if ( Fl::event_state() & FL_SHIFT ) if ( Fl::event_shift() )
{
if ( trimming ) if ( trimming )
{ {
trim( trimming, X ); trim( trimming, X );
@ -224,6 +218,7 @@ Sequence_Region::handle ( int m )
} }
else else
return 0; return 0;
}
else if ( Fl::event_button1() ) else if ( Fl::event_button1() )
{ {
if ( Fl::event_state() & FL_CTRL ) if ( Fl::event_state() & FL_CTRL )
@ -238,7 +233,7 @@ Sequence_Region::handle ( int m )
return 1; return 1;
} }
} }
else if ( ! selected() ) else if ( Fl::test_shortcut( FL_BUTTON1 ) && ! Fl::event_shift() && ! selected() )
{ {
/* track jumping */ /* track jumping */
if ( Y > y() + h() || Y < y() ) if ( Y > y() + h() || Y < y() )
@ -255,8 +250,7 @@ Sequence_Region::handle ( int m )
} }
} }
ret = Sequence_Widget::handle( m ); return Sequence_Widget::handle( m );
return ret | 1;
} }
default: default:
return Sequence_Widget::handle( m ); return Sequence_Widget::handle( m );

View File

@ -252,7 +252,6 @@ Sequence_Widget::dispatch ( int m )
int r = 0; int r = 0;
for ( list <Sequence_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ ) for ( list <Sequence_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ )
if ( *i != this ) if ( *i != this )
r |= (*i)->handle( m ); r |= (*i)->handle( m );
@ -289,27 +288,32 @@ Sequence_Widget::handle ( int m )
Logger _log( this ); Logger _log( this );
switch ( m ) switch ( m )
{ {
case FL_ENTER: case FL_ENTER:
fl_cursor( FL_CURSOR_HAND ); fl_cursor( FL_CURSOR_HAND );
return 1; return 1;
case FL_LEAVE: case FL_LEAVE:
// DMESSAGE( "leave" );
fl_cursor( sequence()->cursor() ); fl_cursor( sequence()->cursor() );
return 1; return 1;
case FL_PUSH: case FL_PUSH:
{ {
/* deletion */ /* deletion */
if ( Fl::event_state() & FL_CTRL && if ( Fl::test_shortcut( FL_CTRL + FL_BUTTON3 ) && ! Fl::event_shift() )
Fl::event_button3() )
{ {
redraw(); redraw();
sequence()->queue_delete( this ); sequence()->queue_delete( this );
return 1; return 1;
} }
else else if ( Fl::test_shortcut( FL_BUTTON1 ) && ! Fl::event_shift() )
if ( Fl::event_button1() ) {
return 1; fl_cursor( FL_CURSOR_MOVE );
/* movement drag */
return 1;
}
return 0; return 0;
} }
@ -331,11 +335,13 @@ Sequence_Widget::handle ( int m )
_log.hold(); _log.hold();
} }
fl_cursor( FL_CURSOR_MOVE ); if ( ( Fl::test_shortcut( FL_BUTTON1 + FL_CTRL ) ||
Fl::test_shortcut( FL_BUTTON1 ) ) && ! Fl::event_shift() )
redraw();
{ {
// fl_cursor( FL_CURSOR_MOVE );
redraw();
const nframes_t of = timeline->x_to_offset( X ); const nframes_t of = timeline->x_to_offset( X );
if ( of >= _drag->start ) if ( of >= _drag->start )
@ -346,36 +352,37 @@ Sequence_Widget::handle ( int m )
if ( Sequence_Widget::_current == this ) if ( Sequence_Widget::_current == this )
sequence()->snap( this ); sequence()->snap( this );
} if ( X >= sequence()->x() + sequence()->w() ||
X <= sequence()->x() )
if ( X >= sequence()->x() + sequence()->w() ||
X <= sequence()->x() )
{
/* this drag needs to scroll */
nframes_t pos = timeline->xoffset;
nframes_t d = timeline->x_to_ts( 100 );
if ( X <= sequence()->x() )
{ {
/* this drag needs to scroll */
if ( pos > d ) nframes_t pos = timeline->xoffset;
pos -= d;
nframes_t d = timeline->x_to_ts( 100 );
if ( X <= sequence()->x() )
{
if ( pos > d )
pos -= d;
else
pos = 0;
}
else else
pos = 0; pos += d;
}
else
pos += d;
timeline->xposition( timeline->ts_to_x( pos ) ); timeline->xposition( timeline->ts_to_x( pos ) );
/* FIXME: why isn't this enough? */ /* FIXME: why isn't this enough? */
// sequence()->redraw(); // sequence()->redraw();
timeline->redraw(); timeline->redraw();
} }
return 1; return 1;
}
else
return 0;
} }
default: default:
return 0; return 0;

View File

@ -962,6 +962,10 @@ Timeline::handle ( int m )
case FL_UNFOCUS: case FL_UNFOCUS:
// redraw(); // redraw();
return 1; return 1;
case FL_ENTER:
return 1;
case FL_LEAVE:
return 1;
case FL_KEYDOWN: case FL_KEYDOWN:
if ( Fl::event_key() == 'r' ) if ( Fl::event_key() == 'r' )
{ {
@ -998,9 +1002,10 @@ Timeline::handle ( int m )
} }
default: default:
{ {
if ( m == FL_PUSH && this != Fl::focus() )
take_focus();
if ( m == FL_PUSH ) //Fl::focus( this );
Fl::focus( this );
int r = Fl_Overlay_Window::handle( m ); int r = Fl_Overlay_Window::handle( m );
@ -1014,18 +1019,15 @@ Timeline::handle ( int m )
{ {
case FL_PUSH: case FL_PUSH:
{ {
// take_focus(); if ( Fl::test_shortcut( FL_BUTTON1 ) && ! Fl::event_shift() )
if ( Fl::event_state() & ( FL_ALT | FL_CTRL | FL_SHIFT ) )
return 0;
if ( Fl::event_button1() )
{ {
assert( ! drag ); assert( ! drag );
drag = new Drag( X - x(), Y - y() ); drag = new Drag( X - x(), Y - y() );
_selection.x = drag->x; _selection.x = drag->x;
_selection.y = drag->y; _selection.y = drag->y;
return 1;
} }
else if ( Fl::test_shortcut( FL_BUTTON3 ) && ! Fl::event_shift() ) else if ( Fl::test_shortcut( FL_BUTTON3 ) && ! Fl::event_shift() )
{ {
@ -1036,11 +1038,10 @@ Timeline::handle ( int m )
r->do_callback( static_cast<Fl_Widget*>(menu) ); r->do_callback( static_cast<Fl_Widget*>(menu) );
} }
return 1;
} }
else
return 0;
break; return 0;
} }
case FL_DRAG: case FL_DRAG:
{ {
@ -1062,6 +1063,9 @@ Timeline::handle ( int m )
redraw(); redraw();
} }
redraw_overlay();
return 1;
break; break;
} }
case FL_RELEASE: case FL_RELEASE:
@ -1069,7 +1073,6 @@ Timeline::handle ( int m )
delete drag; delete drag;
drag = NULL; drag = NULL;
if ( range ) if ( range )
{ {
p1 = x_to_offset( _selection.x ); p1 = x_to_offset( _selection.x );
@ -1080,18 +1083,19 @@ Timeline::handle ( int m )
select( _selection ); select( _selection );
_selection.w = _selection.h = 0; _selection.w = _selection.h = 0;
break;
redraw_overlay();
return 1;
} }
default: default:
return 0; return 0;
break; break;
} }
redraw_overlay(); return 0;
return 1;
} }
} }
} }

View File

@ -452,7 +452,6 @@ Track::draw ( void )
int int
Track::handle ( int m ) Track::handle ( int m )
{ {
switch ( m ) switch ( m )
{ {
case FL_MOUSEWHEEL: case FL_MOUSEWHEEL:
@ -478,7 +477,10 @@ Track::handle ( int m )
int X = Fl::event_x(); int X = Fl::event_x();
int Y = Fl::event_y(); int Y = Fl::event_y();
if ( Fl::event_button3() && X < Track::width() ) if ( Fl_Group::handle( m ) )
return 1;
if ( Fl::test_shortcut( FL_BUTTON3 ) && ! Fl::event_shift() && X < Track::width() )
{ {
int c = output.size(); int c = output.size();
@ -561,14 +563,16 @@ Track::handle ( int m )
} }
} }
} }
return 1;
} }
return 1; return 1;
} }
return 0;
} }
default: default:
return Fl_Group::handle( m ); return Fl_Group::handle( m );
} }
return 0; return 0;