Main MRPT website > C++ reference
MRPT logo
CText3D.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 
00029 #ifndef opengl_CText3D_H
00030 #define opengl_CText3D_H
00031 
00032 #include <mrpt/opengl/CRenderizableDisplayList.h>
00033 
00034 namespace mrpt
00035 {
00036         namespace opengl
00037         {
00038                 class OPENGL_IMPEXP CText3D;
00039 
00040                 // This must be added to any CSerializable derived class:
00041                 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CText3D, CRenderizableDisplayList, OPENGL_IMPEXP )
00042 
00043                 /** A 3D text (rendered with OpenGL primitives), with selectable font face and drawing style.
00044                   *  Use \a setString and \a setFont to change the text displayed by this object (can be multi-lined).
00045                   *
00046                   *  Text is drawn along the (+X,+Y) axes.
00047                   *
00048                   *  Default size of characters is "1.0 units". Change it with the standard method \a CRenderizable::setScale() as with any other 3D object.
00049                   *  The color can be also changed with standard methods in the base class \a CRenderizable.
00050                   *
00051                   *  \sa opengl::COpenGLScene, CText
00052                   *
00053                   *  <div align="center">
00054                   *  <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
00055                   *   <tr> <td> mrpt::opengl::CText3D </td> <td> \image html preview_CText3D.png </td> </tr>
00056                   *  </table>
00057                   *  </div>
00058                   *
00059                   * \note This class is based on code from libcvd (LGPL, http://www.edwardrosten.com/cvd/ )
00060                   * \ingroup mrpt_opengl_grp
00061                   */
00062                 class OPENGL_IMPEXP CText3D : public CRenderizableDisplayList
00063                 {
00064                         DEFINE_SERIALIZABLE( CText3D )
00065                 protected:
00066                         std::string             m_str;
00067             std::string         m_fontName;
00068             TOpenGLFontStyle m_text_style;
00069                         double          m_text_spacing;
00070                         double          m_text_kerning;
00071 
00072                 public:
00073                         /** Sets the displayed string */
00074                         inline void setString( const std::string &s ) {
00075                                 m_str=s;
00076                                 CRenderizableDisplayList::notifyChange();
00077                         }
00078                         /** Returns the currently text associated to this object */
00079                         inline const std::string &getString() const { return m_str; }
00080 
00081                         /** Changes the font name, among accepted values: "sans", "mono", "serif" */
00082                         inline void setFont( const std::string &font ) {
00083                                 m_fontName=font;
00084                                 CRenderizableDisplayList::notifyChange();
00085                         }
00086                         /** Returns the text font  */
00087                         inline const std::string &getFont() const { return m_fontName; }
00088 
00089                         /** Change drawing style: FILL, OUTLINE, NICE */
00090                         void setTextStyle(const mrpt::opengl::TOpenGLFontStyle text_style) {
00091                                 m_text_style = text_style;
00092                                 CRenderizableDisplayList::notifyChange();
00093                         }
00094                         /** Gets the current drawing style */
00095                         mrpt::opengl::TOpenGLFontStyle getTextStyle() const { return m_text_style; }
00096 
00097                         void setTextSpacing(const double text_spacing) {
00098                                 m_text_spacing = text_spacing;
00099                                 CRenderizableDisplayList::notifyChange();
00100                          }
00101                         double setTextSpacing() const { return m_text_spacing; }
00102 
00103                         void setTextKerning(const double text_kerning) {
00104                                 m_text_kerning = text_kerning;
00105                                 CRenderizableDisplayList::notifyChange();
00106                          }
00107                         double setTextKerning() const { return m_text_kerning; }
00108 
00109 
00110                         /** Render */
00111                         void  render_dl() const;
00112 
00113 
00114                         /** Class factory  */
00115                         static CText3DPtr Create(
00116                                 const std::string &str,
00117                                 const std::string &fontName = std::string("sans"),
00118                                 const double scale = 1.0,
00119                                 const mrpt::opengl::TOpenGLFontStyle text_style = mrpt::opengl::FILL,
00120                                 const double text_spacing = 1.5,
00121                                 const double text_kerning = 0.1 )
00122                                 {
00123                                         return CText3DPtr( new CText3D(str,fontName,scale,text_style,text_spacing,text_kerning) );
00124                                 }
00125 
00126                 private:
00127                         /** Constructor */
00128                         CText3D(
00129                                 const std::string &str = std::string(""),
00130                                 const std::string &fontName = std::string("sans"),
00131                                 const double scale = 1.0,
00132                                 const mrpt::opengl::TOpenGLFontStyle text_style = mrpt::opengl::FILL,
00133                                 const double text_spacing = 1.5,
00134                                 const double text_kerning = 0.1 );
00135 
00136                         /** Private, virtual destructor: only can be deleted from smart pointers */
00137                         virtual ~CText3D();
00138                 };
00139 
00140         } // end namespace
00141 
00142 } // End of namespace
00143 
00144 
00145 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011