1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#include "CGUIInOutFader.h"
6
#ifdef _IRR_COMPILE_WITH_GUI_
8
#include "IGUIEnvironment.h"
9
#include "IVideoDriver.h"
19
CGUIInOutFader::CGUIInOutFader(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
20
: IGUIInOutFader(environment, parent, id, rectangle)
23
setDebugName("CGUIInOutFader");
30
setColor(video::SColor(0,0,0,0));
34
//! draws the element and its children
35
void CGUIInOutFader::draw()
37
if (!IsVisible || !Action)
40
u32 now = os::Timer::getTime();
41
if (now > EndTime && Action == EFA_FADE_IN)
47
video::IVideoDriver* driver = Environment->getVideoDriver();
56
d = (EndTime - now) / (f32)(EndTime - StartTime);
58
video::SColor newCol = FullColor.getInterpolated(TransColor, d);
59
driver->draw2DRectangle(newCol, AbsoluteRect, &AbsoluteClippingRect);
66
//! Gets the color to fade out to or to fade in from.
67
video::SColor CGUIInOutFader::getColor() const
73
//! Sets the color to fade out to or to fade in from.
74
void CGUIInOutFader::setColor(video::SColor color)
76
video::SColor s = color;
77
video::SColor d = color;
87
TransColor = Color[0];
89
if (Action == EFA_FADE_OUT)
91
FullColor.setAlpha(0);
92
TransColor.setAlpha(255);
95
if (Action == EFA_FADE_IN)
97
FullColor.setAlpha(255);
98
TransColor.setAlpha(0);
104
void CGUIInOutFader::setColor(video::SColor source, video::SColor dest)
109
if (Action == EFA_FADE_OUT)
111
FullColor = Color[1];
112
TransColor = Color[0];
115
if (Action == EFA_FADE_IN)
117
FullColor = Color[0];
118
TransColor = Color[1];
124
//! Returns if the fade in or out process is done.
125
bool CGUIInOutFader::isReady() const
127
u32 now = os::Timer::getTime();
128
bool ret = (now > EndTime);
129
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
134
//! Starts the fade in process.
135
void CGUIInOutFader::fadeIn(u32 time)
137
StartTime = os::Timer::getTime();
138
EndTime = StartTime + time;
139
Action = EFA_FADE_IN;
140
setColor(Color[0],Color[1]);
144
//! Starts the fade out process.
145
void CGUIInOutFader::fadeOut(u32 time)
147
StartTime = os::Timer::getTime();
148
EndTime = StartTime + time;
149
Action = EFA_FADE_OUT;
150
setColor(Color[0],Color[1]);
154
//! Writes attributes of the element.
155
void CGUIInOutFader::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
157
IGUIInOutFader::serializeAttributes(out,options);
159
out->addColor ("FullColor", FullColor);
160
out->addColor ("TransColor", TransColor);
165
//! Reads attributes of the element
166
void CGUIInOutFader::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
168
IGUIInOutFader::deserializeAttributes(in,options);
170
FullColor = in->getAttributeAsColor("FullColor");
171
TransColor = in->getAttributeAsColor("TransColor");
175
} // end namespace gui
176
} // end namespace irr
178
#endif // _IRR_COMPILE_WITH_GUI_