diff options
Diffstat (limited to 'libraries/irrlicht-1.8.1/source/Irrlicht/CGUIInOutFader.cpp')
-rw-r--r-- | libraries/irrlicht-1.8.1/source/Irrlicht/CGUIInOutFader.cpp | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/source/Irrlicht/CGUIInOutFader.cpp b/libraries/irrlicht-1.8.1/source/Irrlicht/CGUIInOutFader.cpp new file mode 100644 index 0000000..3f63662 --- /dev/null +++ b/libraries/irrlicht-1.8.1/source/Irrlicht/CGUIInOutFader.cpp | |||
@@ -0,0 +1,179 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | ||
2 | // This file is part of the "Irrlicht Engine". | ||
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | ||
4 | |||
5 | #include "CGUIInOutFader.h" | ||
6 | #ifdef _IRR_COMPILE_WITH_GUI_ | ||
7 | |||
8 | #include "IGUIEnvironment.h" | ||
9 | #include "IVideoDriver.h" | ||
10 | #include "os.h" | ||
11 | |||
12 | namespace irr | ||
13 | { | ||
14 | namespace gui | ||
15 | { | ||
16 | |||
17 | |||
18 | //! constructor | ||
19 | CGUIInOutFader::CGUIInOutFader(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle) | ||
20 | : IGUIInOutFader(environment, parent, id, rectangle) | ||
21 | { | ||
22 | #ifdef _DEBUG | ||
23 | setDebugName("CGUIInOutFader"); | ||
24 | #endif | ||
25 | |||
26 | Action = EFA_NOTHING; | ||
27 | StartTime = 0; | ||
28 | EndTime = 0; | ||
29 | |||
30 | setColor(video::SColor(0,0,0,0)); | ||
31 | } | ||
32 | |||
33 | |||
34 | //! draws the element and its children | ||
35 | void CGUIInOutFader::draw() | ||
36 | { | ||
37 | if (!IsVisible || !Action) | ||
38 | return; | ||
39 | |||
40 | u32 now = os::Timer::getTime(); | ||
41 | if (now > EndTime && Action == EFA_FADE_IN) | ||
42 | { | ||
43 | Action = EFA_NOTHING; | ||
44 | return; | ||
45 | } | ||
46 | |||
47 | video::IVideoDriver* driver = Environment->getVideoDriver(); | ||
48 | |||
49 | if (driver) | ||
50 | { | ||
51 | f32 d; | ||
52 | |||
53 | if (now > EndTime) | ||
54 | d = 0.0f; | ||
55 | else | ||
56 | d = (EndTime - now) / (f32)(EndTime - StartTime); | ||
57 | |||
58 | video::SColor newCol = FullColor.getInterpolated(TransColor, d); | ||
59 | driver->draw2DRectangle(newCol, AbsoluteRect, &AbsoluteClippingRect); | ||
60 | } | ||
61 | |||
62 | IGUIElement::draw(); | ||
63 | } | ||
64 | |||
65 | |||
66 | //! Gets the color to fade out to or to fade in from. | ||
67 | video::SColor CGUIInOutFader::getColor() const | ||
68 | { | ||
69 | return Color[1]; | ||
70 | } | ||
71 | |||
72 | |||
73 | //! Sets the color to fade out to or to fade in from. | ||
74 | void CGUIInOutFader::setColor(video::SColor color) | ||
75 | { | ||
76 | video::SColor s = color; | ||
77 | video::SColor d = color; | ||
78 | |||
79 | s.setAlpha ( 255 ); | ||
80 | d.setAlpha ( 0 ); | ||
81 | setColor ( s,d ); | ||
82 | |||
83 | /* | ||
84 | Color[0] = color; | ||
85 | |||
86 | FullColor = Color[0]; | ||
87 | TransColor = Color[0]; | ||
88 | |||
89 | if (Action == EFA_FADE_OUT) | ||
90 | { | ||
91 | FullColor.setAlpha(0); | ||
92 | TransColor.setAlpha(255); | ||
93 | } | ||
94 | else | ||
95 | if (Action == EFA_FADE_IN) | ||
96 | { | ||
97 | FullColor.setAlpha(255); | ||
98 | TransColor.setAlpha(0); | ||
99 | } | ||
100 | */ | ||
101 | } | ||
102 | |||
103 | |||
104 | void CGUIInOutFader::setColor(video::SColor source, video::SColor dest) | ||
105 | { | ||
106 | Color[0] = source; | ||
107 | Color[1] = dest; | ||
108 | |||
109 | if (Action == EFA_FADE_OUT) | ||
110 | { | ||
111 | FullColor = Color[1]; | ||
112 | TransColor = Color[0]; | ||
113 | } | ||
114 | else | ||
115 | if (Action == EFA_FADE_IN) | ||
116 | { | ||
117 | FullColor = Color[0]; | ||
118 | TransColor = Color[1]; | ||
119 | } | ||
120 | |||
121 | } | ||
122 | |||
123 | |||
124 | //! Returns if the fade in or out process is done. | ||
125 | bool CGUIInOutFader::isReady() const | ||
126 | { | ||
127 | u32 now = os::Timer::getTime(); | ||
128 | bool ret = (now > EndTime); | ||
129 | _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; | ||
130 | return ret; | ||
131 | } | ||
132 | |||
133 | |||
134 | //! Starts the fade in process. | ||
135 | void CGUIInOutFader::fadeIn(u32 time) | ||
136 | { | ||
137 | StartTime = os::Timer::getTime(); | ||
138 | EndTime = StartTime + time; | ||
139 | Action = EFA_FADE_IN; | ||
140 | setColor(Color[0],Color[1]); | ||
141 | } | ||
142 | |||
143 | |||
144 | //! Starts the fade out process. | ||
145 | void CGUIInOutFader::fadeOut(u32 time) | ||
146 | { | ||
147 | StartTime = os::Timer::getTime(); | ||
148 | EndTime = StartTime + time; | ||
149 | Action = EFA_FADE_OUT; | ||
150 | setColor(Color[0],Color[1]); | ||
151 | } | ||
152 | |||
153 | |||
154 | //! Writes attributes of the element. | ||
155 | void CGUIInOutFader::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const | ||
156 | { | ||
157 | IGUIInOutFader::serializeAttributes(out,options); | ||
158 | |||
159 | out->addColor ("FullColor", FullColor); | ||
160 | out->addColor ("TransColor", TransColor); | ||
161 | |||
162 | } | ||
163 | |||
164 | |||
165 | //! Reads attributes of the element | ||
166 | void CGUIInOutFader::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) | ||
167 | { | ||
168 | IGUIInOutFader::deserializeAttributes(in,options); | ||
169 | |||
170 | FullColor = in->getAttributeAsColor("FullColor"); | ||
171 | TransColor = in->getAttributeAsColor("TransColor"); | ||
172 | } | ||
173 | |||
174 | |||
175 | } // end namespace gui | ||
176 | } // end namespace irr | ||
177 | |||
178 | #endif // _IRR_COMPILE_WITH_GUI_ | ||
179 | |||