Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/overlays/notifications/NotificationOverlay.cc @ 3110

Last change on this file since 3110 was 3110, checked in by rgrieder, 15 years ago

Removed old msvc specific support for precompiled header files.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.1 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 NotificationOverlay.cc
31    @brief Implementation of the NotificationOverlay class.
32*/
33
34#include "NotificationOverlay.h"
35
36#include <OgreOverlayManager.h>
37#include <OgreTextAreaOverlayElement.h>
38#include <OgrePanelOverlayElement.h>
39
40#include "core/CoreIncludes.h"
41#include "util/Exception.h"
42
43#include "Notification.h"
44#include "NotificationQueue.h"
45
46namespace orxonox
47{
48
49    /**
50    @brief
51        Constructor. Intializes the class.
52    */
53    NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator)
54    {
55        this->initialize();
56    }
57
58    /**
59    @brief
60        Constructor. Initializes the class creates a graphical representation of the input Notification for the input Queue.
61    @param queue
62        A pointer to the queue the NotificatonOverlay belongs to.
63    @param notification
64        A pointer to the Notification represented by this overlay.
65    @throws Argument
66        Throws an Argument-Exception if either no Notification or no NotificationQueue were input.
67    */
68    NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OverlayText(NULL)
69    {
70        this->initialize();
71       
72        if(notification == NULL || queue == NULL) //!> If either notification or queue are not given an Exception is thrown.
73        {
74            ThrowException(Argument, "There were NULL-Pointer arguments in NotificationOverlay creation.");
75        }
76
77        this->queue_ = queue;
78        this->defineOverlay();
79       
80        this->processNotification(notification);
81    }
82   
83    /**
84    @brief
85        Initializes and Registers the object.
86    */
87    void NotificationOverlay::initialize(void)
88    {
89        RegisterObject(NotificationOverlay);
90       
91        this->queue_ = NULL;
92    }
93   
94    /**
95    @brief
96        Set some Overlay-specific values.
97    */
98    void NotificationOverlay::defineOverlay(void)
99    {
100        this->setFont(this->queue_->getFont());
101        this->setTextSize(this->queue_->getFontSize());
102
103        this->setPosition(this->queue_->getPosition());
104    }
105
106    /**
107    @brief
108        Destructor.
109    */
110    NotificationOverlay::~NotificationOverlay()
111    {
112    }
113
114    /**
115    @brief
116        Processes the input notification, resp. sees to it. that the NotificationOverlay displays the Notification message.
117    @param notification
118        A pointer to the notification that should be processed.
119    @return
120        Returns true if successful.
121    */
122    bool NotificationOverlay::processNotification(Notification* notification)
123    {
124        if(notification == NULL)
125            return false;
126        this->setCaption(clipMessage(notification->getMessage()));
127        this->notification_ = notification;
128        return true;
129    }
130
131    /**
132    @brief
133        Clips the input message so that it meets the requirements for the maximal length of Notifications given by the NotificationQueue.
134    */
135    const std::string NotificationOverlay::clipMessage(const std::string & message)
136    {
137        if(message.length() <= (unsigned int)this->queue_->getNotificationLength()) //!< If the message is not too long.
138            return message;
139        return message.substr(0, this->queue_->getNotificationLength());
140    }
141
142}
Note: See TracBrowser for help on using the repository browser.