Timeline: Avoid triggering excessive redraws.

This commit is contained in:
Jonathan Moore Liles 2012-03-13 18:44:26 -07:00
parent a988b18062
commit ca3076d2ec
3 changed files with 47 additions and 15 deletions

View File

@ -55,26 +55,46 @@ public:
_blink_interval = DEFAULT; _blink_interval = DEFAULT;
Fl::add_timeout( _blink_interval, update_cb, this );
type( FL_TOGGLE_BUTTON ); type( FL_TOGGLE_BUTTON );
} }
virtual virtual
~Fl_Blinker () ~Fl_Blinker ()
{ {
Fl::remove_timeout( update_cb, this ); if ( value() )
Fl::remove_timeout( update_cb, this );
} }
void void
interval ( float v ) interval ( float v )
{ {
_blink_interval = v; _blink_interval = v;
Fl::remove_timeout( update_cb, this ); if ( value() )
Fl::add_timeout( _blink_interval, update_cb, this ); {
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 virtual void
draw ( void ) draw ( void )
{ {

View File

@ -22,7 +22,7 @@ comment {//
} {in_source in_header } {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 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} 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 ); snprintf( s, 5, "%d%%", (int)v );
p->label( s );} {} p->label( s );
}
} {}
} }
Function {update_status()} {open private Function {update_status()} {open private
} { } {
@ -885,7 +891,9 @@ if ( timeline->session_manager_name() != NULL )
find_item( menubar, "&Project/&Open" )->deactivate(); find_item( menubar, "&Project/&Open" )->deactivate();
} }
project_name->redraw();} {} // project_name->redraw();
} {}
} }
Function {update_cb( void *v )} {open private return_type {static void} Function {update_cb( void *v )} {open private return_type {static void}
} { } {

View File

@ -83,7 +83,7 @@ bool Timeline::snap_magnetic = true;
bool Timeline::follow_playhead = true; bool Timeline::follow_playhead = true;
bool Timeline::center_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 const char *instance_name;
extern TLE *tle; extern TLE *tle;
@ -1064,18 +1064,22 @@ void
Timeline::redraw_playhead ( void ) Timeline::redraw_playhead ( void )
{ {
static nframes_t last_playhead = -1; 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(); redraw_overlay();
last_playhead = transport->frame; last_playhead = transport->frame;
last_playhead_x = playhead_x;
if ( follow_playhead ) if ( follow_playhead )
{ {
if ( center_playhead && active() ) if ( center_playhead && active() )
xposition( max( 0, ts_to_x( transport->frame ) - ( ( tracks->w() - Track::width() ) >> 1 ) ) ); xposition( max( 0, playhead_x - ( ( tracks->w() - Track::width() ) >> 1 ) ) );
else if ( ts_to_x( transport->frame ) > ts_to_x( xoffset ) + ( tracks->w() - Track::width() ) ) else if ( playhead_x > ts_to_x( xoffset ) + ( tracks->w() - Track::width() ) )
xposition( ts_to_x( transport->frame ) ); xposition( playhead_x );
} }
} }
} }