Commit 455e0ca9 authored by Frédéric Larue's avatar Frédéric Larue

GLViewer::renderCoords() renamed to GLViewer::screenCoords() and...

GLViewer::renderCoords() renamed to GLViewer::screenCoords() and GLViewer::renderText() function made more flexible.
parent 0f47a9a8
......@@ -1369,13 +1369,14 @@ void GLViewer::processSelection( DisplayableInfo &dInfo, BaseSelectionProcessor
}
void GLViewer::renderCoords( double x, double y, double z, double *screenX, double *screenY )
QVector2D GLViewer::screenCoords( float x, float y, float z ) const
{
QVector2D screen( 0.0f, 0.0f );
// Identify x and y locations to render text within widget
QMatrix4x4 mvp = viewProjectionMatrix();
*screenX = *screenY = 0.0;
QVector4D out = mvp.map( QVector4D(x,y,z,1.0f) );
if( out.w() != 0.0f )
......@@ -1384,15 +1385,17 @@ void GLViewer::renderCoords( double x, double y, double z, double *screenX, doub
out.setX( out.x() * wInv );
out.setY( out.y() * wInv );
*screenX = (1 + out.x()) * 0.5 * width();
*screenY = (1 + out.y()) * 0.5 * height();
screen.setX( (1 + out.x()) * 0.5 * width () );
screen.setY( (1 + out.y()) * 0.5 * height() );
}
*screenY = this->height() - *screenY; // y is inverted
screen.setY( height() - screen.y() ); // y is inverted
return screen;
}
void GLViewer::renderText( double x, double y, const QString &text, const QFont &font, Qt::Alignment align )
void GLViewer::renderText( float x, float y, const QString &text, const QFont &font, Qt::Alignment align )
{
QFontMetrics fm( font );
......@@ -1480,14 +1483,6 @@ 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, Qt::Alignment align )
{
double screenX, screenY;
renderCoords( x, y, z, &screenX, &screenY );
renderText( screenX, screenY, text, font, align );
}
bool GLViewer::imageOfCurrentDisplay( const GenericUIData *m, QImage &renderResult )
{
// Check if the provided item is currently displayed.
......
......@@ -370,9 +370,14 @@ public:
void processSelection( GenericUIData *m, BaseSelectionProcessor &proc );
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 = 0 );
void renderText( double x, double y, double z, const QString &text, const QFont &font = QFont(), Qt::Alignment align = 0 );
QVector2D screenCoords( float x, float y, float z ) const;
inline QVector2D screenCoords( const QVector3D &v ) const { return screenCoords(v.x(),v.y(),v.z()); }
inline void renderText( const QVector2D &v, const QString &text, const QFont &font = QFont(), Qt::Alignment align = 0 ) { renderText(v.x(),v.y(),text,font,align); }
inline void renderText( const QVector3D &v, const QString &text, const QFont &font = QFont(), Qt::Alignment align = 0 ) { renderText(screenCoords(v),text,font,align); }
inline void renderText( float x, float y, float z, const QString &text, const QFont &font = QFont(), Qt::Alignment align = 0 ) { renderText(screenCoords(x,y,z),text,font,align); }
void renderText( float x, float y, 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