00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2013-2015, Timm Linder, Social Robotics Lab, University of Freiburg 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are met: 00009 * 00010 * * Redistributions of source code must retain the above copyright notice, this 00011 * list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright notice, 00013 * this list of conditions and the following disclaimer in the documentation 00014 * and/or other materials provided with the distribution. 00015 * * Neither the name of the copyright holder nor the names of its contributors 00016 * may be used to endorse or promote products derived from this software 00017 * without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00023 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00024 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00025 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00026 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00027 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00031 #ifndef TEXT_NODE_H 00032 #define TEXT_NODE_H 00033 00034 #include <rviz/ogre_helpers/shape.h> 00035 #include <rviz/ogre_helpers/movable_text.h> 00036 00037 namespace rviz_textured_quads { 00038 class TextNode { 00039 public: 00040 TextNode(Ogre::SceneManager* sceneManager, Ogre::SceneNode* parentNode, Ogre::Vector3 position = Ogre::Vector3::ZERO) : m_sceneManager(sceneManager) 00041 { 00042 m_sceneNode = parentNode->createChildSceneNode(); 00043 00044 m_text = new rviz::MovableText("text"); 00045 m_text->setTextAlignment(rviz::MovableText::H_CENTER, rviz::MovableText::V_BELOW); 00046 m_sceneNode->attachObject(m_text); 00047 00048 setCharacterHeight(0.1); 00049 setPosition(position); 00050 setVisible(true); 00051 } 00052 00053 virtual ~TextNode() { 00054 m_sceneManager->destroySceneNode(m_sceneNode->getName()); 00055 delete m_text; 00056 }; 00057 00058 void clear() { 00059 setVisible(false); 00060 } 00061 00062 void setCharacterHeight(double characterHeight) { 00063 m_text->setCharacterHeight(characterHeight); 00064 m_text->setSpaceWidth(0.3 * characterHeight); 00065 } 00066 00067 double getCharacterHeight() { 00068 return m_text->getCharacterHeight(); 00069 } 00070 00071 void setCaption(const std::string& caption) { 00072 m_text->setCaption(caption); 00073 setVisible(true); 00074 } 00075 00076 void setPosition(const Ogre::Vector3& position) { 00077 m_sceneNode->setPosition(position); 00078 } 00079 00080 void setVisible(bool visible) { 00081 m_sceneNode->setVisible(visible, true); 00082 } 00083 00084 void setColor(const Ogre::ColourValue& c) { 00085 m_text->setColor(c); 00086 } 00087 00088 void showOnTop(bool onTop = true) { 00089 m_text->showOnTop(onTop); 00090 } 00091 00092 private: 00093 Ogre::SceneManager* m_sceneManager; 00094 Ogre::SceneNode* m_sceneNode; 00095 rviz::MovableText* m_text; 00096 }; 00097 00098 } 00099 00100 #endif // TEXT_NODE_H