Browse Source

First pass at implementing fl_scroll optimization for timeline.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
b6106fc6da
6 changed files with 118 additions and 61 deletions
  1. +17
    -4
      Region.C
  2. +6
    -0
      Scalebar.H
  3. +54
    -31
      Timeline.H
  4. +7
    -3
      Track.C
  5. +11
    -4
      Track_Widget.H
  6. +23
    -19
      main.C

+ 17
- 4
Region.C View File

@@ -92,12 +92,21 @@ Region::Region ( Clip *c )
void void
Region::trim ( enum trim_e t, int X ) Region::trim ( enum trim_e t, int X )
{ {

redraw();

switch ( t ) switch ( t )
{ {
case LEFT: case LEFT:
{ {
int d = X - x(); int d = X - x();


/* if ( d < 0 ) */
/* // _track->damage( FL_DAMAGE_EXPOSE, x() + d, y(), 1 - d, h() ); */
/* _track->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() ); */
/* else */
/* _track->damage( FL_DAMAGE_EXPOSE, x(), y(), d, h() ); */

long td = timeline->x_to_ts( d ); long td = timeline->x_to_ts( d );


if ( td < 0 && _start < 0 - td ) if ( td < 0 && _start < 0 - td )
@@ -106,11 +115,16 @@ Region::trim ( enum trim_e t, int X )
_start += td; _start += td;


_offset += td; _offset += td;


break; break;
} }
case RIGHT: case RIGHT:
{ {
int d = (x() + w()) - X; int d = (x() + w()) - X;

/* _track->damage( FL_DAMAGE_EXPOSE, x() + w(), y(), d, h() ); */

long td = timeline->x_to_ts( d ); long td = timeline->x_to_ts( d );


_end -= td; _end -= td;
@@ -120,9 +134,6 @@ Region::trim ( enum trim_e t, int X )
return; return;


} }

_track->redraw();

} }


int int
@@ -253,7 +264,9 @@ Region::handle ( int m )
_track->prev()->add( this ); _track->prev()->add( this );
} }


_track->redraw();
// _track->redraw();

// _track->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() );


ret = Track_Widget::handle( m ); ret = Track_Widget::handle( m );
return ret | 1; return ret | 1;


+ 6
- 0
Scalebar.H View File

@@ -29,15 +29,19 @@ class Scalebar : public Fl_Scrollbar
{ {
double _zoom; double _zoom;


bool _zoom_changed;

public: public:


Scalebar ( int X, int Y, int W, int H ) : Fl_Scrollbar ( X, Y, W, H ) Scalebar ( int X, int Y, int W, int H ) : Fl_Scrollbar ( X, Y, W, H )
{ {
_zoom = 1.0f; _zoom = 1.0f;
_zoom_changed = true;


step( 1 ); step( 1 );
} }


bool zoom_changed ( void ) const { return _zoom_changed; }
double zoom ( void ) const { return _zoom; } double zoom ( void ) const { return _zoom; }
double value ( void ) const { return Fl_Slider::value(); } double value ( void ) const { return Fl_Slider::value(); }


@@ -57,7 +61,9 @@ public:
while ( d-- ) while ( d-- )
_zoom *= 2; _zoom *= 2;


_zoom_changed = true;
do_callback(); do_callback();
_zoom_changed = false;


slider_size( w() / maximum() ); slider_size( w() / maximum() );




+ 54
- 31
Timeline.H View File

@@ -106,8 +106,9 @@ struct Timeline : public Fl_Group


damage( FL_DAMAGE_SCROLL ); damage( FL_DAMAGE_SCROLL );


rulers->damage( FL_DAMAGE_SCROLL );
tracks->damage( FL_DAMAGE_SCROLL );
/* rulers->damage( FL_DAMAGE_SCROLL ); */
/* tracks->damage( FL_DAMAGE_SCROLL ); */

} }




@@ -121,8 +122,17 @@ struct Timeline : public Fl_Group


fl_push_clip( X, Y, W, H ); fl_push_clip( X, Y, W, H );


tl->tracks->redraw();
tl->rulers->redraw();
fl_color( rand() );
fl_rectf( X, Y, X + W, Y + H );

// tl->tracks->redraw();

tl->draw_child( *tl->rulers );
tl->draw_child( *tl->tracks );


// tl->tracks->draw();
// tl->rulers->draw();


/* FOR_CHILDREN_OF( tracks, o ) */ /* FOR_CHILDREN_OF( tracks, o ) */
/* { */ /* { */
@@ -140,39 +150,52 @@ struct Timeline : public Fl_Group
} }




/* void */
/* draw ( void ) */
/* { */
/* int X, Y, W, H; */
void
draw ( void )
{
int X, Y, W, H;


/* X = x(); */
/* Y = tracks->y(); */
/* W = w(); */
/* H = tracks->h(); */
X = tracks->x() + Fl::box_dx( tracks->child( 0 )->box() ) + 1;
Y = tracks->y();
W = tracks->w() - Fl::box_dw( tracks->child( 0 )->box() ) - 2;
H = tracks->h();


/* if ( damage() & FL_DAMAGE_ALL ) */
/* { */
/* draw_clip( this, X, Y, W, H ); */
/* return; */
/* } */


/* if ( damage() & FL_DAMAGE_SCROLL ) */
/* { */
/* fl_scroll( X, Y, W, H, _old_position - xoffset, Y, draw_clip, this ); */
/* } */
/* fl_color( FL_RED ); */
/* fl_rect( X, Y, X + W, Y + H ); */


/* if ( damage() & FL_DAMAGE_CHILD ) */
/* { */
/* // Fl_Widget *o; */
if ( damage() & FL_DAMAGE_ALL )
{
draw_clip( this, X, tracks->y(), W, tracks->h() );
draw_clip( this, X, rulers->y(), W, rulers->h() );
return;
}


/* /\* FOR_CHILDREN_OF( tracks, o ) *\/ */
/* /\* tracks->update_child( o ); *\/ */
if ( damage() & FL_DAMAGE_SCROLL )
{
printf( "doing scroll\n" );
int dx = ts_to_x( _old_position ) - ts_to_x( xoffset );


/* /\* FOR_CHILDREN_OF( rulers, o ) *\/ */
/* /\* rulers->update_child( o ); *\/ */
fl_scroll( X, tracks->y(), W, tracks->h(), dx, 0, draw_clip, this );
fl_scroll( X, rulers->y(), W, rulers->h(), dx, 0, draw_clip, this );


/* // fl_pop_clip() */
/* } */
/* } */
_old_position = 0;
}

if ( damage() & FL_DAMAGE_CHILD )
{
Fl_Widget *o;
FOR_CHILDREN_OF( this, o )
this->update_child( *o );

/* FOR_CHILDREN_OF( tracks, o ) */
/* tracks->update_child( o ); */

/* FOR_CHILDREN_OF( rulers, o ) */
/* rulers->update_child( o ); */

// fl_pop_clip()
}
}


}; };

+ 7
- 3
Track.C View File

@@ -43,18 +43,22 @@ Track::sort ( void )
void void
Track::draw ( void ) Track::draw ( void )
{ {
fl_push_clip( x(), y(), w(), h() );

Fl_Group::draw(); Fl_Group::draw();


timeline->draw_measure_lines( x(), y(), w(), h(), color() ); timeline->draw_measure_lines( x(), y(), w(), h(), color() );


fl_push_clip( x(), y(), w(), h() );
int X, Y, W, H;

fl_clip_box( x(), y(), w(), h(), X, Y, W, H );


for ( list <Track_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ ) for ( list <Track_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
(*r)->draw_box( x(), y(), w(), h() );
(*r)->draw_box( X, Y, W, H );


/* TODO: detect overlap and draw with transparency/crossfade */ /* TODO: detect overlap and draw with transparency/crossfade */
for ( list <Track_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ ) for ( list <Track_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
(*r)->draw( x(), y(), w(), h() );
(*r)->draw( X, Y, W, H );


fl_pop_clip(); fl_pop_clip();
} }


+ 11
- 4
Track_Widget.H View File

@@ -96,8 +96,13 @@ public:


virtual Fl_Boxtype box ( void ) const { return FL_UP_BOX; } virtual Fl_Boxtype box ( void ) const { return FL_UP_BOX; }


/* just draw a simple box */
void
redraw ( void )
{
_track->damage( FL_DAMAGE_EXPOSE, x(), y(), w(), h() );
}


/* just draw a simple box */
virtual void virtual void
draw_box ( int X, int Y, int W, int H ) draw_box ( int X, int Y, int W, int H )
{ {
@@ -208,6 +213,8 @@ public:
return 1; return 1;
case FL_DRAG: case FL_DRAG:
{ {
redraw();

if ( ox + X >= _track->x() ) if ( ox + X >= _track->x() )
{ {
int nx = ox + X; int nx = ox + X;
@@ -217,7 +224,7 @@ public:
_track->snap( this ); _track->snap( this );
} }


_track->redraw();
// _track->redraw();
fl_cursor( FL_CURSOR_MOVE ); fl_cursor( FL_CURSOR_MOVE );




@@ -241,9 +248,9 @@ public:
else else
pos += d; pos += d;


timeline->xoffset = pos;
timeline->position( timeline->ts_to_x( pos ) );


timeline->tracks->redraw();
// timeline->tracks->redraw();
} }






+ 23
- 19
main.C View File

@@ -55,16 +55,20 @@ cb_scroll ( Fl_Widget *w, void *v )
{ {
Scalebar *sb = (Scalebar*)w; Scalebar *sb = (Scalebar*)w;


timeline->fpp = sb->zoom() * 256;
timeline->fpp = max( min( timeline->fpp, 4096.0f ), (float)2 );
if ( sb->zoom_changed() )
{
timeline->fpp = sb->zoom() * 256;
timeline->fpp = max( min( timeline->fpp, 4096.0f ), (float)2 );


int maxx = timeline->ts_to_x( timeline->length );
sb->range( 0, maxx );
// sb->value( sb->value(), maxx
// sb->slider_size( sb->w() / maxx );
// ((Fl_Scrollbar*)sb)->value( sb->value(), 60, 10, maxx );
int maxx = timeline->ts_to_x( timeline->length );
sb->range( 0, maxx );


timeline->position( sb->value() );
timeline->redraw();
}
else
{
timeline->position( sb->value() );
}


/* timeline->xoffset = timeline->x_to_ts( sb->value() ); */ /* timeline->xoffset = timeline->x_to_ts( sb->value() ); */
/* // timeline->tracks->redraw(); */ /* // timeline->tracks->redraw(); */
@@ -72,17 +76,17 @@ cb_scroll ( Fl_Widget *w, void *v )


printf( "%lu\n", timeline->xoffset ); printf( "%lu\n", timeline->xoffset );


for ( int i = timeline->tracks->children(); i-- ; )
{
Fl_Group *track = (Fl_Group*)timeline->tracks->child( i );
track->damage( FL_DAMAGE_SCROLL );
}
/* for ( int i = timeline->tracks->children(); i-- ; ) */
/* { */
/* Fl_Group *track = (Fl_Group*)timeline->tracks->child( i ); */
/* track->damage( FL_DAMAGE_SCROLL ); */
/* } */


for ( int i = timeline->rulers->children(); i-- ; )
{
Fl_Group *track = (Fl_Group*)timeline->rulers->child( i );
track->damage( FL_DAMAGE_SCROLL );
}
/* for ( int i = timeline->rulers->children(); i-- ; ) */
/* { */
/* Fl_Group *track = (Fl_Group*)timeline->rulers->child( i ); */
/* track->damage( FL_DAMAGE_SCROLL ); */
/* } */






@@ -100,7 +104,7 @@ cb_scroll ( Fl_Widget *w, void *v )
int int
main ( int argc, char **argv ) main ( int argc, char **argv )
{ {
Fl_Double_Window *main_window = new Fl_Double_Window( 0, 0, 800, 600 );
Fl_Window *main_window = new Fl_Window( 0, 0, 800, 600 );


Fl::get_system_colors(); Fl::get_system_colors();
Fl::scheme( "plastic" ); Fl::scheme( "plastic" );


Loading…
Cancel
Save