Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2781


Ignore:
Timestamp:
Mar 12, 2009, 10:42:56 PM (15 years ago)
Author:
dafrick
Message:

Got the Notifications to work. Rudimentarily, at least… \nNow comes the polish…

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  
    4343{
    4444
    45     NotificationOverlay::NotificationOverlay(BaseObject* creator) : OrxonoxOverlay(creator)
     45    NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator)
    4646    {
    4747        this->initialize();
    4848    }
    49    
    50     NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OrxonoxOverlay(this)
     49
     50    NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OverlayText(this)
    5151    {
    5252        this->initialize();
     
    6161       
    6262        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;
    7063    }
    7164   
     
    7568       
    7669        this->queue_ = NULL;
    77         this->notificationText_ = NULL;
    78         this->width_ = 0;
    7970    }
    8071   
     
    8273    {
    8374        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());
    9476    }
    95    
     77
    9678    NotificationOverlay::~NotificationOverlay()
    9779    {
    98    
    99     }
    100    
    101     void NotificationOverlay::setFont(const std::string & font)
    102     {
    103         if (this->notificationText_ && font != "")
    104             this->notificationText_->setFontName(font);
    10580    }
    10681
    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) const
    120     {
    121         if (this->notificationText_)
    122             return this->notificationText_->getCharHeight();
    123         else
    124             return 0;
    125     }
    126    
    12782    bool NotificationOverlay::processNotification(Notification* notification)
    12883    {
    129         this->notificationText_->setCaption(clipMessage(notification->getMessage()));
     84        this->setCaption(clipMessage(notification->getMessage()));
    13085        this->notification_ = notification;
    13186        return true;
     
    13994    }
    14095
    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             else
    183             {
    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         else
    206             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 default
    218             this->setAlignment(Ogre::TextAreaOverlayElement::Left);
    219     }
    220 
    221     std::string NotificationOverlay::getAlignmentString() const
    222     {
    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 
    23896}
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.h

    r2779 r2781  
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include "orxonox/overlays/OrxonoxOverlay.h"
     34#include "orxonox/overlays/OverlayText.h"
    3535
    3636#include <string>
     
    4848        Damian 'Mozork' Frick
    4949    */
    50     class _OrxonoxExport NotificationOverlay : public OrxonoxOverlay
     50    class _OrxonoxExport NotificationOverlay : public OverlayText
    5151    {
    52    
    53         friend class NotificationQueue; //TDO: Best solution?
    54    
     52
    5553        public:
    5654            NotificationOverlay(BaseObject* creator);
     
    5957           
    6058            bool processNotification(Notification* notification);
     59
     60            void setFontSize(float size)
     61                { this->setTextSize(size); }
    6162       
    6263        protected:
    6364            const std::string clipMessage(const std::string & message);
    64             const std::string clipMessage2(const std::string & message); //Outdated
    65        
     65
    6666        private:
    6767            NotificationQueue* queue_;
    6868            Notification* notification_;
    69            
    70             int width_;
    71            
    72             Ogre::TextAreaOverlayElement* notificationText_;
    73            
     69
    7470            void initialize(void);
    7571            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() const
    93                 { return this->notificationText_->getAlignment(); }
    94             std::string getCaption() const
    95                 { return this->notificationText_->getCaption(); }
    96             float getFontSize(void) const;
    97             const std::string & getFont(void) const
    98                 { return this->notificationText_->getFontName(); }
    99             int getWidth(void) const
    100                 { return this->width_; }
    101             const ColourValue& getColour() const
    102                 { return this->notificationText_->getColour(); }
    103             std::string getAlignmentString() const;
    104             float getTextSize() const
    105                 { return this->getSize().y; }
    10672
    10773    };
Note: See TracChangeset for help on using the changeset viewer.