Open Inventor Reference
MeVis/ThirdParty/Sources/Inventor/inventor/lib/database/include/Inventor/nodes/SoAsciiText.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  * 
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027  *  Mountain View, CA  94043, or:
00028  * 
00029  *  http://www.sgi.com 
00030  * 
00031  *  For further information regarding this notice, see: 
00032  * 
00033  *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034  *
00035  */
00036 
00037 /**************************************************************************
00038  *               Copyright (C) 1991-94, Silicon Graphics, Inc.            *
00039  *  These coded instructions, statements, and computer programs  contain  *
00040  *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
00041  *  are protected by Federal copyright law.  They  may  not be disclosed  *
00042  *  to  third  parties  or copied or duplicated in any form, in whole or  *
00043  *  in part, without the prior written consent of Silicon Graphics, Inc.  *
00044  **************************************************************************/
00045 
00046 
00047 /*
00048  *
00049  _______________________________________________________________________
00050  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00051  |
00052  |   $Revision: 1.1.1.1 $
00053  |
00054  |   Description:
00055  |      This file defines the SoAsciiText node class.
00056  |
00057  |   Author(s)          : Chris Marrin,  Gavin Bell
00058  |
00059  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00060  _______________________________________________________________________
00061  */
00062 
00063 #ifndef  _SO_ASCIITEXT_
00064 #define  _SO_ASCIITEXT_
00065 
00066 #include <Inventor/SbBox.h>
00067 #include <Inventor/fields/SoMFString.h>
00068 #include <Inventor/fields/SoSFEnum.h>
00069 #include <Inventor/fields/SoSFBitMask.h>
00070 #include <Inventor/fields/SoSFFloat.h>
00071 #include <Inventor/fields/SoMFFloat.h>
00072 #include <Inventor/nodes/SoShape.h>
00073 
00074 #include <Inventor/system/SbOpenGL.h>   // For GLenum declaration
00075 
00077 #ifndef gluTESSELATOR
00078 #if defined(__glu_h__) && (GLU_VERSION_1_2)
00079 #define gluTESSELATOR  GLUtesselator
00080 #else
00081 #define gluTESSELATOR  GLUtriangulatorObj
00082 extern "C" struct GLUtriangulatorObj;
00083 #endif
00084 #endif
00085 
00086 
00087 
00088 class MyOutlineFontCache;
00089 class SoPrimitiveVertex;
00090 class SoTextureCoordinateElement;
00091 
00094 
00146 
00147 
00148 class INVENTOR_API SoAsciiText : public SoShape {
00149 
00150     SO_NODE_HEADER(SoAsciiText);
00151 
00152   public:
00154     enum Justification {
00155         LEFT    = 0x01,
00156         RIGHT   = 0x02,
00157         CENTER  = 0x03
00158     };
00159 
00161 
00162 
00164     SoMFString          string;         
00165 
00170     SoSFFloat           spacing;        
00171 
00178     SoSFEnum            justification;
00179 
00182     SoMFFloat           width;          
00183 
00185 
00187     SoAsciiText();
00188 
00189   SoEXTENDER public:
00190 
00191     virtual void        GLRender(SoGLRenderAction *action);
00192     virtual void        rayPick(SoRayPickAction *action);
00193 
00194   SoINTERNAL public:
00195     static void         initClass();
00196 
00197   protected:
00199     virtual void        computeBBox(SoAction *action, SbBox3f &box,
00200                                     SbVec3f &center);
00201 
00203     virtual void        generatePrimitives(SoAction *);
00204     
00205     virtual ~SoAsciiText();
00206 
00207   private:
00209     SbBool setupFontCache(SoState *state, SbBool forRender = FALSE);
00210 
00212     void getFrontBBox(SbBox2f &result);
00213 
00215 
00218     SbVec2f getStringOffset(int line, float width);
00219     
00221     void renderFront(SoGLRenderAction *action, const SbString &string,
00222                      float width, GLUtriangulatorObj *tobj);
00223     
00225     SoDetail * createTriangleDetail(SoRayPickAction *,
00226                                     const SoPrimitiveVertex *,
00227                                     const SoPrimitiveVertex *,
00228                                     const SoPrimitiveVertex *,
00229                                     SoPickedPoint *);
00230 
00233     void generateFront(const SbString &string, float width);
00234     
00236     static void CALLBACK beginCB(GLenum primType);
00237     static void CALLBACK endCB();
00238     static void CALLBACK vtxCB(void *vertex);
00239     
00244     MyOutlineFontCache *myFont;
00245 
00247     static SoAsciiText *currentGeneratingNode;
00248     static SoPrimitiveVertex *genPrimVerts[3];
00249     static SbVec3f genTranslate;
00250     static int genWhichVertex;
00251     static uint32_t genPrimType;
00252     static SoAction *genAction;
00253     static SbBool genBack;
00254     static SbBool genTexCoord;
00255     static const SoTextureCoordinateElement *tce;
00256 };
00257 
00258 #endif /* _SO_ASCIITEXT_ */