[Orxonox-commit 3201] r7894 - in code/branches/tutoriallevel: data/gui/scripts src/libraries/core src/modules/notifications
dafrick at orxonox.net
dafrick at orxonox.net
Mon Feb 14 23:02:58 CET 2011
Author: dafrick
Date: 2011-02-14 23:02:58 +0100 (Mon, 14 Feb 2011)
New Revision: 7894
Modified:
code/branches/tutoriallevel/data/gui/scripts/NotificationLayer.lua
code/branches/tutoriallevel/src/libraries/core/GUIManager.cc
code/branches/tutoriallevel/src/libraries/core/GUIManager.h
code/branches/tutoriallevel/src/modules/notifications/NotificationManager.cc
code/branches/tutoriallevel/src/modules/notifications/NotificationManager.h
code/branches/tutoriallevel/src/modules/notifications/NotificationQueue.cc
code/branches/tutoriallevel/src/modules/notifications/NotificationQueue.h
Log:
Some extension of NotificationQueue, font size and color can now be specified.
Modified: code/branches/tutoriallevel/data/gui/scripts/NotificationLayer.lua
===================================================================
--- code/branches/tutoriallevel/data/gui/scripts/NotificationLayer.lua 2011-02-14 21:59:22 UTC (rev 7893)
+++ code/branches/tutoriallevel/data/gui/scripts/NotificationLayer.lua 2011-02-14 22:02:58 UTC (rev 7894)
@@ -20,16 +20,18 @@
queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent.
root:addChildWindow(queue)
- queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
- queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size))))
-
local queueTuple =
{
- ["window"] = queue,
- ["name"] = name,
- ["edit"] = nil,
- ["visible"] = false
+ ["window"] = queue,
+ ["name"] = name,
+ ["edit"] = nil,
+ ["visible"] = false,
+ ["fontSize"] = 12,
+ ["fontColor"] = CEGUI.colour(1.0, 1.0, 1.0, 1.0)
}
+
+ queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
+ queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queueTuple, size))))
P.queueList[name] = queueTuple -- name access
P.setVisible(queueTuple, false) -- Set the queue to invisible as long as there are no notifications in it.
@@ -52,6 +54,7 @@
return
end
item = CEGUI.createListboxTextItem(notification)
+ P.setItemFontHelper(item, queue, true)
local listbox = CEGUI.toListbox(queue.window)
-- Add the item to the top of the listbox.
if listbox:getItemCount() == 0 then
@@ -120,6 +123,69 @@
queue.visible = visible
end
+-- Change the position of the queue.
+-- The parameters are (in order) 'name of the queue', 'relative x-position', 'absolute x-position in pixel', 'relative y-position', 'absolute y-position in pixel'.
+function P.moveQueue(queueName, relativeXPos, absoluteXPos, relativeYpos, absoluteYPos)
+ local queueWindow = P.queueList[queueName].window
+ queueWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(relativeXPos, absoluteXPos), CEGUI.UDim(relativeYpos, absoluteYPos)))
+end
+
+-- Change the size of the queue.
+-- The parameters are (in order) 'name of the queue', 'relative width', 'absolute width in pixel', 'relative height', 'absolute heigth in pixel'.
+-- Additionally the last parameter can be ommitted and relativeHeight can be set to the size (i.e. the maximal number of notifications displayed) of the queue, which leads to the height being set such that all notifications can be displayed.
+function P.resizeQueue(queueName, relativeWidth, absoluteWidth, relativeHeight, absoluteHeigth)
+ local queueWindow = P.queueList[queueName].window
+ if queueWindow == nil then
+ return
+ end
+ if absoluteHeigth == nil then
+ absoluteHeigth = P.queueHeightHelper(P.queueList[queueName], relativeHeight)
+ relativeHeight = 0
+ end
+ queueWindow:setSize(CEGUI.UVector2(CEGUI.UDim(relativeWidth, absoluteWidth), CEGUI.UDim(relativeHeight, absoluteHeigth)))
+end
+
+-- Change the font size and font color of all notifications in a queueHeightHelper
+-- The parameters are (in order) 'name of the queue', 'font size', 'RGBA of the font color, with values from 0 to 1 each'.
+function P.changeQueueFont(queueName, size, colorRed, colorGreen, colorBlue, colorAlpha)
+ local queue = P.queueList[queueName]
+ local queueWindow = queue.window
+ if queueWindow == nil then
+ return
+ end
+ if colorAlpha == nil then
+ colorAlpha = 1.0
+ end
+
+ local list = CEGUI.toListbox(queueWindow)
+ local num = list:getItemCount()
+ queue.fontSize = size
+ local changeColor = false
+ if colorRed ~= nil and colorGreen ~= nil and colorBlue ~= nil then
+ queue.fontColor:set(colorRed, colorGreen, colorBlue, colorAlpha)
+ changeColor = true
+ end
+ for i=0,num-1 do
+ P.setItemFontHelper(item, queue, changeColor)
+ end
+end
+
+-- Helper function to set the font size and color of a item of a queue.
+-- The parameters are (in order) 'the ListboxItem', 'the queue table', 'whether color should be changed as well'
+function P.setItemFontHelper(item, queue, changeColor)
+ local item = tolua.cast(item, "CEGUI::ListboxTextItem")
+ local fontMgr = CEGUI.FontManager:getSingleton()
+ if fontMgr:isFontPresent("BlueHighway-" .. queue.fontSize) then
+ item:setFont("BlueHighway-" .. queue.fontSize)
+ else
+ orxonox.GUIManager:addFontHelper("BlueHighway-" .. queue.fontSize, queue.fontSize, "bluehigh.ttf")
+ item:setFont("BlueHighway-" .. queue.fontSize)
+ end
+ if changeColor then
+ item:setTextColours(queue.fontColor)
+ end
+end
+
-- Enter the edit mode of the notification layer.
function P.enterEditMode()
P.editMode = true
@@ -341,7 +407,7 @@
end
-- If the button to save the targets of a queue has been clicked.
-function P. saveTargets_clicked(e)
+function P.saveTargets_clicked(e)
local we = CEGUI.toWindowEventArgs(e)
local name = we.window:getName()
@@ -368,7 +434,7 @@
end
-- If the button to save the size if a queue has been clicked.
-function P. saveSize_clicked(e)
+function P.saveSize_clicked(e)
local we = CEGUI.toWindowEventArgs(e)
local name = we.window:getName()
@@ -395,7 +461,7 @@
end
-- If the button to save the display time if a queue has been clicked.
-function P. saveDisplayTime_clicked(e)
+function P.saveDisplayTime_clicked(e)
local we = CEGUI.toWindowEventArgs(e)
local name = we.window:getName()
@@ -477,13 +543,14 @@
-- Helper function. Returns height a queue needs to have to display 'size' items.
function P.queueHeightHelper(queue, size)
- local listbox = CEGUI.toListbox(queue)
+ local listbox = CEGUI.toListbox(queue.window)
local item = CEGUI.createListboxTextItem("Text")
+ P.setItemFontHelper(item, queue, false)
listbox:addItem(item)
local singleItemHeight = listbox:getTotalItemsHeight()
- local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel())
- local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue)
- local frameHeight = queue:getUnclippedPixelRect():getHeight() - formattedArea:getHeight()
+ local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel())
+ local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window)
+ local frameHeight = queue.window:getUnclippedPixelRect():getHeight() - formattedArea:getHeight()
listbox:removeItem(item)
return frameHeight + singleItemHeight*size
end
Modified: code/branches/tutoriallevel/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/tutoriallevel/src/libraries/core/GUIManager.cc 2011-02-14 21:59:22 UTC (rev 7893)
+++ code/branches/tutoriallevel/src/libraries/core/GUIManager.cc 2011-02-14 22:02:58 UTC (rev 7894)
@@ -36,12 +36,14 @@
}
#include <CEGUIDefaultLogger.h>
#include <CEGUIExceptions.h>
+#include <CEGUIFontManager.h>
#include <CEGUIInputEvent.h>
#include <CEGUIMouseCursor.h>
#include <CEGUIResourceProvider.h>
#include <CEGUISystem.h>
#include <CEGUIWindow.h>
#include <CEGUIWindowManager.h>
+#include <CEGUIXMLAttributes.h>
#include <elements/CEGUIListbox.h>
#include <elements/CEGUIListboxItem.h>
#include <ogreceguirenderer/OgreCEGUIRenderer.h>
@@ -497,4 +499,39 @@
listbox->setItemTooltipsEnabled(enabled);
}
+ /**
+ @brief
+ Adds a new freetype font to the CEGUI system.
+ @param name
+ The name of the new font.
+ @param size
+ The font size of the new font in pixels.
+ @param fontName
+ The filename of the font.
+ */
+ /*static*/ void GUIManager::addFontHelper(const std::string& name, int size, const std::string& fontName)
+ {
+ if(CEGUI::FontManager::getSingleton().isFontPresent(name)) // If a font with that name already exists.
+ return;
+
+ CEGUI::Font* font = NULL;
+ CEGUI::XMLAttributes xmlAttributes;
+
+ // Attributes specified within CEGUIFont
+ xmlAttributes.add("Name", name);
+ xmlAttributes.add("Filename", fontName);
+ xmlAttributes.add("ResourceGroup", "");
+ xmlAttributes.add("AutoScaled", "true");
+ xmlAttributes.add("NativeHorzRes", "800");
+ xmlAttributes.add("NativeVertRes", "600");
+
+ // Attributes specified within CEGUIXMLAttributes
+ xmlAttributes.add("Size", multi_cast<std::string>(size));
+ xmlAttributes.add("AntiAlias", "true");
+
+ font = CEGUI::FontManager::getSingleton().createFont("FreeType", xmlAttributes);
+ if(font != NULL)
+ font->load();
+ }
+
}
Modified: code/branches/tutoriallevel/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/tutoriallevel/src/libraries/core/GUIManager.h 2011-02-14 21:59:22 UTC (rev 7893)
+++ code/branches/tutoriallevel/src/libraries/core/GUIManager.h 2011-02-14 22:02:58 UTC (rev 7894)
@@ -108,9 +108,10 @@
inline orxonox::PlayerInfo* getPlayer(const std::string& guiname) const { std::map<std::string, PlayerInfo*>::const_iterator it = this->players_.find(guiname); return (it != this->players_.end()) ? it->second : 0; } // tolua_export
// TODO: Temporary hack because the tolua exported CEGUI method does not seem to work
- static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); //tolua_export
- static void setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& toooltip); //tolua_export
- static void setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled); //tolua_export
+ static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); // tolua_export
+ static void setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& toooltip); // tolua_export
+ static void setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled); // tolua_export
+ static void addFontHelper(const std::string& name, int size, const std::string& fontName); // tolua_export
static GUIManager& getInstance() { return Singleton<GUIManager>::getInstance(); } // tolua_export
Modified: code/branches/tutoriallevel/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/branches/tutoriallevel/src/modules/notifications/NotificationManager.cc 2011-02-14 21:59:22 UTC (rev 7893)
+++ code/branches/tutoriallevel/src/modules/notifications/NotificationManager.cc 2011-02-14 22:02:58 UTC (rev 7894)
@@ -39,6 +39,7 @@
#include "core/LuaState.h"
#include "network/Host.h"
#include "network/NetworkFunction.h"
+#include "util/Convert.h"
#include "util/ScopedSingletonManager.h"
#include "interfaces/NotificationListener.h"
@@ -337,6 +338,38 @@
/**
@brief
+ Fetches the newest Notifications for a specific NotificationListener and stores them in the input map.
+ @param listener
+ The NotificationListener the Notifications are fetched for.
+ @param map
+ A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
+ @param numberOfNotifications
+ The number of newest Notifications to be got.
+ @return
+ Returns true if successful.
+ */
+ void NotificationManager::getNewestNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications)
+ {
+ assert(listener);
+ assert(map);
+
+ std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // All the Notifications for the input NotificationListener.
+
+ if(!notifications->empty()) // If the list of Notifications is not empty.
+ {
+ std::multimap<std::time_t,Notification*>::iterator it = notifications->end();
+ for(int i = 0; i < numberOfNotifications; i++) // Iterate through the Notifications from the newest until we have the specified number of notifications.
+ {
+ it--;
+ map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); // Add the found Notifications to the map.
+ if(it == notifications->begin())
+ break;
+ }
+ }
+ }
+
+ /**
+ @brief
Enters the edit mode of the NotificationLayer.
*/
void NotificationManager::enterEditMode(void)
@@ -380,7 +413,14 @@
*/
void NotificationManager::loadQueues(void)
{
- new NotificationQueue("all");
+ NotificationQueue* allQueue = new NotificationQueue("all");
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"all\", 0.5, 0, " + multi_cast<std::string>(allQueue->getMaxSize()) + ")");
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"all\", 0, 10, 0.3, 0)");
+
+ NotificationQueue* infoQueue = new NotificationQueue("info", NotificationManager::ALL, 1, -1);
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, 1.0, 1.0, 0.0, 0.8)");
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"info\", 0.6, 0, " + multi_cast<std::string>(infoQueue->getMaxSize()) + ")");
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"info\", 0.2, 0, 0.8, 0)");
}
/**
Modified: code/branches/tutoriallevel/src/modules/notifications/NotificationManager.h
===================================================================
--- code/branches/tutoriallevel/src/modules/notifications/NotificationManager.h 2011-02-14 21:59:22 UTC (rev 7893)
+++ code/branches/tutoriallevel/src/modules/notifications/NotificationManager.h 2011-02-14 22:02:58 UTC (rev 7894)
@@ -97,6 +97,8 @@
void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)
{ this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
+ void getNewestNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications); //!< Fetches the newest Notifications for a specific NotificationListener and stores them in the input map.
+
void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer.
bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue.
Modified: code/branches/tutoriallevel/src/modules/notifications/NotificationQueue.cc
===================================================================
--- code/branches/tutoriallevel/src/modules/notifications/NotificationQueue.cc 2011-02-14 21:59:22 UTC (rev 7893)
+++ code/branches/tutoriallevel/src/modules/notifications/NotificationQueue.cc 2011-02-14 22:02:58 UTC (rev 7894)
@@ -158,7 +158,7 @@
void NotificationQueue::tick(float dt)
{
this->tickTime_ += dt; // Add the time interval that has passed to the time counter.
- if(this->tickTime_ >= 1.0) // If the time counter is greater than 1s all Notifications that have expired are removed, if it is smaller we wait to the next tick.
+ if(this->displayTime_ != INF && this->tickTime_ >= 1.0) // If the time counter is greater than 1s all Notifications that have expired are removed, if it is smaller we wait to the next tick.
{
this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time.
@@ -186,7 +186,10 @@
std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>;
// Get the Notifications sent in the interval from now to now minus the display time.
- NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
+ if(this->displayTime_ == INF)
+ NotificationManager::getInstance().getNewestNotifications(this, notifications, this->getMaxSize());
+ else
+ NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
if(!notifications->empty())
{
@@ -354,11 +357,9 @@
@brief
Sets the maximum number of seconds a Notification is displayed.
@param time
- The number of seconds the Notifications is displayed.
- @return
- Returns true if successful.
+ The number of seconds a Notification is displayed.
*/
- void NotificationQueue::setDisplayTime(unsigned int time)
+ void NotificationQueue::setDisplayTime(int time)
{
if(this->displayTime_ == time)
return;
Modified: code/branches/tutoriallevel/src/modules/notifications/NotificationQueue.h
===================================================================
--- code/branches/tutoriallevel/src/modules/notifications/NotificationQueue.h 2011-02-14 21:59:22 UTC (rev 7893)
+++ code/branches/tutoriallevel/src/modules/notifications/NotificationQueue.h 2011-02-14 22:02:58 UTC (rev 7894)
@@ -120,12 +120,12 @@
inline unsigned int getMaxSize() const
{ return this->maxSize_; }
- void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
+ void setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed.
/**
@brief Returns the time interval the Notification is displayed.
@return Returns the display time.
*/
- inline unsigned int getDisplayTime() const
+ inline int getDisplayTime() const
{ return this->displayTime_; }
// tolua_end
@@ -151,12 +151,13 @@
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 int INF = -1; //!< Constant denoting infinity.
std::string name_; //!< The name of the NotificationQueue.
unsigned int maxSize_; //!< The maximal number of Notifications displayed.
unsigned int size_; //!< The number of Notifications displayed.
- unsigned int displayTime_; //!< The time a Notification is displayed.
+ int displayTime_; //!< The time a Notification is displayed.
bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
More information about the Orxonox-commit
mailing list