Clean up zooming/horizontal scrolling.

This commit is contained in:
Jonathan Moore Liles 2008-04-27 08:37:50 -05:00
parent bbc4376ee2
commit fb5f111167
2 changed files with 18 additions and 9 deletions

View File

@ -71,7 +71,7 @@ public:
bool zoom_changed ( void ) const { return _zoom_changed; } bool zoom_changed ( void ) const { return _zoom_changed; }
double zoom ( void ) const { return _zoom; } double zoom ( void ) const { return _zoom; }
void zoom ( double v ) { _zoom = v; } void zoom ( double v ) { _zoom = v; }
double value ( void ) const { return Fl_Slider::value(); } // double value ( void ) const { return Fl_Slider::value(); }
void zoom_range ( double zmin, double zmax ) { _zoom_min = zmin; _zoom_max = zmax; } void zoom_range ( double zmin, double zmax ) { _zoom_min = zmin; _zoom_max = zmax; }
void zoom_out ( void ) { int z = _zoom; _zoom *= 2; constrain(); maybe_do_callback( z ); } void zoom_out ( void ) { int z = _zoom; _zoom *= 2; constrain(); maybe_do_callback( z ); }

View File

@ -67,15 +67,14 @@ Timeline::cb_scroll ( Fl_Widget *w )
{ {
_fpp = hscroll->zoom() * 1; _fpp = hscroll->zoom() * 1;
int maxx = ts_to_x( _length ); // hscroll->range( 0, ts_to_x( _length ) - tracks->w() - Track::width() );
hscroll->range( 0, maxx ); const int tw = tracks->w() - Track::width() - vscroll->w();
hscroll->value( ts_to_x( xoffset ), tw, 0, ts_to_x( _length ) - ( tw << 1 ) );
redraw(); redraw();
} }
else
{ xposition( hscroll->value() );
xposition( hscroll->value() );
}
} }
} }
@ -94,7 +93,8 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Overlay_Wi
Scalebar *o = new Scalebar( X, Y + H - 18, W - 18, 18 ); Scalebar *o = new Scalebar( X, Y + H - 18, W - 18, 18 );
o->range( 0, 48000 * 300 ); o->range( 0, 48000 * 300 );
o->zoom_range( 2, 8192 ); // o->zoom_range( 1, 16384 );
o->zoom_range( 1, 65536 << 4 );
o->zoom( 256 ); o->zoom( 256 );
o->type( FL_HORIZONTAL ); o->type( FL_HORIZONTAL );
o->callback( cb_scroll, this ); o->callback( cb_scroll, this );
@ -250,6 +250,9 @@ Timeline::nearest_line ( int ix )
{ {
const int measure = ts_to_x( (double)(sample_rate() * 60) / beats_per_minute( x_to_ts( x - Track::width() ) + xoffset )); const int measure = ts_to_x( (double)(sample_rate() * 60) / beats_per_minute( x_to_ts( x - Track::width() ) + xoffset ));
if ( measure == 0 )
break;
// const int abs_x = ts_to_x( xoffset ) + x - Track::width(); // const int abs_x = ts_to_x( xoffset ) + x - Track::width();
const int abs_x = ts_to_x( xoffset ) + x; const int abs_x = ts_to_x( xoffset ) + x;
@ -293,9 +296,11 @@ Timeline::draw_measure ( int X, int Y, int W, int H, Fl_Color color, bool BBT )
for ( int x = X; x < X + W; ++x ) for ( int x = X; x < X + W; ++x )
{ {
measure = ts_to_x( (double)(sample_rate() * 60) / beats_per_minute( x_to_ts( x - Track::width() ) + xoffset ) ); measure = ts_to_x( (double)(sample_rate() * 60) / beats_per_minute( x_to_ts( x - Track::width() ) + xoffset ) );
if ( measure == 0 )
break;
const int abs_x = ts_to_x( xoffset ) + x - Track::width(); const int abs_x = ts_to_x( xoffset ) + x - Track::width();
if ( 0 == abs_x % measure ) if ( 0 == abs_x % measure )
@ -357,6 +362,7 @@ Timeline::draw_measure ( int X, int Y, int W, int H, Fl_Color color, bool BBT )
} }
} }
fl_line_style( FL_SOLID, 0 ); fl_line_style( FL_SOLID, 0 );
} }
@ -379,6 +385,9 @@ Timeline::xposition ( int X )
{ {
// _old_xposition = xoffset; // _old_xposition = xoffset;
/* FIXME: shouldn't have to do this... */
X = min( X, ts_to_x( _length ) - tracks->w() - Track::width() );
xoffset = x_to_ts( X ); xoffset = x_to_ts( X );
damage( FL_DAMAGE_SCROLL ); damage( FL_DAMAGE_SCROLL );