Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 14, 2011, 11:02:58 PM (14 years ago)
Author:
dafrick
Message:

Some extension of NotificationQueue, font size and color can now be specified.

Location:
code/branches/tutoriallevel
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel/data/gui/scripts/NotificationLayer.lua

    r7413 r7894  
    2121    root:addChildWindow(queue)
    2222
    23     queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
    24     queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size))))
    25 
    2623    local queueTuple =
    2724    {
    28         ["window"]  = queue,
    29         ["name"]    = name,
    30         ["edit"]    = nil,
    31         ["visible"] = false
     25        ["window"]    = queue,
     26        ["name"]      = name,
     27        ["edit"]      = nil,
     28        ["visible"]   = false,
     29        ["fontSize"]  = 12,
     30        ["fontColor"] = CEGUI.colour(1.0, 1.0, 1.0, 1.0)
    3231    }
     32   
     33    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
     34    queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queueTuple, size))))
    3335
    3436    P.queueList[name] = queueTuple -- name access
     
    5355    end
    5456    item = CEGUI.createListboxTextItem(notification)
     57    P.setItemFontHelper(item, queue, true)
    5558    local listbox = CEGUI.toListbox(queue.window)
    5659    -- Add the item to the top of the listbox.
     
    119122    queue.window:setVisible(visible)
    120123    queue.visible = visible
     124end
     125
     126-- Change the position of the queue.
     127-- 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'.
     128function P.moveQueue(queueName, relativeXPos, absoluteXPos, relativeYpos, absoluteYPos)
     129    local queueWindow = P.queueList[queueName].window
     130    queueWindow:setPosition(CEGUI.UVector2(CEGUI.UDim(relativeXPos, absoluteXPos), CEGUI.UDim(relativeYpos, absoluteYPos)))
     131end
     132
     133-- Change the size of the queue.
     134-- The parameters are (in order) 'name of the queue', 'relative width', 'absolute width in pixel', 'relative height', 'absolute heigth in pixel'.
     135-- 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.
     136function P.resizeQueue(queueName, relativeWidth, absoluteWidth, relativeHeight, absoluteHeigth)
     137    local queueWindow = P.queueList[queueName].window
     138    if queueWindow == nil then
     139        return
     140    end
     141    if absoluteHeigth == nil then
     142        absoluteHeigth = P.queueHeightHelper(P.queueList[queueName], relativeHeight)
     143        relativeHeight = 0
     144    end
     145    queueWindow:setSize(CEGUI.UVector2(CEGUI.UDim(relativeWidth, absoluteWidth), CEGUI.UDim(relativeHeight, absoluteHeigth)))
     146end
     147
     148-- Change the font size and font color of all notifications in a queueHeightHelper
     149-- The parameters are (in order) 'name of the queue', 'font size', 'RGBA of the font color, with values from 0 to 1 each'.
     150function P.changeQueueFont(queueName, size, colorRed, colorGreen, colorBlue, colorAlpha)
     151    local queue = P.queueList[queueName]
     152    local queueWindow = queue.window
     153    if queueWindow == nil then
     154        return
     155    end
     156    if colorAlpha == nil then
     157        colorAlpha = 1.0
     158    end
     159
     160    local list = CEGUI.toListbox(queueWindow)
     161    local num = list:getItemCount()
     162    queue.fontSize = size
     163    local changeColor = false
     164    if colorRed ~= nil and colorGreen ~= nil and colorBlue ~= nil then
     165        queue.fontColor:set(colorRed, colorGreen, colorBlue, colorAlpha)
     166        changeColor = true
     167    end
     168    for i=0,num-1 do
     169        P.setItemFontHelper(item, queue, changeColor)
     170    end
     171end
     172
     173-- Helper function to set the font size and color of a item of a queue.
     174-- The parameters are (in order) 'the ListboxItem', 'the queue table', 'whether color should be changed as well'
     175function P.setItemFontHelper(item, queue, changeColor)
     176    local item = tolua.cast(item, "CEGUI::ListboxTextItem")
     177    local fontMgr = CEGUI.FontManager:getSingleton()
     178    if fontMgr:isFontPresent("BlueHighway-" .. queue.fontSize) then
     179        item:setFont("BlueHighway-" .. queue.fontSize)
     180    else
     181        orxonox.GUIManager:addFontHelper("BlueHighway-" .. queue.fontSize, queue.fontSize, "bluehigh.ttf")
     182        item:setFont("BlueHighway-" .. queue.fontSize)
     183    end
     184    if changeColor then
     185        item:setTextColours(queue.fontColor)
     186    end
    121187end
    122188
     
    342408
    343409-- If the button to save the targets of a queue has been clicked.
    344 function P. saveTargets_clicked(e)
     410function P.saveTargets_clicked(e)
    345411    local we = CEGUI.toWindowEventArgs(e)
    346412    local name = we.window:getName()
     
    369435
    370436-- If the button to save the size if a queue has been clicked.
    371 function P. saveSize_clicked(e)
     437function P.saveSize_clicked(e)
    372438    local we = CEGUI.toWindowEventArgs(e)
    373439    local name = we.window:getName()
     
    396462
    397463-- If the button to save the display time if a queue has been clicked.
    398 function P. saveDisplayTime_clicked(e)
     464function P.saveDisplayTime_clicked(e)
    399465    local we = CEGUI.toWindowEventArgs(e)
    400466    local name = we.window:getName()
     
    478544-- Helper function. Returns height a queue needs to have to display 'size' items.
    479545function P.queueHeightHelper(queue, size)
    480     local listbox = CEGUI.toListbox(queue)
     546    local listbox = CEGUI.toListbox(queue.window)
    481547    local item = CEGUI.createListboxTextItem("Text")
     548    P.setItemFontHelper(item, queue, false)
    482549    listbox:addItem(item)
    483550    local singleItemHeight = listbox:getTotalItemsHeight()
    484     local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel())
    485     local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue)
    486     local frameHeight = queue:getUnclippedPixelRect():getHeight() - formattedArea:getHeight()
     551    local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue.window:getLookNFeel())
     552    local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue.window)
     553    local frameHeight = queue.window:getUnclippedPixelRect():getHeight() - formattedArea:getHeight()
    487554    listbox:removeItem(item)
    488555    return frameHeight + singleItemHeight*size
  • code/branches/tutoriallevel/src/libraries/core/GUIManager.cc

    r7811 r7894  
    3737#include <CEGUIDefaultLogger.h>
    3838#include <CEGUIExceptions.h>
     39#include <CEGUIFontManager.h>
    3940#include <CEGUIInputEvent.h>
    4041#include <CEGUIMouseCursor.h>
     
    4344#include <CEGUIWindow.h>
    4445#include <CEGUIWindowManager.h>
     46#include <CEGUIXMLAttributes.h>
    4547#include <elements/CEGUIListbox.h>
    4648#include <elements/CEGUIListboxItem.h>
     
    498500    }
    499501
     502    /**
     503    @brief
     504        Adds a new freetype font to the CEGUI system.
     505    @param name
     506        The name of the new font.
     507    @param size
     508        The font size of the new font in pixels.
     509        @param fontName
     510        The filename of the font.
     511    */
     512    /*static*/ void GUIManager::addFontHelper(const std::string& name, int size, const std::string& fontName)
     513    {
     514        if(CEGUI::FontManager::getSingleton().isFontPresent(name)) // If a font with that name already exists.
     515            return;
     516
     517        CEGUI::Font* font = NULL;
     518        CEGUI::XMLAttributes xmlAttributes;
     519
     520        // Attributes specified within CEGUIFont
     521        xmlAttributes.add("Name", name);
     522        xmlAttributes.add("Filename", fontName);
     523        xmlAttributes.add("ResourceGroup", "");
     524        xmlAttributes.add("AutoScaled", "true");
     525        xmlAttributes.add("NativeHorzRes", "800");
     526        xmlAttributes.add("NativeVertRes", "600");
     527
     528        // Attributes specified within CEGUIXMLAttributes
     529        xmlAttributes.add("Size", multi_cast<std::string>(size));
     530        xmlAttributes.add("AntiAlias", "true");
     531
     532        font = CEGUI::FontManager::getSingleton().createFont("FreeType", xmlAttributes);
     533        if(font != NULL)
     534            font->load();
     535    }
     536
    500537}
  • code/branches/tutoriallevel/src/libraries/core/GUIManager.h

    r7801 r7894  
    109109
    110110        // TODO: Temporary hack because the tolua exported CEGUI method does not seem to work
    111         static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); //tolua_export
    112         static void setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& toooltip); //tolua_export
    113         static void setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled); //tolua_export
     111        static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); // tolua_export
     112        static void setTooltipTextHelper(CEGUI::ListboxItem* item, const std::string& toooltip); // tolua_export
     113        static void setItemTooltipsEnabledHelper(CEGUI::Listbox* listbox, bool enabled); // tolua_export
     114        static void addFontHelper(const std::string& name, int size, const std::string& fontName); // tolua_export
    114115
    115116        static GUIManager& getInstance() { return Singleton<GUIManager>::getInstance(); } // tolua_export
  • code/branches/tutoriallevel/src/modules/notifications/NotificationManager.cc

    r7552 r7894  
    4040#include "network/Host.h"
    4141#include "network/NetworkFunction.h"
     42#include "util/Convert.h"
    4243#include "util/ScopedSingletonManager.h"
    4344
     
    338339    /**
    339340    @brief
     341        Fetches the newest Notifications for a specific NotificationListener and stores them in the input map.
     342    @param listener
     343        The NotificationListener the Notifications are fetched for.
     344    @param map
     345        A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
     346    @param numberOfNotifications
     347        The number of newest Notifications to be got.
     348    @return
     349        Returns true if successful.
     350    */
     351    void NotificationManager::getNewestNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications)
     352    {
     353        assert(listener);
     354        assert(map);
     355
     356        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // All the Notifications for the input NotificationListener.
     357
     358        if(!notifications->empty()) // If the list of Notifications is not empty.
     359        {
     360            std::multimap<std::time_t,Notification*>::iterator it = notifications->end();
     361            for(int i = 0; i < numberOfNotifications; i++) // Iterate through the Notifications from the newest until we have the specified number of notifications.
     362            {
     363                it--;
     364                map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); // Add the found Notifications to the map.
     365                if(it == notifications->begin())
     366                    break;
     367            }
     368        }
     369    }
     370
     371    /**
     372    @brief
    340373        Enters the edit mode of the NotificationLayer.
    341374    */
     
    381414    void NotificationManager::loadQueues(void)
    382415    {
    383         new NotificationQueue("all");
     416        NotificationQueue* allQueue = new NotificationQueue("all");
     417        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"all\", 0.5, 0, " + multi_cast<std::string>(allQueue->getMaxSize()) + ")");
     418        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"all\", 0, 10, 0.3, 0)");
     419
     420        NotificationQueue* infoQueue = new NotificationQueue("info", NotificationManager::ALL, 1, -1);
     421        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, 1.0, 1.0, 0.0, 0.8)");
     422        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"info\", 0.6, 0, " + multi_cast<std::string>(infoQueue->getMaxSize()) + ")");
     423        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"info\", 0.2, 0, 0.8, 0)");
    384424    }
    385425
  • code/branches/tutoriallevel/src/modules/notifications/NotificationManager.h

    r7552 r7894  
    9898                { this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
    9999
     100            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.
     101
    100102            void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer.
    101103
  • code/branches/tutoriallevel/src/modules/notifications/NotificationQueue.cc

    r7489 r7894  
    159159    {
    160160        this->tickTime_ += dt; // Add the time interval that has passed to the time counter.
    161         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.
     161        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.
    162162        {
    163163            this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time.
     
    187187        std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>;
    188188        // Get the Notifications sent in the interval from now to now minus the display time.
    189         NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
     189        if(this->displayTime_ == INF)
     190            NotificationManager::getInstance().getNewestNotifications(this, notifications, this->getMaxSize());
     191        else
     192            NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
    190193
    191194        if(!notifications->empty())
     
    355358        Sets the maximum number of seconds a Notification is displayed.
    356359    @param time
    357         The number of seconds the Notifications is displayed.
    358     @return
    359         Returns true if successful.
    360     */
    361     void NotificationQueue::setDisplayTime(unsigned int time)
     360        The number of seconds a Notification is displayed.
     361    */
     362    void NotificationQueue::setDisplayTime(int time)
    362363    {
    363364        if(this->displayTime_ == time)
  • code/branches/tutoriallevel/src/modules/notifications/NotificationQueue.h

    r7552 r7894  
    121121                { return this->maxSize_; }
    122122
    123             void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
     123            void setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed.
    124124            /**
    125125            @brief Returns the time interval the Notification is displayed.
    126126            @return Returns the display time.
    127127            */
    128             inline unsigned int getDisplayTime() const
     128            inline int getDisplayTime() const
    129129                { return this->displayTime_; }
    130130            // tolua_end
     
    152152            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
    153153            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
     154            static const int INF = -1; //!< Constant denoting infinity.
    154155
    155156            std::string name_; //!< The name of the NotificationQueue.
     
    157158            unsigned int maxSize_; //!< The maximal number of Notifications displayed.
    158159            unsigned int size_; //!< The number of Notifications displayed.
    159             unsigned int displayTime_; //!< The time a Notification is displayed.
     160            int displayTime_; //!< The time a Notification is displayed.
    160161
    161162            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
Note: See TracChangeset for help on using the changeset viewer.