From 3897aa453b3956cd66cc5e5638647148ae383925 Mon Sep 17 00:00:00 2001 From: TheTravelingSpaceman Date: Mon, 27 Feb 2017 17:27:10 +0200 Subject: [PATCH] Anti-Aliasing of Automation Editor --- include/AutomationEditor.h | 2 +- src/gui/editors/AutomationEditor.cpp | 31 +++++++++++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/AutomationEditor.h b/include/AutomationEditor.h index b926b2613..ffd92c40a 100644 --- a/include/AutomationEditor.h +++ b/include/AutomationEditor.h @@ -125,7 +125,7 @@ protected: float getLevel( int y ); int xCoordOfTick( int tick ); - int yCoordOfLevel( float level ); + float yCoordOfLevel( float level ); inline void drawLevelTick( QPainter & p, int tick, float value, bool is_selected ); void removeSelection(); diff --git a/src/gui/editors/AutomationEditor.cpp b/src/gui/editors/AutomationEditor.cpp index a425b0dea..d9105915a 100644 --- a/src/gui/editors/AutomationEditor.cpp +++ b/src/gui/editors/AutomationEditor.cpp @@ -1329,12 +1329,26 @@ void AutomationEditor::paintEvent(QPaintEvent * pe ) } float *values = m_pattern->valuesAfter( it.key() ); - for( int i = 0; i < (it+1).key() - it.key(); i++ ) - { - drawLevelTick( p, it.key() + i, values[i], - is_selected ); + float nextValue; + if ( m_pattern->valuesAfter( ( it + 1 ).key() ) != NULL ) + nextValue = *( m_pattern->valuesAfter( ( it + 1 ).key() ) ); + else + nextValue = values[ ( it + 1 ).key() - it.key() -1 ]; + + p.setRenderHints( QPainter::Antialiasing, true ); + QPainterPath path; + path.moveTo( QPointF( xCoordOfTick( it.key() ), yCoordOfLevel( 0 ) ) ); + for( int i = 0; i < ( it + 1 ).key() - it.key(); i++ ) + { path.lineTo( QPointF( xCoordOfTick( it.key() + i ), yCoordOfLevel( values[i] ) ) ); + //drawLevelTick( p, it.key() + i, values[i], is_selected ); + } + path.lineTo( QPointF( xCoordOfTick( ( it + 1 ).key() ), yCoordOfLevel( nextValue ) ) ); + path.lineTo( QPointF( xCoordOfTick( ( it + 1 ).key() ), yCoordOfLevel( 0 ) ) ); + path.lineTo( QPointF( xCoordOfTick( it.key() ), yCoordOfLevel( 0 ) ) ); + p.fillPath( path, graphColor() ); + p.setRenderHints( QPainter::Antialiasing, false ); delete [] values; // Draw circle @@ -1433,19 +1447,16 @@ int AutomationEditor::xCoordOfTick(int tick ) -int AutomationEditor::yCoordOfLevel(float level ) +float AutomationEditor::yCoordOfLevel(float level ) { int grid_bottom = height() - SCROLLBAR_SIZE - 1; if( m_y_auto ) { - return (int)( grid_bottom - ( grid_bottom - TOP_MARGIN ) - * ( level - m_minLevel ) - / ( m_maxLevel - m_minLevel ) ); + return ( grid_bottom - ( grid_bottom - TOP_MARGIN ) * ( level - m_minLevel ) / ( m_maxLevel - m_minLevel ) ); } else { - return (int)( grid_bottom - ( level - m_bottomLevel ) - * m_y_delta ); + return ( grid_bottom - ( level - m_bottomLevel ) * m_y_delta ); } }