From 319a393cd6035783a55e48207151868ca89ff0f2 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Thu, 17 Sep 2015 19:34:22 -0700 Subject: [PATCH] Timeline: Fix region/fade drawing at tight zoom levels. Closes #164 --- timeline/src/Audio_Region.C | 11 +++++------ timeline/src/Control_Point.H | 2 +- timeline/src/Sequence_Point.H | 2 +- timeline/src/Sequence_Region.C | 2 +- timeline/src/Sequence_Widget.H | 23 ++++++++++++++++------- 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/timeline/src/Audio_Region.C b/timeline/src/Audio_Region.C index fdc1f6b..9c36581 100644 --- a/timeline/src/Audio_Region.C +++ b/timeline/src/Audio_Region.C @@ -405,7 +405,7 @@ Audio_Region::draw_fade ( const Fade &fade, Fade::fade_dir_e dir, bool line, int if ( dir == Fade::In ) { - fx = line_x(); + fx = curve_x(); if ( fx + width < X || fx > X + W ) @@ -414,7 +414,7 @@ Audio_Region::draw_fade ( const Fade &fade, Fade::fade_dir_e dir, bool line, int } else { - fx = line_x() + abs_w(); + fx = curve_x() + abs_w(); if ( fx - width > X + W || fx < X ) @@ -431,8 +431,8 @@ Audio_Region::draw_fade ( const Fade &fade, Fade::fade_dir_e dir, bool line, int fl_vertex( fx, dy + height ); { - const float ti = 1.0f / (float)width; - float ts = 0.0f; + const double ti = 1.0 / (double)width; + double ts = 0.0; const int xi = dir == Fade::In ? 1 : -1; @@ -487,8 +487,7 @@ Audio_Region::draw_box( void ) b = FL_DOWN_FRAME; } - fl_draw_box( b, line_x(), y(), abs_w(), h(), c ); - + fl_draw_box( b, x(), y(), w(), h(), c ); // fl_pop_clip(); } diff --git a/timeline/src/Control_Point.H b/timeline/src/Control_Point.H index 10535bd..171be96 100644 --- a/timeline/src/Control_Point.H +++ b/timeline/src/Control_Point.H @@ -57,7 +57,7 @@ public: /* only for playback thread */ nframes_t when ( void ) const { return _range.start; } - int abs_w ( void ) const { return 8; } + long abs_w ( void ) const { return 8; } int y ( void ) const { return parent()->y() + ((float)parent()->h() * _y); } int h ( void ) const { return 8; } diff --git a/timeline/src/Sequence_Point.H b/timeline/src/Sequence_Point.H index f80a79a..af64b46 100644 --- a/timeline/src/Sequence_Point.H +++ b/timeline/src/Sequence_Point.H @@ -41,7 +41,7 @@ protected: public: Fl_Align align ( void ) const { return FL_ALIGN_RIGHT; } - virtual int abs_w ( void ) const { return 8; } + virtual long abs_w ( void ) const { return 8; } // virtual int abs_x ( void ) const { return Sequence_Widget::abs_x() - ( abs_w() >> 1 ); } // virtual int x ( void ) const { return Sequence_Widget::line_x() - ( abs_w() >> 1 ); } diff --git a/timeline/src/Sequence_Region.C b/timeline/src/Sequence_Region.C index cc26c4a..c119467 100644 --- a/timeline/src/Sequence_Region.C +++ b/timeline/src/Sequence_Region.C @@ -239,7 +239,7 @@ Sequence_Region::draw_box ( void ) { Fl_Color c = selected() ? selection_color() : box_color(); - fl_draw_box( box(), line_x(), y(), abs_w(), h(), fl_color_add_alpha( c, 127 ) ); + fl_draw_box( box(), x(), y(), w(), h(), fl_color_add_alpha( c, 127 ) ); } void diff --git a/timeline/src/Sequence_Widget.H b/timeline/src/Sequence_Widget.H index 4a16896..ba1e2f0 100644 --- a/timeline/src/Sequence_Widget.H +++ b/timeline/src/Sequence_Widget.H @@ -189,8 +189,9 @@ public: int get_x( nframes_t frame ) const { return frame < timeline->xoffset ? - _sequence->drawable_x() : - min( _sequence->drawable_x() + _sequence->drawable_w(), _sequence->drawable_x() + timeline->ts_to_x( frame - timeline->xoffset ) ); + _sequence->drawable_x() - 10 : + min( _sequence->drawable_x() + _sequence->drawable_w(), + _sequence->drawable_x() + timeline->ts_to_x( frame - timeline->xoffset ) ); } virtual int x ( void ) const @@ -198,19 +199,27 @@ public: return get_x( _r->start ); } - /* use this as x() when you need to draw lines between widgets */ + /* use this as x() when you need to draw lines between widgets. Clamped to -32767-32767 to match max canvas size of FLTK/NTK */ int line_x ( void ) const { return _r->start < timeline->xoffset ? max( -32767, _sequence->drawable_x() - timeline->ts_to_x( timeline->xoffset - _r->start )) : - min( 32767, _sequence->drawable_x() + timeline->ts_to_x( _r->start - timeline->xoffset ) ); + min( 32767, _sequence->drawable_x() + timeline->ts_to_x( _r->start - timeline->xoffset )); + } + + /* same as above but un-clamped for cairo */ + long curve_x ( void ) const + { + return _r->start < timeline->xoffset ? + _sequence->drawable_x() - timeline->ts_to_x( timeline->xoffset - _r->start ) : + _sequence->drawable_x() + timeline->ts_to_x( _r->start - timeline->xoffset ); } virtual int w ( void ) const { // int tx = timeline->ts_to_x( _r->start ); - int rw; + long rw; if ( _r->start < timeline->xoffset ) { @@ -222,11 +231,11 @@ public: else rw = abs_w(); - return min( rw, _sequence->drawable_w() ); + return (int)min( rw, (long)(_sequence->drawable_w() + 20) ); } int abs_x ( void ) const { return timeline->ts_to_x( _r->start ); } - virtual int abs_w ( void ) const { return timeline->ts_to_x( _r->length ); } + virtual long abs_w ( void ) const { return timeline->ts_to_x( _r->length ); } Fl_Color color ( void ) const { return _color; } void color ( Fl_Color v ) { _color = v; }