[Orxonox-commit 82] r2781 - branches/questsystem5/src/orxonox/overlays/notifications
dafrick at orxonox.net
dafrick at orxonox.net
Thu Mar 12 22:42:56 CET 2009
Author: dafrick
Date: 2009-03-12 21:42:56 +0000 (Thu, 12 Mar 2009)
New Revision: 2781
Modified:
branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc
branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.h
Log:
Got the Notifications to work. Rudimentarily, at least... \nNow comes the polish...
Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc 2009-03-12 18:36:12 UTC (rev 2780)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc 2009-03-12 21:42:56 UTC (rev 2781)
@@ -42,12 +42,12 @@
namespace orxonox
{
- NotificationOverlay::NotificationOverlay(BaseObject* creator) : OrxonoxOverlay(creator)
+ NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator)
{
this->initialize();
}
-
- NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OrxonoxOverlay(this)
+
+ NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OverlayText(this)
{
this->initialize();
@@ -60,13 +60,6 @@
this->defineOverlay();
this->processNotification(notification);
-
- COUT(3) << getCaption() << std::endl;
- COUT(3) << getFontSize() << std::endl;
- //COUT(3) << getFont() << std::endl;
- COUT(3) << getWidth() << std::endl;
- COUT(3) << getAlignmentString() << std::endl;
- COUT(3) << getTextSize() << std::endl;
}
void NotificationOverlay::initialize(void)
@@ -74,59 +67,21 @@
RegisterObject(NotificationOverlay);
this->queue_ = NULL;
- this->notificationText_ = NULL;
- this->width_ = 0;
}
void NotificationOverlay::defineOverlay(void)
{
this->setFont(this->queue_->getFont());
- this->setFontSize(this->queue_->getFontSize());
-
- this->notificationText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", "NotificationOverlay_notificationText_" + getUniqueNumberString()));
- this->notificationText_->setCharHeight(1.0);
- this->notificationText_->setColour(ColourValue(1.0, 1.0, 1.0, 1.0));
- this->notificationText_->setAlignment(Ogre::TextAreaOverlayElement::Center);
- this->notificationText_->setCaption("");
-
- this->background_->addChild(this->notificationText_);
- COUT(3) << this->queue_->getFont() << std::endl;
+ this->setTextSize(this->queue_->getFontSize());
}
-
+
NotificationOverlay::~NotificationOverlay()
{
-
}
-
- void NotificationOverlay::setFont(const std::string & font)
- {
- if (this->notificationText_ && font != "")
- this->notificationText_->setFontName(font);
- }
- void NotificationOverlay::setFontSize(float size)
- {
- if (this->notificationText_ && size >= 0)
- this->notificationText_->setCharHeight(size);
- }
-
- void NotificationOverlay::setWidth(int width)
- {
- this->width_ = width;
- this->notificationText_->setCaption(clipMessage(this->notification_->getMessage()));
- }
-
- float NotificationOverlay::getFontSize(void) const
- {
- if (this->notificationText_)
- return this->notificationText_->getCharHeight();
- else
- return 0;
- }
-
bool NotificationOverlay::processNotification(Notification* notification)
{
- this->notificationText_->setCaption(clipMessage(notification->getMessage()));
+ this->setCaption(clipMessage(notification->getMessage()));
this->notification_ = notification;
return true;
}
@@ -138,101 +93,4 @@
return str.substr(0, this->queue_->getNotificationLength());
}
- const std::string NotificationOverlay::clipMessage2(const std::string & str)
- {
-
- std::string message = str;
- unsigned int i = 0;
-
- unsigned int found = message.find("\\n", i);
- while(found != std::string::npos)
- {
- message.replace(found, 2, "\n");
- i = found+2;
- found = message.find("\\n", i);
- }
-
- std::string clippedMessage = "";
- int wordLength = 0;
- i = 0;
- int widthLeft = this->getWidth();
- while(i < message.length())
- {
- while(i < message.length() && message[i] != ' ' && message[i] != '\n')
- {
- i++;
- wordLength++;
- }
-
- if(wordLength <= widthLeft)
- {
- clippedMessage = clippedMessage + message.substr(i-wordLength, wordLength);
- if(i < message.length())
- {
- clippedMessage = clippedMessage + message.substr(i,1);
- }
- widthLeft -= (wordLength+1);
- if(message[i] == '\n')
- {
- widthLeft = this->getWidth() - (wordLength+1);
- }
- wordLength = 0;
- i++;
- }
- else
- {
- clippedMessage.push_back('\n');
- clippedMessage = clippedMessage + message.substr(i-wordLength, wordLength);
- if(i < message.length())
- {
- clippedMessage = clippedMessage + message.substr(i,1);
- }
- widthLeft = this->getWidth() - (wordLength+1);
- i++;
- wordLength = 0;
- }
- }
-
- return clippedMessage;
- }
-
- void NotificationOverlay::sizeChanged()
- {
- if (this->rotState_ == Horizontal)
- this->overlay_->setScale(size_.y * sizeCorrection_.y, size_.y * sizeCorrection_.y);
- else if (this->rotState_ == Vertical)
- this->overlay_->setScale(size_.y / (sizeCorrection_.y * sizeCorrection_.y), size_.y * sizeCorrection_.y);
- else
- this->overlay_->setScale(size_.y, size_.y);
-
- positionChanged();
- }
-
- void NotificationOverlay::setAlignmentString(const std::string& alignment)
- {
- if (alignment == "right")
- this->setAlignment(Ogre::TextAreaOverlayElement::Right);
- else if (alignment == "center")
- this->setAlignment(Ogre::TextAreaOverlayElement::Center);
- else // "left" and default
- this->setAlignment(Ogre::TextAreaOverlayElement::Left);
- }
-
- std::string NotificationOverlay::getAlignmentString() const
- {
- Ogre::TextAreaOverlayElement::Alignment alignment = this->notificationText_->getAlignment();
-
- switch (alignment)
- {
- case Ogre::TextAreaOverlayElement::Right:
- return "right";
- case Ogre::TextAreaOverlayElement::Center:
- return "center";
- case Ogre::TextAreaOverlayElement::Left:
- return "left";
- default:
- assert(false); return "";
- }
- }
-
}
Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.h
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.h 2009-03-12 18:36:12 UTC (rev 2780)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.h 2009-03-12 21:42:56 UTC (rev 2781)
@@ -31,7 +31,7 @@
#include "OrxonoxPrereqs.h"
-#include "orxonox/overlays/OrxonoxOverlay.h"
+#include "orxonox/overlays/OverlayText.h"
#include <string>
#include <set>
@@ -47,63 +47,29 @@
@author
Damian 'Mozork' Frick
*/
- class _OrxonoxExport NotificationOverlay : public OrxonoxOverlay
+ class _OrxonoxExport NotificationOverlay : public OverlayText
{
-
- friend class NotificationQueue; //TDO: Best solution?
-
+
public:
NotificationOverlay(BaseObject* creator);
NotificationOverlay(NotificationQueue* queue, Notification* notification);
virtual ~NotificationOverlay();
bool processNotification(Notification* notification);
+
+ void setFontSize(float size)
+ { this->setTextSize(size); }
protected:
const std::string clipMessage(const std::string & message);
- const std::string clipMessage2(const std::string & message); //Outdated
-
+
private:
NotificationQueue* queue_;
Notification* notification_;
-
- int width_;
-
- Ogre::TextAreaOverlayElement* notificationText_;
-
+
void initialize(void);
void defineOverlay(void);
- virtual void sizeChanged();
-
- void setAlignment(Ogre::TextAreaOverlayElement::Alignment alignment)
- { this->notificationText_->setAlignment(alignment); }
- void setCaption(const std::string& caption)
- { this->notificationText_->setCaption(caption); }
- void setColour(const ColourValue& colour)
- { this->notificationText_->setColour(colour); }
- void setFont(const std::string & font);
- void setFontSize(float size);
- void setWidth(int width);
- void setAlignmentString(const std::string& alignment);
- void setTextSize(float size)
- { this->setSize(Vector2(size, size)); }
-
- Ogre::TextAreaOverlayElement::Alignment getAlignment() const
- { return this->notificationText_->getAlignment(); }
- std::string getCaption() const
- { return this->notificationText_->getCaption(); }
- float getFontSize(void) const;
- const std::string & getFont(void) const
- { return this->notificationText_->getFontName(); }
- int getWidth(void) const
- { return this->width_; }
- const ColourValue& getColour() const
- { return this->notificationText_->getColour(); }
- std::string getAlignmentString() const;
- float getTextSize() const
- { return this->getSize().y; }
-
};
}
More information about the Orxonox-commit
mailing list