Give Clock the ability to update itself.

pull/3/head
Jonathan Moore Liles 2008-04-22 23:27:55 -05:00
parent db5febb64e
commit fd9667ea25
2 changed files with 34 additions and 1 deletions

View File

@ -23,14 +23,32 @@ switched between Bar Beat Tick and Wallclock displays */
#include <FL/Fl_Widget.H>
#include <FL/fl_draw.H>
#include <FL/Fl.H>
#include "Timeline.H"
#include "types.h"
const float CLOCK_UPDATE_FREQ = 0.05f;
class Clock : public Fl_Widget
{
nframes_t _when;
nframes_t *_v;
static void
update_cb ( void *v )
{
((Clock*)v)->update_cb();
}
void
update_cb ( void )
{
Fl::repeat_timeout( CLOCK_UPDATE_FREQ, update_cb, this );
set( *_v );
}
public:
@ -47,10 +65,12 @@ public:
snprintf( dst, n, "%02d:%02d:%02.1f", H, M, S );
}
Clock ( int X, int Y, int W, int H, const char *L=0 )
: Fl_Widget( X, Y, W, H, L )
{
_when = 0;
_v = 0;
box( FL_BORDER_BOX );
type( HMS );
@ -58,6 +78,18 @@ public:
size( 170, 40 );
}
~Clock ( )
{
Fl::remove_timeout( update_cb );
}
void run ( nframes_t *v )
{
_v = v;
Fl::add_timeout( CLOCK_UPDATE_FREQ, update_cb, this );
}
void set ( nframes_t frame )
{
if ( _when != frame )

View File

@ -236,10 +236,11 @@ Fl::scheme( "plastic" );} {}
label PLAYHEAD selected
xywh {139 29 137 40} box BORDER_BOX color 46
code0 {o->type( Clock::HMS );}
code1 {o->run( &transport->frame );}
class Clock
}
Fl_Box {} {
label PLAYHEAD selected
label PLAYHEAD
xywh {278 29 142 40} box BORDER_BOX color 46
code0 {o->type( Clock::BBT );}
class Clock