From a1dd1192cc31d4d05182a548fa17451dc48d3963 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Wed, 20 Feb 2008 22:03:48 -0600 Subject: [PATCH] Add Track_Point class for track widgets with no meaningful length. --- Region.H | 73 ++++++++++++++++++++++++++++++++++++-------------------- main.C | 10 -------- 2 files changed, 47 insertions(+), 36 deletions(-) diff --git a/Region.H b/Region.H index 9a1b8ac..b498223 100644 --- a/Region.H +++ b/Region.H @@ -75,6 +75,10 @@ public: virtual int w ( void ) const { return timeline.ts_to_x( _end - _start ); } // int w ( void ) const { return timeline.ts_to_x( (_end - _start) - ( timeline.xoffset - _offset) ); } + int abs_x ( void ) const { return timeline.ts_to_x( timeline.xoffset ); } + int abs_w ( void ) const { return timeline.ts_to_x( _end - _start ); } + + Fl_Color color ( void ) { return _color; } Fl_Color box_color ( void ) { return _box_color; } @@ -218,44 +222,61 @@ public: }; - class Tempo_Point : public Track_Widget - { - float _tempo; +class Track_Point : public Track_Widget +{ - public: +protected: -/* Tempo_Point ( ) */ -/* { */ -/* _tempo = 120; */ -/* } */ + char *_label; - Tempo_Point ( nframes_t when, float bpm ) - { - _tempo = bpm; - _offset = when; - } +public: - int w ( void ) const { return 10; } - nframes_t length ( void ) const { return timeline.x_to_ts( w() ); } + int w ( void ) const { return 10; } + nframes_t length ( void ) const { return timeline.x_to_ts( w() ); } - void - draw ( int X, int Y, int W, int H ) - { - if ( x() < 0 ) - return; + Track_Point ( ) + { + _label = NULL; + } - Track_Widget::draw( x(), Y, w(), H ); + void + draw ( int X, int Y, int W, int H ) + { + if ( x() < 0 ) + return; + Track_Widget::draw( x(), Y, w(), H ); - char pat[40]; + draw_label( _label, FL_ALIGN_RIGHT ); + } +}; - snprintf( pat, 40, "%.1f", _tempo ); +class Tempo_Point : public Track_Point +{ + float _tempo; - draw_label( pat, FL_ALIGN_RIGHT ); + void + _make_label ( void ) + { + if ( ! _label ) + _label = new char[40]; - } + snprintf( _label, 40, "%.1f", _tempo ); + } +public: - }; + Tempo_Point ( nframes_t when, float bpm ) + { + _tempo = bpm; + _offset = when; + + _make_label(); + } + + ~Tempo_Point ( ) + { if ( _label ) delete[] _label; } + +}; class Region : public Track_Widget { diff --git a/main.C b/main.C index e9f8955..0ca0bea 100644 --- a/main.C +++ b/main.C @@ -36,19 +36,11 @@ #include #include -Fl_Color velocity_colors[128]; - #include "Track.H" #include "Timeline.H" #include "const.h" -void -init_colors ( void ) -{ - for ( int i = 128; i--; ) - velocity_colors[i] = fl_rgb_color( 23, 255 - i * 2, 32 ); -} Timeline timeline; @@ -106,8 +98,6 @@ int main ( int argc, char **argv ) { - init_colors(); - Fl_Double_Window *main_window = new Fl_Double_Window( 0, 0, 800, 600 ); timeline.scroll = new Fl_Scroll( 0, 24, 800, 600 - (24 * 2) );