UI: smoother knobs
This updates knobs to feel smoother and allow the user to have finer control over the value of the knob by multiplying the mouse drag delta by a smoothness factor. Also since it is significantly easier to point the knob where you want it, I removed the magnet effect. This can easily be put back in; try it out and see what you think.
This commit is contained in:
@@ -148,12 +148,11 @@ private:
|
||||
QPixmap * m_knobPixmap;
|
||||
BoolModel m_volumeKnob;
|
||||
|
||||
float m_mouseOffset;
|
||||
QPoint m_mouseOffset;
|
||||
QPoint m_origMousePos;
|
||||
float m_origValue;
|
||||
bool m_buttonPressed;
|
||||
|
||||
int m_magneticDecay;
|
||||
|
||||
float m_totalAngle;
|
||||
int m_angle;
|
||||
QImage m_cache;
|
||||
|
||||
@@ -61,9 +61,7 @@ knob::knob( int _knob_num, QWidget * _parent, const QString & _name ) :
|
||||
m_label( "" ),
|
||||
m_knobPixmap( NULL ),
|
||||
m_volumeKnob( false ),
|
||||
m_mouseOffset( 0.0f ),
|
||||
m_buttonPressed( false ),
|
||||
m_magneticDecay( 0 ),
|
||||
m_angle( -10 ),
|
||||
m_outerColor( NULL )
|
||||
{
|
||||
@@ -364,16 +362,15 @@ void knob::drawKnob( QPainter * _p )
|
||||
_p->drawImage( 0, 0, m_cache );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
float knob::getValue( const QPoint & _p )
|
||||
{
|
||||
const float SMOOTH_FACTOR = 0.125f;
|
||||
int yDist = (_p.y() - m_origMousePos.y()) * SMOOTH_FACTOR;
|
||||
if( engine::mainWindow()->isShiftPressed() )
|
||||
{
|
||||
return( ( _p.y() - m_origMousePos.y() ) * model()->step<float>() );
|
||||
return m_origValue - (yDist * model()->step<float>());
|
||||
}
|
||||
return( ( _p.y() - m_origMousePos.y() ) * pageSize() );
|
||||
return m_origValue - (yDist * pageSize());
|
||||
}
|
||||
|
||||
|
||||
@@ -442,6 +439,8 @@ void knob::mousePressEvent( QMouseEvent * _me )
|
||||
|
||||
const QPoint & p = _me->pos();
|
||||
m_origMousePos = p;
|
||||
m_mouseOffset = QPoint(0, 0);
|
||||
m_origValue = model()->value();
|
||||
|
||||
emit sliderPressed();
|
||||
|
||||
@@ -470,9 +469,10 @@ void knob::mousePressEvent( QMouseEvent * _me )
|
||||
|
||||
void knob::mouseMoveEvent( QMouseEvent * _me )
|
||||
{
|
||||
if( m_buttonPressed == true && _me->pos() != m_origMousePos )
|
||||
if( m_buttonPressed && _me->pos() != m_origMousePos )
|
||||
{
|
||||
setPosition( _me->pos() );
|
||||
m_mouseOffset += _me->pos() - m_origMousePos;
|
||||
setPosition( m_mouseOffset );
|
||||
emit sliderMoved( model()->value() );
|
||||
QCursor::setPos( mapToGlobal( m_origMousePos ) );
|
||||
}
|
||||
@@ -489,7 +489,6 @@ void knob::mouseReleaseEvent( QMouseEvent * /* _me*/ )
|
||||
|
||||
m_buttonPressed = false;
|
||||
|
||||
m_mouseOffset = 0;
|
||||
emit sliderReleased();
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
@@ -559,31 +558,7 @@ void knob::wheelEvent( QWheelEvent * _we )
|
||||
|
||||
void knob::setPosition( const QPoint & _p )
|
||||
{
|
||||
const float current = model()->value();
|
||||
const float next = current - getValue( _p );
|
||||
|
||||
if( model()->initValue() == current )
|
||||
{
|
||||
if( ++m_magneticDecay > 20 )
|
||||
{
|
||||
m_magneticDecay = 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 );
|
||||
}
|
||||
model()->setValue( getValue(_p) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user