1 // Copyright (C) 2005 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 /***************************************************************************
23 ** Class: GLViewer_Text
24 ** Descr: Substitution of Prs3d_Text for OpenGL
26 ** Created: UI team, 10.07.03
27 ****************************************************************************/
29 //#include <GLViewerAfx.h>
30 #include "GLViewer_Text.h"
32 GLViewer_Text::GLViewer_Text( const QString& text, float xPos, float yPos, const QColor& color )
38 myQFont = QFont::defaultFont();
43 GLViewer_Text::GLViewer_Text( const QString& text, float xPos, float yPos, const QColor& color, QFont theFont, int theSeparator )
50 mySeparator = theSeparator;
54 GLViewer_Text::~GLViewer_Text()
58 int GLViewer_Text::getWidth()
61 QFontMetrics aFM( myQFont );
62 for( uint i = 0; i < myText.length(); i++ )
63 aResult += aFM.width( myText.at(i) ) + mySeparator;
67 int GLViewer_Text::getHeight()
69 QFontMetrics aFM( myQFont );
73 QByteArray GLViewer_Text::getByteCopy() const
76 int aSize = 5*sizeof( int ) + myText.length();
78 int aR = myColor.red();
79 int aG = myColor.green();
80 int aB = myColor.blue();
81 const char* aStr = myText.data();
83 int anISize = sizeof( int );
84 QByteArray aResult( aSize );
86 char* aPointer = (char*)&myXPos;
87 for( i = 0; i < anISize; i++, aPointer++ )
88 aResult[i] = *aPointer;
89 aPointer = (char*)&myYPos;
90 for( ; i < 2*anISize; i++, aPointer++ )
91 aResult[i] = *aPointer;
93 aPointer = (char*)&aR;
94 for( ; i < 3*anISize; i++, aPointer++ )
95 aResult[i] = *aPointer;
96 aPointer = (char*)&aG;
97 for( ; i < 4*anISize; i++, aPointer++ )
98 aResult[i] = *aPointer;
99 aPointer = (char*)&aB;
100 for( ; i < 5*anISize; i++, aPointer++ )
101 aResult[i] = *aPointer;
103 int aTextSize = myText.length();
104 aPointer = (char*)&aTextSize;
105 for( ; i < 6*anISize; i++, aPointer++ )
106 aResult[i] = *aPointer;
108 for( i = 0; i < aTextSize; i++ )
109 aResult[6*anISize + i] = aStr[i];
111 aPointer = (char*)&mySeparator;
112 for( ; i < 7*anISize + aTextSize; i++, aPointer++ )
113 aResult[i] = *aPointer;
115 const char* aFontStr = myQFont.toString().data();
116 int aFontSize = myQFont.toString().length();
118 for( i = 0; i < aFontSize; i++ )
119 aResult[7*anISize + aTextSize + i] = aFontStr[i];
124 GLViewer_Text* GLViewer_Text::fromByteCopy( QByteArray theBuf )
127 int aSize = (int)theBuf.size();
128 int aR = 0, aG = 0, aB = 0;
130 int xPos = 0, yPos = 0;
132 int anISize = sizeof( int );
133 char* aPointer = (char*)&xPos;
134 for ( i = 0; i < anISize; i++, aPointer++ )
135 *aPointer = theBuf[i];
137 aPointer = (char*)&yPos;
138 for ( ; i < 2*anISize; i++, aPointer++ )
139 *aPointer = theBuf[i];
141 aPointer = (char*)&aR;
142 for( ; i < 3*anISize; i++, aPointer++ )
143 *aPointer = theBuf[i];
144 aPointer = (char*)&aG;
145 for( ; i < 4*anISize; i++, aPointer++ )
146 *aPointer = theBuf[i];
147 aPointer = (char*)&aB;
148 for( ; i < 5*anISize; i++, aPointer++ )
149 *aPointer = theBuf[i];
152 aPointer = (char*)&aTextSize;
153 for( ; i < 6*anISize; i++, aPointer++ )
154 *aPointer = theBuf[i];
157 for( ; i < 6*anISize + aTextSize; i++ )
159 QChar aChar( theBuf[i] );
164 aPointer = (char*)&aSeparator;
165 for( ; i < 7*anISize + aTextSize; i++, aPointer++ )
166 *aPointer = theBuf[i];
169 for( ; i < aSize; i++ )
171 QChar aChar( theBuf[i] );
176 if( !aFont.fromString( aFontStr ) )
179 GLViewer_Text* aGlText = new GLViewer_Text( aText, xPos, yPos, QColor( aR,aG,aB ), aFont, aSeparator );