Add magnetic effect (for init value) on knobs

This commit is contained in:
NoiseByNorthwest
2012-01-21 20:34:24 +01:00
committed by Tobias Doerffel
parent cacc0d6c3e
commit 9215800114
2 changed files with 32 additions and 1 deletions

View File

@@ -268,6 +268,11 @@ signals:
return AutomatableModel::value<type>( _frameOffset ); \
} \
\
inline type initValue() const \
{ \
return AutomatableModel::initValue<type>(); \
} \
\
inline type minValue() const \
{ \
return AutomatableModel::minValue<type>(); \

View File

@@ -558,7 +558,33 @@ void knob::wheelEvent( QWheelEvent * _we )
void knob::setPosition( const QPoint & _p )
{
model()->setValue( model()->value() - getValue( _p ) );
const float current = model()->value();
const float next = current - getValue( _p );
if( model()->initValue() == current )
{
// not critical but should be a property
static int magnet_dec = 0;
if( ++magnet_dec > 20 )
{
magnet_dec = 0;
model()->setValue( next );
}
return;
}
const bool current_sign = model()->initValue() - current < 0;
const bool next_sign = model()->initValue() - next < 0;
if( current_sign != next_sign )
{
model()->setValue( model()->initValue() );
}
else
{
model()->setValue( next );
}
}