]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/SGText.cxx
Make return type from loadPagedModel explicit.
[simgear.git] / simgear / scene / model / SGText.cxx
index 3599a1dc29d104f90dc16398859e72ddc45b7d73..1da6c57cc2e8ac3aa1450fe5d8965511ce138d9d 100644 (file)
 #  include <simgear_config.h>
 #endif
 
 #  include <simgear_config.h>
 #endif
 
+#include <cstdio>
+
 #include "SGText.hxx"
 
 #include <simgear/math/SGMath.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include "SGText.hxx"
 
 #include <simgear/math/SGMath.hxx>
 #include <simgear/misc/sg_path.hxx>
+#include <simgear/misc/strutils.hxx>
 
 #include <osg/Geode>
 #include <osg/MatrixTransform>
 #include <osgText/Text>
 #include <osgText/Font>
 
 
 #include <osg/Geode>
 #include <osg/MatrixTransform>
 #include <osgText/Text>
 #include <osgText/Font>
 
+using std::string;
+
 class SGText::UpdateCallback : public osg::NodeCallback {
 public:
 class SGText::UpdateCallback : public osg::NodeCallback {
 public:
-  UpdateCallback( osgText::Text * aText, SGConstPropertyNode_ptr aProperty, double aScale, double aOffset, double aTruncate, double aNumeric, const char * aFormat ) :
+  UpdateCallback( osgText::Text * aText, SGConstPropertyNode_ptr aProperty, double aScale, double aOffset, bool aTruncate, bool aNumeric, const char * aFormat ) :
     text( aText ),
     property( aProperty ),
     scale( aScale ),
     offset( aOffset ),
     truncate( aTruncate ),
     numeric( aNumeric ),
     text( aText ),
     property( aProperty ),
     scale( aScale ),
     offset( aOffset ),
     truncate( aTruncate ),
     numeric( aNumeric ),
-    format( aFormat )
+    format( simgear::strutils::sanitizePrintfFormat( aFormat ) )
   {
   {
-    if( format.size() == 0 ) {
+    if( format.empty() ) {
       if( numeric ) format = "%f";
       else format = "%s";
     }
       if( numeric ) format = "%f";
       else format = "%s";
     }
@@ -81,46 +86,14 @@ void SGText::UpdateCallback::operator()(osg::Node * node, osg::NodeVisitor *nv )
   traverse( node, nv );
 }
 
   traverse( node, nv );
 }
 
-osg::Group * SGText::appendText(const SGPropertyNode* configNode, 
-  SGPropertyNode* modelRoot, const osgDB::ReaderWriter::Options* options)
+osg::Node * SGText::appendText(const SGPropertyNode* configNode, 
+  SGPropertyNode* modelRoot, const osgDB::Options* options)
 {
   SGConstPropertyNode_ptr p;
 
 {
   SGConstPropertyNode_ptr p;
 
-  SG_LOG(SG_GENERAL, SG_DEBUG, "Creating a text object");
-
-  // Set up the alignment node ("stolen" from animation.cxx)
-  // XXX Order of rotations is probably not correct.
-  osg::MatrixTransform *align = new osg::MatrixTransform;
-  osg::Matrix res_matrix;
-  res_matrix.makeRotate(
-      configNode->getFloatValue("offsets/pitch-deg", 0.0)*SG_DEGREES_TO_RADIANS,
-      osg::Vec3(0, 1, 0),
-      configNode->getFloatValue("offsets/roll-deg", 0.0)*SG_DEGREES_TO_RADIANS,
-      osg::Vec3(1, 0, 0),
-      configNode->getFloatValue("offsets/heading-deg", 0.0)*SG_DEGREES_TO_RADIANS,
-      osg::Vec3(0, 0, 1));
-
-  osg::Matrix tmat;
-  tmat.makeTranslate(configNode->getFloatValue("offsets/x-m", 0.0),
-                     configNode->getFloatValue("offsets/y-m", 0.0),
-                     configNode->getFloatValue("offsets/z-m", 0.0));
-
-  align->setMatrix(res_matrix * tmat);
-
-  if( (p = configNode->getNode( "name" )) != NULL )
-    align->setName(p->getStringValue());
-  else
-    align->setName("text align");
-/*
-  Create a fragment of the graph:
-  MatrixTransform
-   +-Geode
-    +-Text
-*/
   osgText::Text * text = new osgText::Text();
   osg::Geode * g = new osg::Geode;
   g->addDrawable( text );
   osgText::Text * text = new osgText::Text();
   osg::Geode * g = new osg::Geode;
   g->addDrawable( text );
-  align->addChild( g );
 
   SGPath path("Fonts" );
   path.append( configNode->getStringValue( "font", "Helvetica" ));
 
   SGPath path("Fonts" );
   path.append( configNode->getStringValue( "font", "Helvetica" ));
@@ -248,5 +221,35 @@ osg::Group * SGText::appendText(const SGPropertyNode* configNode,
     }
   }
 
     }
   }
 
-  return align;
+  osg::Node * reply = NULL;
+  if( (p = configNode->getNode( "offsets")) == NULL ) {
+    reply = g;
+  } else {
+    // Set up the alignment node ("stolen" from animation.cxx)
+    // XXX Order of rotations is probably not correct.
+    osg::MatrixTransform *align = new osg::MatrixTransform;
+    osg::Matrix res_matrix;
+    res_matrix.makeRotate(
+        p->getFloatValue("pitch-deg", 0.0)*SG_DEGREES_TO_RADIANS,
+        osg::Vec3(0, 1, 0),
+        p->getFloatValue("roll-deg", 0.0)*SG_DEGREES_TO_RADIANS,
+        osg::Vec3(1, 0, 0),
+        p->getFloatValue("heading-deg", 0.0)*SG_DEGREES_TO_RADIANS,
+        osg::Vec3(0, 0, 1));
+
+    osg::Matrix tmat;
+    tmat.makeTranslate(configNode->getFloatValue("offsets/x-m", 0.0),
+                       configNode->getFloatValue("offsets/y-m", 0.0),
+                       configNode->getFloatValue("offsets/z-m", 0.0));
+
+    align->setMatrix(res_matrix * tmat);
+    align->addChild( g );
+    reply = align;
+  }
+
+  if( (p = configNode->getNode( "name" )) != NULL )
+    reply->setName(p->getStringValue());
+  else
+    reply->setName("text");
+  return reply;
 }
 }