- Timestamp:
- Mar 26, 2009, 9:45:23 PM (16 years ago)
- Location:
- code/branches/questsystem5/src/orxonox/overlays/notifications
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc
r2788 r2858 174 174 @param queue 175 175 The NotificationQueue the Notifications are fetched for. 176 @param map 177 A multimap, in which the notifications are stored. 176 178 @param timeFrameStart 177 179 The start time of the timeframe. … … 179 181 The end time of the timeframe. 180 182 @return 181 Returns a time-ordered list of Notifications. 182 @todo 183 Make sure the map is deleted. 184 */ 185 std::multimap<std::time_t,Notification*>* NotificationManager::getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd) 186 { 187 std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->queueList_[queue]]; 188 189 if(notifications == NULL) 190 return NULL; 183 Returns true if successful. 184 */ 185 bool NotificationManager::getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd) 186 { 187 if(queue == NULL || map == NULL) 188 return false; 189 190 std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->queueList_[queue]]; //!< The Notifications for the input NotificationQueue. 191 192 if(notifications == NULL) //!< Returns NULL, if there are no Notifications. 193 return true; 191 194 192 195 std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest; … … 194 197 itHighest = notifications->upper_bound(timeFrameStart); 195 198 196 std::multimap<std::time_t,Notification*>* map = new std::multimap<std::time_t,Notification*>(); 197 198 for(it = itLowest; it != itHighest; it++) 199 { 200 map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); 201 } 202 203 if(map->size() == 0) 204 { 205 delete map; 206 return NULL; 207 } 208 209 return map; 199 for(it = itLowest; it != itHighest; it++) //!< Iterate through the Notifications from the start of the time Frame to the end of it. 200 { 201 map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); //!< Add the found Notifications to the map. 202 } 203 204 return true; 210 205 } 211 206 -
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h
r2788 r2858 66 66 static NotificationManager & getInstance(); //! Returns a reference to the single instance of the NotificationManager. 67 67 68 //TDO: Visibility?69 68 bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager. 70 69 bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager. 71 70 72 std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe.71 bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe. 73 72 74 73 /** 75 74 @brief Fetches the Notifications for a specific NotificationQueue starting at a specified time. 76 75 @param queue The NotificationQueue the Notifications are fetched for. 76 @param map A multimap, in which the notifications are stored. 77 77 @param timeFrameStart The start time the Notifications are fetched from. 78 @return Returns a time-ordered list of Notifications.78 @return Returns true if successful. 79 79 */ 80 std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart)81 { return this->getNotifications(queue, timeFrameStart, std::time(0)); }80 bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart) 81 { return this->getNotifications(queue, map, timeFrameStart, std::time(0)); } 82 82 /** 83 83 @brief Fetches the Notifications for a specific NotificationQueue starting at a specified timespan before now. 84 84 @param queue The NotificationQueue the Notifications are fetched for. 85 @param map A multimap, in which the notifications are stored. 85 86 @param timeDelay The timespan. 86 @return Returns a time-ordered list of Notifications.87 @return Returns true if successful. 87 88 */ 88 std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, int timeDelay)89 { return this->getNotifications(queue, std::time(0)-timeDelay, std::time(0)); }89 bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, int timeDelay) 90 { return this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); } 90 91 91 92 private: -
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc
r2785 r2858 27 27 */ 28 28 29 /** 30 @file NotificationOverlay.cc 31 @brief Implementation of the NotificationOverlay class. 32 */ 33 29 34 #include "OrxonoxStableHeaders.h" 30 35 #include "NotificationOverlay.h" … … 43 48 { 44 49 50 /** 51 @brief 52 Constructor. Intializes the class. 53 */ 45 54 NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator) 46 55 { … … 48 57 } 49 58 59 /** 60 @brief 61 Constructor. Initilaizes the class creates a graphical representation of the input Notification for the input Queue. 62 @param queue 63 A pointer to the queue the NotificatonOverlay belongs to. 64 @param notification 65 A pointer to the Notification represented by this overlay. 66 @throws Argument 67 Throws an Argument-Exception if either no Notification or no NotificationQueue were input. 68 */ 50 69 NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OverlayText(this) 51 70 { 52 71 this->initialize(); 53 72 54 if(notification == NULL || queue == NULL) 73 if(notification == NULL || queue == NULL) //!> If either notification or queue are not given an Exception is thrown. 55 74 { 56 75 ThrowException(Argument, "There were NULL-Pointer arguments in NotificationOverlay creation."); … … 63 82 } 64 83 84 /** 85 @brief 86 Initializes and Registers the object. 87 */ 65 88 void NotificationOverlay::initialize(void) 66 89 { … … 70 93 } 71 94 95 /** 96 @brief 97 Set some Overlay-specific values. 98 */ 72 99 void NotificationOverlay::defineOverlay(void) 73 100 { … … 78 105 } 79 106 107 /** 108 @brief 109 Destructor. 110 */ 80 111 NotificationOverlay::~NotificationOverlay() 81 112 { 82 113 } 83 114 115 /** 116 @brief 117 Processes the input notification, resp. sees to it. that the NotificationOverlay displays the Notification message. 118 @param notification 119 A pointer to the notification that should be processed. 120 @return 121 Returns true if successful. 122 */ 84 123 bool NotificationOverlay::processNotification(Notification* notification) 85 124 { 125 if(notification == NULL) 126 return false; 86 127 this->setCaption(clipMessage(notification->getMessage())); 87 128 this->notification_ = notification; … … 89 130 } 90 131 132 /** 133 @brief 134 Clips the input message so that it meets the requirements for the maximal length of Notifications given by the NotificationQueue. 135 */ 91 136 const std::string NotificationOverlay::clipMessage(const std::string & message) 92 137 { 93 if(message.length() <= (unsigned int)this->queue_->getNotificationLength()) 138 if(message.length() <= (unsigned int)this->queue_->getNotificationLength()) //!< If the message is not too long. 94 139 return message; 95 140 return message.substr(0, this->queue_->getNotificationLength()); -
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.h
r2781 r2858 27 27 */ 28 28 29 /** 30 @file NotificationOverlay.h 31 @brief Definition of the NotificationOverlay class. 32 */ 33 34 29 35 #ifndef _NotificationOverlay_H__ 30 36 #define _NotificationOverlay_H__ … … 44 50 /** 45 51 @brief 46 52 The NotificationOverlay is used to display single Notifications, then bundled in a NotificationQUeue. 47 53 @author 48 54 Damian 'Mozork' Frick … … 56 62 virtual ~NotificationOverlay(); 57 63 58 bool processNotification(Notification* notification); 64 bool processNotification(Notification* notification); //!< Processes the input Notification. 59 65 60 void setFontSize(float size) 66 /** 67 @brief Sets the font size of this overlay's text. 68 @param size The font size. 69 */ 70 inline void setFontSize(float size) 61 71 { this->setTextSize(size); } 62 72 63 73 protected: 64 const std::string clipMessage(const std::string & message); 74 const std::string clipMessage(const std::string & message); //!< Clips the input message if too long. 65 75 66 76 private: 67 NotificationQueue* queue_; 68 Notification* notification_; 77 NotificationQueue* queue_; //!< The NotificationQeue this overlay belongs to. 78 Notification* notification_; //!< The Notification this overlay displays. 69 79 70 void initialize(void); 71 void defineOverlay(void); 80 void initialize(void); //!< Initializes the object. 81 void defineOverlay(void); //!< Sets some overlay-specific values. 72 82 73 83 }; -
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc
r2785 r2858 27 27 */ 28 28 29 /** 30 @file NotificationQueue.cc 31 @brief Implementation of the NotificationQueue class. 32 */ 33 29 34 #include "OrxonoxStableHeaders.h" 30 35 #include "NotificationQueue.h" … … 33 38 #include <OgreTextAreaOverlayElement.h> 34 39 #include <list> 40 #include <iostream> 41 #include <sstream> 35 42 36 43 #include "core/CoreIncludes.h" … … 155 162 this->clear(); 156 163 157 std::multimap<std::time_t,Notification*>* notifications = NotificationManager::getInstance().getNotifications(this, this->displayTime_); 158 159 if(notifications == NULL) 164 std::multimap<std::time_t,Notification*>* notifications = new std::multimap<std::time_t,Notification*>; 165 if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) //!< Get the Notifications sent in the interval form now to minus the display time. 166 { 167 COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl; 160 168 return; 161 162 for(std::multimap<std::time_t,Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) 169 } 170 171 if(notifications->empty()) 172 return; 173 174 for(std::multimap<std::time_t,Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) //!> Add all Notifications. 163 175 { 164 176 this->addNotification(it->second, it->first); 165 177 } 178 179 delete notifications; 166 180 167 181 COUT(3) << "NotificationQueue updated." << std::endl; … … 343 357 } 344 358 359 /** 360 @brief 361 Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector. 362 @param pos 363 The vector the NotificationQueue is scrolled. 364 */ 345 365 void NotificationQueue::scroll(const Vector2 pos) 346 366 { … … 351 371 } 352 372 353 void NotificationQueue::positionChanged() 373 /** 374 @brief 375 Aligns all the Notifications to the position of the NotificationQueue. 376 */ 377 void NotificationQueue::positionChanged(void) 354 378 { 355 379 int counter = 0; … … 379 403 std::string timeString = std::ctime(&time); 380 404 timeString.erase(timeString.length()-1); 381 char buffer[64]; //TDO: Very un-nice.382 st d::sprintf(buffer,"%x",(unsigned long)notification); //TDO: Use other conversion to avoid 64bit problems.383 std::string addressString = buffer;405 std::ostringstream stream; 406 stream << (unsigned long)notification; 407 std::string addressString = stream.str() ; 384 408 container->name = "NotificationOverlay(" + timeString + ")&" + addressString; 385 409 -
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h
r2785 r2858 71 71 @brief 72 72 Displays Notifications from specific senders. 73 Beware! The NotificationQueue is an OverlayGruop and thus cannot be be a sub-element of an OverlayGroup (at least no for now.) 74 75 Creating a NotificationQueue through XML goes as follows: 76 <NotificationQueue 77 name = "SuperQueue" //Name of your OverlayQueue. 78 maxSize = "5" //The maximum size of Notifications displayed. 79 notificationLength = "64" //The maximum number of characters of a Notification, that are displayed. (Default is 5) 80 displayTime = "30" //The time a Notification is displayed in seconds. (Default is 30) 81 targets = "target1, target2" //The senders this NotificationQueue displays Notifications from. (all, if all Notifications should be displayed.) 82 font = "VeraMono" //The font (Default is VeraMono) 83 fontSize = '0.4' //The font size. (Default is 0.025) 84 position = "0.0, .0.0" //The position of the NotificationQueue. (Default is 0.0,0.0) 85 /> 73 86 @author 74 87 Damian 'Mozork' Frick … … 140 153 bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets. 141 154 142 inline void setPosition(Vector2 pos) 155 /** 156 @brief Sets the position of the NotificationQueue. 157 @param pos The position. 158 */ 159 inline void setPosition(Vector2 pos) 143 160 { this->position_ = pos; this->positionChanged(); } 144 161 145 void scroll(const Vector2 pos); 162 void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector. 146 163 147 164 private: … … 183 200 bool setFont(const std::string & font); //!< Set the font. 184 201 185 void positionChanged( );202 void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue. 186 203 187 204 void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
Note: See TracChangeset
for help on using the changeset viewer.