Make track use track_widget base class instead of regions.

This commit is contained in:
Jonathan Moore Liles 2008-02-20 18:14:44 -06:00
parent a2ea182810
commit 08182d2c5f
4 changed files with 47 additions and 21 deletions

View File

@ -300,15 +300,13 @@ Region::resize ( void )
int measure = 40; int measure = 40;
/* X is the timeline offset, W is the width of the track */ /* Draw (part of) region. Start is */
void void
Region::draw ( int X, int Y, int W, int H ) Region::draw ( int X, int Y, int W, int H )
{ {
if ( ! ( W > 0 && H > 0 ) ) if ( ! ( W > 0 && H > 0 ) )
return; return;
if ( _offset > timeline.xoffset + timeline.x_to_ts( _track->w() ) || if ( _offset > timeline.xoffset + timeline.x_to_ts( _track->w() ) ||
( _offset < timeline.xoffset && ( _offset < timeline.xoffset &&
_offset + (_end - _start) < timeline.xoffset ) ) _offset + (_end - _start) < timeline.xoffset ) )

View File

@ -35,7 +35,7 @@ using namespace std;
/* Base class for virtual widget on a track */ /* Base class for virtual widget on a track */
class TrackWidget class Track_Widget
{ {
protected: protected:
@ -78,9 +78,36 @@ public:
nframes_t start ( void ) const { return _start; } nframes_t start ( void ) const { return _start; }
nframes_t length ( void ) const { return _end - _start; } nframes_t length ( void ) const { return _end - _start; }
virtual void
draw ( int X, int Y, int W, int H )
{
fl_draw_box( FL_FLAT_BOX, X, Y, W, H, _box_color );
}
virtual int
handle ( int m ) { return 0; }
}; };
class Region : public TrackWidget
class Tempo : public Track_Widget
{
float _tempo;
void
draw ( int X, int Y, int W, int H )
{
}
};
class Region : public Track_Widget
{ {
Clip *_clip; /* clip this region represents */ Clip *_clip; /* clip this region represents */

20
Track.C
View File

@ -33,7 +33,7 @@ Track::draw ( void )
fl_push_clip( x(), y(), w(), h() ); fl_push_clip( x(), y(), w(), h() );
for ( list <Region *>::iterator r = _regions.begin(); r != _regions.end(); r++ ) for ( list <Track_Widget *>::iterator r = _regions.begin(); r != _regions.end(); r++ )
{ {
// (*r)->draw( timeline.xoffset + x(), y(), w(), h() ); // (*r)->draw( timeline.xoffset + x(), y(), w(), h() );
(*r)->draw( x(), y(), w(), h() ); (*r)->draw( x(), y(), w(), h() );
@ -43,18 +43,18 @@ Track::draw ( void )
} }
void void
Track::remove_region ( Region *r ) Track::remove_region ( Track_Widget *r )
{ {
_regions.remove( r ); _regions.remove( r );
} }
Region * Track_Widget *
Track::event_region ( void ) Track::event_region ( void )
{ {
// FIXME: doesn't handle overlap! // FIXME: doesn't handle overlap!
int ets = timeline.xoffset + timeline.x_to_ts( Fl::event_x() ); int ets = timeline.xoffset + timeline.x_to_ts( Fl::event_x() );
for ( list <Region *>::iterator r = _regions.begin(); r != _regions.end(); r++ ) for ( list <Track_Widget *>::iterator r = _regions.begin(); r != _regions.end(); r++ )
if ( ets > (*r)->offset() && ets < (*r)->offset() + (*r)->length() ) if ( ets > (*r)->offset() && ets < (*r)->offset() + (*r)->length() )
return (*r); return (*r);
@ -62,7 +62,7 @@ Track::event_region ( void )
} }
void void
Track::add ( Region *r ) Track::add ( Track_Widget *r )
{ {
if ( r->track() ) if ( r->track() )
{ {
@ -83,16 +83,16 @@ Track::add ( Region *r )
/* snap /r/ to nearest edge */ /* snap /r/ to nearest edge */
void void
Track::snap ( Region *r ) Track::snap ( Track_Widget *r )
{ {
const int snap_pixels = 10; const int snap_pixels = 10;
int rx1 = r->x(); int rx1 = r->x();
int rx2 = r->x() + r->w(); int rx2 = r->x() + r->w();
for ( list <Region*>::iterator i = _regions.begin(); i != _regions.end(); i++ ) for ( list <Track_Widget*>::iterator i = _regions.begin(); i != _regions.end(); i++ )
{ {
const Region *w = (*i); const Track_Widget *w = (*i);
if ( w == r ) if ( w == r )
continue; continue;
@ -131,7 +131,7 @@ done:
int int
Track::handle ( int m ) Track::handle ( int m )
{ {
static Region *current_region; static Track_Widget *current_region;
switch ( m ) switch ( m )
{ {
@ -180,7 +180,7 @@ Track::handle ( int m )
return 1; return 1;
default: default:
{ {
Region *r = event_region(); Track_Widget *r = event_region();
if ( current_region ) if ( current_region )
r = current_region; r = current_region;

11
Track.H
View File

@ -32,17 +32,18 @@
using std::list; using std::list;
class Region; class Region;
class Track_Widget;
class Track : public Fl_Group class Track : public Fl_Group
{ {
Track *_next; Track *_next;
Track *_prev; Track *_prev;
list <Region *> _regions; list <Track_Widget *> _regions;
char *_name; char *_name;
Region *event_region ( void ); Track_Widget *event_region ( void );
public: public:
@ -62,9 +63,9 @@ public:
void draw ( void ); void draw ( void );
void remove_region ( Region *r ); void remove_region ( Track_Widget *r );
void add ( Region *r ); void add ( Track_Widget *r );
void snap ( Region *r ); void snap ( Track_Widget *r );
int handle ( int m ); int handle ( int m );
}; };