Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/overlays/FadeoutText.cc @ 12398

Last change on this file since 12398 was 11795, checked in by landauf, 7 years ago

merged ogre1.9 (including cegui0.8) into new branch

  • Property svn:eol-style set to native
File size: 3.1 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#if OGRE_VERSION >= 0x010900
32#   include <Overlay/OgreTextAreaOverlayElement.h>
33#else
34#   include <OgreTextAreaOverlayElement.h>
35#endif
36#include "util/Math.h"
37#include "core/CoreIncludes.h"
38#include "core/XMLPort.h"
39
40namespace orxonox
41{
42    RegisterClass(FadeoutText);
43
44    FadeoutText::FadeoutText(Context* context) : OverlayText(context)
45    {
46        RegisterObject(FadeoutText);
47
48        this->delay_ = 3.0f;
49        this->fadeouttime_ = 1.0f;
50
51        this->bFadingOut_ = false;
52        this->fadeouttimer_.setTimer(3.0f, false, createExecutor(createFunctor(&FadeoutText::fadeout, this)));
53        this->fadeouttimer_.stopTimer();
54
55        this->initialAlpha_ = 1.0f;
56    }
57
58    void FadeoutText::XMLPort(Element& xmlelement, XMLPort::Mode mode)
59    {
60        SUPER(FadeoutText, XMLPort, xmlelement, mode);
61
62        XMLPortParam(FadeoutText, "delay", setDelay, getDelay, xmlelement, mode);
63        XMLPortParam(FadeoutText, "fadeout", setFadeouttime, getFadeouttime, xmlelement, mode);
64    }
65
66    void FadeoutText::tick(float dt)
67    {
68        if (this->bFadingOut_)
69        {
70            ColourValue colour = this->getColour();
71
72            if (colour.a > 0)
73            {
74                float alpha = colour.a;
75
76                alpha -= dt / this->fadeouttime_;
77                if (alpha < 0)
78                    alpha = 0;
79                colour.a = alpha;
80
81                this->text_->setColour(colour);
82            }
83            else
84            {
85                this->text_->setCaption("");
86                this->reset();
87            }
88        }
89    }
90
91    void FadeoutText::fadeout()
92    {
93        this->bFadingOut_ = true;
94    }
95
96    void FadeoutText::reset()
97    {
98        this->bFadingOut_ = false;
99
100        ColourValue colour = this->getColour();
101        colour.a = this->initialAlpha_;
102        this->text_->setColour(colour);
103    }
104
105    void FadeoutText::changedColour()
106    {
107        OverlayText::changedColour();
108
109        this->initialAlpha_ = this->getColour().a;
110    }
111
112    void FadeoutText::changedCaption()
113    {
114        OverlayText::changedCaption();
115
116        this->reset();
117        this->fadeouttimer_.setInterval(this->delay_);
118        this->fadeouttimer_.startTimer();
119    }
120}
Note: See TracBrowser for help on using the repository browser.