}
else
{
- glRasterPos2f( xPos, yPos );
- glListBase( displayListBase( theFont ) );
- glCallLists( text.length(), GL_UNSIGNED_BYTE, text.toLocal8Bit().data() );
+ drawBitmapText( text, theFont, xPos, yPos );
}
}
glEnd();
}
+/*!
+ Draws simple bitmap text
+ \param theText - text string
+ \param theFont - font of the text
+ \param theXPos - x coordinate of the text
+ \param theYPos - y coordinate of the text
+*/
+void GLViewer_Drawer::drawBitmapText( const QString& theText,
+ QFont* theFont,
+ GLfloat theXPos,
+ GLfloat theYPos )
+{
+ glRasterPos2f( theXPos, theYPos );
+ glListBase( displayListBase( theFont ) );
+ glCallLists( theText.length(), GL_UNSIGNED_BYTE, theText.toLocal8Bit().data() );
+}
+
/*!
Draws filled rectangle
\param rect - instance of primitive
//! Draw filled rectangle with predefined color
static void drawFilledRectangle( GLViewer_Rect*, QColor = Qt::black );
+ //! Draw simple bitmap text
+ static void drawBitmapText( const QString& theText,
+ QFont* theFont,
+ GLfloat theXPos,
+ GLfloat theYPos );
+
protected:
static void drawContour( GLViewer_Rect*, QColor, GLfloat, GLushort, bool );
static void drawContour( const GLViewer_PntList&, QColor, GLfloat );
connect( myObjectTip, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ),
this, SLOT( onMaybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) );
//myGLWidget->installEventFilter( myObjectTip );
+
+ myIsLegendEnabled = false;
+ myLegendXOffset = 10.0;
+ myLegendYOffset = 10.0;
+ myLegendFont = QFont( "Arial", 9 );
}
/*!
glCallList( aTextList );
}
+/*!
+ Draws legend
+*/
+void GLViewer_ViewPort2d::drawLegend()
+{
+ if( !myIsLegendEnabled || myLegendText.isEmpty() )
+ return;
+
+ int w = getWidth();
+ int h = getHeight();
+
+ GLfloat xScale, yScale, xPan, yPan;
+ getScale( xScale, yScale );
+ getPan( xPan, yPan );
+
+ GLdouble x1 = -w / 2. / xScale - xPan;
+ GLdouble y1 = -h / 2. / yScale - yPan;
+ GLdouble z1 = 0;
+
+ GLint viewport[4];
+ glGetIntegerv( GL_VIEWPORT, viewport );
+
+ GLdouble modelMatrix[16], projMatrix[16];
+ glGetDoublev( GL_MODELVIEW_MATRIX, modelMatrix );
+ glGetDoublev( GL_PROJECTION_MATRIX, projMatrix );
+
+ GLdouble x2, y2, z2;
+ gluProject( x1, y1, z1, modelMatrix, projMatrix, viewport, &x2, &y2, &z2 );
+
+ glColor3f( 0.0, 0.0, 0.0 );
+
+ glMatrixMode( GL_PROJECTION );
+ glPushMatrix();
+ glLoadIdentity();
+ glOrtho( 0, viewport[2], 0, viewport[3], -100, 100 );
+ glMatrixMode( GL_MODELVIEW );
+ glPushMatrix();
+ glLoadIdentity();
+
+ QStringList aStringList = myLegendText.split( "\n" );
+
+ int aCounter = 0;
+ int aTextHeight = 0;
+ QStringListIterator anIter( aStringList );
+ anIter.toBack();
+ while( anIter.hasPrevious() )
+ {
+ const QString& aString = anIter.previous();
+ if( aCounter > 0 && aTextHeight == 0 )
+ aTextHeight = QFontMetrics( myLegendFont ).height();
+ GLViewer_Drawer::drawBitmapText( aString,
+ &myLegendFont,
+ x2 + myLegendXOffset,
+ y2 + myLegendYOffset + aCounter * aTextHeight );
+ aCounter++;
+ }
+
+ glMatrixMode( GL_PROJECTION );
+ glPopMatrix();
+ glMatrixMode( GL_MODELVIEW );
+ glPopMatrix();
+}
+
/*!
\return blocking status for current started operations
*/
//! Draws compass
void drawCompass();
+ //! Draws legend
+ void drawLegend();
+
//! Returns unique ID of ViewPort
int getViewPortId(){ return myViewPortId; }
QImage dumpContents( bool theWholeScene = false,
double theScale = 1.0 );
+ //! Sets the legend enable state
+ void setLegendEnabled( const bool theState ) { myIsLegendEnabled = theState; }
+
+ //! Sets the legend text
+ void setLegendText( const QString& theText ) { myLegendText = theText; }
+
signals:
//! Emits after any transformation
void vpUpdateValues();
bool myIsMouseReleaseBlock;
QRubberBand* myRectBand; //!< selection rectangle rubber band
+
+ // legend
+ bool myIsLegendEnabled;
+ QString myLegendText;
+ GLfloat myLegendXOffset;
+ GLfloat myLegendYOffset;
+ QFont myLegendFont;
};
#ifdef WIN32