Changeset 8688 in orxonox.OLD for branches/gui/src/lib
- Timestamp:
- Jun 21, 2006, 10:33:24 PM (19 years ago)
- Location:
- branches/gui/src/lib/gui/gl
- Files:
-
- 1 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/gui/src/lib/gui/gl/Makefile.am
r8619 r8688 31 31 glgui_cursor.cc \ 32 32 \ 33 specials/glgui_notifier.cc 33 specials/glgui_notifier.cc \ 34 specials/glgui_imagebutton.cc 34 35 35 36 … … 58 59 glgui_cursor.h \ 59 60 \ 60 specials/glgui_notifier.h 61 62 63 64 61 specials/glgui_notifier.h \ 62 specials/glgui_imagebutton.h 65 63 66 64 EXTRA_DIST = 67 -
branches/gui/src/lib/gui/gl/specials/glgui_imagebutton.cc
r8686 r8688 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SHELL 17 17 18 #include "glgui_ notifier.h"18 #include "glgui_imagebutton.h" 19 19 #include "multi_line_text.h" 20 20 … … 24 24 { 25 25 26 /**27 * @brief standard constructor28 */29 GLGuiNotifier::GLGuiNotifier ()30 {31 this->setClassID(CL_GLGUI_NOTIFIER, "GLGuiNotifier");32 26 33 // Element2D and generals34 this->lineSpacing = 0;35 this->linesProcessed = 0;36 this->_fadeAge = 3.0;37 this->setHideAge(4.0);38 39 this->setDisplayLineCount(10);40 }41 42 /**43 * @brief standard deconstructor44 */45 GLGuiNotifier::~GLGuiNotifier ()46 {47 // delete the displayable Buffers48 /* 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 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 instantaniously66 * The possibility may arise, that the DisplayLines are all in use, then one67 * has to wait until a line gets hidden, until a new one can be pushed to be68 * displayed.69 */70 void GLGuiNotifier::pushNotifyMessage(const std::string& message)71 {72 if (!this->hiddenText.empty())73 {74 DisplayLine dl; // put everything in here, and then display it75 76 // retrieve a Text.77 dl.text = this->hiddenText.top();78 this->hiddenText.pop();79 80 // setup Text81 dl.text->setBlending(1.0f);82 dl.text->setText(message);83 dl.text->setVisibility(true);84 dl.text->setRelCoor2D(this->calculateLinePosition(0));85 86 dl.age = 0.0f;87 this->displayLines.push_front(dl);88 this->repositionText();89 }90 else91 {92 // push it onto the List of messages we still need.93 this->inputBuffer.push_front(message);94 }95 }96 97 98 /**99 * @brief sets the Dipsplay Line Count of the Notifier.100 * @param coun the count of displayLines.101 */102 void GLGuiNotifier::setDisplayLineCount(unsigned int count)103 {104 unsigned int currentCount = displayLines.size() + hiddenText.size();105 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 115 void GLGuiNotifier::setFadeAge(float fadeAge)116 {117 this->_fadeAge = fadeAge;118 this->_transformAge = hideAge() - this->fadeAge();119 }120 121 void GLGuiNotifier::setHideAge(float hideAge)122 {123 this->_hideAge = hideAge;124 this->_transformAge = this->hideAge() - fadeAge();125 }126 127 128 /**129 * @brief repositiones all the Texts to their position.130 */131 void GLGuiNotifier::repositionText()132 {133 int linePos = -1;134 std::list<DisplayLine>::iterator textIt;135 for (textIt = this->displayLines.begin() ; textIt != this->displayLines.end(); ++textIt )136 {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);140 }141 }142 143 144 /**145 * @brief applies the GLGuiNotifiers Settings to a single Text of the GLGuiNotifier.146 * @param text the Text to apply the settings to.147 */148 void GLGuiNotifier::applyTextSettings(MultiLineText* text)149 {150 text->setSize(this->textSize());151 text->setLineWidth( 300 );152 text->setFont("fonts/final_frontier.ttf", (int)this->textSize());153 154 text->setColor(this->foregroundColor() );155 if (text->getParent2D() != this)156 text->setParent2D(this);157 }158 159 160 /**161 * @brief ticks the entire Notifier.162 * @param dt the time passed since the last Tick163 */164 void GLGuiNotifier::tick(float dt)165 {166 std::list<DisplayLine>::iterator line;167 for (line = this->displayLines.begin() ; line != this->displayLines.end(); ++line )168 {169 (*line).age+=dt;170 if ((*line).age > this->fadeAge())171 {172 (*line).text->setBlending((hideAge() - (*line).age)/_transformAge);173 if ((*line).age > hideAge())174 {175 std::list<DisplayLine>::iterator tmp = line;176 ++line;177 178 (*tmp).text->setVisibility(false);179 this->hiddenText.push((*tmp).text);180 this->displayLines.erase(tmp);181 182 if (!inputBuffer.empty())183 {184 this->pushNotifyMessage(inputBuffer.back());185 inputBuffer.pop_back();186 }187 }188 }189 }190 }191 192 193 /**194 * displays the GLGuiNotifier195 */196 void GLGuiNotifier::draw() const197 {198 // transform for alignment.199 // setting the Blending effects200 this->beginDraw();201 202 this->background().select();203 this->drawRect(this->backRect());204 this->endDraw();205 }206 207 ///////////////////////208 // HELPER FUNCTIONS //209 ///////////////////////210 211 /**212 * @brief calculates the position of a Buffer-Display Line213 * @param lineNumber the lineNumber from the bottom to calculate the position from214 * @returns the Position of the Line.215 */216 Vector2D GLGuiNotifier::calculateLinePosition(unsigned int lineNumber)217 {218 return Vector2D(0.0f, (float)(textSize() + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1));219 }220 221 222 void GLGuiNotifier::resize()223 {}224 225 /**226 * @brief displays some nice output from the GLGuiNotifier227 */228 void GLGuiNotifier::debug() const229 {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 27 } -
branches/gui/src/lib/gui/gl/specials/glgui_imagebutton.h
r8686 r8688 7 7 */ 8 8 9 #ifndef _GLGUI_ NOTIFIER_H10 #define _GLGUI_ NOTIFIER_H9 #ifndef _GLGUI_IMAGEBUTTON_H 10 #define _GLGUI_IMAGEBUTTON_H 11 11 12 12 #include "glgui_widget.h" … … 15 15 #include <stack> 16 16 17 // FORWARD DECLARATION 18 class MultiLineText; 19 class Text; 20 21 //! Namespace of the GLGuiNotifier of ORXONOX. 17 //! Namespace of the GLGuiImageButton of ORXONOX. 22 18 namespace OrxGui 23 19 { 24 class GLGui Notifier: public GLGuiWidget20 class GLGuiImageButton : public GLGuiWidget 25 21 { 26 22 public: 27 GLGuiNotifier(); 28 virtual ~GLGuiNotifier(); 29 30 void pushNotifyMessage(const std::string& message); 31 32 /// Setup 33 void setDisplayLineCount(unsigned int count); 34 void setFadeAge(float fadeAge); 35 void setHideAge(float hideAge); 36 37 /** @returns the beginning of the Hiding process */ 38 inline float fadeAge() const { return _fadeAge; }; 39 /** @returns at what age elements should be fully hidden */ 40 inline float hideAge() const { return _hideAge; }; 41 42 void clear(); 43 44 // Element2D-functions 45 virtual void tick(float dt); 46 virtual void draw() const; 23 GLGuiImageButton(); 24 virtual ~GLGuiImageButton(); 47 25 48 26 void debug() const; … … 52 30 53 31 private: 54 void repositionText();55 void applyTextSettings(MultiLineText* text);56 void applySettings();57 // helpers //58 Vector2D calculateLinePosition(unsigned int lineNumber);59 60 61 32 62 33 private: 63 //! structure that defines a Displayed line.64 typedef struct65 {66 float age;67 MultiLineText* text;68 69 } DisplayLine;70 71 72 float _fadeAge;73 float _hideAge;74 float _transformAge;75 76 unsigned int lineSpacing; //!< The Spacing between lines.77 78 // BUFFER79 unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters).80 std::list<DisplayLine> displayLines; //!< A list of stored bufferTexts for the display of the buffer.81 82 std::stack<MultiLineText*> hiddenText; //!< Text that is not shown, and not used is thrown in here83 84 85 unsigned long linesProcessed; //!< How many Lines have been processed so far.86 std::list<std::string> inputBuffer; //!< The input buffer for lines that were not yet printet out, because there is too much input.87 34 88 35 }; … … 90 37 } 91 38 92 #endif /* _GLGUI_ NOTIFIER_H */39 #endif /* _GLGUI_IMAGEBUTTON_H */
Note: See TracChangeset
for help on using the changeset viewer.