From ca3076d2ecbe3e63cd8785d7e916462af592b87b Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Tue, 13 Mar 2012 18:44:26 -0700 Subject: [PATCH] Timeline: Avoid triggering excessive redraws. --- FL/Fl_Blinker.H | 32 ++++++++++++++++++++++++++------ timeline/src/TLE.fl | 16 ++++++++++++---- timeline/src/Timeline.C | 14 +++++++++----- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/FL/Fl_Blinker.H b/FL/Fl_Blinker.H index ff3ac84..6044bf1 100644 --- a/FL/Fl_Blinker.H +++ b/FL/Fl_Blinker.H @@ -55,26 +55,46 @@ public: _blink_interval = DEFAULT; - Fl::add_timeout( _blink_interval, update_cb, this ); - - type( FL_TOGGLE_BUTTON ); } virtual ~Fl_Blinker () { - Fl::remove_timeout( update_cb, this ); + if ( value() ) + Fl::remove_timeout( update_cb, this ); } void interval ( float v ) { _blink_interval = v; - Fl::remove_timeout( update_cb, this ); - Fl::add_timeout( _blink_interval, update_cb, this ); + if ( value() ) + { + Fl::remove_timeout( update_cb, this ); + Fl::add_timeout( _blink_interval, update_cb, this ); + } } + virtual void value ( float v ) + { + if ( v ) + { + Fl::add_timeout( _blink_interval, update_cb, this ); + Fl_Button::value( v ); + redraw(); + } + else + { + Fl_Button::value( v ); + Fl::remove_timeout( update_cb, this ); + redraw(); + } + + } + + virtual float value ( void ) { return Fl_Button::value(); } + virtual void draw ( void ) { diff --git a/timeline/src/TLE.fl b/timeline/src/TLE.fl index 0c7a094..f637fab 100644 --- a/timeline/src/TLE.fl +++ b/timeline/src/TLE.fl @@ -22,7 +22,7 @@ comment {// } {in_source in_header } -decl {const float STATUS_UPDATE_FREQ = 0.1f;} {private local +decl {const float STATUS_UPDATE_FREQ = 0.5f;} {private local } decl {\#include "Fl_Menu_Settings.H"} {private local @@ -824,11 +824,17 @@ project_name->redraw();} {} } Function {update_progress( Fl_Progress *p, char *s, float v )} {private return_type {static void} } { - code {p->value( v ); + code { +if ( p->value() != v ) +{ +p->value( v ); snprintf( s, 5, "%d%%", (int)v ); -p->label( s );} {} +p->label( s ); + +} +} {} } Function {update_status()} {open private } { @@ -885,7 +891,9 @@ if ( timeline->session_manager_name() != NULL ) find_item( menubar, "&Project/&Open" )->deactivate(); } -project_name->redraw();} {} +// project_name->redraw(); + +} {} } Function {update_cb( void *v )} {open private return_type {static void} } { diff --git a/timeline/src/Timeline.C b/timeline/src/Timeline.C index 90ce084..d076fc0 100644 --- a/timeline/src/Timeline.C +++ b/timeline/src/Timeline.C @@ -83,7 +83,7 @@ bool Timeline::snap_magnetic = true; bool Timeline::follow_playhead = true; bool Timeline::center_playhead = true; -const float UPDATE_FREQ = 0.02f; +const float UPDATE_FREQ = 1.0 / 18.0f; extern const char *instance_name; extern TLE *tle; @@ -1064,18 +1064,22 @@ void Timeline::redraw_playhead ( void ) { static nframes_t last_playhead = -1; + static int last_playhead_x = -1; - if ( last_playhead != transport->frame ) + int playhead_x = ts_to_x( transport->frame ); + + if ( last_playhead_x != playhead_x ) { redraw_overlay(); last_playhead = transport->frame; + last_playhead_x = playhead_x; if ( follow_playhead ) { if ( center_playhead && active() ) - xposition( max( 0, ts_to_x( transport->frame ) - ( ( tracks->w() - Track::width() ) >> 1 ) ) ); - else if ( ts_to_x( transport->frame ) > ts_to_x( xoffset ) + ( tracks->w() - Track::width() ) ) - xposition( ts_to_x( transport->frame ) ); + xposition( max( 0, playhead_x - ( ( tracks->w() - Track::width() ) >> 1 ) ) ); + else if ( playhead_x > ts_to_x( xoffset ) + ( tracks->w() - Track::width() ) ) + xposition( playhead_x ); } } }