Try to be more efficient about clipping.

pull/3/head
Jonathan Moore Liles 2008-02-14 00:35:32 -06:00
parent a7f590aa40
commit 4b290d3372
3 changed files with 38 additions and 19 deletions

View File

@ -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;

View File

@ -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; }

6
main.C
View File

@ -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 );