aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/gui/gui_transitions.cpp
blob: 09e58e0e7117515a03239f63e04b6a1ff7d25d68 (plain)
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
/* 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.
 *
 * $URL$
 * $Id$
 *
 */

#include "common/util.h"
#include "common/stack.h"
#include "graphics/primitives.h"

#include "sci/sci.h"
#include "sci/engine/state.h"
#include "sci/gui/gui.h"
#include "sci/gui/gui_screen.h"
#include "sci/gui/gui_palette.h"
#include "sci/gui/gui_transitions.h"

namespace Sci {

SciGuiTransitions::SciGuiTransitions(SciGui *gui, SciGuiScreen *screen, SciGuiPalette *palette, bool isVGA)
	: _gui(gui), _screen(screen), _palette(palette), _isVGA(isVGA) {
	init();
}

SciGuiTransitions::~SciGuiTransitions() {
	delete[] _oldScreen;
}

// This table contains a mapping between oldIDs (prior SCI1LATE) and newIDs
static const GuiTransitionTranslateEntry oldTransitionIDs[] = {
	{   0, SCI_TRANSITIONS_VERTICALROLLFROMCENTER,		false },
	{   1, SCI_TRANSITIONS_HORIZONTALROLLFROMCENTER,	false },
	{   6, SCI_TRANSITIONS_DIAGONALROLLFROMCENTER,		false },
	{   7, SCI_TRANSITIONS_DIAGONALROLLTOCENTER,		false },
	{   8, SCI_TRANSITIONS_BLOCKS,						false },
	{   9, SCI_TRANSITIONS_VERTICALROLLTOCENTER,		false },
	{  10, SCI_TRANSITIONS_HORIZONTALROLLTOCENTER,		false },
	{  15, SCI_TRANSITIONS_DIAGONALROLLFROMCENTER,		true },
	{  16, SCI_TRANSITIONS_DIAGONALROLLTOCENTER,		true },
	{  17, SCI_TRANSITIONS_BLOCKS,						true },
	{  18, SCI_TRANSITIONS_PIXELATION,					false },
	{  27, SCI_TRANSITIONS_PIXELATION	,				true },
	{  30, SCI_TRANSITIONS_FADEPALETTE,					false },
	{  40, SCI_TRANSITIONS_SCROLLRIGHT,					false },
	{  41, SCI_TRANSITIONS_SCROLLLEFT,					false },
	{  42, SCI_TRANSITIONS_SCROLLUP,					false },
	{  43, SCI_TRANSITIONS_SCROLLDOWN,					false },
	{ 100, SCI_TRANSITIONS_NONE,						false },
	{ 255, 255,											false }
};

void SciGuiTransitions::init() {
	_oldScreen = new byte[_screen->_displayHeight * _screen->_displayWidth];

	if (getSciVersion() >= SCI_VERSION_1_LATE)
		_translationTable = NULL;
	else
		_translationTable = oldTransitionIDs;
}

void SciGuiTransitions::setup(int16 number, bool blackoutFlag) {
	_number = number;
	_blackoutFlag = blackoutFlag;
}

void SciGuiTransitions::doit(Common::Rect picRect) {
	const GuiTransitionTranslateEntry *translationEntry = _translationTable;

	_picRect = picRect;

	if (translationEntry) {
		// We need to translate the ID
		while (1) {
			if (translationEntry->oldId == 255) {
				warning("SciGuiTransitions: old ID %d not supported", _number);
				setNewPalette(); setNewScreen();
				_screen->_picNotValid = 0;
				return;
			}
			if (translationEntry->oldId == _number) {
				_number = translationEntry->realId;
				_blackoutFlag = translationEntry->blackoutFlag;
				break;
			}
			translationEntry++;
		}
	}

	if (_blackoutFlag)
		warning("SciGuiTransitions: blackout flag currently not supported");

	switch (_number) {
	case SCI_TRANSITIONS_VERTICALROLLFROMCENTER:
		setNewPalette(); verticalRollFromCenter();
		break;
	case SCI_TRANSITIONS_VERTICALROLLTOCENTER:
		setNewPalette(); verticalRollFromCenter();
		break;
	case SCI_TRANSITIONS_HORIZONTALROLLFROMCENTER:
		setNewPalette(); horizontalRollFromCenter();
		break;
	case SCI_TRANSITIONS_HORIZONTALROLLTOCENTER:
		setNewPalette(); horizontalRollToCenter();
		break;
	case SCI_TRANSITIONS_DIAGONALROLLTOCENTER:
		setNewPalette(); diagonalRollToCenter();
	case SCI_TRANSITIONS_DIAGONALROLLFROMCENTER:
		setNewPalette(); diagonalRollFromCenter();

	case SCI_TRANSITIONS_PIXELATION:
		setNewPalette(); pixelation();
		break;

	case SCI_TRANSITIONS_BLOCKS:
		setNewPalette(); blocks();
		break;

	case SCI_TRANSITIONS_FADEPALETTE:
		fadeOut(); setNewScreen(); fadeIn();
		break;

	case SCI_TRANSITIONS_SCROLLRIGHT:
	case SCI_TRANSITIONS_SCROLLLEFT:
	case SCI_TRANSITIONS_SCROLLUP:
	case SCI_TRANSITIONS_SCROLLDOWN:
		setNewPalette(); scroll();
		break;

	case SCI_TRANSITIONS_NONE_LONGBOW:
	case SCI_TRANSITIONS_NONE:
		setNewPalette(); setNewScreen();
		break;
	default:
		warning("SciGuiTransitions: ID %d not implemented", _number);
		setNewPalette(); setNewScreen();
	}

	_screen->_picNotValid = 0;
}

void SciGuiTransitions::setNewPalette() {
	if (_isVGA)
		_palette->setOnScreen();
}

void SciGuiTransitions::setNewScreen() {
	_screen->copyRectToScreen(_picRect);
	g_system->updateScreen();
}

// Note: dont do too many steps in here, otherwise cpu will crap out because of the load
void SciGuiTransitions::fadeOut() {
	byte oldPalette[4 * 256], workPalette[4 * 256];
	int16 stepNr, colorNr;

	g_system->grabPalette(oldPalette, 0, 256);

	for (stepNr = 100; stepNr >= 0; stepNr -= 10) {
		for (colorNr = 1; colorNr < 255; colorNr++){
			workPalette[colorNr * 4 + 0] = oldPalette[colorNr * 4] * stepNr / 100;
			workPalette[colorNr * 4 + 1] = oldPalette[colorNr * 4 + 1] * stepNr / 100;
			workPalette[colorNr * 4 + 2] = oldPalette[colorNr * 4 + 2] * stepNr / 100;
		}
		g_system->setPalette(workPalette + 4, 1, 254);
		_gui->wait(2);
	}
}

// Note: dont do too many steps in here, otherwise cpu will crap out because of the load
void SciGuiTransitions::fadeIn() {
	int16 stepNr;

	for (stepNr = 0; stepNr <= 100; stepNr += 10) {
		_palette->setIntensity(1, 254, 100, true);
		_gui->wait(2);
	}
}

// pixelates the new picture over the old one - works against the whole screen
void SciGuiTransitions::pixelation () {
	uint16 mask = 0x40, stepNr = 0;
	Common::Rect pixelRect;

	do {
		mask = (mask & 1) ? (mask >> 1) ^ 0xB400 : mask >> 1;
		if (mask >= 320 * 200)
			continue;
		pixelRect.left = mask % 320; pixelRect.right = pixelRect.left + 1;
		pixelRect.top = mask / 320;	pixelRect.bottom = pixelRect.top + 1;
		_screen->copyRectToScreen(pixelRect);
		if ((stepNr & 0x3FF) == 0) {
			g_system->updateScreen();
			g_system->delayMillis(5);
		}
		stepNr++;
	} while (mask != 0x40);
}

// like pixelation but uses 8x8 blocks - works against the whole screen
void SciGuiTransitions::blocks() {
	uint16 mask = 0x40, stepNr = 0;
	Common::Rect blockRect;

	do {
		mask = (mask & 1) ? (mask >> 1) ^ 0x240 : mask >> 1;
		if (mask >= 40 * 25)
			continue;
		blockRect.left = (mask % 40) << 3; blockRect.right = blockRect.left + 8;
		blockRect.top = (mask / 40) << 3; blockRect.bottom = blockRect.top + 8;
		_screen->copyRectToScreen(blockRect);
		if ((stepNr & 7) == 0) {
			g_system->updateScreen();
			g_system->delayMillis(4);
		}
		stepNr++;
	} while (mask != 0x40);
}

// scroll old screen (up/down/left/right) and insert new screen that way - works on _picRect area only
void SciGuiTransitions::scroll() {
	int16 screenWidth, screenHeight;
	byte *oldScreenPtr;
	int16 stepNr = 0;
	Common::Rect oldMoveRect = _picRect;
	Common::Rect newMoveRect = _picRect;
	Common::Rect newScreenRect = _picRect;

	_screen->copyFromScreen(_oldScreen);
	screenWidth = _screen->_displayWidth; screenHeight = _screen->_displayHeight;

	oldScreenPtr = _oldScreen + _picRect.left + _picRect.top * screenWidth;

	switch (_number) {
	case SCI_TRANSITIONS_SCROLLLEFT:
		newScreenRect.right = newScreenRect.left;
		newMoveRect.left = newMoveRect.right;
		while (oldMoveRect.left < oldMoveRect.right) {
			oldScreenPtr++; oldMoveRect.right--;
			if (oldMoveRect.right > oldMoveRect.left)
				g_system->copyRectToScreen(oldScreenPtr, screenWidth, oldMoveRect.left, oldMoveRect.top, oldMoveRect.width(), oldMoveRect.height());
			newScreenRect.right++; newMoveRect.left--;
			_screen->copyRectToScreen(newScreenRect, newMoveRect.left, newMoveRect.top);
			if ((stepNr & 1) == 0) {
				g_system->updateScreen();
				g_system->delayMillis(1);
			}
			stepNr++;
		}
		if ((stepNr & 1) == 0)
			g_system->updateScreen();
		break;

	case SCI_TRANSITIONS_SCROLLRIGHT:
		newScreenRect.left = newScreenRect.right;
		while (oldMoveRect.left < oldMoveRect.right) {
			oldMoveRect.left++;
			if (oldMoveRect.right > oldMoveRect.left)
				g_system->copyRectToScreen(oldScreenPtr, screenWidth, oldMoveRect.left, oldMoveRect.top, oldMoveRect.width(), oldMoveRect.height());
			newScreenRect.left--;
			_screen->copyRectToScreen(newScreenRect, newMoveRect.left, newMoveRect.top);
			if ((stepNr & 1) == 0) {
				g_system->updateScreen();
				g_system->delayMillis(1);
			}
			stepNr++;
		}
		if ((stepNr & 1) == 0)
			g_system->updateScreen();
		break;

	case SCI_TRANSITIONS_SCROLLUP:
		newScreenRect.bottom = newScreenRect.top;
		newMoveRect.top = newMoveRect.bottom;
		while (oldMoveRect.top < oldMoveRect.bottom) {
			oldScreenPtr += screenWidth; oldMoveRect.top++;
			if (oldMoveRect.top < oldMoveRect.bottom)
				g_system->copyRectToScreen(oldScreenPtr, screenWidth, _picRect.left, _picRect.top, oldMoveRect.width(), oldMoveRect.height());
			newScreenRect.bottom++;	newMoveRect.top--;
			_screen->copyRectToScreen(newScreenRect, newMoveRect.left, newMoveRect.top);
			g_system->updateScreen();
			g_system->delayMillis(3);
		}
		break;

	case SCI_TRANSITIONS_SCROLLDOWN:
		newScreenRect.top = newScreenRect.bottom;
		while (oldMoveRect.top < oldMoveRect.bottom) {
			oldMoveRect.top++;
			if (oldMoveRect.top < oldMoveRect.bottom)
				g_system->copyRectToScreen(oldScreenPtr, screenWidth, oldMoveRect.left, oldMoveRect.top, oldMoveRect.width(), oldMoveRect.height());
			newScreenRect.top--;
			_screen->copyRectToScreen(newScreenRect, _picRect.left, _picRect.top);
			g_system->updateScreen();
			g_system->delayMillis(3);
		}
		break;
	}
}

// vertically displays new screen starting from center - works on _picRect area only
void SciGuiTransitions::verticalRollFromCenter() {
	Common::Rect leftRect = Common::Rect(_picRect.left + (_picRect.width() / 2) -1, _picRect.top, _picRect.left + (_picRect.width() / 2), _picRect.bottom);
	Common::Rect rightRect = Common::Rect(leftRect.right, _picRect.top, leftRect.right + 1, _picRect.bottom);

	while ((leftRect.left >= _picRect.left) || (rightRect.right <= _picRect.right)) {
		if (leftRect.left < _picRect.left)
			leftRect.translate(1, 0);
		if (rightRect.right > _picRect.right)
			rightRect.translate(-1, 0);
		_screen->copyRectToScreen(leftRect); leftRect.translate(-1, 0);
		_screen->copyRectToScreen(rightRect); rightRect.translate(1, 0);
		g_system->updateScreen();
		g_system->delayMillis(2);
	}
}

// vertically displays new screen starting from edges - works on _picRect area only
void SciGuiTransitions::verticalRollToCenter() {
	Common::Rect leftRect = Common::Rect(_picRect.left, _picRect.top, _picRect.left + 1, _picRect.bottom);
	Common::Rect rightRect = Common::Rect(leftRect.right - 1, _picRect.top, leftRect.right, _picRect.bottom);

	while (leftRect.left < rightRect.right) {
		_screen->copyRectToScreen(leftRect); leftRect.translate(1, 0);
		_screen->copyRectToScreen(rightRect); rightRect.translate(-1, 0);
		g_system->updateScreen();
		g_system->delayMillis(2);
	}
}

// horizontally displays new screen starting from center - works on _picRect area only
void SciGuiTransitions::horizontalRollFromCenter() {
	Common::Rect upperRect = Common::Rect(_picRect.left, _picRect.top + (_picRect.height() / 2) - 1, _picRect.right, _picRect.top + (_picRect.height() / 2));
	Common::Rect lowerRect = Common::Rect(upperRect.left, upperRect.bottom, upperRect.right, upperRect.bottom + 1);

	while ((upperRect.top >= _picRect.top) || (lowerRect.bottom <= _picRect.bottom)) {
		if (upperRect.top < _picRect.top)
			upperRect.translate(0, 1);
		if (lowerRect.bottom > _picRect.bottom)
			lowerRect.translate(0, -1);
		_screen->copyRectToScreen(upperRect); upperRect.translate(0, -1);
		_screen->copyRectToScreen(lowerRect); lowerRect.translate(0, 1);
		g_system->updateScreen();
		g_system->delayMillis(3);
	}
}

// horizontally displays new screen starting from upper and lower edge - works on _picRect area only
void SciGuiTransitions::horizontalRollToCenter() {
	Common::Rect upperRect = Common::Rect(_picRect.left, _picRect.top, _picRect.right, _picRect.top + 1);
	Common::Rect lowerRect = Common::Rect(upperRect.left, _picRect.bottom - 1, upperRect.right, _picRect.bottom);

	while (upperRect.top < lowerRect.bottom) {
		_screen->copyRectToScreen(upperRect); upperRect.translate(0, 1);
		_screen->copyRectToScreen(lowerRect); lowerRect.translate(0, -1);
		g_system->updateScreen();
		g_system->delayMillis(3);
	}
}

// diagonally displays new screen starting from center - works on _picRect area only
//  assumes that height of rect is larger than width, is also currently not optimized (TODO)
void SciGuiTransitions::diagonalRollFromCenter() {
	int16 halfHeight = _picRect.height() / 2;
	Common::Rect upperRect(_picRect.left + halfHeight - 2, _picRect.top + halfHeight, _picRect.right - halfHeight + 1, _picRect.top + halfHeight + 1);
	Common::Rect lowerRect(upperRect.left, upperRect.top, upperRect.right, upperRect.bottom);
	Common::Rect leftRect(upperRect.left, upperRect.top, upperRect.left + 1, lowerRect.bottom);
	Common::Rect rightRect(upperRect.right, upperRect.top, upperRect.right + 1, lowerRect.bottom);

	while ((upperRect.top >= _picRect.top) || (lowerRect.bottom <= _picRect.bottom)) {
		if (upperRect.top < _picRect.top) {
			upperRect.translate(0, 1); leftRect.top++; rightRect.top++;
		}
		if (lowerRect.bottom > _picRect.bottom) {
			lowerRect.translate(0, -1); leftRect.bottom--; rightRect.bottom--;
		}
		if (leftRect.left < _picRect.left) {
			leftRect.translate(1, 0); upperRect.left++; lowerRect.left++;
		}
		if (rightRect.right > _picRect.right) {
			rightRect.translate(-1, 0); upperRect.right--; lowerRect.right--;
		}
		_screen->copyRectToScreen(upperRect); upperRect.translate(0, -1); upperRect.left--; upperRect.right++;
		_screen->copyRectToScreen(lowerRect); lowerRect.translate(0, 1); lowerRect.left--; lowerRect.right++;
		_screen->copyRectToScreen(leftRect); leftRect.translate(-1, 0);	leftRect.top--; leftRect.bottom++;
		_screen->copyRectToScreen(rightRect); rightRect.translate(1, 0); rightRect.top--; rightRect.bottom++;
		g_system->updateScreen();
		g_system->delayMillis(3);
	}
}

// diagonally displays new screen starting from edges - works on _picRect area only
//  assumes that height of rect is larger than width
void SciGuiTransitions::diagonalRollToCenter() {
	Common::Rect upperRect(_picRect.left, _picRect.top, _picRect.right, _picRect.top + 1);
	Common::Rect lowerRect(_picRect.left, _picRect.bottom - 1, _picRect.right, _picRect.bottom);
	Common::Rect leftRect(_picRect.left, _picRect.top, _picRect.left + 1, _picRect.bottom);
	Common::Rect rightRect(_picRect.right - 1, _picRect.top, _picRect.right, _picRect.bottom);

	while (upperRect.top < lowerRect.bottom) {
		_screen->copyRectToScreen(upperRect); upperRect.translate(0, 1); upperRect.left++; upperRect.right--;
		_screen->copyRectToScreen(lowerRect); lowerRect.translate(0, -1); lowerRect.left++; lowerRect.right--;
		_screen->copyRectToScreen(leftRect); leftRect.translate(1, 0);
		_screen->copyRectToScreen(rightRect); rightRect.translate(-1, 0);
		g_system->updateScreen();
		g_system->delayMillis(3);
	}
}

} // End of namespace Sci