Make vertical scrolling work.

pull/3/head
Jonathan Moore Liles 2008-02-25 22:58:15 -06:00
parent 364fee5983
commit 63fb8971a2
4 changed files with 145 additions and 109 deletions

View File

@ -23,13 +23,72 @@
#include "Time_Track.H"
#include "Audio_Track.H"
#include <FL/Fl_Scrollbar.H>
void
cb_hscroll ( Fl_Widget *w, void *v )
{
Scalebar *sb = (Scalebar*)w;
if ( sb->zoom_changed() )
{
timeline->fpp = sb->zoom() * 1;
int maxx = timeline->ts_to_x( timeline->length );
sb->range( 0, maxx );
timeline->redraw();
}
else
{
timeline->position( sb->value() );
}
printf( "%lu\n", timeline->xoffset );
}
void
cb_vscroll ( Fl_Widget *w, void *v )
{
Fl_Scrollbar *sb = (Fl_Scrollbar*)w;
timeline->tracks->position( timeline->tracks->x(), (timeline->rulers->y() + timeline->rulers->h()) - sb->value() );
timeline->yposition = sb->value();
timeline->vscroll->range( 0, timeline->tracks->h() - timeline->h() - timeline->rulers->h() );
timeline->damage( FL_DAMAGE_SCROLL );
}
Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Group( X, Y, W, H, L )
{
xoffset = 0;
{
Fl_Pack *o = new Fl_Pack( 0, 0, 800, 600, "rulers" );
Scalebar *o = new Scalebar( X, H - 18, W - 18, 18 );
o->range( 0, 48000 * 2 );
o->zoom_range( 2, 8192 );
o->zoom( 256 );
o->type( FL_HORIZONTAL );
o->callback( cb_hscroll, 0 );
hscroll = o;
}
{
Fl_Scrollbar *o = new Fl_Scrollbar( W - 18, Y, 18, H - 18 );
o->type( FL_VERTICAL );
o->step( 10 );
o->callback( cb_vscroll, 0 );
vscroll = o;
}
{
Fl_Pack *o = new Fl_Pack( 0, 0, W - vscroll->w(), H - hscroll->h(), "rulers" );
o->type( Fl_Pack::VERTICAL );
{
@ -59,13 +118,16 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Group( X,
}
o->size( o->w(), o->child( 0 )->h() * o->children() );
rulers = o;
o->end();
}
{
Fl_Scroll *o = new Fl_Scroll( 0, 24 * 2, 800, 600 - (24 * 3) );
o->type( Fl_Scroll::VERTICAL_ALWAYS );
/* Fl_Scroll *o = new Fl_Scroll( 0, 24 * 2, 800, 600 - (24 * 3) ); */
/* o->type( Fl_Scroll::VERTICAL_ALWAYS ); */
sample_rate = 44100;
fpp = 256;
@ -73,12 +135,12 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Group( X,
length = sample_rate * 60 * 2;
{
Fl_Pack *o = new Fl_Pack( 0, 0, 800, 5000 );
Fl_Pack *o = new Fl_Pack( X, rulers->y() + rulers->h(), W - vscroll->w(), 5000 );
o->type( Fl_Pack::VERTICAL );
o->spacing( 10 );
Track *l = NULL;
for ( int i = 6; i--; )
for ( int i = 16; i--; )
{
Track *o = new Audio_Track( 0, 0, 800, 100 );
@ -93,10 +155,13 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Group( X,
o->end();
}
scroll = o;
o->end();
/* scroll = o; */
/* o->end(); */
}
vscroll->range( 0, tracks->h() );
redraw();
end();

View File

@ -51,7 +51,8 @@ using std::list;
struct Timeline : public Fl_Group
{
int _old_position;
int _old_xposition;
int _old_yposition;
enum snap_flags_e {
SNAP_TO_REGION,
@ -62,7 +63,8 @@ struct Timeline : public Fl_Group
Fl_Scroll *scroll;
Fl_Pack *tracks;
Fl_Pack *rulers;
Scalebar *scrollbar;
Scalebar *hscroll;
Fl_Scrollbar *vscroll;
Tempo_Track *tempo_track;
Time_Track *time_track;
@ -76,6 +78,8 @@ struct Timeline : public Fl_Group
nframes_t length;
int yposition;
int _beats_per_bar;
float _beats_per_minute;
@ -102,7 +106,7 @@ struct Timeline : public Fl_Group
void
position ( int X )
{
_old_position = xoffset;
_old_xposition = xoffset;
xoffset = x_to_ts( X );
@ -114,7 +118,7 @@ struct Timeline : public Fl_Group
}
#define FOR_CHILDREN_OF( name, ind ) \
#define FOR_CHILDREN_OF( name, ind ) \
for ( int i = (name) ->children(); i-- && ( (ind) = (name) ->child( i ) ); )
static void
@ -127,26 +131,8 @@ struct Timeline : public Fl_Group
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 ) */
/* { */
/* tracks->draw_child( *o ); */
/* tracks->draw_outside_label( *o ); */
/* } */
/* FOR_CHILDREN_OF( rulers, o ) */
/* { */
/* tracks->draw_child( o ); */
/* tracks->draw_outside_label( o ); */
/* } */
tl->draw_child( *tl->rulers );
fl_pop_clip();
}
@ -163,45 +149,84 @@ struct Timeline : public Fl_Group
H = tracks->h();
/* fl_color( FL_RED ); */
/* fl_rect( X, Y, X + W, Y + H ); */
if ( damage() & FL_DAMAGE_ALL )
{
Fl_Group::draw();
/* draw_clip( this, X, tracks->y(), W, tracks->h() ); */
/* draw_clip( this, X, rulers->y(), W, rulers->h() ); */
/* fl_push_clip( x(), y(), w() - vscroll->w(), h() - hscroll->h() ); */
/* Fl_Group::draw(); */
/* fl_pop_clip(); */
/* draw_child( *hscroll ); */
/* draw_child( *vscroll ); */
fl_push_clip( rulers->x(), rulers->y(), rulers->w(), rulers->h() );
draw_child( *rulers );
fl_pop_clip();
fl_push_clip( tracks->x(), rulers->y() + rulers->h(), tracks->w(), h() - hscroll->h() );
draw_child( *tracks );
fl_pop_clip();
draw_child( *hscroll );
draw_child( *vscroll );
return;
}
if ( damage() & FL_DAMAGE_SCROLL )
{
// printf( "doing scroll\n" );
int dx = ts_to_x( _old_position ) - ts_to_x( xoffset );
int dx = ts_to_x( _old_xposition ) - ts_to_x( xoffset );
int dy = _old_yposition - yposition;
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 );
if ( ! dy )
fl_scroll( X, rulers->y(), W, rulers->h(), dx, 0, draw_clip, this );
Y = rulers->y() + rulers->h();
H = h() - rulers->h() - hscroll->h();
fl_scroll( X, Y, W, H, dx, dy, draw_clip, this );
_old_xposition = xoffset;
_old_yposition = yposition;
_old_position = 0;
}
if ( damage() & FL_DAMAGE_CHILD )
{
Fl_Widget *o;
FOR_CHILDREN_OF( this, o )
this->update_child( *o );
fl_push_clip( rulers->x(), rulers->y(), rulers->w(), rulers->h() );
update_child( *rulers );
fl_pop_clip();
/* FOR_CHILDREN_OF( tracks, o ) */
/* tracks->update_child( o ); */
fl_push_clip( tracks->x(), rulers->y() + rulers->h(), tracks->w(), h() - rulers->h() - hscroll->h() );
update_child( *tracks );
fl_pop_clip();
/* FOR_CHILDREN_OF( rulers, o ) */
/* rulers->update_child( o ); */
// fl_pop_clip()
update_child( *hscroll );
update_child( *vscroll );
}
}
int handle ( int m )
{
switch ( m )
{
case FL_MOUSEWHEEL:
{
if ( hscroll->handle( m ) )
return 1;
return vscroll->handle( m );
}
default:
return Fl_Group::handle( m );
}
}
};

View File

@ -47,7 +47,11 @@ Track::sort ( void )
void
Track::draw ( void )
{
fl_push_clip( x(), y(), w(), h() );
if ( ! fl_not_clipped( x(), y(), w(), h() ) )
return;
/* fl_push_clip( x(), y(), w(), h() ); */
Fl_Group::draw();
@ -64,7 +68,7 @@ Track::draw ( void )
for ( list <Track_Widget *>::const_iterator r = _widgets.begin(); r != _widgets.end(); r++ )
(*r)->draw( X, Y, W, H );
fl_pop_clip();
/* fl_pop_clip(); */
}
void

60
main.C
View File

@ -51,59 +51,6 @@
Timeline *timeline;
void
cb_scroll ( Fl_Widget *w, void *v )
{
Scalebar *sb = (Scalebar*)w;
if ( sb->zoom_changed() )
{
// timeline->fpp = sb->zoom() * 256;
timeline->fpp = sb->zoom() * 1;
/* timeline->fpp = max( min( timeline->fpp, 4096.0f ), (float)2 ); */
int maxx = timeline->ts_to_x( timeline->length );
sb->range( 0, maxx );
// timeline->redraw();
timeline->redraw();
}
else
{
timeline->position( sb->value() );
}
/* timeline->xoffset = timeline->x_to_ts( sb->value() ); */
/* // timeline->tracks->redraw(); */
/* timeline->scroll->redraw(); */
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->rulers->children(); i-- ; ) */
/* { */
/* Fl_Group *track = (Fl_Group*)timeline->rulers->child( i ); */
/* track->damage( FL_DAMAGE_SCROLL ); */
/* } */
/* /\* for ( int j = track->children(); j-- ; ) *\/ */
/* /\* ((Region*)(track->child( j )))->resize(); *\/ */
/* /\* } *\/ */
}
void cb_undo ( Fl_Widget *w, void *v )
{
Loggable::undo();
@ -126,12 +73,7 @@ main ( int argc, char **argv )
/* track1->next( track2 ); */
/* track2->prev( track1 ); */
timeline->scrollbar = new Scalebar( 0, 600 - 24, 800, 24 );
timeline->scrollbar->range( 0, 48000 * 2 );
timeline->scrollbar->zoom_range( 2, 8192 );
timeline->scrollbar->zoom( 256 );
timeline->scrollbar->type( 1 );
timeline->scrollbar->callback( cb_scroll, 0 );
// timeline->scrollbar = new Scalebar( 0, 600 - 24, 800, 24 );
Fl_Button *o = new Fl_Button( 0, 0, 50, 50, "undo" );
o->callback( cb_undo, 0 );