Mixer/DPM: Avoid clipping topmost segment when drawing.

This commit is contained in:
Jonathan Moore Liles 2013-09-12 00:09:16 -07:00
parent 6d7a71636a
commit a9d547e794
2 changed files with 43 additions and 22 deletions

View File

@ -80,6 +80,7 @@ const int marks [] = { -70, -50, -40, -30, -20, -10, -3, 0, 4 };
void void
DPM::draw_label ( void ) DPM::draw_label ( void )
{ {
/* dirty hack */ /* dirty hack */
if ( parent()->child( 0 ) == this ) if ( parent()->child( 0 ) == this )
{ {
@ -107,7 +108,7 @@ DPM::draw_label ( void )
int v = h() * deflection( (float)marks[ i ] ); int v = h() * deflection( (float)marks[ i ] );
fl_draw( pat, x() - 20, (y() + h() - 8) - v, 19, 8, (Fl_Align) (FL_ALIGN_RIGHT | FL_ALIGN_TOP) ); fl_draw( pat, x() - 20, (y() + h() - 4) - v, 19, 8, (Fl_Align) (FL_ALIGN_RIGHT | FL_ALIGN_TOP) );
} }
} }
} }
@ -118,15 +119,26 @@ DPM::resize ( int X, int Y, int W, int H )
{ {
int old_segments = _segments; int old_segments = _segments;
Fl_Widget::resize( X, Y, W, H );
int tx,ty,tw,th;
bbox(tx,ty,tw,th);
if ( type() == FL_HORIZONTAL ) if ( type() == FL_HORIZONTAL )
_segments = floor( W / (double)_pixels_per_segment ); _segments = floor( tw / (double)_pixels_per_segment );
else else
_segments = floor( H / (double)_pixels_per_segment ); _segments = floor( th / (double)_pixels_per_segment );
if ( old_segments != _segments ) if ( old_segments != _segments )
_last_drawn_hi_segment = 0; _last_drawn_hi_segment = 0;
}
Fl_Widget::resize( X, Y, W, H ); void DPM::bbox ( int &X, int &Y, int &W, int &H )
{
X = x() + 2;
Y = y() + 2;
W = w() - 4;
H = h() - 4;
} }
void void
@ -135,18 +147,18 @@ DPM::draw ( void )
snprintf( peak_string, sizeof( peak_string ), "%.1f", peak() ); snprintf( peak_string, sizeof( peak_string ), "%.1f", peak() );
tooltip( peak_string ); tooltip( peak_string );
int X = x() + 2; int X,Y,W,H;
int Y = y() + 2; bbox(X,Y,W,H);
int W = w() - 4;
int H = h() - 4;
int v = pos( value() ); int v = pos( value() );
int pv = pos( peak() ); int pv = pos( peak() );
int clipv = pos( 0 ); int clipv = pos( 0 );
int bh = h() / _segments; int bh = H / _segments;
int bw = w() / _segments; /* int bh = _pixels_per_segment; */
/* int bw = _pixels_per_segment; */
int bw = W / _segments;
if ( damage() & FL_DAMAGE_ALL ) if ( damage() & FL_DAMAGE_ALL )
{ {
@ -187,12 +199,17 @@ DPM::draw ( void )
{ {
Fl_Color c; Fl_Color c;
if ( p > v && p != pv ) if ( p <= v )
c = dim_div_color( p ); {
else if ( p != clipv ) if ( p == clipv )
c = fl_color_average( FL_YELLOW, div_color( p ), 0.40 );
else
c = div_color( p );
}
else if ( p == pv )
c = div_color( p ); c = div_color( p );
else else
c = fl_color_average( FL_YELLOW, div_color( p ), 0.40 ); c = dim_div_color( p );
if ( ! active ) if ( ! active )
c = fl_inactive( c ); c = fl_inactive( c );
@ -207,11 +224,11 @@ DPM::draw ( void )
} }
else else
{ {
yy = Y + H - ((p + 1) * bh); yy = Y + H - ((p+1) * bh);
fl_rectf( X, yy, W, bh, c ); fl_rectf( X, yy, W, bh, c );
} }
if ( _pixels_per_segment > 3 ) if ( _pixels_per_segment >= 3 )
{ {
fl_color( FL_DARK1 ); fl_color( FL_DARK1 );

View File

@ -35,7 +35,9 @@ class DPM : public Meter
int pos ( float v ) int pos ( float v )
{ {
return deflection( v ) * _segments; float pv = deflection( v ) * ( _segments - 1 );
return pv;
} }
static float _dim; static float _dim;
@ -61,6 +63,8 @@ protected:
virtual void draw ( void ); virtual void draw ( void );
virtual void resize ( int, int, int, int ); virtual void resize ( int, int, int, int );
void bbox ( int &X, int &Y, int &W, int &H );
public: public:
DPM ( int X, int Y, int W, int H, const char *L = 0 ); DPM ( int X, int Y, int W, int H, const char *L = 0 );
@ -97,7 +101,7 @@ public:
_gradient[ j ] = fl_color_average( c[i+1], c[i], ( k ) / (float)(b[i+1] - b[i] )); _gradient[ j ] = fl_color_average( c[i+1], c[i], ( k ) / (float)(b[i+1] - b[i] ));
} }
for ( int i = 0; i < 127; i++ ) for ( int i = 0; i < 128; i++ )
_dim_gradient[ i ] = fl_color_average( FL_BLACK, _gradient[ i ], _dim ); _dim_gradient[ i ] = fl_color_average( FL_BLACK, _gradient[ i ], _dim );
} }
}; };