Commit b4c68d6b authored by Frédéric Larue's avatar Frédéric Larue
Browse files

Text alignment fixed in the renderText function of the GLViewer class.

Performance counter activated when F12 is pressed.
parent 685e2162
......@@ -216,6 +216,7 @@ void GLViewer::init( DisplayDoF dof )
m_AnimationsRunningAtPreviousFrame = false;
m_PerformanceCounterEnabled = false;
// Initialize the layout that will contains options for all active displayables.
......@@ -901,6 +902,7 @@ void GLViewer::manageAnimations()
TimeMeasurement now = std::chrono::high_resolution_clock::now();
double dt = 0.000001 * std::chrono::duration_cast< std::chrono::microseconds >( now - m_AnimationFrameTime ).count();
m_AnimationFrameTime = now;
m_AnimationFrameRate = float( 1.0 / dt );
// Make all active animated objects to execute a new animation step.
......@@ -1078,7 +1080,7 @@ void GLViewer::paintGL()
QString label = m_BelowCursor->displayable->label();
QFont f( font().family(), 10, QFont::Bold );
Qt::Alignment align = static_cast<Qt::Alignment>( Qt::AlignHCenter | Qt::AlignTop );
Qt::Alignment align = static_cast<Qt::Alignment>( Qt::AlignHCenter | Qt::AlignBottom );
glColor3ub( 220, 220, 220 );
renderText( textX-1, textY-1, label, f, align );
......@@ -1097,6 +1099,15 @@ void GLViewer::paintGL()
}
if( m_PerformanceCounterEnabled )
{
QString label = QString::number( m_AnimationFrameRate, 'f', 2 ) + " FPS";
glColor3ub( 0, 0, 0 );
renderText( 10, 10, label, QFont( font().family(), 20, QFont::Bold ), static_cast<Qt::Alignment>( Qt::AlignLeft | Qt::AlignTop ) );
update();
}
// Display the information bar.
m_InfoBarManager->display();
}
......@@ -1213,12 +1224,12 @@ void GLViewer::displayLabel( DisplayableInterface *d )
int textY = bottomLeft.y() - 2;
glColor3ub( 220, 220, 220 );
renderText( textX-1, textY-1, imgName, f, Qt::AlignTop );
renderText( textX-1, textY+1, imgName, f, Qt::AlignTop );
renderText( textX+1, textY-1, imgName, f, Qt::AlignTop );
renderText( textX+1, textY+1, imgName, f, Qt::AlignTop );
renderText( textX-1, textY-1, imgName, f, Qt::AlignBottom );
renderText( textX-1, textY+1, imgName, f, Qt::AlignBottom );
renderText( textX+1, textY-1, imgName, f, Qt::AlignBottom );
renderText( textX+1, textY+1, imgName, f, Qt::AlignBottom );
glColor3ub( 64, 64, 64 );
renderText( textX, textY, imgName, f, Qt::AlignTop );
renderText( textX, textY, imgName, f, Qt::AlignBottom );
}
}
}
......@@ -1516,10 +1527,12 @@ void GLViewer::renderText( double x, double y, const QString &text, const QFont
// Paint text.
if( align & Qt::AlignTop )
y -= (textLines.size()-1) * fm.height() + fm.descent();
else if( align & Qt::AlignCenter )
y -= ((textLines.size()-2) * fm.height())/2/* + fm.descent()*/;
if( align & Qt::AlignBottom )
y -= (textLines.size()-1) * fm.lineSpacing() + fm.descent();
else if( align & Qt::AlignVCenter )
y -= ((textLines.size()) * fm.lineSpacing())/2 - fm.ascent();
else if( align & Qt::AlignTop )
y += fm.ascent();
QPainter painter;
painter.begin( this );
......@@ -1533,7 +1546,7 @@ void GLViewer::renderText( double x, double y, const QString &text, const QFont
painter.drawText( x - fm.width(l)/2, y, l );
else
painter.drawText( x, y, l );
y += fm.height();
y += fm.lineSpacing();
}
painter.end();
......@@ -2105,7 +2118,6 @@ void GLViewer::keyPressEvent( QKeyEvent *evt )
case Qt::Key_F9:
case Qt::Key_F10:
case Qt::Key_F11:
case Qt::Key_F12:
{
qint32 viewId = evt->key() - Qt::Key_F1;
std::ostringstream filename;
......@@ -2129,7 +2141,13 @@ void GLViewer::keyPressEvent( QKeyEvent *evt )
break;
}
case Qt::Key_PageDown: m_ChangeNearPlaneMode = true; break;
case Qt::Key_F12:
{
m_PerformanceCounterEnabled = !m_PerformanceCounterEnabled;
update();
break;
}
case Qt::Key_PageDown: m_ChangeNearPlaneMode = true; break;
case Qt::Key_PageUp: m_ChangeFarPlaneMode = true; break;
default: emit keyPressed( evt );
}
......
......@@ -142,6 +142,9 @@ protected:
TimeMeasurement m_AnimationFrameTime;
QMap<DisplayableInterface*,double> m_ActiveAnimations;
bool m_AnimationsRunningAtPreviousFrame;
float m_AnimationFrameRate;
bool m_PerformanceCounterEnabled;
bool m_SelectionEnabled;
SelectionToolName m_SelectionCurrentToolName;
......@@ -330,8 +333,8 @@ public:
void processSelection( DisplayableInterface *d, BaseSelectionProcessor &proc );
void renderCoords( double x, double y, double z, double *screenX, double *screenY );
void renderText( double x, double y, const QString &text, const QFont &font = QFont(), Qt::Alignment align = Qt::AlignLeft );
void renderText( double x, double y, double z, const QString &text, const QFont &font = QFont(), Qt::Alignment align = Qt::AlignLeft );
void renderText( double x, double y, const QString &text, const QFont &font = QFont(), Qt::Alignment align = 0 );
void renderText( double x, double y, double z, const QString &text, const QFont &font = QFont(), Qt::Alignment align = 0 );
bool imageOfCurrentDisplay( const GenericUIData *m, QImage &renderResult );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment