Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/specials/glgui_notifier.cc @ 9744

Last change on this file since 9744 was 8619, checked in by bensch, 18 years ago

trunk: merged the gui-branche back.
merged with command:
svn merge -r8520:HEAD https://svn.orxonox.net/orxonox/branches/gui
no conflicts

File size: 6.0 KB
Line 
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
18#include "glgui_notifier.h"
19#include "multi_line_text.h"
20
21#include "debug.h"
22
23namespace OrxGui
24{
25
26  /**
27   * @brief standard constructor
28   */
29  GLGuiNotifier::GLGuiNotifier ()
30  {
31    this->setClassID(CL_GLGUI_NOTIFIER, "GLGuiNotifier");
32
33    // Element2D and generals
34    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 deconstructor
44   */
45  GLGuiNotifier::~GLGuiNotifier ()
46  {
47    // delete the displayable Buffers
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
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   */
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 it
75
76      // retrieve a Text.
77      dl.text = this->hiddenText.top();
78      this->hiddenText.pop();
79
80      // setup Text
81      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    else
91    {
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 Tick
163   */
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 GLGuiNotifier
195   */
196  void GLGuiNotifier::draw() const
197  {
198    // transform for alignment.
199    // setting the Blending effects
200    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 Line
213   * @param lineNumber the lineNumber from the bottom to calculate the position from
214   * @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 GLGuiNotifier
227   */
228  void GLGuiNotifier::debug() const
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}
Note: See TracBrowser for help on using the repository browser.