- Timestamp:
- Oct 29, 2008, 11:55:37 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/overlays/OverlayText.cc
r2024 r2046 41 41 CreateFactory(OverlayText); 42 42 43 OverlayText::OverlayText(BaseObject* creator) : OrxonoxOverlay(creator), text_(0) 43 OverlayText::OverlayText(BaseObject* creator) 44 : OrxonoxOverlay(creator) 44 45 { 45 46 RegisterObject(OverlayText); 47 48 this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 49 .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberString())); 50 this->text_->setCharHeight(1.0); 51 52 setFont("Monofur"); 53 setColour(ColourValue(1.0, 1.0, 1.0, 1.0)); 54 setCaption(""); 55 setTextSize(1.0f); 56 setAlignmentString("left"); 57 58 this->background_->addChild(this->text_); 46 59 } 47 60 48 61 OverlayText::~OverlayText() 49 62 { 50 if (this-> text_)63 if (this->isInitialized()) 51 64 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->text_); 52 65 } … … 56 69 SUPER(OverlayText, XMLPort, xmlElement, mode); 57 70 58 if (mode == XMLPort::LoadObject) 59 { 60 this->text_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 61 .createOverlayElement("TextArea", "OverlayText_text_" + getUniqueNumberString())); 62 this->text_->setCharHeight(1.0); 63 64 this->background_->addChild(this->text_); 65 } 66 67 XMLPortParam(OverlayText, "font", setFont, getFont, xmlElement, mode).defaultValues("Monofur"); 68 XMLPortParam(OverlayText, "colour", setColour, getColour, xmlElement, mode).defaultValues(ColourValue(1.0, 1.0, 1.0, 1.0)); 69 XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlElement, mode).defaultValues(""); 70 XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode).defaultValues(1.0f); 71 XMLPortParam(OverlayText, "align", setAlignmentString, getAlignmentString, xmlElement, mode).defaultValues("left"); 71 XMLPortParam(OverlayText, "font", setFont, getFont, xmlElement, mode); 72 XMLPortParam(OverlayText, "colour", setColour, getColour, xmlElement, mode); 73 XMLPortParam(OverlayText, "caption", setCaption, getCaption, xmlElement, mode); 74 XMLPortParam(OverlayText, "textSize", setTextSize, getTextSize, xmlElement, mode); 75 XMLPortParam(OverlayText, "align", setAlignmentString, getAlignmentString, xmlElement, mode); 72 76 } 73 77 74 78 void OverlayText::setFont(const std::string& font) 75 79 { 76 if ( this->text_ &&font != "")80 if (font != "") 77 81 this->text_->setFontName(font); 78 }79 80 const std::string& OverlayText::getFont() const81 {82 if (this->text_)83 return this->text_->getFontName();84 else85 return BLANKSTRING;86 }87 88 void OverlayText::setColour(const ColourValue& colour)89 {90 if (this->text_)91 this->text_->setColour(colour);92 }93 94 const ColourValue& OverlayText::getColour() const95 {96 if (this->text_)97 return this->text_->getColour();98 else99 return ColourValue::White;100 }101 102 void OverlayText::setAlignment(Ogre::TextAreaOverlayElement::Alignment alignment)103 {104 if (this->text_)105 this->text_->setAlignment(alignment);106 }107 108 Ogre::TextAreaOverlayElement::Alignment OverlayText::getAlignment() const109 {110 if (this->text_)111 return this->text_->getAlignment();112 else113 return Ogre::TextAreaOverlayElement::Left;114 82 } 115 83 … … 126 94 std::string OverlayText::getAlignmentString() const 127 95 { 128 if (this->text_) 96 Ogre::TextAreaOverlayElement::Alignment alignment = this->text_->getAlignment(); 97 98 switch (alignment) 129 99 { 130 Ogre::TextAreaOverlayElement::Alignment alignment = this->text_->getAlignment(); 131 132 switch (alignment) 133 { 134 case Ogre::TextAreaOverlayElement::Right: 135 return "right"; 136 case Ogre::TextAreaOverlayElement::Center: 137 return "center"; 138 case Ogre::TextAreaOverlayElement::Left: 139 default:; 140 } 100 case Ogre::TextAreaOverlayElement::Right: 101 return "right"; 102 case Ogre::TextAreaOverlayElement::Center: 103 return "center"; 104 case Ogre::TextAreaOverlayElement::Left: 105 return "left"; 106 default: 107 assert(false); return ""; 141 108 } 142 return "left";143 }144 145 void OverlayText::setCaption(const std::string& caption)146 {147 this->caption_ = caption;148 this->text_->setCaption(caption);149 109 } 150 110 151 111 void OverlayText::sizeChanged() 152 112 { 153 if (!this->overlay_)154 return;155 156 113 if (this->rotState_ == Horizontal) 157 114 this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y);
Note: See TracChangeset
for help on using the changeset viewer.