1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/*
* This file is based on WME Lite.
* http://dead-code.org/redir.php?target=wmelite
* Copyright (c) 2011 Jan Nedoma
*/
#include "engines/wintermute/base/base_fader.h"
#include "engines/wintermute/base/base_game.h"
#include "engines/wintermute/base/gfx/base_renderer.h"
#include "common/util.h"
namespace Wintermute {
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_PERSISTENT(BaseFader, false)
//////////////////////////////////////////////////////////////////////////
BaseFader::BaseFader(BaseGame *inGame) : BaseObject(inGame) {
_active = false;
_red = _green = _blue = 0;
_currentAlpha = 0x00;
_sourceAlpha = 0;
_targetAlpha = 0;
_duration = 1000;
_startTime = 0;
_system = false;
}
//////////////////////////////////////////////////////////////////////////
BaseFader::~BaseFader() {
}
//////////////////////////////////////////////////////////////////////////
bool BaseFader::update() {
if (!_active) {
return STATUS_OK;
}
int alphaDelta = _targetAlpha - _sourceAlpha;
uint32 time;
if (_system) {
time = g_system->getMillis() - _startTime;
} else {
time = _gameRef->_timer - _startTime;
}
if (time >= _duration) {
_currentAlpha = _targetAlpha;
} else {
_currentAlpha = (byte)(_sourceAlpha + (float)time / (float)_duration * alphaDelta);
}
_currentAlpha = MIN((unsigned char)255, MAX(_currentAlpha, (byte)0)); // TODO: clean
_ready = time >= _duration;
if (_ready && _currentAlpha == 0x00) {
_active = false;
}
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool BaseFader::display() {
if (!_active) {
return STATUS_OK;
}
if (_currentAlpha > 0x00) {
_gameRef->_renderer->fadeToColor(_red, _green, _blue, _currentAlpha);
}
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool BaseFader::deactivate() {
_active = false;
_ready = true;
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool BaseFader::fadeIn(uint32 sourceColor, uint32 duration, bool system) {
_ready = false;
_active = true;
_red = RGBCOLGetR(sourceColor);
_green = RGBCOLGetG(sourceColor);
_blue = RGBCOLGetB(sourceColor);
_sourceAlpha = RGBCOLGetA(sourceColor);
_targetAlpha = 0;
_duration = duration;
_system = system;
if (_system) {
_startTime = g_system->getMillis();
} else {
_startTime = _gameRef->_timer;
}
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool BaseFader::fadeOut(uint32 targetColor, uint32 duration, bool system) {
_ready = false;
_active = true;
_red = RGBCOLGetR(targetColor);
_green = RGBCOLGetG(targetColor);
_blue = RGBCOLGetB(targetColor);
//_sourceAlpha = 0;
_sourceAlpha = _currentAlpha;
_targetAlpha = RGBCOLGetA(targetColor);
_duration = duration;
_system = system;
if (_system) {
_startTime = g_system->getMillis();
} else {
_startTime = _gameRef->_timer;
}
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
uint32 BaseFader::getCurrentColor() {
return BYTETORGBA(_red, _green, _blue, _currentAlpha);
}
//////////////////////////////////////////////////////////////////////////
bool BaseFader::persist(BasePersistenceManager *persistMgr) {
BaseObject::persist(persistMgr);
persistMgr->transfer(TMEMBER(_active));
persistMgr->transfer(TMEMBER(_blue));
persistMgr->transfer(TMEMBER(_currentAlpha));
persistMgr->transfer(TMEMBER(_duration));
persistMgr->transfer(TMEMBER(_green));
persistMgr->transfer(TMEMBER(_red));
persistMgr->transfer(TMEMBER(_sourceAlpha));
persistMgr->transfer(TMEMBER(_startTime));
persistMgr->transfer(TMEMBER(_targetAlpha));
persistMgr->transfer(TMEMBER(_system));
if (_system && !persistMgr->getIsSaving()) {
_startTime = 0;
}
return STATUS_OK;
}
} // end of namespace Wintermute
|