From 4b290d3372b4610c951042adbd8a01e227c1da7c Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Thu, 14 Feb 2008 00:35:32 -0600 Subject: [PATCH] Try to be more efficient about clipping. --- Waveform.C | 50 +++++++++++++++++++++++++++++++------------------- Waveform.H | 1 + main.C | 6 ++++++ 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/Waveform.C b/Waveform.C index cd3322d..8585ac5 100644 --- a/Waveform.C +++ b/Waveform.C @@ -79,6 +79,10 @@ Waveform::handle ( int m ) _end -= 100; redraw(); break; + case 2: + selection_color( selection_color() + 10 ); + redraw(); + break; default: return 0; } @@ -92,28 +96,39 @@ Waveform::handle ( int m ) void Waveform::draw ( void ) { - fl_push_clip( x(), y(), w(), h() ); draw_box( FL_PLASTIC_UP_BOX, x(), y(), w(), h(), color() ); + int X, Y, W, H; + + fl_clip_box( x(), y(), w(), h(), X, Y, W, H ); + + draw( X, y(), W, h() ); +} + +void +Waveform::draw ( int X, int Y, int W, int H ) +{ +// fl_push_clip( X, Y, W, H ); + fl_push_matrix(); fl_color( selection_color() ); int j; - float scale = 1; + float _scale = 1; + + int start = (X - x()) * 2; j = 0; - for ( tick_t x = 0; x < w() && x < _end; ++x ) + for ( int x = X; x < X + W; ++x ) { - float lo = _peaks[ _start + j++ ] * scale; - float hi = _peaks[ _start + j++ ] * scale; + float lo = _peaks[ start + _start + j++ ] * _scale; + float hi = _peaks[ start + _start + j++ ] * _scale; - int mid = y() + (h() / 2); + int mid = Y + (H / 2); - int rx = this->x() + x; - - fl_line( rx, mid + (h() * lo), rx, mid + (h() * hi) ); + fl_line( x, mid + (H * lo), x, mid + (H * hi) ); } fl_color( fl_darker( fl_darker( selection_color() ) ) ); @@ -121,11 +136,11 @@ Waveform::draw ( void ) fl_begin_line(); j = 0; - for ( tick_t x = 0; x < w() && x < _end; ++x ) + for ( int x = X; x < X + W; ++x ) { - float v = _peaks[ _start + j ] * scale; + float v = _peaks[ start + _start + j ] * _scale; j += 2; - fl_vertex( this->x() + x, y() + (h() / 2) + ((float)h() * v )); + fl_vertex( x, Y + (H / 2) + ((float)H * v )); } fl_end_line(); @@ -133,19 +148,18 @@ Waveform::draw ( void ) fl_begin_line(); j = 1; - for ( tick_t x = 0; x < w() && x < _end; ++x ) + for ( int x = X; x < X + W; ++x ) { - float v = _peaks[ _start + j ] * scale; + float v = _peaks[ start + _start + j ] * _scale; j += 2; - fl_vertex( this->x() + x, y() + (h() / 2) + ((float)h() * v )); + fl_vertex( x, Y + (H / 2) + ((float)H * v )); } fl_end_line(); - fl_pop_matrix(); - fl_pop_clip(); + // fl_pop_clip(); } #if 0 @@ -153,8 +167,6 @@ void Waveform::draw ( void ) { fl_push_clip( x(), y(), w(), h() ); - draw_box( FL_PLASTIC_UP_BOX, x(), y(), w(), h(), color() ); - fl_push_matrix(); int inc = 1; diff --git a/Waveform.H b/Waveform.H index 8bc9aba..6800131 100644 --- a/Waveform.H +++ b/Waveform.H @@ -38,6 +38,7 @@ public: int handle ( int m ); void draw ( void ); + void draw ( int X, int Y, int W, int H ); void start ( tick_t s ) { _start = s; } void end ( tick_t e ) { _end = e; } diff --git a/main.C b/main.C index 8f99d50..56a54e5 100644 --- a/main.C +++ b/main.C @@ -61,10 +61,16 @@ main ( int argc, char **argv ) size_t len = st.st_size; +/* float chunk_size; */ +/* fread( &chunk_size, sizeof( chunk_size ), 1, fp ); */ + +/* printf( "%f\n", chunk_size ); */ + float *peaks = new float[ len / sizeof( float ) ]; fread( peaks, len, 1, fp ); + wave->peaks( peaks ); wave->start( 0 ); wave->end( len );