diff --git a/include/graph.h b/include/graph.h index 808baf2e3..1936da635 100644 --- a/include/graph.h +++ b/include/graph.h @@ -46,6 +46,7 @@ public: { NearestStyle, LinearStyle, + LinearNonCyclicStyle, NumGraphStyles }; diff --git a/plugins/waveshaper/artwork.png b/plugins/waveshaper/artwork.png index 768e52e4a..fac96bcb4 100644 Binary files a/plugins/waveshaper/artwork.png and b/plugins/waveshaper/artwork.png differ diff --git a/plugins/waveshaper/waveshaper_control_dialog.cpp b/plugins/waveshaper/waveshaper_control_dialog.cpp index ca47c52e8..dac97bfa0 100644 --- a/plugins/waveshaper/waveshaper_control_dialog.cpp +++ b/plugins/waveshaper/waveshaper_control_dialog.cpp @@ -45,7 +45,7 @@ waveShaperControlDialog::waveShaperControlDialog( setPalette( pal ); setFixedSize( 224, 300 ); - graph * waveGraph = new graph( this, graph::NearestStyle, 204, 204 ); + graph * waveGraph = new graph( this, graph::LinearNonCyclicStyle, 204, 204 ); waveGraph -> move( 10, 32 ); waveGraph -> setModel( &_controls -> m_wavegraphModel ); waveGraph -> setAutoFillBackground( true ); diff --git a/src/gui/widgets/graph.cpp b/src/gui/widgets/graph.cpp index 7f24a91df..e3f20391b 100644 --- a/src/gui/widgets/graph.cpp +++ b/src/gui/widgets/graph.cpp @@ -119,26 +119,26 @@ void graph::mouseMoveEvent ( QMouseEvent * _me ) // avoid mouse leaps int diff = x - m_lastCursorX; - if( diff >= 1 ) +/* if( diff >= 1 ) { x = qMin( width() - 3, m_lastCursorX + 1 ); } else if( diff <= -1 ) { x = qMax( 2, m_lastCursorX - 1 ); - } - + }*/ + + x = qMax( 2, qMin( x, width()-3 ) ); y = qMax( 2, qMin( y, height()-3 ) ); -/* if( qAbs( diff ) > 1 ) + if( qAbs( diff ) > 1 ) { - drawLineAt( x, y, m_lastCursorX ); - + drawLineAt( x, y, m_lastCursorX ); } else - {*/ + { changeSampleAt( x, y ); -// } + } // update mouse if( diff != 0 ) @@ -205,6 +205,8 @@ void graph::drawLineAt( int _x, int _y, int _lastx ) _x -= 2; _y -= 2; _lastx -= 2; + + _lastx = qMax( 0, qMin( _lastx, width()-5 ) ); float range = minVal - maxVal; float val = ( _y*range/( height()-4 ) ) + maxVal; @@ -272,7 +274,7 @@ void graph::paintEvent( QPaintEvent * ) QVector * samps = &(model()->m_samples); int length = model()->length(); const float maxVal = model()->maxValue(); - + float xscale = (float)( width()-4 ) / length; float yscale = (float)( height()-4 ) / ( model()->minValue() - maxVal ); @@ -282,13 +284,14 @@ void graph::paintEvent( QPaintEvent * ) switch( m_graphStyle ) { - case graph::LinearStyle: + case graph::LinearStyle: p.setRenderHints( QPainter::Antialiasing, true ); for( int i=0; i < length; i++ ) { // Needs to be rewritten - p.drawLine(2+static_cast(i*xscale), + p.drawLine( + 2+static_cast(i*xscale), 2+static_cast( ( (*samps)[i] - maxVal ) * yscale ), 2+static_cast((i+1)*xscale), 2+static_cast( ( (*samps)[i+1] - maxVal ) * yscale ) @@ -298,7 +301,7 @@ void graph::paintEvent( QPaintEvent * ) // Draw last segment wrapped around p.drawLine(2+static_cast(length*xscale), 2+static_cast( ( (*samps)[length] - maxVal ) * yscale ), - width()-2, + width()-3, 2+static_cast( ( (*samps)[0] - maxVal ) * yscale ) ); p.setRenderHints( QPainter::Antialiasing, false ); @@ -322,9 +325,29 @@ void graph::paintEvent( QPaintEvent * ) p.drawLine(2+static_cast(length*xscale), 2+static_cast( ( (*samps)[length] - maxVal ) * yscale ), - width()-2, + width()-3, 2+static_cast( ( (*samps)[length] - maxVal ) * yscale ) ); break; + + case graph::LinearNonCyclicStyle: + p.setRenderHints( QPainter::Antialiasing, true ); + + for( int i=0; i < length; i++ ) + { + // Needs to be rewritten + p.drawLine( + 2+static_cast(i*xscale), + 2+static_cast( ( (*samps)[i] - maxVal ) * yscale ), + 2+static_cast((i+1)*xscale), + 2+static_cast( ( (*samps)[i+1] - maxVal ) * yscale ) + ); + } + + // Do not draw last segment wrapped around - hence, "non-cyclic" + + p.setRenderHints( QPainter::Antialiasing, false ); + break; + default: break; @@ -448,15 +471,14 @@ void graphModel::setSampleAt( int _x, float _val ) { //snap to the grid _val -= ( m_step != 0.0 ) ? fmod( _val, m_step ) * m_step : 0; - // boundary check - if ( _x >= 0 && _x < length() && - _val >= minValue() && _val < maxValue() ) - { - // change sample shape - m_samples[_x] = _val; - emit samplesChanged( _x, _x ); - } + // boundary crop + _x = qMax( 0, qMin( length()-1, _x ) ); + _val = qMax( minValue(), qMin( maxValue(), _val ) ); + + // change sample shape + m_samples[_x] = _val; + emit samplesChanged( _x, _x ); }