Try to generalize the Track_Widget display calculations.

pull/3/head
Jonathan Moore Liles 2008-02-21 00:02:43 -06:00
parent a1dd1192cc
commit 2902ea92dc
4 changed files with 40 additions and 14 deletions

View File

@ -266,7 +266,15 @@ Region::handle ( int m )
}
}
void
Region::draw_box( int X, int Y, int W, int H )
{
/* dirty hack to keep the box from flipping to vertical at small sizes */
fl_push_clip( x(), Y, w(), H );
fl_draw_box( box(), x() - 10, Y, w() + 50, H, _box_color );
fl_pop_clip();
}
/* Draw (part of) region. OX is pixel offset from start of timeline, X
Y W and H are the portion of the widget to draw (arrived at by
@ -281,7 +289,7 @@ Region::draw ( int X, int Y, int W, int H )
int ox = timeline.ts_to_x( _offset );
if ( ox > OX + _track->w() ||
ox < OX && ox + w() < OX )
ox < OX && ox + abs_w() < OX )
return;
int rw = timeline.ts_to_x( _end - _start );
@ -306,7 +314,7 @@ Region::draw ( int X, int Y, int W, int H )
fl_push_clip( rx, Y, rw, H );
/* dirty hack to keep the box from flipping to vertical at small sizes */
fl_draw_box( box(), rx - 10, Y, rw + 50, H, _box_color );
// fl_draw_box( box(), rx - 10, Y, rw + 50, H, _box_color );
// fl_push_clip( x() + Fl::box_dx( box() ), y(), w() - Fl::box_dw( box() ), h() );

View File

@ -69,14 +69,23 @@ public:
int y ( void ) const { return _track->y(); }
int h ( void ) const { return _track->h(); }
int x ( void ) const { return _offset < timeline.xoffset ? -1 : min( 32767, _track->x() + timeline.ts_to_x( _offset - timeline.xoffset ) ); }
// int x ( void ) const { return (short)( _track->x() + timeline.ts_to_x( _offset - timeline.xoffset )); }
virtual int w ( void ) const { return timeline.ts_to_x( _end - _start ); }
// int w ( void ) const { return timeline.ts_to_x( (_end - _start) - ( timeline.xoffset - _offset) ); }
int x ( void ) const { return _offset < timeline.xoffset ? -1 : min( 32767, _track->x() + timeline.ts_to_x( _offset - timeline.xoffset ) ); }
virtual int w ( void ) const
{
int tx = timeline.ts_to_x( _offset );
int rw;
if ( tx < scroll_x() )
rw = abs_w() - (scroll_x() - tx);
else
rw = abs_w();
return min( rw, _track->w() );
}
int abs_x ( void ) const { return timeline.ts_to_x( timeline.xoffset ); }
int abs_w ( void ) const { return timeline.ts_to_x( _end - _start ); }
virtual int abs_w ( void ) const { return timeline.ts_to_x( _end - _start ); }
Fl_Color color ( void ) { return _color; }
@ -98,10 +107,17 @@ public:
virtual Fl_Boxtype box ( void ) const { return FL_UP_BOX; }
/* just draw a simple box */
virtual void
draw_box ( int X, int Y, int W, int H )
{
fl_draw_box( box(), x(), y(), w(), y(), _box_color );
}
virtual void
draw ( int X, int Y, int W, int H )
{
fl_draw_box( box(), x(), y(), w(), y(), _box_color );
draw_box( X, Y, W, H );
}
@ -231,8 +247,8 @@ protected:
public:
int w ( void ) const { return 10; }
nframes_t length ( void ) const { return timeline.x_to_ts( w() ); }
int abs_w ( void ) const { return 10; }
nframes_t length ( void ) const { return timeline.x_to_ts( abs_w() ); }
Track_Point ( )
{
@ -242,9 +258,6 @@ public:
void
draw ( int X, int Y, int W, int H )
{
if ( x() < 0 )
return;
Track_Widget::draw( x(), Y, w(), H );
draw_label( _label, FL_ALIGN_RIGHT );
@ -302,6 +315,7 @@ public:
Region ( Clip *c );
int handle ( int m );
void draw_box( int X, int Y, int W, int H );
void draw ( int X, int Y, int W, int H );
void resize ( void );

View File

@ -47,6 +47,10 @@ Track::draw ( void )
fl_push_clip( x(), y(), w(), h() );
for ( list <Track_Widget *>::iterator r = _regions.begin(); r != _regions.end(); r++ )
(*r)->draw_box( x(), y(), w(), h() );
/* TODO: detect overlap and draw with transparency/crossfade */
for ( list <Track_Widget *>::iterator r = _regions.begin(); r != _regions.end(); r++ )
(*r)->draw( x(), y(), w(), h() );

2
main.C
View File

@ -123,7 +123,7 @@ main ( int argc, char **argv )
// Fl_Group *pack = new Fl_Group( 0, 0, 5000, 600 );
{
Track *tempo_track = new Track( 0, 0, 800, 24 );
Track *tempo_track = new Track( 100, 0, 800, 24 );
tempo_track->label( "tempo map" );
tempo_track->add( new Tempo_Point( 0, 120 ) );