From 221242a27da12649c7f0d99f5aa1d1ceea576605 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Tue, 15 Jul 2008 00:41:05 -0500 Subject: [PATCH] Implement traditional mouse selection model. --- Timeline/Sequence.C | 120 ++++++++++++++++++++----------------- Timeline/Sequence_Region.C | 14 +++-- Timeline/Sequence_Widget.C | 17 +++++- Timeline/Timeline.C | 5 +- 4 files changed, 93 insertions(+), 63 deletions(-) diff --git a/Timeline/Sequence.C b/Timeline/Sequence.C index ffc0884..ea9fe0d 100644 --- a/Timeline/Sequence.C +++ b/Timeline/Sequence.C @@ -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 ::const_iterator r = _widgets.begin(); r != _widgets.end(); ++r ) - l = max( l, (*r)->start() + (*r)->length() ); + for ( list ::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 ::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 ::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 ::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 ::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 ::iterator r = _widgets.begin(); r != _widgets.end(); ) - if ( (*r)->selected() ) - { - Sequence_Widget *t = *r; - _widgets.erase( r++ ); - delete t; - } - else - ++r; + for ( list ::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 ::const_reverse_iterator r = _widgets.rbegin(); r != _widgets.rend(); ++r ) - if ( ! ( (*r)->start() > ets || (*r)->start() + (*r)->length() < sts ) ) - (*r)->select(); -} + for ( list ::const_reverse_iterator r = _widgets.rbegin(); r != _widgets.rend(); ++r ) + if ( ! ( (*r)->start() > ets || (*r)->start() + (*r)->length() < sts ) ) + (*r)->select(); + } diff --git a/Timeline/Sequence_Region.C b/Timeline/Sequence_Region.C index 5e7f86e..67584f6 100644 --- a/Timeline/Sequence_Region.C +++ b/Timeline/Sequence_Region.C @@ -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 ); } diff --git a/Timeline/Sequence_Widget.C b/Timeline/Sequence_Widget.C index 7d2d4d3..14c3435 100644 --- a/Timeline/Sequence_Widget.C +++ b/Timeline/Sequence_Widget.C @@ -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(); diff --git a/Timeline/Timeline.C b/Timeline/Timeline.C index a385618..0d51be9 100644 --- a/Timeline/Timeline.C +++ b/Timeline/Timeline.C @@ -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 ) )