[Orxonox-commit 2638] r7343 - in code/branches/notifications: data/gui/scripts src/modules/notifications
dafrick at orxonox.net
dafrick at orxonox.net
Fri Sep 3 23:30:24 CEST 2010
Author: dafrick
Date: 2010-09-03 23:30:24 +0200 (Fri, 03 Sep 2010)
New Revision: 7343
Modified:
code/branches/notifications/data/gui/scripts/NotificationLayer.lua
code/branches/notifications/src/modules/notifications/NotificationQueue.cc
code/branches/notifications/src/modules/notifications/NotificationQueue.h
Log:
Some documenting and adjustment.
Modified: code/branches/notifications/data/gui/scripts/NotificationLayer.lua
===================================================================
--- code/branches/notifications/data/gui/scripts/NotificationLayer.lua 2010-09-03 19:17:51 UTC (rev 7342)
+++ code/branches/notifications/data/gui/scripts/NotificationLayer.lua 2010-09-03 21:30:24 UTC (rev 7343)
@@ -8,6 +8,8 @@
function P.createQueue(name, size)
local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
+ queue:setProperty("Alpha", 0.3)
+ queue:setProperty("InheritsAlpha", "setFalse")
root:addChildWindow(queue)
queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
@@ -35,15 +37,6 @@
end
end
-function P.changePosition(name, xPos, yPos)
- local queue = P.nameToQueueHelper(name)
- if queue == nil then
- cout(0, "Queue is nil!")
- return
- end
- queue:setPosition(CEGUI.UVector2(CEGUI.UDim(tonumber(xPos), 0), CEGUI.UDim(tonumber(yPos), 0)))
-end
-
function P.pushNotification(queueName, notification)
local queue = P.nameToQueueHelper(queueName)
if queue == nil then
@@ -89,6 +82,25 @@
CEGUI.toListbox(queue):resetList()
end
+function P.changePosition(name, xPos, yPos)
+ local queue = P.nameToQueueHelper(name)
+ if queue == nil then
+ cout(0, "Queue is nil!")
+ return
+ end
+ queue:setPosition(CEGUI.UVector2(CEGUI.UDim(tonumber(xPos), 0), CEGUI.UDim(tonumber(yPos), 0)))
+ queue:setWidth(CEGUI.UDim(1.0, -xPos))
+end
+
+function P.changeSize(name, size)
+ local queue = P.nameToQueueHelper(name)
+ if queue == nil then
+ cout(0, "Queue is nil!")
+ return
+ end
+ queue:setHeight(CEGUI.UDim(0, P.queueHeightHelper(queue, size)))
+end
+
function P.nameToQueueHelper(name)
local queue = nil
for k,v in pairs(P.nameList) do
Modified: code/branches/notifications/src/modules/notifications/NotificationQueue.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationQueue.cc 2010-09-03 19:17:51 UTC (rev 7342)
+++ code/branches/notifications/src/modules/notifications/NotificationQueue.cc 2010-09-03 21:30:24 UTC (rev 7343)
@@ -175,7 +175,7 @@
/**
@brief
- Adds a Notification, to the queue.
+ Adds a Notification to the NotificationQueue.
It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI.
@param notification
The Notification.
@@ -233,15 +233,14 @@
/**
@brief
- Clears the queue by removing all containers.
+ Clears the queue by removing all Notifications.
*/
void NotificationQueue::clear(void)
{
this->ordering_.clear();
for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++)
- {
delete *it;
- }
+
this->notifications_.clear();
this->size_ = 0;
GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
@@ -249,6 +248,15 @@
/**
@brief
+ Adjusts the NotificationQueue, when the position has changed.
+ */
+ void NotificationQueue::positionChanged(void)
+ {
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changePosition(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getPosition().x) + ", " + multi_cast<std::string>(this->getPosition().y) + ")");
+ }
+
+ /**
+ @brief
Sets the name of the NotificationQueue.
@param name
The name to be set.
@@ -273,6 +281,16 @@
void NotificationQueue::setMaxSize(unsigned int size)
{
this->maxSize_ = size;
+ this->sizeChanged();
+ }
+
+ /**
+ @brief
+ Adjusts the NotificationQueue, when the maximum size has changed.
+ */
+ void NotificationQueue::sizeChanged(void)
+ {
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeSize(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getSize()) + ")");
this->update();
}
@@ -307,16 +325,12 @@
}
string->clear();
bool first = true;
- for(std::set<std::string>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) //!< Iterate through the set of targets.
+ for(std::set<std::string>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) // Iterate through the set of targets.
{
if(!first)
- {
*string += ',';
- }
else
- {
first = false;
- }
*string += *it;
}
@@ -338,7 +352,7 @@
std::string* pTemp;
unsigned int index = 0;
- while( index < targets.size() ) //!< Go through the string, character by character until the end is reached.
+ while(index < targets.size()) // Go through the string, character by character until the end is reached.
{
pTemp = new std::string();
while(index < targets.size() && targets[index] != ',' && targets[index] != ' ')
@@ -353,13 +367,4 @@
return true;
}
- /**
- @brief
- Aligns all the Notifications to the position of the NotificationQueue.
- */
- void NotificationQueue::positionChanged(void)
- {
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changePosition(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getPosition().x) + ", " + multi_cast<std::string>(this->getPosition().y) + ")");
- }
-
}
Modified: code/branches/notifications/src/modules/notifications/NotificationQueue.h
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationQueue.h 2010-09-03 19:17:51 UTC (rev 7342)
+++ code/branches/notifications/src/modules/notifications/NotificationQueue.h 2010-09-03 21:30:24 UTC (rev 7343)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file NotificationQueue.h
@brief Definition of the NotificationQueue class.
*/
@@ -54,11 +54,11 @@
//! Container to allow easy handling.
struct NotificationContainer
{
- Notification* notification; //!< The Notification displayed by the overlay.
+ Notification* notification; //!< The Notification displayed.
time_t time; //!< The time the Notification was sent and thus first displayed.
};
- //! Struct to allow ordering of NotificationOverlayContainers.
+ //! Struct to allow ordering of NotificationContainers.
struct NotificationContainerCompare {
bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
{ return a->time < b->time; } //!< Ordered by time.
@@ -70,7 +70,6 @@
@author
Damian 'Mozork' Frick
*/
-
class _NotificationsExport NotificationQueue : public Tickable, public NotificationListener
{
@@ -133,7 +132,6 @@
private:
static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
-
static const Vector2 DEFAULT_POSITION; //!< the default position.
std::string name_; //!< The name of the NotificationQueue.
@@ -146,31 +144,32 @@
std::set<std::string> targets_; //!< The targets the Queue displays Notifications of.
- std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps. //TODO: Would set work as well?
- std::vector<NotificationContainer*> notifications_;
+ std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered. //TODO: Would set work as well?
+ std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue.
- float tickTime_; //!< Helper variable, to not have to check for overlays that have been displayed too long, every tick.
+ float tickTime_; //!< Helper variable, to not have to check for Notifications that have been displayed too long, every tick.
NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
void initialize(void); //!< Initializes the object.
- void create(void);
+ void create(void); //!< Creates the NotificationQueue in lua.
bool setName(const std::string& name); //!< Sets the name of the NotificationQueue.
void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications.
void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
- bool setTargets(const std::string & targets); //!< Set the targets of this queue.
+ bool setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue.
+ void sizeChanged(void); //!< Adjusts the NotificationQueue, when the maximum size has changed.
- void push(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
- void pop(void);
- void remove(NotificationContainer* container);
+ void push(Notification* notification, const std::time_t & time); //!< Add a Notification to the NotificationQueue.
+ void pop(void); //!< Removes the least recently added Notification form the NotificationQueue.
+ void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input container.
- void clear(void); //!< Clear the queue.
+ void clear(void); //!< Clears the queue by removing all Notifications.
};
More information about the Orxonox-commit
mailing list