[2779] | 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 | |
---|
[2781] | 45 | NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator) |
---|
[2779] | 46 | { |
---|
| 47 | this->initialize(); |
---|
| 48 | } |
---|
[2781] | 49 | |
---|
| 50 | NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OverlayText(this) |
---|
[2779] | 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()); |
---|
[2781] | 75 | this->setTextSize(this->queue_->getFontSize()); |
---|
[2785] | 76 | |
---|
| 77 | this->setPosition(this->queue_->getPosition()); |
---|
[2779] | 78 | } |
---|
[2781] | 79 | |
---|
[2779] | 80 | NotificationOverlay::~NotificationOverlay() |
---|
| 81 | { |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | bool NotificationOverlay::processNotification(Notification* notification) |
---|
| 85 | { |
---|
[2781] | 86 | this->setCaption(clipMessage(notification->getMessage())); |
---|
[2779] | 87 | this->notification_ = notification; |
---|
| 88 | return true; |
---|
| 89 | } |
---|
| 90 | |
---|
[2783] | 91 | const std::string NotificationOverlay::clipMessage(const std::string & message) |
---|
[2779] | 92 | { |
---|
[2783] | 93 | if(message.length() <= (unsigned int)this->queue_->getNotificationLength()) |
---|
| 94 | return message; |
---|
| 95 | return message.substr(0, this->queue_->getNotificationLength()); |
---|
[2779] | 96 | } |
---|
| 97 | |
---|
| 98 | } |
---|