[8498] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Benjamin Grauer |
---|
| 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SHELL |
---|
| 17 | |
---|
[8503] | 18 | #include "glgui_notifier.h" |
---|
[8498] | 19 | #include "multi_line_text.h" |
---|
| 20 | |
---|
| 21 | #include "debug.h" |
---|
| 22 | |
---|
[8503] | 23 | namespace OrxGui |
---|
[8498] | 24 | { |
---|
[9869] | 25 | ObjectListDefinition(GLGuiNotifier); |
---|
[8498] | 26 | /** |
---|
[8619] | 27 | * @brief standard constructor |
---|
[8498] | 28 | */ |
---|
[8503] | 29 | GLGuiNotifier::GLGuiNotifier () |
---|
[8498] | 30 | { |
---|
[9869] | 31 | this->registerObject(this, GLGuiNotifier::_objectList); |
---|
[8498] | 32 | |
---|
| 33 | // Element2D and generals |
---|
| 34 | this->lineSpacing = 0; |
---|
[8509] | 35 | this->linesProcessed = 0; |
---|
[8619] | 36 | this->_fadeAge = 3.0; |
---|
| 37 | this->setHideAge(4.0); |
---|
[8498] | 38 | |
---|
[8509] | 39 | this->setDisplayLineCount(10); |
---|
[8498] | 40 | } |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * @brief standard deconstructor |
---|
| 44 | */ |
---|
[8503] | 45 | GLGuiNotifier::~GLGuiNotifier () |
---|
[8498] | 46 | { |
---|
| 47 | // delete the displayable Buffers |
---|
[8509] | 48 | /* while (!this->displayLines.empty()) |
---|
| 49 | { |
---|
| 50 | delete this->displayLines.front().text; |
---|
| 51 | this->displayLines.pop_front(); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | while (!this->hiddenText.empty()) |
---|
| 55 | { |
---|
| 56 | delete this->hiddenText.top(); |
---|
| 57 | this->hiddenText.pop(); |
---|
| 58 | }*/ |
---|
| 59 | } |
---|
| 60 | |
---|
[8619] | 61 | /** |
---|
| 62 | * @brief push a message onto the notifier. |
---|
| 63 | * @param message the message to be pushed. |
---|
| 64 | * |
---|
| 65 | * @note it is not guaranteed, that the message is delivered instantaniously |
---|
| 66 | * The possibility may arise, that the DisplayLines are all in use, then one |
---|
| 67 | * has to wait until a line gets hidden, until a new one can be pushed to be |
---|
| 68 | * displayed. |
---|
| 69 | */ |
---|
[8509] | 70 | void GLGuiNotifier::pushNotifyMessage(const std::string& message) |
---|
| 71 | { |
---|
| 72 | if (!this->hiddenText.empty()) |
---|
[8498] | 73 | { |
---|
[8619] | 74 | DisplayLine dl; // put everything in here, and then display it |
---|
| 75 | |
---|
| 76 | // retrieve a Text. |
---|
[8509] | 77 | dl.text = this->hiddenText.top(); |
---|
[8619] | 78 | this->hiddenText.pop(); |
---|
[8509] | 79 | |
---|
[8619] | 80 | // setup Text |
---|
[8510] | 81 | dl.text->setBlending(1.0f); |
---|
[8509] | 82 | dl.text->setText(message); |
---|
[8619] | 83 | dl.text->setVisibility(true); |
---|
| 84 | dl.text->setRelCoor2D(this->calculateLinePosition(0)); |
---|
| 85 | |
---|
[8509] | 86 | dl.age = 0.0f; |
---|
[8512] | 87 | this->displayLines.push_front(dl); |
---|
[8509] | 88 | this->repositionText(); |
---|
[8498] | 89 | } |
---|
[8509] | 90 | else |
---|
| 91 | { |
---|
[8619] | 92 | // push it onto the List of messages we still need. |
---|
[8512] | 93 | this->inputBuffer.push_front(message); |
---|
[8509] | 94 | } |
---|
[8498] | 95 | } |
---|
| 96 | |
---|
| 97 | |
---|
[8619] | 98 | /** |
---|
| 99 | * @brief sets the Dipsplay Line Count of the Notifier. |
---|
| 100 | * @param coun the count of displayLines. |
---|
| 101 | */ |
---|
[8509] | 102 | void GLGuiNotifier::setDisplayLineCount(unsigned int count) |
---|
| 103 | { |
---|
| 104 | unsigned int currentCount = displayLines.size() + hiddenText.size(); |
---|
[8498] | 105 | |
---|
[8509] | 106 | for (unsigned int i = currentCount; i < count; ++i) |
---|
| 107 | { |
---|
| 108 | MultiLineText* text = new MultiLineText(); |
---|
| 109 | this->applyTextSettings(text); |
---|
| 110 | this->hiddenText.push(text); |
---|
| 111 | } |
---|
| 112 | bufferDisplaySize = count; |
---|
| 113 | } |
---|
| 114 | |
---|
[8619] | 115 | void GLGuiNotifier::setFadeAge(float fadeAge) |
---|
| 116 | { |
---|
| 117 | this->_fadeAge = fadeAge; |
---|
| 118 | this->_transformAge = hideAge() - this->fadeAge(); |
---|
| 119 | } |
---|
[8509] | 120 | |
---|
[8619] | 121 | void GLGuiNotifier::setHideAge(float hideAge) |
---|
| 122 | { |
---|
| 123 | this->_hideAge = hideAge; |
---|
| 124 | this->_transformAge = this->hideAge() - fadeAge(); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | |
---|
[8498] | 128 | /** |
---|
| 129 | * @brief repositiones all the Texts to their position. |
---|
| 130 | */ |
---|
[8503] | 131 | void GLGuiNotifier::repositionText() |
---|
[8498] | 132 | { |
---|
| 133 | int linePos = -1; |
---|
[8509] | 134 | std::list<DisplayLine>::iterator textIt; |
---|
| 135 | for (textIt = this->displayLines.begin() ; textIt != this->displayLines.end(); ++textIt ) |
---|
[8498] | 136 | { |
---|
[8509] | 137 | linePos += (*textIt).text->getLineCount(); |
---|
| 138 | (*textIt).text->setRelCoorSoft2D(this->calculateLinePosition(linePos), 8); |
---|
| 139 | // printf("%f %f\n", (*textIt).text->getAbsCoor2D().x, (*textIt).text->getAbsCoor2D().y); |
---|
[8498] | 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | /** |
---|
[8503] | 145 | * @brief applies the GLGuiNotifiers Settings to a single Text of the GLGuiNotifier. |
---|
[8498] | 146 | * @param text the Text to apply the settings to. |
---|
| 147 | */ |
---|
[8509] | 148 | void GLGuiNotifier::applyTextSettings(MultiLineText* text) |
---|
[8498] | 149 | { |
---|
[8619] | 150 | text->setSize(this->textSize()); |
---|
[8509] | 151 | text->setLineWidth( 300 ); |
---|
[8619] | 152 | text->setFont("fonts/final_frontier.ttf", (int)this->textSize()); |
---|
[8509] | 153 | |
---|
[8619] | 154 | text->setColor(this->foregroundColor() ); |
---|
[8498] | 155 | if (text->getParent2D() != this) |
---|
[8509] | 156 | text->setParent2D(this); |
---|
[8498] | 157 | } |
---|
| 158 | |
---|
| 159 | |
---|
[8619] | 160 | /** |
---|
| 161 | * @brief ticks the entire Notifier. |
---|
| 162 | * @param dt the time passed since the last Tick |
---|
| 163 | */ |
---|
[8503] | 164 | void GLGuiNotifier::tick(float dt) |
---|
[8498] | 165 | { |
---|
[8510] | 166 | std::list<DisplayLine>::iterator line; |
---|
| 167 | for (line = this->displayLines.begin() ; line != this->displayLines.end(); ++line ) |
---|
| 168 | { |
---|
| 169 | (*line).age+=dt; |
---|
[8619] | 170 | if ((*line).age > this->fadeAge()) |
---|
[8510] | 171 | { |
---|
[8619] | 172 | (*line).text->setBlending((hideAge() - (*line).age)/_transformAge); |
---|
| 173 | if ((*line).age > hideAge()) |
---|
[8510] | 174 | { |
---|
| 175 | std::list<DisplayLine>::iterator tmp = line; |
---|
| 176 | ++line; |
---|
| 177 | |
---|
[8513] | 178 | (*tmp).text->setVisibility(false); |
---|
[8510] | 179 | this->hiddenText.push((*tmp).text); |
---|
| 180 | this->displayLines.erase(tmp); |
---|
[8512] | 181 | |
---|
| 182 | if (!inputBuffer.empty()) |
---|
| 183 | { |
---|
| 184 | this->pushNotifyMessage(inputBuffer.back()); |
---|
| 185 | inputBuffer.pop_back(); |
---|
| 186 | } |
---|
[8510] | 187 | } |
---|
| 188 | } |
---|
| 189 | } |
---|
[8498] | 190 | } |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | /** |
---|
[8503] | 194 | * displays the GLGuiNotifier |
---|
[8498] | 195 | */ |
---|
[8503] | 196 | void GLGuiNotifier::draw() const |
---|
[8498] | 197 | { |
---|
| 198 | // transform for alignment. |
---|
| 199 | // setting the Blending effects |
---|
[8503] | 200 | this->beginDraw(); |
---|
[8498] | 201 | |
---|
[8619] | 202 | this->background().select(); |
---|
[8503] | 203 | this->drawRect(this->backRect()); |
---|
| 204 | this->endDraw(); |
---|
[8498] | 205 | } |
---|
| 206 | |
---|
| 207 | /////////////////////// |
---|
| 208 | // HELPER FUNCTIONS // |
---|
| 209 | /////////////////////// |
---|
| 210 | |
---|
| 211 | /** |
---|
| 212 | * @brief calculates the position of a Buffer-Display Line |
---|
| 213 | * @param lineNumber the lineNumber from the bottom to calculate the position from |
---|
| 214 | * @returns the Position of the Line. |
---|
| 215 | */ |
---|
[8503] | 216 | Vector2D GLGuiNotifier::calculateLinePosition(unsigned int lineNumber) |
---|
[8498] | 217 | { |
---|
[8619] | 218 | return Vector2D(0.0f, (float)(textSize() + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1)); |
---|
[8498] | 219 | } |
---|
| 220 | |
---|
| 221 | |
---|
[8509] | 222 | void GLGuiNotifier::resize() |
---|
| 223 | {} |
---|
[8498] | 224 | |
---|
| 225 | /** |
---|
[8503] | 226 | * @brief displays some nice output from the GLGuiNotifier |
---|
[8498] | 227 | */ |
---|
[8503] | 228 | void GLGuiNotifier::debug() const |
---|
[8498] | 229 | { |
---|
| 230 | PRINT(3)("Debugging output to console (not this shell)\n"); |
---|
| 231 | |
---|
| 232 | // if (this->pressedKey != SDLK_FIRST) |
---|
| 233 | // printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay); |
---|
| 234 | } |
---|
| 235 | } |
---|