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
|
/* 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.
*
*/
#include "gob/gob.h"
#include "gob/palanim.h"
#include "gob/global.h"
#include "gob/util.h"
#include "gob/video.h"
namespace Gob {
PalAnim::PalAnim(GobEngine *vm) : _vm(vm) {
_fadeValue = 1;
for (int i = 0; i < 256; i++) {
_toFadeRed[i] = 0;
_toFadeGreen[i] = 0;
_toFadeBlue[i] = 0;
}
_palArray[0] = _vm->_global->_redPalette;
_palArray[1] = _vm->_global->_greenPalette;
_palArray[2] = _vm->_global->_bluePalette;
_fadeArray[0] = _toFadeRed;
_fadeArray[1] = _toFadeGreen;
_fadeArray[2] = _toFadeBlue;
}
char PalAnim::fadeColor(int16 from, int16 to) {
if ((from - _fadeValue) > to)
return from - _fadeValue;
else if ((from + _fadeValue) < to)
return from + _fadeValue;
else return to;
}
bool PalAnim::fadeStepColor(int color) {
bool stop = true;
char colors[3];
for (int i = 0; i < 16; i++) {
colors[0] = _palArray[0][i];
colors[1] = _palArray[1][i];
colors[2] = _palArray[2][i];
colors[color] = fadeColor(_palArray[color][i], _fadeArray[color][i]);
_vm->_video->setPalElem(i, colors[0], colors[1], colors[2],
-1, _vm->_global->_videoMode);
if (_palArray[color][i] != _fadeArray[color][i])
stop = false;
}
return stop;
}
bool PalAnim::fadeStep(int16 oper) {
bool stop = true;
if (oper == 0) {
int colorCount = _vm->_global->_setAllPalette ? _vm->_global->_colorCount : 256;
for (int i = 0; i < colorCount; i++) {
byte newRed = fadeColor(_vm->_global->_redPalette [i], _toFadeRed [i]);
byte newGreen = fadeColor(_vm->_global->_greenPalette[i], _toFadeGreen[i]);
byte newBlue = fadeColor(_vm->_global->_bluePalette [i], _toFadeBlue [i]);
if ((_vm->_global->_redPalette [i] != newRed ) ||
(_vm->_global->_greenPalette[i] != newGreen) ||
(_vm->_global->_bluePalette [i] != newBlue)) {
_vm->_video->setPalElem(i, newRed, newGreen, newBlue, 0, 0x13);
_vm->_global->_redPalette [i] = newRed;
_vm->_global->_greenPalette[i] = newGreen;
_vm->_global->_bluePalette [i] = newBlue;
stop = false;
}
}
} else if ((oper > 0) && (oper < 4))
stop = fadeStepColor(oper - 1);
return stop;
}
void PalAnim::fade(Video::PalDesc *palDesc, int16 fadeV, int16 allColors) {
bool stop;
if (_vm->shouldQuit())
return;
_fadeValue = (fadeV < 0) ? -fadeV : 2;
int colorCount = _vm->_global->_setAllPalette ? _vm->_global->_colorCount : 256;
for (int i = 0; i < colorCount; i++) {
_toFadeRed [i] = (palDesc == 0) ? 0 : palDesc->vgaPal[i].red;
_toFadeGreen[i] = (palDesc == 0) ? 0 : palDesc->vgaPal[i].green;
_toFadeBlue [i] = (palDesc == 0) ? 0 : palDesc->vgaPal[i].blue;
}
if (allColors == 0) {
do {
stop = fadeStep(0);
_vm->_video->waitRetrace();
if (fadeV > 0)
_vm->_util->delay(fadeV);
} while (!stop);
if (palDesc)
_vm->_video->setFullPalette(palDesc);
else
_vm->_util->clearPalette();
}
if (allColors == 1) {
do {
_vm->_video->waitRetrace();
stop = fadeStep(1);
} while (!stop);
do {
_vm->_video->waitRetrace();
stop = fadeStep(2);
} while (!stop);
do {
_vm->_video->waitRetrace();
stop = fadeStep(3);
} while (!stop);
if (palDesc)
_vm->_video->setFullPalette(palDesc);
else
_vm->_util->clearPalette();
}
}
} // End of namespace Gob
|