Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/sfxThilo/src/modules/overlays/FadeoutText.cc @ 10107

Last change on this file since 10107 was 9667, checked in by landauf, 11 years ago

merged core6 back to trunk

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "FadeoutText.h"
30
31#include <OgreTextAreaOverlayElement.h>
32#include "util/Math.h"
33#include "core/CoreIncludes.h"
34#include "core/XMLPort.h"
35
36namespace orxonox
37{
38    RegisterClass(FadeoutText);
39
40    FadeoutText::FadeoutText(Context* context) : OverlayText(context)
41    {
42        RegisterObject(FadeoutText);
43
44        this->delay_ = 3.0f;
45        this->fadeouttime_ = 1.0f;
46
47        this->bFadingOut_ = false;
48        this->fadeouttimer_.setTimer(3.0f, false, createExecutor(createFunctor(&FadeoutText::fadeout, this)));
49        this->fadeouttimer_.stopTimer();
50
51        this->initialAlpha_ = 1.0f;
52    }
53
54    void FadeoutText::XMLPort(Element& xmlelement, XMLPort::Mode mode)
55    {
56        SUPER(FadeoutText, XMLPort, xmlelement, mode);
57
58        XMLPortParam(FadeoutText, "delay", setDelay, getDelay, xmlelement, mode);
59        XMLPortParam(FadeoutText, "fadeout", setFadeouttime, getFadeouttime, xmlelement, mode);
60    }
61
62    void FadeoutText::tick(float dt)
63    {
64        if (this->bFadingOut_)
65        {
66            ColourValue colour = this->getColour();
67
68            if (colour.a > 0)
69            {
70                float alpha = colour.a;
71
72                alpha -= dt / this->fadeouttime_;
73                if (alpha < 0)
74                    alpha = 0;
75                colour.a = alpha;
76
77                this->text_->setColour(colour);
78            }
79            else
80            {
81                this->text_->setCaption("");
82                this->reset();
83            }
84        }
85    }
86
87    void FadeoutText::fadeout()
88    {
89        this->bFadingOut_ = true;
90    }
91
92    void FadeoutText::reset()
93    {
94        this->bFadingOut_ = false;
95
96        ColourValue colour = this->getColour();
97        colour.a = this->initialAlpha_;
98        this->text_->setColour(colour);
99    }
100
101    void FadeoutText::changedColour()
102    {
103        OverlayText::changedColour();
104
105        this->initialAlpha_ = this->getColour().a;
106    }
107
108    void FadeoutText::changedCaption()
109    {
110        OverlayText::changedCaption();
111
112        this->reset();
113        this->fadeouttimer_.setInterval(this->delay_);
114        this->fadeouttimer_.startTimer();
115    }
116}
Note: See TracBrowser for help on using the repository browser.