H3D API  2.4.1
Text.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __TEXT_H__
30 #define __TEXT_H__
31 
32 #include <H3D/X3DGeometryNode.h>
33 #include <H3D/X3DFontStyleNode.h>
34 #include <H3D/MFFloat.h>
35 #include <H3D/SFFloat.h>
36 #include <H3D/MFString.h>
37 #include <H3D/MFVec2f.h>
38 #include <H3D/SFVec2f.h>
39 #include <H3D/SFVec3f.h>
40 #include <H3D/FontStyle.h>
41 #include <H3D/PeriodicUpdate.h>
42 
43 namespace H3D {
44 
96  class H3DAPI_API Text : public X3DGeometryNode {
97  protected:
99 
107  class H3DAPI_API SFBound:
108  public TypedField< X3DGeometryNode::SFBound,
109  Types< SFFontStyleNode, MFFloat, SFFloat, MFString > >{
110  protected:
112  virtual void update();
113  };
114 
122  class H3DAPI_API DisplayList : public X3DGeometryNode::DisplayList {
125  virtual void callList( bool build_list );
126  };
127 
131  class H3DAPI_API OutputUpdater :
132  public PeriodicUpdate< TypedField< Field,
133  Types<SFFontStyleNode, MFString> > > {
134  protected:
136  virtual void update();
137  };
138 
139  public:
140 
142  Text( Inst< SFNode > _metadata = 0,
143  Inst< SFBound > _bound = 0,
144  Inst< DisplayList > _displayList = 0,
145  Inst< SFFontStyleNode > _fontStyle = 0,
146  Inst< MFFloat > _length = 0,
147  Inst< SFFloat > _maxExtent = 0,
148  Inst< MFString > _string = 0,
149  Inst< MFVec2f > _lineBounds = 0,
150  Inst< SFVec3f > _origin = 0,
151  Inst< SFVec2f > _textBounds = 0,
152  Inst< SFBool > _solid = 0,
153  Inst< OutputUpdater > _outputUpdater = 0 );
154 
156  virtual void render();
157 
158  // Traverse the scenegraph. See X3DGeometryNode::traverseSG
159  // for more info.
160  virtual void traverseSG( TraverseInfo& ti );
161 
164  virtual int nrTriangles() {
165  return -1;
166  }
167 
174  virtual bool lineIntersect(
175  const Vec3f& from,
176  const Vec3f& to,
177  LineIntersectResult& result );
178 
184  H3DUniquePtr< SFFontStyleNode > fontStyle;
185 
201  H3DUniquePtr< MFFloat > length;
202 
217  H3DUniquePtr< SFFloat > maxExtent;
218 
224  H3DUniquePtr< MFString > stringF;
225 
233  H3DUniquePtr< MFVec2f > lineBounds;
234 
243  H3DUniquePtr< SFVec3f > origin;
244 
250  H3DUniquePtr< SFVec2f > textBounds;
251 
261  H3DUniquePtr< SFBool > solid;
262 
265 
266  protected:
268  H3DUniquePtr< OutputUpdater > outputUpdater;
269 
271  void updateLineBounds();
272 
275 
280  virtual void scaleToMaxExtent( const std::vector< std::string >& text,
281  X3DFontStyleNode* font );
282 
285  virtual void justifyMinor( const std::vector< std::string >& text,
286  X3DFontStyleNode* font );
287 
292  virtual void moveToNewLine( const std::string& text, X3DFontStyleNode* font );
293 
296  virtual void renderTextLine( const std::string& text,
297  X3DFontStyleNode* font );
298 
301  virtual void justifyLine( const std::string& text,
302  X3DFontStyleNode* font );
303  };
304 }
305 
306 #endif
Header file for FontStyle, X3D scene-graph node.
Contains the MFFloat field class.
Contains the MFString field class.
Contains the MFVec2f field class.
Header file for PeriodicUpdate, template field modifier.
Contains the SFFloat field class.
Contains the SFVec2f field class.
Contains the SFVec3f field class.
Header file for X3DFontStyleNode, X3D scene-graph node.
Header file for X3DGeometryNode, X3D scene-graph node.
The PeriodicUpdate is a template modifier that changes the way the field is updated.
Definition: PeriodicUpdate.h:74
We extend the DisplayList to build the fonts of the X3DFontStyleNode in the fontStyle field of the Te...
Definition: Text.h:122
Internal field class to update values of origin, textBounds, lineBounds.
Definition: Text.h:133
The SFBound field is specialized to update itself from the values in the fields of the Text node.
Definition: Text.h:109
The Text node specifies a two-sided, flat text string object positioned in the Z=0 plane of the local...
Definition: Text.h:96
virtual int nrTriangles()
The number of triangles renderered in this geometry, we don't know so return -1.
Definition: Text.h:164
H3DUniquePtr< MFVec2f > lineBounds
A set of 2D vectors where each vector contains the size of the 2D bounding box for each line of rende...
Definition: Text.h:233
H3DUniquePtr< SFFloat > maxExtent
The maxExtent field limits and compresses all of the text strings if the length of the maximum string...
Definition: Text.h:217
H3DUniquePtr< SFVec2f > textBounds
The dimensions of Text node's 2D bounding box.
Definition: Text.h:250
H3DUniquePtr< SFVec3f > origin
3D position that specifies the origin of the text local coordinate system in units of the coordinate ...
Definition: Text.h:243
H3DUniquePtr< MFString > stringF
The strings to render.
Definition: Text.h:224
H3DUniquePtr< SFFontStyleNode > fontStyle
The style the text should be rendered with.
Definition: Text.h:184
H3DUniquePtr< OutputUpdater > outputUpdater
Internal field to update output fields origin, lineBounds, textBounds.
Definition: Text.h:268
H3DUniquePtr< MFFloat > length
The length field contains an MFFloat value that specifies the length of each text string in the local...
Definition: Text.h:201
H3DUniquePtr< SFBool > solid
The solid field determines whether one or both sides of each polygon shall be displayed.
Definition: Text.h:261
static AutoRef< FontStyle > default_font_style
The font style to use when no style is specified.
Definition: Text.h:274
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: Text.h:264
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
A template modifier class for adding type checking on the routes to any Field class.
Definition: TypedField.h:84
Template to make sure that the Node that is set in a SFNode is of a specified Node type.
Definition: SFNode.h:97
This abstract node type is the base node type for all FontStyle nodes.
Definition: X3DFontStyleNode.h:41
Display list is extended in order to set front sidedness of triangles outside the display list.
Definition: X3DGeometryNode.h:76
This is the base node type for all geometry in X3D.
Definition: X3DGeometryNode.h:61
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194