Implement traditional mouse selection model.

This commit is contained in:
Jonathan Moore Liles 2008-07-15 00:41:05 -05:00
parent ffaa7bff61
commit 221242a27d
4 changed files with 93 additions and 63 deletions

View File

@ -281,6 +281,8 @@ Sequence::draw ( void )
}
#include "FL/test_press.H"
int
Sequence::handle ( int m )
{
@ -448,12 +450,20 @@ Sequence::handle ( int m )
return retval;
}
else
{
if ( test_press( FL_BUTTON1 ) )
{
/* traditional selection model */
Sequence_Widget::select_none();
}
return Fl_Widget::handle( m );
}
}
}
}
/**********/
/* Public */
@ -464,73 +474,73 @@ Sequence::handle ( int m )
/** return the length in frames of this sequence calculated from the
* right edge of the rightmost widget */
nframes_t
Sequence::length ( void ) const
{
nframes_t l = 0;
nframes_t
Sequence::length ( void ) const
{
nframes_t l = 0;
for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); ++r )
l = max( l, (*r)->start() + (*r)->length() );
for ( list <Sequence_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); ++r )
l = max( l, (*r)->start() + (*r)->length() );
return l;
}
return l;
}
/** return the location of the next widget from frame /from/ */
nframes_t
Sequence::next ( nframes_t from ) const
{
for ( list <Sequence_Widget*>::const_iterator i = _widgets.begin(); i != _widgets.end(); i++ )
if ( (*i)->start() > from )
return (*i)->start();
nframes_t
Sequence::next ( nframes_t from ) const
{
for ( list <Sequence_Widget*>::const_iterator i = _widgets.begin(); i != _widgets.end(); i++ )
if ( (*i)->start() > from )
return (*i)->start();
if ( _widgets.size() )
return _widgets.back()->start();
else
return 0;
}
if ( _widgets.size() )
return _widgets.back()->start();
else
return 0;
}
/** return the location of the next widget from frame /from/ */
nframes_t
Sequence::prev ( nframes_t from ) const
{
for ( list <Sequence_Widget*>::const_reverse_iterator i = _widgets.rbegin(); i != _widgets.rend(); i++ )
if ( (*i)->start() < from )
return (*i)->start();
nframes_t
Sequence::prev ( nframes_t from ) const
{
for ( list <Sequence_Widget*>::const_reverse_iterator i = _widgets.rbegin(); i != _widgets.rend(); i++ )
if ( (*i)->start() < from )
return (*i)->start();
if ( _widgets.size() )
return _widgets.front()->start();
else
return 0;
}
if ( _widgets.size() )
return _widgets.front()->start();
else
return 0;
}
/** delete all selected widgets in this sequence */
void
Sequence::remove_selected ( void )
{
Loggable::block_start();
void
Sequence::remove_selected ( void )
{
Loggable::block_start();
for ( list <Sequence_Widget *>::iterator r = _widgets.begin(); r != _widgets.end(); )
if ( (*r)->selected() )
{
Sequence_Widget *t = *r;
_widgets.erase( r++ );
delete t;
}
else
++r;
for ( list <Sequence_Widget *>::iterator r = _widgets.begin(); r != _widgets.end(); )
if ( (*r)->selected() )
{
Sequence_Widget *t = *r;
_widgets.erase( r++ );
delete t;
}
else
++r;
Loggable::block_end();
}
Loggable::block_end();
}
/** select all widgets intersecting with the range defined by the
* pixel coordinates X through W */
void
Sequence::select_range ( int X, int W )
{
nframes_t sts = x_to_offset( X );
nframes_t ets = sts + timeline->x_to_ts( W );
void
Sequence::select_range ( int X, int W )
{
nframes_t sts = x_to_offset( X );
nframes_t ets = sts + timeline->x_to_ts( W );
for ( list <Sequence_Widget *>::const_reverse_iterator r = _widgets.rbegin(); r != _widgets.rend(); ++r )
if ( ! ( (*r)->start() > ets || (*r)->start() + (*r)->length() < sts ) )
(*r)->select();
}
for ( list <Sequence_Widget *>::const_reverse_iterator r = _widgets.rbegin(); r != _widgets.rend(); ++r )
if ( ! ( (*r)->start() > ets || (*r)->start() + (*r)->length() < sts ) )
(*r)->select();
}

View File

@ -187,12 +187,14 @@ Sequence_Region::handle ( int m )
redraw();
return 1;
}
else if ( test_press( FL_CTRL + FL_BUTTON1 ) )
{
/* duplication */
fl_cursor( FL_CURSOR_MOVE );
return 1;
}
/* else if ( test_press( FL_CTRL + FL_BUTTON1 ) ) */
/* { */
/* /\* duplication *\/ */
/* fl_cursor( FL_CURSOR_MOVE ); */
/* return 1; */
/* } */
else
return Sequence_Widget::handle( m );
}

View File

@ -370,6 +370,15 @@ Sequence_Widget::handle ( int m )
}
else if ( test_press( FL_BUTTON1 ) || test_press( FL_BUTTON1 + FL_CTRL ) )
{
/* traditional selection model */
if ( Fl::event_ctrl() )
select();
else if ( ! selected() )
{
select_none();
select();
}
fl_cursor( FL_CURSOR_MOVE );
/* movement drag */
@ -450,7 +459,7 @@ Sequence_Widget::handle ( int m )
timeline->redraw();
}
if ( ! selected() )
if ( ! selected() || _selection.size() == 1 )
{
/* track jumping */
if ( Y > y() + h() || Y < y() )
@ -537,8 +546,14 @@ Sequence_Widget::select_none ( void )
while ( _selection.size() )
{
Sequence_Widget *w = _selection.front();
w->log_start();
_selection.front()->redraw();
_selection.pop_front();
w->log_end();
}
Loggable::block_end();

View File

@ -1177,7 +1177,7 @@ Timeline::handle ( int m )
{
case FL_PUSH:
{
if ( test_press( FL_BUTTON1 ) )
if ( test_press( FL_BUTTON1 ) || test_press( FL_BUTTON1 + FL_CTRL ) )
{
assert( ! drag );
@ -1185,6 +1185,9 @@ Timeline::handle ( int m )
_selection.x = drag->x;
_selection.y = drag->y;
if ( ! Fl::event_ctrl() )
select_none();
return 1;
}
else if ( test_press( FL_BUTTON3 ) )