00001 // #################################################################### 00002 // File: textBox.h 00003 // Purpose: This class is a wrapper around OSG's text functionality. 00004 // It may be expanded to encompass more of osgText's options; 00005 // it currently demos the display of text in a SceneGraph. 00006 // #################################################################### 00007 00008 #ifndef TEXT_BOX_H 00009 #define TEXT_BOX_H 00010 #include <string> 00011 using std::string; 00012 #include <osgText/Text> 00013 #include <osg/Geode> 00014 #include <osg/Projection> 00015 #include <osg/MatrixTransform> 00016 #include <osg/Transform> 00017 00018 // #################################################################### 00019 00020 class TextBox{ 00021 public: 00022 00023 TextBox(); 00024 00025 ~TextBox() {} 00026 void setText(const string& text); 00027 void setFont(const string& font); 00028 00029 // Sets the text based on an osg::Vec4d color vector 00030 // Properties: 00031 // (red, green, blue, alpha) 00032 // values range from 0.0 to 1.0: 0.0 is off, and 1.0 is complete. 00033 void setColor(osg::Vec4d color); 00034 00035 // Sets the text position as an offset from the lower left corner 00036 // of the wcreen; thus, any positive values for the osg::Vec3d 00037 // will offset the text to the right and/or up. 00038 void setPosition(osg::Vec3d position); 00039 void setTextSize(unsigned int size); 00040 00041 osg::Group& getGroup() const; 00042 00043 string getText() const; 00044 00045 private: 00046 00047 // Provides a buffer between any parent transformations and our 00048 // new matrix projection, ensures that we're working in our own 00049 // coordinate space. 00050 osg::MatrixTransform * matrixTransform; 00051 00052 // Projection that provides a surface on which to paint the text. 00053 osg::Projection * projectionMatrix; 00054 00055 // The Geode textGeode is used to hold our text. 00056 // osgText is a drawable, so osg::Geode is 00057 // needed to add the text to the SceneGraph 00058 osg::Geode * textGeode; 00059 00060 // The actual osgText object that holds textual data 00061 osgText::Text * text; 00062 }; 00063 #endif