Changeset 2781
- Timestamp:
- Mar 12, 2009, 10:42:56 PM (16 years ago)
- Location:
- code/branches/questsystem5/src/orxonox/overlays/notifications
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc
r2779 r2781 43 43 { 44 44 45 NotificationOverlay::NotificationOverlay(BaseObject* creator) : O rxonoxOverlay(creator)45 NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator) 46 46 { 47 47 this->initialize(); 48 48 } 49 50 NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : O rxonoxOverlay(this)49 50 NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OverlayText(this) 51 51 { 52 52 this->initialize(); … … 61 61 62 62 this->processNotification(notification); 63 64 COUT(3) << getCaption() << std::endl;65 COUT(3) << getFontSize() << std::endl;66 //COUT(3) << getFont() << std::endl;67 COUT(3) << getWidth() << std::endl;68 COUT(3) << getAlignmentString() << std::endl;69 COUT(3) << getTextSize() << std::endl;70 63 } 71 64 … … 75 68 76 69 this->queue_ = NULL; 77 this->notificationText_ = NULL;78 this->width_ = 0;79 70 } 80 71 … … 82 73 { 83 74 this->setFont(this->queue_->getFont()); 84 this->setFontSize(this->queue_->getFontSize()); 85 86 this->notificationText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", "NotificationOverlay_notificationText_" + getUniqueNumberString())); 87 this->notificationText_->setCharHeight(1.0); 88 this->notificationText_->setColour(ColourValue(1.0, 1.0, 1.0, 1.0)); 89 this->notificationText_->setAlignment(Ogre::TextAreaOverlayElement::Center); 90 this->notificationText_->setCaption(""); 91 92 this->background_->addChild(this->notificationText_); 93 COUT(3) << this->queue_->getFont() << std::endl; 75 this->setTextSize(this->queue_->getFontSize()); 94 76 } 95 77 96 78 NotificationOverlay::~NotificationOverlay() 97 79 { 98 99 }100 101 void NotificationOverlay::setFont(const std::string & font)102 {103 if (this->notificationText_ && font != "")104 this->notificationText_->setFontName(font);105 80 } 106 81 107 void NotificationOverlay::setFontSize(float size)108 {109 if (this->notificationText_ && size >= 0)110 this->notificationText_->setCharHeight(size);111 }112 113 void NotificationOverlay::setWidth(int width)114 {115 this->width_ = width;116 this->notificationText_->setCaption(clipMessage(this->notification_->getMessage()));117 }118 119 float NotificationOverlay::getFontSize(void) const120 {121 if (this->notificationText_)122 return this->notificationText_->getCharHeight();123 else124 return 0;125 }126 127 82 bool NotificationOverlay::processNotification(Notification* notification) 128 83 { 129 this-> notificationText_->setCaption(clipMessage(notification->getMessage()));84 this->setCaption(clipMessage(notification->getMessage())); 130 85 this->notification_ = notification; 131 86 return true; … … 139 94 } 140 95 141 const std::string NotificationOverlay::clipMessage2(const std::string & str)142 {143 144 std::string message = str;145 unsigned int i = 0;146 147 unsigned int found = message.find("\\n", i);148 while(found != std::string::npos)149 {150 message.replace(found, 2, "\n");151 i = found+2;152 found = message.find("\\n", i);153 }154 155 std::string clippedMessage = "";156 int wordLength = 0;157 i = 0;158 int widthLeft = this->getWidth();159 while(i < message.length())160 {161 while(i < message.length() && message[i] != ' ' && message[i] != '\n')162 {163 i++;164 wordLength++;165 }166 167 if(wordLength <= widthLeft)168 {169 clippedMessage = clippedMessage + message.substr(i-wordLength, wordLength);170 if(i < message.length())171 {172 clippedMessage = clippedMessage + message.substr(i,1);173 }174 widthLeft -= (wordLength+1);175 if(message[i] == '\n')176 {177 widthLeft = this->getWidth() - (wordLength+1);178 }179 wordLength = 0;180 i++;181 }182 else183 {184 clippedMessage.push_back('\n');185 clippedMessage = clippedMessage + message.substr(i-wordLength, wordLength);186 if(i < message.length())187 {188 clippedMessage = clippedMessage + message.substr(i,1);189 }190 widthLeft = this->getWidth() - (wordLength+1);191 i++;192 wordLength = 0;193 }194 }195 196 return clippedMessage;197 }198 199 void NotificationOverlay::sizeChanged()200 {201 if (this->rotState_ == Horizontal)202 this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y);203 else if (this->rotState_ == Vertical)204 this->overlay_->setScale(size_.y / (sizeCorrection_.y * sizeCorrection_.y), size_.y * sizeCorrection_.y);205 else206 this->overlay_->setScale(size_.y, size_.y);207 208 positionChanged();209 }210 211 void NotificationOverlay::setAlignmentString(const std::string& alignment)212 {213 if (alignment == "right")214 this->setAlignment(Ogre::TextAreaOverlayElement::Right);215 else if (alignment == "center")216 this->setAlignment(Ogre::TextAreaOverlayElement::Center);217 else // "left" and default218 this->setAlignment(Ogre::TextAreaOverlayElement::Left);219 }220 221 std::string NotificationOverlay::getAlignmentString() const222 {223 Ogre::TextAreaOverlayElement::Alignment alignment = this->notificationText_->getAlignment();224 225 switch (alignment)226 {227 case Ogre::TextAreaOverlayElement::Right:228 return "right";229 case Ogre::TextAreaOverlayElement::Center:230 return "center";231 case Ogre::TextAreaOverlayElement::Left:232 return "left";233 default:234 assert(false); return "";235 }236 }237 238 96 } -
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.h
r2779 r2781 32 32 #include "OrxonoxPrereqs.h" 33 33 34 #include "orxonox/overlays/O rxonoxOverlay.h"34 #include "orxonox/overlays/OverlayText.h" 35 35 36 36 #include <string> … … 48 48 Damian 'Mozork' Frick 49 49 */ 50 class _OrxonoxExport NotificationOverlay : public O rxonoxOverlay50 class _OrxonoxExport NotificationOverlay : public OverlayText 51 51 { 52 53 friend class NotificationQueue; //TDO: Best solution? 54 52 55 53 public: 56 54 NotificationOverlay(BaseObject* creator); … … 59 57 60 58 bool processNotification(Notification* notification); 59 60 void setFontSize(float size) 61 { this->setTextSize(size); } 61 62 62 63 protected: 63 64 const std::string clipMessage(const std::string & message); 64 const std::string clipMessage2(const std::string & message); //Outdated 65 65 66 66 private: 67 67 NotificationQueue* queue_; 68 68 Notification* notification_; 69 70 int width_; 71 72 Ogre::TextAreaOverlayElement* notificationText_; 73 69 74 70 void initialize(void); 75 71 void defineOverlay(void); 76 77 virtual void sizeChanged();78 79 void setAlignment(Ogre::TextAreaOverlayElement::Alignment alignment)80 { this->notificationText_->setAlignment(alignment); }81 void setCaption(const std::string& caption)82 { this->notificationText_->setCaption(caption); }83 void setColour(const ColourValue& colour)84 { this->notificationText_->setColour(colour); }85 void setFont(const std::string & font);86 void setFontSize(float size);87 void setWidth(int width);88 void setAlignmentString(const std::string& alignment);89 void setTextSize(float size)90 { this->setSize(Vector2(size, size)); }91 92 Ogre::TextAreaOverlayElement::Alignment getAlignment() const93 { return this->notificationText_->getAlignment(); }94 std::string getCaption() const95 { return this->notificationText_->getCaption(); }96 float getFontSize(void) const;97 const std::string & getFont(void) const98 { return this->notificationText_->getFontName(); }99 int getWidth(void) const100 { return this->width_; }101 const ColourValue& getColour() const102 { return this->notificationText_->getColour(); }103 std::string getAlignmentString() const;104 float getTextSize() const105 { return this->getSize().y; }106 72 107 73 };
Note: See TracChangeset
for help on using the changeset viewer.