Work on handling selection.

pull/3/head
Jonathan Moore Liles 2008-03-03 18:25:05 -06:00
parent ee577bc06b
commit 4f2a6a28d1
5 changed files with 77 additions and 24 deletions

View File

@ -361,7 +361,6 @@ Loggable::flush ( void )
if ( n > 1 ) if ( n > 1 )
fprintf( _fp, "}\n" ); fprintf( _fp, "}\n" );
fflush( _fp ); fflush( _fp );
} }

14
Track.C
View File

@ -25,9 +25,7 @@
#include <FL/fl_draw.H> #include <FL/fl_draw.H>
Track_Widget * Track::_queued_widget = NULL; queue <Track_Widget *> Track::_delete_queue;
@ -202,7 +200,7 @@ Track::handle ( int m )
if ( r ) if ( r )
{ {
int retval = r->handle( m ); int retval = r->dispatch( m );
if ( retval && m == FL_PUSH ) if ( retval && m == FL_PUSH )
pushed = r; pushed = r;
@ -210,11 +208,11 @@ Track::handle ( int m )
if ( retval && m == FL_RELEASE ) if ( retval && m == FL_RELEASE )
pushed = NULL; pushed = NULL;
if ( _queued_widget ) while ( _delete_queue.size() )
{ {
// remove( _queued_widget );
delete _queued_widget; delete _delete_queue.front();
_queued_widget = NULL; _delete_queue.pop();
pushed = NULL; pushed = NULL;
} }

View File

@ -30,7 +30,8 @@
#include <assert.h> #include <assert.h>
#include <list> #include <list>
using std::list; #include <queue>
using namespace std;
class Region; class Region;
class Track_Widget; class Track_Widget;
@ -41,7 +42,7 @@ class Track : public Fl_Group, public Loggable
Track *_prev; Track *_prev;
char *_name; char *_name;
static Track_Widget * _queued_widget; static queue <Track_Widget *> _delete_queue;
protected: protected:
@ -118,9 +119,7 @@ public:
void queue_delete ( Track_Widget *r ) void queue_delete ( Track_Widget *r )
{ {
assert( ! _queued_widget ); _delete_queue.push( r );
_queued_widget = r;
} }
virtual void snap ( Track_Widget *r ); virtual void snap ( Track_Widget *r );

View File

@ -20,6 +20,7 @@
#include "Track_Widget.H" #include "Track_Widget.H"
list <Track_Widget *> Track_Widget::_selection; list <Track_Widget *> Track_Widget::_selection;
Track_Widget * Track_Widget::_current;
void void
Track_Widget::draw_label ( const char *label, Fl_Align align ) Track_Widget::draw_label ( const char *label, Fl_Align align )
@ -76,13 +77,38 @@ Track_Widget::draw_label ( const char *label, Fl_Align align )
} }
int
Track_Widget::dispatch ( int m )
{
Track_Widget::_current = this;
if ( selected() )
{
Loggable::block_start();
int r = 0;
for ( list <Track_Widget *>::iterator i = _selection.begin(); i != _selection.end(); i++ )
if ( *i != this )
r |= (*i)->handle( m );
r |= handle( m );
Loggable::block_end();
return r;
}
else
return handle( m );
}
/* base hanlde just does basic dragging */ /* base hanlde just does basic dragging */
int int
Track_Widget::handle ( int m ) Track_Widget::handle ( int m )
{ {
static int ox, oy; /* static int ox, oy; */
static bool dragging = false; /* static bool dragging = false; */
int X = Fl::event_x(); int X = Fl::event_x();
int Y = Fl::event_y(); int Y = Fl::event_y();
@ -99,8 +125,9 @@ Track_Widget::handle ( int m )
return 1; return 1;
case FL_PUSH: case FL_PUSH:
{ {
ox = x() - X;
oy = y() - Y; /* ox = x() - X; */
/* oy = y() - Y; */
if ( Fl::event_state() & FL_CTRL && if ( Fl::event_state() & FL_CTRL &&
Fl::event_button() == 3 ) Fl::event_button() == 3 )
@ -115,19 +142,30 @@ Track_Widget::handle ( int m )
return 1; return 1;
} }
case FL_RELEASE: case FL_RELEASE:
if ( dragging ) if ( _drag )
{
_log.release(); _log.release();
dragging = false; delete _drag;
_drag = NULL;
}
fl_cursor( FL_CURSOR_DEFAULT ); fl_cursor( FL_CURSOR_DEFAULT );
return 1; return 1;
case FL_DRAG: case FL_DRAG:
{ {
if ( ! dragging ) if ( ! _drag )
{ {
dragging = true; _drag = new Drag( x() - X, y() - Y );
_log.hold(); _log.hold();
} }
const int ox = _drag->x;
// _current->_drag->x;
/* const int ox = _drag->x; */
/* const int oy = _drag->y; */
redraw(); redraw();
if ( timeline->ts_to_x( timeline->xoffset ) + ox + X > _track->x() ) if ( timeline->ts_to_x( timeline->xoffset ) + ox + X > _track->x() )
@ -137,7 +175,8 @@ Track_Widget::handle ( int m )
// _offset = timeline->x_to_ts( nx ) + timeline->xoffset; // _offset = timeline->x_to_ts( nx ) + timeline->xoffset;
offset( timeline->x_to_ts( nx ) + timeline->xoffset ); offset( timeline->x_to_ts( nx ) + timeline->xoffset );
_track->snap( this ); if ( Track_Widget::_current == this )
_track->snap( this );
} }
// _track->redraw(); // _track->redraw();

View File

@ -31,7 +31,8 @@ using namespace std;
class Track_Widget : public Loggable class Track_Widget : public Loggable
{ {
static list <Track_Widget *> _selection; static list <Track_Widget *> _selection; /* all the widgets making up the selection */
static Track_Widget * _current; /* the widget initiating events that affect the selection */
protected: protected:
@ -44,6 +45,17 @@ protected:
Fl_Color _color; /* color of waveform */ Fl_Color _color; /* color of waveform */
Fl_Color _box_color; /* color of background (box) */ Fl_Color _box_color; /* color of background (box) */
struct Drag
{
/* mouse coords at start of drag */
int x;
int y;
Drag( int X, int Y ) : x( X ), y( Y ) {}
};
Drag *_drag;
public: public:
Track_Widget ( ) Track_Widget ( )
@ -51,6 +63,8 @@ public:
_track = NULL; _track = NULL;
_offset = _start = _end = 0; _offset = _start = _end = 0;
_drag = NULL;
} }
virtual ~Track_Widget ( ) virtual ~Track_Widget ( )
@ -85,6 +99,8 @@ public:
delete _selection.front(); delete _selection.front();
} }
static Track_Widget *current ( void ) { return _current; }
void void
offset ( nframes_t where ) offset ( nframes_t where )
{ {
@ -112,6 +128,8 @@ public:
} }
int dispatch ( int m );
Fl_Group * parent ( void ) const { return _track; } Fl_Group * parent ( void ) const { return _track; }
int scroll_x ( void ) const { return timeline->ts_to_x( timeline->xoffset ); } int scroll_x ( void ) const { return timeline->ts_to_x( timeline->xoffset ); }