1 /***************************************************************************
2 ** Class: GLViewer_Text
3 ** Descr: Substitution of Prs3d_Text for OpenGL
5 ** Created: UI team, 10.07.03
6 ****************************************************************************/
8 //#include <GLViewerAfx.h>
9 #include "GLViewer_Text.h"
11 GLViewer_Text::GLViewer_Text( const QString& text, float xPos, float yPos, const QColor& color )
17 myQFont = QFont::defaultFont();
22 GLViewer_Text::GLViewer_Text( const QString& text, float xPos, float yPos, const QColor& color, QFont theFont, int theSeparator )
29 mySeparator = theSeparator;
33 GLViewer_Text::~GLViewer_Text()
37 int GLViewer_Text::getWidth()
40 QFontMetrics aFM( myQFont );
41 for( uint i = 0; i < myText.length(); i++ )
42 aResult += aFM.width( myText.at(i) ) + mySeparator;
46 int GLViewer_Text::getHeight()
48 QFontMetrics aFM( myQFont );
52 QByteArray GLViewer_Text::getByteCopy() const
55 int aSize = 5*sizeof( int ) + myText.length();
57 int aR = myColor.red();
58 int aG = myColor.green();
59 int aB = myColor.blue();
60 const char* aStr = myText.data();
62 int anISize = sizeof( int );
63 QByteArray aResult( aSize );
65 char* aPointer = (char*)&myXPos;
66 for( i = 0; i < anISize; i++, aPointer++ )
67 aResult[i] = *aPointer;
68 aPointer = (char*)&myYPos;
69 for( ; i < 2*anISize; i++, aPointer++ )
70 aResult[i] = *aPointer;
72 aPointer = (char*)&aR;
73 for( ; i < 3*anISize; i++, aPointer++ )
74 aResult[i] = *aPointer;
75 aPointer = (char*)&aG;
76 for( ; i < 4*anISize; i++, aPointer++ )
77 aResult[i] = *aPointer;
78 aPointer = (char*)&aB;
79 for( ; i < 5*anISize; i++, aPointer++ )
80 aResult[i] = *aPointer;
82 int aTextSize = myText.length();
83 aPointer = (char*)&aTextSize;
84 for( ; i < 6*anISize; i++, aPointer++ )
85 aResult[i] = *aPointer;
87 for( i = 0; i < aTextSize; i++ )
88 aResult[6*anISize + i] = aStr[i];
90 aPointer = (char*)&mySeparator;
91 for( ; i < 7*anISize + aTextSize; i++, aPointer++ )
92 aResult[i] = *aPointer;
94 const char* aFontStr = myQFont.toString().data();
95 int aFontSize = myQFont.toString().length();
97 for( i = 0; i < aFontSize; i++ )
98 aResult[7*anISize + aTextSize + i] = aFontStr[i];
103 GLViewer_Text* GLViewer_Text::fromByteCopy( QByteArray theBuf )
106 int aSize = (int)theBuf.size();
107 int aR = 0, aG = 0, aB = 0;
109 int xPos = 0, yPos = 0;
111 int anISize = sizeof( int );
112 char* aPointer = (char*)&xPos;
113 for ( i = 0; i < anISize; i++, aPointer++ )
114 *aPointer = theBuf[i];
116 aPointer = (char*)&yPos;
117 for ( ; i < 2*anISize; i++, aPointer++ )
118 *aPointer = theBuf[i];
120 aPointer = (char*)&aR;
121 for( ; i < 3*anISize; i++, aPointer++ )
122 *aPointer = theBuf[i];
123 aPointer = (char*)&aG;
124 for( ; i < 4*anISize; i++, aPointer++ )
125 *aPointer = theBuf[i];
126 aPointer = (char*)&aB;
127 for( ; i < 5*anISize; i++, aPointer++ )
128 *aPointer = theBuf[i];
131 aPointer = (char*)&aTextSize;
132 for( ; i < 6*anISize; i++, aPointer++ )
133 *aPointer = theBuf[i];
136 for( ; i < 6*anISize + aTextSize; i++ )
138 QChar aChar( theBuf[i] );
143 aPointer = (char*)&aSeparator;
144 for( ; i < 7*anISize + aTextSize; i++, aPointer++ )
145 *aPointer = theBuf[i];
148 for( ; i < aSize; i++ )
150 QChar aChar( theBuf[i] );
155 if( !aFont.fromString( aFontStr ) )
158 GLViewer_Text* aGlText = new GLViewer_Text( aText, xPos, yPos, QColor( aR,aG,aB ), aFont, aSeparator );