2005-04-05 18:08:02 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2004 Ivan Dubrov
|
|
|
|
* Copyright (C) 2004-2005 The ScummVM project
|
|
|
|
*
|
|
|
|
* 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
|
2005-04-09 19:19:54 +00:00
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-04-05 18:08:02 +00:00
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
2005-04-05 15:07:40 +00:00
|
|
|
#include "gob/gob.h"
|
|
|
|
#include "gob/video.h"
|
|
|
|
#include "gob/util.h"
|
|
|
|
#include "gob/global.h"
|
|
|
|
#include "gob/palanim.h"
|
|
|
|
|
|
|
|
namespace Gob {
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
PalAnim::PalAnim(GobEngine *vm) : _vm(vm) {
|
|
|
|
fadeValue = 1;
|
|
|
|
for (int i = 0; i < 256; i++) {
|
|
|
|
toFadeRed[i] = 0;
|
|
|
|
toFadeGreen[i] = 0;
|
|
|
|
toFadeBlue[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
char PalAnim::fadeColor(char from, char to) {
|
|
|
|
if ((int16)from - fadeValue > (int16)to)
|
|
|
|
return from - fadeValue;
|
|
|
|
else if ((int16)from + fadeValue < (int16)to)
|
|
|
|
return from + fadeValue;
|
2005-04-05 15:07:40 +00:00
|
|
|
else
|
|
|
|
return to;
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
char PalAnim::fadeStep(int16 oper) {
|
2005-06-14 20:05:31 +00:00
|
|
|
byte newRed;
|
|
|
|
byte newGreen;
|
|
|
|
byte newBlue;
|
2005-04-05 15:07:40 +00:00
|
|
|
char stop;
|
|
|
|
int16 i;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
if (_vm->_global->colorCount != 256)
|
|
|
|
error("fadeStep: Only 256 color mode is supported!");
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
if (oper == 0) {
|
|
|
|
stop = 1;
|
2006-01-03 23:14:39 +00:00
|
|
|
if (_vm->_global->setAllPalette) {
|
|
|
|
if (_vm->_global->inVM != 0)
|
|
|
|
error("fade: _vm->_global->inVM != 0 not supported.");
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
newRed =
|
2006-01-03 23:14:39 +00:00
|
|
|
fadeColor(_vm->_global->redPalette[i],
|
|
|
|
toFadeRed[i]);
|
2005-04-05 15:07:40 +00:00
|
|
|
newGreen =
|
2006-01-03 23:14:39 +00:00
|
|
|
fadeColor(_vm->_global->greenPalette[i],
|
|
|
|
toFadeGreen[i]);
|
2005-04-05 15:07:40 +00:00
|
|
|
newBlue =
|
2006-01-03 23:14:39 +00:00
|
|
|
fadeColor(_vm->_global->bluePalette[i],
|
|
|
|
toFadeBlue[i]);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
if (_vm->_global->redPalette[i] != newRed
|
|
|
|
|| _vm->_global->greenPalette[i] != newGreen
|
|
|
|
|| _vm->_global->bluePalette[i] != newBlue) {
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_video->setPalElem(i, newRed, newGreen, newBlue, 0, 0x13);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_global->redPalette[i] = newRed;
|
|
|
|
_vm->_global->greenPalette[i] = newGreen;
|
|
|
|
_vm->_global->bluePalette[i] = newBlue;
|
2005-04-05 15:07:40 +00:00
|
|
|
stop = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_video->setPalElem(i,
|
|
|
|
fadeColor(_vm->_global->redPalette[i],
|
|
|
|
toFadeRed[i]),
|
|
|
|
fadeColor(_vm->_global->greenPalette[i],
|
|
|
|
toFadeGreen[i]),
|
|
|
|
fadeColor(_vm->_global->bluePalette[i],
|
|
|
|
toFadeBlue[i]), -1, _vm->_global->videoMode);
|
|
|
|
|
|
|
|
if (_vm->_global->redPalette[i] != toFadeRed[i] ||
|
|
|
|
_vm->_global->greenPalette[i] != toFadeGreen[i] ||
|
|
|
|
_vm->_global->bluePalette[i] != toFadeBlue[i])
|
2005-04-05 15:07:40 +00:00
|
|
|
stop = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stop;
|
|
|
|
} else if (oper == 1) {
|
|
|
|
stop = 1;
|
|
|
|
for (i = 0; i < 16; i++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_video->setPalElem(i,
|
|
|
|
fadeColor(_vm->_global->redPalette[i], toFadeRed[i]),
|
|
|
|
_vm->_global->greenPalette[i], _vm->_global->bluePalette[i], -1, _vm->_global->videoMode);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
if (_vm->_global->redPalette[i] != toFadeRed[i])
|
2005-04-05 15:07:40 +00:00
|
|
|
stop = 0;
|
|
|
|
}
|
|
|
|
return stop;
|
|
|
|
} else if (oper == 2) {
|
|
|
|
stop = 1;
|
|
|
|
for (i = 0; i < 16; i++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_video->setPalElem(i,
|
|
|
|
_vm->_global->redPalette[i],
|
|
|
|
fadeColor(_vm->_global->greenPalette[i], toFadeGreen[i]),
|
|
|
|
_vm->_global->bluePalette[i], -1, _vm->_global->videoMode);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
if (_vm->_global->greenPalette[i] != toFadeGreen[i])
|
2005-04-05 15:07:40 +00:00
|
|
|
stop = 0;
|
|
|
|
}
|
|
|
|
return stop;
|
|
|
|
} else if (oper == 3) {
|
|
|
|
stop = 1;
|
|
|
|
for (i = 0; i < 16; i++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_video->setPalElem(i,
|
|
|
|
_vm->_global->redPalette[i],
|
|
|
|
_vm->_global->greenPalette[i],
|
|
|
|
fadeColor(_vm->_global->bluePalette[i], toFadeBlue[i]),
|
|
|
|
-1, _vm->_global->videoMode);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
if (_vm->_global->bluePalette[i] != toFadeBlue[i])
|
2005-04-05 15:07:40 +00:00
|
|
|
stop = 0;
|
|
|
|
}
|
|
|
|
return stop;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
void PalAnim::fade(Video::PalDesc *palDesc, int16 fadeV, int16 allColors) {
|
2005-04-05 15:07:40 +00:00
|
|
|
char stop;
|
|
|
|
int16 i;
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
if (fadeV < 0)
|
|
|
|
fadeValue = -fadeV;
|
2005-04-05 15:07:40 +00:00
|
|
|
else
|
2006-01-03 23:14:39 +00:00
|
|
|
fadeValue = 2;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
if (_vm->_global->colorCount < 256) {
|
2005-04-05 15:07:40 +00:00
|
|
|
if (palDesc != 0)
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_video->setFullPalette(palDesc);
|
2005-04-05 15:07:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
if (_vm->_global->setAllPalette == 0) {
|
2005-04-05 15:07:40 +00:00
|
|
|
if (palDesc == 0) {
|
|
|
|
for (i = 0; i < 16; i++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
toFadeRed[i] = 0;
|
|
|
|
toFadeGreen[i] = 0;
|
|
|
|
toFadeBlue[i] = 0;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 16; i++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
toFadeRed[i] = palDesc->vgaPal[i].red;
|
|
|
|
toFadeGreen[i] = palDesc->vgaPal[i].green;
|
|
|
|
toFadeBlue[i] = palDesc->vgaPal[i].blue;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2006-01-03 23:14:39 +00:00
|
|
|
if (_vm->_global->inVM != 0)
|
|
|
|
error("fade: _vm->_global->inVM != 0 is not supported");
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
if (palDesc == 0) {
|
|
|
|
for (i = 0; i < 256; i++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
toFadeRed[i] = 0;
|
|
|
|
toFadeGreen[i] = 0;
|
|
|
|
toFadeBlue[i] = 0;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 256; i++) {
|
2006-01-03 23:14:39 +00:00
|
|
|
toFadeRed[i] = palDesc->vgaPal[i].red;
|
|
|
|
toFadeGreen[i] = palDesc->vgaPal[i].green;
|
|
|
|
toFadeBlue[i] = palDesc->vgaPal[i].blue;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allColors == 0) {
|
|
|
|
do {
|
2006-01-03 23:14:39 +00:00
|
|
|
if (_vm->_global->tmpPalBuffer == 0)
|
|
|
|
_vm->_video->waitRetrace(_vm->_global->videoMode);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
stop = fadeStep(0);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
if (fadeV > 0)
|
|
|
|
_vm->_util->delay(fadeV);
|
2005-04-05 15:07:40 +00:00
|
|
|
} while (stop == 0);
|
|
|
|
|
|
|
|
if (palDesc != 0)
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_video->setFullPalette(palDesc);
|
2005-04-05 15:07:40 +00:00
|
|
|
else
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_util->clearPalette();
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (allColors == 1) {
|
|
|
|
do {
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_video->waitRetrace(_vm->_global->videoMode);
|
|
|
|
stop = fadeStep(1);
|
2005-04-05 15:07:40 +00:00
|
|
|
} while (stop == 0);
|
|
|
|
|
|
|
|
do {
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_video->waitRetrace(_vm->_global->videoMode);
|
|
|
|
stop = fadeStep(2);
|
2005-04-05 15:07:40 +00:00
|
|
|
} while (stop == 0);
|
|
|
|
|
|
|
|
do {
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_video->waitRetrace(_vm->_global->videoMode);
|
|
|
|
stop = fadeStep(3);
|
2005-04-05 15:07:40 +00:00
|
|
|
} while (stop == 0);
|
|
|
|
|
|
|
|
if (palDesc != 0)
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_video->setFullPalette(palDesc);
|
2005-04-05 15:07:40 +00:00
|
|
|
else
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_util->clearPalette();
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
free(_vm->_global->tmpPalBuffer);
|
|
|
|
_vm->_global->tmpPalBuffer = 0;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Gob
|