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 | #include "OrxonoxStableHeaders.h" |
---|
30 | #include "NotificationOverlay.h" |
---|
31 | |
---|
32 | #include <OgreOverlayManager.h> |
---|
33 | #include <OgreTextAreaOverlayElement.h> |
---|
34 | #include <OgrePanelOverlayElement.h> |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "util/Exception.h" |
---|
38 | |
---|
39 | #include "Notification.h" |
---|
40 | #include "NotificationQueue.h" |
---|
41 | |
---|
42 | namespace orxonox |
---|
43 | { |
---|
44 | |
---|
45 | NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator) |
---|
46 | { |
---|
47 | this->initialize(); |
---|
48 | } |
---|
49 | |
---|
50 | NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OverlayText(this) |
---|
51 | { |
---|
52 | this->initialize(); |
---|
53 | |
---|
54 | if(notification == NULL || queue == NULL) |
---|
55 | { |
---|
56 | ThrowException(Argument, "There were NULL-Pointer arguments in NotificationOverlay creation."); |
---|
57 | } |
---|
58 | |
---|
59 | this->queue_ = queue; |
---|
60 | this->defineOverlay(); |
---|
61 | |
---|
62 | this->processNotification(notification); |
---|
63 | } |
---|
64 | |
---|
65 | void NotificationOverlay::initialize(void) |
---|
66 | { |
---|
67 | RegisterObject(NotificationOverlay); |
---|
68 | |
---|
69 | this->queue_ = NULL; |
---|
70 | } |
---|
71 | |
---|
72 | void NotificationOverlay::defineOverlay(void) |
---|
73 | { |
---|
74 | this->setFont(this->queue_->getFont()); |
---|
75 | this->setTextSize(this->queue_->getFontSize()); |
---|
76 | |
---|
77 | this->setPosition(this->queue_->getPosition()); |
---|
78 | } |
---|
79 | |
---|
80 | NotificationOverlay::~NotificationOverlay() |
---|
81 | { |
---|
82 | } |
---|
83 | |
---|
84 | bool NotificationOverlay::processNotification(Notification* notification) |
---|
85 | { |
---|
86 | this->setCaption(clipMessage(notification->getMessage())); |
---|
87 | this->notification_ = notification; |
---|
88 | return true; |
---|
89 | } |
---|
90 | |
---|
91 | const std::string NotificationOverlay::clipMessage(const std::string & message) |
---|
92 | { |
---|
93 | if(message.length() <= (unsigned int)this->queue_->getNotificationLength()) |
---|
94 | return message; |
---|
95 | return message.substr(0, this->queue_->getNotificationLength()); |
---|
96 | } |
---|
97 | |
---|
98 | } |
---|