Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/gui/gl/specials/glgui_notifier.cc @ 8510

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

gui: notifier: yeah. fading works

File size: 4.7 KB
RevLine 
[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]23namespace OrxGui
[8498]24{
25
26  /**
27   * standard constructor
28   */
[8503]29  GLGuiNotifier::GLGuiNotifier ()
[8498]30  {
[8503]31    this->setClassID(CL_GLGUI_NOTIFIER, "GLGuiNotifier");
[8498]32
33    // Element2D and generals
34    this->lineSpacing = 0;
[8509]35    this->linesProcessed = 0;
[8498]36
[8509]37    this->setDisplayLineCount(10);
[8498]38  }
39
40  /**
41   * @brief standard deconstructor
42   */
[8503]43  GLGuiNotifier::~GLGuiNotifier ()
[8498]44  {
45    // delete the displayable Buffers
[8509]46    /*    while (!this->displayLines.empty())
47        {
48          delete this->displayLines.front().text;
49          this->displayLines.pop_front();
50        }
51
52        while (!this->hiddenText.empty())
53        {
54          delete this->hiddenText.top();
55          this->hiddenText.pop();
56        }*/
57  }
58
59  void GLGuiNotifier::pushNotifyMessage(const std::string& message)
60  {
61    if (!this->hiddenText.empty())
[8498]62    {
[8509]63      printf("%s\n", message.c_str());
64      DisplayLine dl;
65      dl.text = this->hiddenText.top();
66
[8510]67      dl.text->setBlending(1.0f);
[8509]68      dl.text->setText(message);
69      this->hiddenText.pop();
70      dl.age = 0.0f;
71      this->displayLines.push_back(dl);
72
73      this->repositionText();
[8498]74    }
[8509]75    else
76    {
77      printf("grumble... must be fixed\n");
78    }
[8498]79  }
80
81
[8509]82  void GLGuiNotifier::setDisplayLineCount(unsigned int count)
83  {
84    unsigned int currentCount = displayLines.size() + hiddenText.size();
[8498]85
[8509]86    for (unsigned int i = currentCount; i < count; ++i)
87    {
88      MultiLineText* text = new MultiLineText();
89      this->applyTextSettings(text);
90      this->hiddenText.push(text);
91    }
92    bufferDisplaySize = count;
93  }
94
95
[8498]96  /**
97   * @brief repositiones all the Texts to their position.
98   */
[8503]99  void GLGuiNotifier::repositionText()
[8498]100  {
101    int linePos = -1;
[8509]102    std::list<DisplayLine>::iterator textIt;
103    for (textIt = this->displayLines.begin() ; textIt != this->displayLines.end(); ++textIt )
[8498]104    {
[8509]105      linePos += (*textIt).text->getLineCount();
106      (*textIt).text->setRelCoorSoft2D(this->calculateLinePosition(linePos), 8);
107      //      printf("%f %f\n", (*textIt).text->getAbsCoor2D().x, (*textIt).text->getAbsCoor2D().y);
[8498]108    }
109  }
110
111
112  /**
[8503]113   * @brief applies the GLGuiNotifiers Settings to a single Text of the GLGuiNotifier.
[8498]114   * @param text the Text to apply the settings to.
115   */
[8509]116  void GLGuiNotifier::applyTextSettings(MultiLineText* text)
[8498]117  {
[8509]118    text->setSize(this->style().textSize());
119    text->setLineWidth( 300 );
120    //text->setFont(this->fontFile, this->textSize);
121
122    //text->setColor( Color(1,1,1,1)/*this->style().foregroundColor() */);
[8498]123    if (text->getParent2D() != this)
[8509]124      text->setParent2D(this);
[8498]125  }
126
127
[8503]128  void GLGuiNotifier::tick(float dt)
[8498]129  {
[8510]130    std::list<DisplayLine>::iterator line;
131    for (line = this->displayLines.begin() ; line != this->displayLines.end(); ++line )
132    {
133      (*line).age+=dt;
134      if ((*line).age > 3.0f)
135      {
136        (*line).text->setBlending(4.0 - (*line).age);
137        if ((*line).age > 4.0f)
138        {
139          std::list<DisplayLine>::iterator tmp = line;
140          ++line;
141
142          this->hiddenText.push((*tmp).text);
143          this->displayLines.erase(tmp);
144        }
145      }
146    }
[8498]147  }
148
149
150  /**
[8503]151   * displays the GLGuiNotifier
[8498]152   */
[8503]153  void GLGuiNotifier::draw() const
[8498]154  {
155    // transform for alignment.
156    // setting the Blending effects
[8503]157    this->beginDraw();
[8498]158
[8503]159    this->backMaterial().select();
160    this->drawRect(this->backRect());
161    this->endDraw();
[8498]162  }
163
164  ///////////////////////
165  // HELPER FUNCTIONS  //
166  ///////////////////////
167
168  /**
169   * @brief calculates the position of a Buffer-Display Line
170   * @param lineNumber the lineNumber from the bottom to calculate the position from
171   * @returns the Position of the Line.
172   */
[8503]173  Vector2D GLGuiNotifier::calculateLinePosition(unsigned int lineNumber)
[8498]174  {
[8509]175    return Vector2D(0.0f, (float)(this->style().textSize() + this->lineSpacing)*(float)((int)this->bufferDisplaySize - (int)lineNumber - (int)1));
[8498]176  }
177
178
[8509]179  void GLGuiNotifier::resize()
180  {}
[8498]181
182  /**
[8503]183   * @brief displays some nice output from the GLGuiNotifier
[8498]184   */
[8503]185  void GLGuiNotifier::debug() const
[8498]186  {
187    PRINT(3)("Debugging output to console (not this shell)\n");
188
189    //   if (this->pressedKey != SDLK_FIRST)
190    //     printf("%s::%f %f\n", SDLKToKeyname(this->pressedKey), this->delayed, this->repeatDelay);
191  }
192}
Note: See TracBrowser for help on using the repository browser.