Changeset 1615 for code/branches/hud/src/orxonox/overlays/OverlayText.cc
- Timestamp:
- Jun 22, 2008, 12:06:55 AM (16 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud/src/orxonox/overlays/OverlayText.cc
r1614 r1615 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include " HUDText.h"30 #include "OverlayText.h" 31 31 32 32 #include <OgreOverlayManager.h> … … 35 35 36 36 #include "util/Convert.h" 37 #include "util/String.h" 37 38 38 39 namespace orxonox 39 40 { 40 CreateFactory(HUDText);41 CreateFactory(OverlayText); 41 42 42 using namespace Ogre; 43 44 HUDText::HUDText() 45 : text_(0) 46 { 47 RegisterObject(HUDText); 48 } 49 50 HUDText::~HUDText() 51 { 52 if (this->isInitialized()) 43 OverlayText::OverlayText() 44 : text_(0) 53 45 { 54 if (this->text_) 55 OverlayManager::getSingleton().destroyOverlayElement(this->text_); 56 } 57 } 58 59 void HUDText::XMLPort(Element& xmlElement, XMLPort::Mode mode) 60 { 61 OrxonoxOverlay::XMLPort(xmlElement, mode); 62 63 if (mode == XMLPort::LoadObject) 64 { 65 this->text_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_Text")); 66 this->text_->setCharHeight(1.0f); 67 this->text_->setFontName("Monofur"); 68 69 this->background_->addChild(this->text_); 46 RegisterObject(OverlayText); 70 47 } 71 48 72 XMLPortParam(HUDText, "font", setFont, getFont, xmlElement, mode); 73 XMLPortParam(HUDText, "caption", setCaption, getCaption, xmlElement, mode); 49 OverlayText::~OverlayText() 50 { 51 if (this->text_) 52 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_); 53 } 74 54 75 if (mode == XMLPort::LoadObject)55 void OverlayText::XMLPort(Element& xmlElement, XMLPort::Mode mode) 76 56 { 77 this->text_->setCaption(this->caption_); 57 if (mode == XMLPort::LoadObject) 58 { 59 // setting this to true makes the text more readable when the 60 // resolution aspect is far from 1.0 61 this->bCorrectAspect_ = true; // can be overridden by xml 62 } 63 64 OrxonoxOverlay::XMLPort(xmlElement, mode); 65 66 if (mode == XMLPort::LoadObject) 67 { 68 this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 69 .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberStr())); 70 this->text_->setCharHeight(1.0f); 71 this->text_->setFontName("Monofur"); 72 73 this->background_->addChild(this->text_); 74 } 75 76 XMLPortParam(OverlayText, "font", setFont, getFont, xmlElement, mode); 77 XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlElement, mode); 78 XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode); 79 80 if (mode == XMLPort::LoadObject) 81 { 82 this->text_->setCaption(this->caption_); 83 } 78 84 } 79 }80 85 81 void HUDText::setCaption(const std::string& caption) 82 { 83 this->caption_ = caption; 84 } 86 void OverlayText::setFont(const std::string& font) 87 { 88 if (this->text_ && font != "") 89 this->text_->setFontName(font); 90 } 85 91 86 const std::string& HUDText::getCaption() const 87 { 88 return this->caption_; 89 } 92 const std::string& OverlayText::getFont() const 93 { 94 if (this->text_) 95 return this->text_->getFontName(); 96 else 97 return blankString; 98 } 90 99 91 void HUDText::setFont(const std::string& font) 92 { 93 if (this->text_ && font != "") 94 this->text_->setFontName(font); 95 } 96 97 std::string HUDText::getFont() const 98 { 99 if (this->text_) 100 return this->text_->getFontName(); 101 else 102 return ""; 103 } 100 void OverlayText::sizeChanged() 101 { 102 this->overlay_->setScale(getSize().y, getSize().y); 103 positionChanged(); 104 } 104 105 }
Note: See TracChangeset
for help on using the changeset viewer.