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

Display of 3D object labels improved.

parent 71959b68
......@@ -989,9 +989,24 @@ void GLViewer::paintGL()
// Display the label of the object under the mouse cursor.
if( dof() == DISPLAY_DOF_3D && m_BelowCursor )
{
double textX, textY;
QVector3D c = m_BelowCursor->GetTransform().map( m_BelowCursor->boundingBox.Center() );
renderCoords( c.x(), c.y(), c.z(), &textX, &textY );
QString label = m_BelowCursor->displayable->label();
QFont fonte( font().family(), font().pointSize(), QFont::Bold );
QFontMetrics fm( fonte );
textY -= 0.5*fm.height();
textX -= 0.5*fm.width( label );
glColor3ub( 220, 220, 220 );
renderText( textX-1, textY-1, label, fonte );
renderText( textX-1, textY+1, label, fonte );
renderText( textX+1, textY-1, label, fonte );
renderText( textX+1, textY+1, label, fonte );
glColor3ub( 64, 64, 64 );
renderText( c.x(), c.y(), c.z(), m_BelowCursor->displayable->label() );
renderText( textX, textY, label, fonte );
}
// Display the selection tool, if selection mode is enabled.
......@@ -1347,6 +1362,33 @@ void GLViewer::processSelection( GenericUIData *m, BaseSelectionProcessor &proc
}
void GLViewer::renderCoords( double x, double y, double z, double *screenX, double *screenY )
{
// Identify x and y locations to render text within widget
QMatrix4x4 model, proj;
GLint viewport[4];
glGetFloatv( GL_MODELVIEW_MATRIX, model.data() );
glGetFloatv( GL_PROJECTION_MATRIX, proj.data() );
glGetIntegerv( GL_VIEWPORT, viewport );
*screenX = *screenY = 0.0;
QVector4D out = proj.map( model.map( QVector4D(x,y,z,1.0f) ) );
if( out.w() != 0.0f )
{
float wInv = 1.0f / out.w();
out.setX( out.x() * wInv );
out.setY( out.y() * wInv );
*screenX = viewport[0] + (1 + out.x()) * 0.5 * viewport[2];
*screenY = viewport[1] + (1 + out.y()) * 0.5 * viewport[3];
}
*screenY = this->height() - *screenY; // y is inverted
}
void GLViewer::renderText( double x, double y, const QString &text, const QFont &font )
{
// Save OpenGL states.
......@@ -1392,31 +1434,9 @@ void GLViewer::renderText( double x, double y, const QString &text, const QFont
void GLViewer::renderText( double x, double y, double z, const QString &text, const QFont &font )
{
// Identify x and y locations to render text within widget
QMatrix4x4 model, proj;
GLint viewport[4];
glGetFloatv( GL_MODELVIEW_MATRIX, model.data() );
glGetFloatv( GL_PROJECTION_MATRIX, proj.data() );
glGetIntegerv( GL_VIEWPORT, viewport );
GLdouble textPosX = 0.0, textPosY = 0.0;
QVector4D out = proj.map( model.map( QVector4D(x,y,z,1.0f) ) );
if( out.w() != 0.0f )
{
float wInv = 1.0f / out.w();
out.setX( out.x() * wInv );
out.setY( out.y() * wInv );
textPosX = viewport[0] + (1 + out.x()) * 0.5 * viewport[2];
textPosY = viewport[1] + (1 + out.y()) * 0.5 * viewport[3];
}
textPosY = this->height() - textPosY; // y is inverted
// Render text
renderText( textPosX, textPosY, text, font );
double screenX, screenY;
renderCoords( x, y, z, &screenX, &screenY );
renderText( screenX, screenY, text, font );
}
......
......@@ -295,6 +295,7 @@ public:
void processSelection( std::list<BaseSelectionProcessor*> &procList );
void processSelection( GenericUIData *m, 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() );
void renderText( double x, double y, double z, const QString &text, const QFont &font = QFont() );
......
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