00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef GLVIEWER_DRAWER_H
00028 #define GLVIEWER_DRAWER_H
00029
00030 #ifdef WIN32
00031 #include "windows.h"
00032 #endif
00033
00034 #include <QColor>
00035 #include <QFont>
00036
00037 class QFile;
00038
00039 #include <GL/gl.h>
00040
00041 #include "GLViewer.h"
00042 #include "GLViewer_Defs.h"
00043 #include "GLViewer_Geom.h"
00044
00045 class GLViewer_Object;
00046 class GLViewer_Rect;
00047 class GLViewer_CoordSystem;
00048
00049 #ifdef WIN32
00050 #pragma warning( disable:4251 )
00051 #endif
00052
00056 struct GLVIEWER_API GLViewer_TexIdStored
00057 {
00059 GLuint myTexFontId;
00061 int myTexFontWidth;
00063 int myTexFontHeight;
00064 };
00065
00070 struct GLVIEWER_API GLViewer_TexFindId
00071 {
00073 QString myFontFamily;
00075 bool myIsBold;
00077 bool myIsItal;
00079 bool myIsUndl;
00081 int myPointSize;
00083 int myViewPortId;
00085 bool operator < (const GLViewer_TexFindId theStruct) const
00086 {
00087 if ( myViewPortId != theStruct.myViewPortId )
00088 return myViewPortId < theStruct.myViewPortId;
00089 else if ( myPointSize != theStruct.myPointSize )
00090 return myPointSize < theStruct.myPointSize;
00091 else if ( myIsBold != theStruct.myIsBold )
00092 return myIsBold < theStruct.myIsBold;
00093 else if ( myIsItal != theStruct.myIsItal )
00094 return myIsItal < theStruct.myIsItal;
00095 else if ( myIsUndl != theStruct.myIsUndl )
00096 return myIsUndl < theStruct.myIsUndl;
00097 else
00098 return myFontFamily < theStruct.myFontFamily;
00099 }
00100 };
00101
00107 class GLVIEWER_API GLViewer_TexFont
00108 {
00109 public:
00111 GLViewer_TexFont();
00113
00114
00115
00116
00117
00118
00119 GLViewer_TexFont( QFont* theFont,
00120 int theSeparator = 2,
00121 bool theIsResizeable = false,
00122 GLuint theMinMagFilter = GL_LINEAR );
00124 ~GLViewer_TexFont();
00125
00127 bool generateTexture();
00129 void drawString( QString theStr,
00130 GLdouble theX = 0.0,
00131 GLdouble theY = 0.0,
00132 GLfloat theScale = 1.0 );
00133
00135 int getSeparator(){ return mySeparator; }
00137 void setSeparator( int theSeparator ){ mySeparator = theSeparator; }
00138
00140 int getStringWidth( QString theString );
00142 int getStringHeight();
00143
00145 static void clearTextBases();
00146
00148 static QMap<GLViewer_TexFindId,GLViewer_TexIdStored> TexFontBase;
00150 static QMap<GLViewer_TexFindId,GLuint> BitmapFontCache;
00151
00152 private:
00154 void init();
00155
00156 private:
00158 int myNbSymbols;
00160 int* myWidths;
00162 int* myPositions;
00164 QFont myQFont;
00166 GLuint myTexFont;
00168 int myTexFontWidth;
00170 int myTexFontHeight;
00172 int mySeparator;
00174 bool myIsResizeable;
00176 GLuint myMinMagFilter;
00178 int myFontHeight;
00180 int myMaxRowWidth;
00181 };
00182
00188 class GLVIEWER_API GLViewer_Drawer
00189 {
00190 public:
00192 enum
00193 {
00194 GLText_Center = 0,
00195 GLText_Left,
00196 GLText_Right,
00197 GLText_Top,
00198 GLText_Bottom
00199 };
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00217 GLViewer_Drawer();
00219 virtual ~GLViewer_Drawer();
00220
00222
00223
00224
00225
00226
00227 virtual void create( float xScale, float yScale, bool onlyUpdate ) = 0;
00228
00230 virtual void addObject( GLViewer_Object* theObject ){ myObjects.append( theObject ); }
00232 virtual void clear(){ myObjects.clear(); }
00233
00235 QString getObjectType() const { return myObjectType; }
00236
00238 int getPriority() const { return myPriority; }
00239
00241 void setAntialiasing(const bool on);
00242
00244 static void destroyAllTextures();
00245
00247
00252 virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
00253
00255
00260 virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
00261
00262 #ifdef WIN32
00263
00264
00271 virtual bool translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
00272 #endif
00273
00275
00281 static GLuint loadTexture( const QString& fileName,
00282 GLint* x_size = 0,
00283 GLint* y_size = 0,
00284 GLint* t_size = 0);
00285
00287
00293 void drawTexture( GLuint texture,
00294 GLint size,
00295 GLfloat x,
00296 GLfloat y );
00297
00299
00306 void drawTexture( GLuint texture,
00307 GLint x_size,
00308 GLint y_size,
00309 GLfloat x,
00310 GLfloat y );
00311
00313
00323 void drawTexturePart( GLuint texture,
00324 GLfloat x_ratio,
00325 GLfloat y_ratio,
00326 GLfloat x_size,
00327 GLfloat y_size,
00328 GLfloat x,
00329 GLfloat y,
00330 GLfloat scale = 0 );
00331
00332
00333
00335
00344 void drawText( const QString& text,
00345 GLfloat xPos,
00346 GLfloat yPos,
00347 const QColor& color,
00348 QFont* aFont,
00349 int theSeparator,
00350 DisplayTextFormat = DTF_BITMAP );
00351
00353
00362 void drawGLText( QString text,
00363 float x,
00364 float y,
00365 int hPosition = GLText_Center,
00366 int vPosition = GLText_Center,
00367 QColor color = Qt::black,
00368 bool smallFont = false );
00369
00371
00374 inline void setFont( const QFont& font ) { myFont = font; }
00375
00377 inline QFont font() const { return myFont; }
00378
00380
00383 inline void setTextFormat( const DisplayTextFormat format ) { myTextFormat = format; }
00384
00386 inline DisplayTextFormat textFormat() const { return myTextFormat; }
00387
00389
00392 inline void setTextScale( const GLfloat factor ) { myTextScale = factor; }
00393
00395 inline GLfloat textScale() const { return myTextScale; }
00396
00398 GLViewer_Rect textRect( const QString& ) const;
00399
00400
00402 static void drawRectangle( GLViewer_Rect* theRect, QColor = Qt::black );
00403
00404 protected:
00406
00407 static void drawRectangle( GLViewer_Rect*, GLfloat, GLfloat = 0, QColor = Qt::black,
00408 bool = false, QColor = Qt::white );
00409 static void drawContour( GLViewer_Rect*, QColor, GLfloat, GLushort, bool );
00410 static void drawContour( const GLViewer_PntList&, QColor, GLfloat );
00411 static void drawPolygon( GLViewer_Rect*, QColor, GLushort, bool );
00412 static void drawPolygon( const GLViewer_PntList&, QColor );
00413 static void drawVertex( GLfloat, GLfloat, QColor );
00414 static void drawCross( GLfloat, GLfloat, QColor );
00415 static void drawArrow( const GLfloat red, const GLfloat green, const GLfloat blue,
00416 GLfloat, GLfloat, GLfloat, GLfloat,
00417 GLfloat, GLfloat, GLfloat, GLboolean = GL_FALSE );
00418
00420 virtual void drawText( GLViewer_Object* theObject );
00421
00423 float myXScale;
00425 float myYScale;
00426
00428 QList<GLViewer_Object*> myObjects;
00430 GLuint myTextList;
00431
00433 QString myObjectType;
00435 int myPriority;
00436
00438 QFont myFont;
00440 DisplayTextFormat myTextFormat;
00441
00444 GLfloat myTextScale;
00445 };
00446
00447 #ifdef WIN32
00448 #pragma warning ( default:4251 )
00449 #endif
00450
00451 #endif // GLVIEWER_DRAWER_H