Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/notifications/NotificationOverlay.cc @ 7307

Last change on this file since 7307 was 7163, checked in by dafrick, 14 years ago

Merged presentation3 branch into trunk.

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Damian 'Mozork' Frick
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file
31    @brief Implementation of the NotificationOverlay class.
32*/
33
34#include "NotificationOverlay.h"
35
36#include "util/Exception.h"
37#include "core/CoreIncludes.h"
38#include "Notification.h"
39#include "NotificationQueue.h"
40
41namespace orxonox
42{
43
44    /**
45    @brief
46        Constructor. Intializes the class.
47    */
48    NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator)
49    {
50        RegisterObject(NotificationOverlay);
51        this->initialize();
52    }
53
54    /**
55    @brief
56        Constructor. Initializes the class creates a graphical representation of the input Notification for the input Queue.
57    @param queue
58        A pointer to the queue the NotificatonOverlay belongs to.
59    @param notification
60        A pointer to the Notification represented by this overlay.
61    @throws Argument
62        Throws an Argument-Exception if either no Notification or no NotificationQueue were input.
63    */
64    NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OverlayText(NULL)
65    {
66        this->initialize();
67
68        if(notification == NULL || queue == NULL) //!> If either notification or queue are not given an Exception is thrown.
69        {
70            ThrowException(Argument, "There were NULL-Pointer arguments in NotificationOverlay creation.");
71        }
72
73        this->queue_ = queue;
74        this->defineOverlay();
75
76        this->processNotification(notification);
77    }
78
79    /**
80    @brief
81        Initializes and Registers the object.
82    */
83    void NotificationOverlay::initialize(void)
84    {
85        this->queue_ = NULL;
86    }
87
88    /**
89    @brief
90        Set some Overlay-specific values.
91    */
92    void NotificationOverlay::defineOverlay(void)
93    {
94        this->setFont(this->queue_->getFont());
95        this->setTextSize(this->queue_->getFontSize());
96
97        this->setPosition(this->queue_->getPosition());
98    }
99
100    /**
101    @brief
102        Destructor.
103    */
104    NotificationOverlay::~NotificationOverlay()
105    {
106    }
107
108    /**
109    @brief
110        Processes the input notification, resp. sees to it. that the NotificationOverlay displays the Notification message.
111    @param notification
112        A pointer to the notification that should be processed.
113    @return
114        Returns true if successful.
115    */
116    bool NotificationOverlay::processNotification(Notification* notification)
117    {
118        if(notification == NULL)
119            return false;
120        this->setCaption(clipMessage(notification->getMessage()));
121        this->notification_ = notification;
122        return true;
123    }
124
125    /**
126    @brief
127        Clips the input message so that it meets the requirements for the maximal length of Notifications given by the NotificationQueue.
128    */
129    std::string NotificationOverlay::clipMessage(const std::string & message)
130    {
131        if(message.length() <= static_cast<unsigned int>(this->queue_->getNotificationLength())) //!< If the message is not too long.
132            return message;
133        return message.substr(0, this->queue_->getNotificationLength());
134    }
135
136}
Note: See TracBrowser for help on using the repository browser.