- Timestamp:
- May 11, 2011, 10:45:56 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.cc
r8446 r8448 33 33 34 34 #include "NotificationQueueCEGUI.h" 35 36 #include <sstream> 35 37 36 38 #include "core/CoreIncludes.h" … … 42 44 #include "Notification.h" 43 45 46 #include "ToluaBindNotifications.h" 47 44 48 namespace orxonox 45 49 { 46 50 51 // Register tolua_open function when loading the library. 52 DeclareToluaInterface(Notifications); 53 47 54 NotificationQueueCEGUI::NotificationQueueCEGUI(const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime) : NotificationQueue(name, senders, size, displayTime) 48 55 { 49 56 RegisterObject(NotificationQueueCEGUI); 57 58 this->displaySize_ = Vector4(1.0, 0.0, 0.0, 0.0); 59 this->position_ = Vector4(0.0, 0.0, 0.0, 0.0); 60 this->alignment_ = "LeftAligned"; 61 this->fontSize_ = 12; 62 this->fontColor_ = Vector4(1.0, 1.0, 1.0, 1.0); 63 this->fontColorStr_ = "FFFFFFFF"; 50 64 51 65 // Create the NotificationQueueCEGUI in lua. … … 73 87 NotificationQueue::destroy(); 74 88 } 75 89 90 /** 91 @brief 92 Set the size of the window that displays the NotificationQueue. 93 @param size 94 The size is a vector with components: 95 - The relative width of the window. (A value between 0 and 1) 96 - The absolute width in pixels. (Additional to the relative width, can be negative) 97 - The relative height of the window. (A value between 0 and 1) 98 - The absolute height in pixels. (Additional to the relative width, can be negative.) 99 If both the 3rd and 4th component of size are set to 0 the height is set such that exactly as many Notifications fit as is the maximum size of the NotificationQueue (in terms of the number of Notifications). 100 */ 101 void NotificationQueueCEGUI::setDisplaySize(const Vector4& size) 102 { 103 if(this->displaySize_ == size) 104 return; 105 106 if(size.x < 0.0 || size.x > 1.0 || size.z < 0.0 || size.z > 1.0) 107 { 108 COUT(2) << "The display size of the NotificationQueueCEGUI " << this->getName() << " was trying to be set, but the relative size was not in [0,1]. Aborting..." << endl; 109 return; 110 } 111 112 this->displaySize_ = size; 113 if(size.z == 0.0 && size.w == 0.0) 114 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->displaySize_.x) + ", " + multi_cast<std::string>(this->displaySize_.y) + ")"); 115 else 116 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->displaySize_.x) + ", " + multi_cast<std::string>(this->displaySize_.y) + ", " + multi_cast<std::string>(this->displaySize_.z) + ", " + multi_cast<std::string>(this->displaySize_.w) + ")"); 117 } 118 119 /** 120 @brief 121 Set the position of the window that displays the NotificationQueue. 122 @param position 123 The position is a vector with components: 124 - The relative x-position of the window. (A value between 0 and 1) 125 - The absolute x-position in pixels. (Additional to the relative x-position, can be negative) 126 - The relative y-position of the window. (A value between 0 and 1) 127 - The absolute y-position in pixels. (Additional to the relative y-position, can be negative.) 128 */ 129 void NotificationQueueCEGUI::setPosition(const Vector4& position) 130 { 131 if(this->position_ == position) 132 return; 133 134 if(position.x < 0.0 || position.x > 1.0 || position.z < 0.0 || position.z > 1.0) 135 { 136 COUT(2) << "The position the NotificationQueueCEGUI " << this->getName() << " was trying to be set, but the relative position was not in [0,1]. Aborting..." << endl; 137 return; 138 } 139 140 this->position_ = position; 141 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->position_.x) + ", " + multi_cast<std::string>(this->position_.y) + ", " + multi_cast<std::string>(this->position_.z) + ", " + multi_cast<std::string>(this->position_.w) + ")"); 142 } 143 144 /** 145 @brief 146 Set the horizontal alignment of the Notifications text. 147 @param alignment 148 The alignment of the Notifications, they are the possible string that the CEGUI Falagard StaticText HorzFormatting property can take. 149 @see http://cegui.org.uk/api_reference/classCEGUI_1_1FalagardStaticTextProperties_1_1HorzFormatting.html 150 */ 151 void NotificationQueueCEGUI::setAlignment(const std::string& alignment) 152 { 153 if(this->alignment_ == alignment) 154 return; 155 156 // TODO: Check whether the alignment string is correct? 157 this->alignment_ = alignment; 158 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueAlignment(\"" + this->getName() + "\", \"" + this->alignment_ + "\")"); 159 } 160 161 /** 162 @brief 163 Set the font size of the text displayed by this NotificationQueue. 164 @param size 165 The font size. 166 */ 167 void NotificationQueueCEGUI::setFontSize(unsigned int size) 168 { 169 if(this->fontSize_ == size) 170 return; 171 172 this->fontSize_ = size; 173 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFontSize(\"" + this->getName() + "\", " + multi_cast<std::string>(this->fontSize_) + ")"); 174 } 175 176 /** 177 @brief 178 Set the font color if the text displayed by this NotificationQueue. 179 @param color 180 The color is a vector with the components being RGBA and taking values from 0 to 1. 181 */ 182 void NotificationQueueCEGUI::setFontColor(const Vector4& color) 183 { 184 if(this->fontColor_ == color) 185 return; 186 187 this->fontColor_ = color; 188 // Convert to ARGB format. 189 std::stringstream stream; 190 for(unsigned int i = 0; i < 4; i++) 191 stream << std::hex << std::setw(2) << std::setfill('0') << int(this->fontColor_[(i+3)%4]*255); 192 this->fontColorStr_ = stream.str(); 193 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFontColor(\"" + this->getName() + "\", \"" + this->fontColorStr_ + "\")"); 194 } 195 196 /** 197 @brief 198 Get the NotificationQueueCEGUI with the input name. 199 @param name 200 The name of the NotificationQueueCEGUI to be got. 201 @return 202 Returns a pointer to the NotificationQueueCEGUI, or NULL if it doesn't exist. 203 */ 204 /*static*/ NotificationQueueCEGUI* NotificationQueueCEGUI::getQueue(const std::string& name) 205 { 206 NotificationQueue* queue = NotificationManager::getInstance().getQueue(name); 207 if(queue == NULL || !queue->isA(Class(NotificationQueueCEGUI))) 208 return NULL; 209 return static_cast<NotificationQueueCEGUI*>(queue); 210 } 211 76 212 /** 77 213 @brief … … 86 222 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")"); 87 223 } 88 224 89 225 /** 90 226 @brief … … 97 233 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")"); 98 234 } 99 235 100 236 /** 101 237 @brief Is called when a notification was removed. … … 108 244 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")"); 109 245 } 110 246 111 247 /** 112 248 @brief … … 118 254 { 119 255 NotificationQueue::clear(noGraphics); 120 256 121 257 // Clear the NotificationQueue in the GUI. 122 258 if(GameMode::showsGraphics() && !noGraphics) 123 259 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")"); 124 260 } 125 261 126 262 /** 127 263 @brief
Note: See TracChangeset
for help on using the changeset viewer.