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