[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 | |
---|
[2858] | 29 | /** |
---|
| 30 | @file NotificationOverlay.cc |
---|
| 31 | @brief Implementation of the NotificationOverlay class. |
---|
| 32 | */ |
---|
| 33 | |
---|
[2779] | 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 | |
---|
[2858] | 50 | /** |
---|
| 51 | @brief |
---|
| 52 | Constructor. Intializes the class. |
---|
| 53 | */ |
---|
[2781] | 54 | NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator) |
---|
[2779] | 55 | { |
---|
| 56 | this->initialize(); |
---|
| 57 | } |
---|
[2781] | 58 | |
---|
[2858] | 59 | /** |
---|
| 60 | @brief |
---|
[2994] | 61 | Constructor. Initializes the class creates a graphical representation of the input Notification for the input Queue. |
---|
[2858] | 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 | */ |
---|
[2994] | 69 | NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OverlayText(NULL) |
---|
[2779] | 70 | { |
---|
| 71 | this->initialize(); |
---|
| 72 | |
---|
[2858] | 73 | if(notification == NULL || queue == NULL) //!> If either notification or queue are not given an Exception is thrown. |
---|
[2779] | 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 | |
---|
[2858] | 84 | /** |
---|
| 85 | @brief |
---|
| 86 | Initializes and Registers the object. |
---|
| 87 | */ |
---|
[2779] | 88 | void NotificationOverlay::initialize(void) |
---|
| 89 | { |
---|
| 90 | RegisterObject(NotificationOverlay); |
---|
| 91 | |
---|
| 92 | this->queue_ = NULL; |
---|
| 93 | } |
---|
| 94 | |
---|
[2858] | 95 | /** |
---|
| 96 | @brief |
---|
| 97 | Set some Overlay-specific values. |
---|
| 98 | */ |
---|
[2779] | 99 | void NotificationOverlay::defineOverlay(void) |
---|
| 100 | { |
---|
| 101 | this->setFont(this->queue_->getFont()); |
---|
[2781] | 102 | this->setTextSize(this->queue_->getFontSize()); |
---|
[2785] | 103 | |
---|
| 104 | this->setPosition(this->queue_->getPosition()); |
---|
[2779] | 105 | } |
---|
[2781] | 106 | |
---|
[2858] | 107 | /** |
---|
| 108 | @brief |
---|
| 109 | Destructor. |
---|
| 110 | */ |
---|
[2779] | 111 | NotificationOverlay::~NotificationOverlay() |
---|
| 112 | { |
---|
| 113 | } |
---|
| 114 | |
---|
[2858] | 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 | */ |
---|
[2779] | 123 | bool NotificationOverlay::processNotification(Notification* notification) |
---|
| 124 | { |
---|
[2858] | 125 | if(notification == NULL) |
---|
| 126 | return false; |
---|
[2781] | 127 | this->setCaption(clipMessage(notification->getMessage())); |
---|
[2779] | 128 | this->notification_ = notification; |
---|
| 129 | return true; |
---|
| 130 | } |
---|
| 131 | |
---|
[2858] | 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 | */ |
---|
[2783] | 136 | const std::string NotificationOverlay::clipMessage(const std::string & message) |
---|
[2779] | 137 | { |
---|
[2858] | 138 | if(message.length() <= (unsigned int)this->queue_->getNotificationLength()) //!< If the message is not too long. |
---|
[2783] | 139 | return message; |
---|
| 140 | return message.substr(0, this->queue_->getNotificationLength()); |
---|
[2779] | 141 | } |
---|
| 142 | |
---|
| 143 | } |
---|