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