]> SALOME platform Git repositories - modules/gui.git/blob - src/GLViewer/GLViewer_Drawer.h
Salome HOME
644e76411d4f6e54c1dcf6151362d3c263a9fc4d
[modules/gui.git] / src / GLViewer / GLViewer_Drawer.h
1 // File:      GLViewer_Drawer.h
2 // Created:   November, 2004
3 // Author:    OCC team
4 // Copyright (C) CEA 2004
5
6 /***************************************************************************
7 **  Class:   GLViewer_Drawer
8 **  Descr:   Drawer for GLViewer_Object
9 **  Module:  GLViewer
10 **  Created: UI team, 01.10.01
11 ****************************************************************************/
12 #ifndef GLVIEWER_DRAWER_H
13 #define GLVIEWER_DRAWER_H
14
15 #ifdef WNT
16 #include "windows.h"
17 #endif
18
19 #include <qcolor.h>
20 #include <qobject.h>
21 #include <qfile.h>
22 #include <qfont.h>
23 #include <qgl.h>
24
25 #include <GL/gl.h>
26
27 #include "GLViewer.h"
28 #include "GLViewer_Defs.h"
29
30 class GLViewer_Object;
31 class GLViewer_Rect;
32 class GLViewer_CoordSystem;
33
34 #ifdef WNT
35 #pragma warning( disable:4251 )
36 #endif
37
38 struct GLVIEWER_API GLViewer_TexIdStored
39 {
40   GLuint      myTexFontId;
41   int         myTexFontWidth;
42   int         myTexFontHeight;
43 };
44
45 struct GLVIEWER_API GLViewer_TexFindId
46 {
47   QString     myFontString;
48   int         myViewPortId;
49   bool operator < (const GLViewer_TexFindId theStruct) const 
50   { 
51     if ( myViewPortId != theStruct.myViewPortId ) return myViewPortId < theStruct.myViewPortId; 
52     else return myFontString < theStruct.myFontString;
53   }
54 };
55
56 class GLVIEWER_API GLViewer_TexFont
57 {
58 public:
59   GLViewer_TexFont();
60   GLViewer_TexFont( QFont* theFont, int theSeparator = 2 );
61   ~GLViewer_TexFont();
62   
63   void            generateTexture();
64   void            drawString( QString theStr, GLdouble theX = 0.0, GLdouble theY = 0.0 );
65   
66   int             getSeparator(){ return mySeparator; }
67   void            setSeparator( int theSeparator ){ mySeparator = theSeparator; }
68   
69   int             getStringWidth( QString );
70   int             getStringHeight();
71   
72   static  QMap<GLViewer_TexFindId,GLViewer_TexIdStored> TexFontBase;
73   static  int         LastmyTexStoredId;
74   
75 protected:
76   int*            myWidths;
77   int*            myPositions;
78   QFont           myQFont;
79   GLuint          myTexFont;
80   int             myTexFontWidth;
81   int             myTexFontHeight;
82   int             mySeparator;
83 };
84
85 /***************************************************************************
86 **  Class:   GLViewer_Drawer
87 **  Descr:   Drawer for GLObject
88 **  Module:  GLViewer
89 **  Created: UI team, 03.10.01
90 ****************************************************************************/
91 class GLVIEWER_API GLViewer_Drawer
92 {
93 public:
94     enum { GLText_Center = 0, GLText_Left, GLText_Right, GLText_Top, GLText_Bottom };
95
96 public:
97   GLViewer_Drawer();
98   virtual ~GLViewer_Drawer();
99   
100   enum ObjectStatus { OS_Normal = 0, OS_Highlighted = 1, OS_Selected = 2 };
101   enum ClosedStatus { CS_CLOSED = 0, CS_OPEN = 1 };  
102   
103   virtual void                    create( float, float, bool ) = 0;  
104   
105   virtual void                    addObject( GLViewer_Object* theObject ){ myObjects.append( theObject ); }
106   virtual void                    clear(){ myObjects.clear(); }
107   
108   QString                         getObjectType() const { return myObjectType; }
109   int                             getPriority() const { return myPriority; }
110   
111   static void                     destroyAllTextures();
112   
113   virtual bool                    translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
114   virtual bool                    translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS ); 
115   
116 #ifdef WIN32
117   virtual bool                    translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
118 #endif
119   
120   GLuint                          loadTexture( const QString& fileName );
121   void                            drawTexture( GLuint texture, GLint size, GLfloat x, GLfloat y );
122
123   void                            drawText( const QString& text,
124                                             GLfloat xPos, GLfloat yPos,
125                                             const QColor& color,
126                                             QFont* aFont, int,
127                                             DisplayTextFormat = DTF_BITMAP );
128
129   void                            drawGLText( QString text, float x, float y,
130                                               int hPosition = GLText_Center, int vPosition = GLText_Center,
131                                               QColor color = Qt::black, bool smallFont = false );
132
133   static void                     drawRectangle( GLViewer_Rect*, QColor = Qt::black );
134
135 protected:
136   virtual void                    drawText( GLViewer_Object* );
137
138   float                           myXScale;
139   float                           myYScale;
140   
141   QValueList<GLViewer_Object*>    myObjects;
142   GLuint                          myTextList;
143   
144   QString                         myObjectType;
145   int                             myPriority;
146 };
147
148 #ifdef WNT
149 #pragma warning ( default:4251 )
150 #endif
151
152 #endif // GLVIEWER_DRAWER_H