diff options
Diffstat (limited to 'engines/groovie/graphics.cpp')
-rw-r--r-- | engines/groovie/graphics.cpp | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/engines/groovie/graphics.cpp b/engines/groovie/graphics.cpp new file mode 100644 index 0000000000..a7ad88a443 --- /dev/null +++ b/engines/groovie/graphics.cpp @@ -0,0 +1,161 @@ +/* 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 "groovie/groovie.h" +#include "groovie/graphics.h" + +namespace Groovie { + +GraphicsMan::GraphicsMan(GroovieEngine *vm) : + _vm(vm), _changed(false), _fading(0) { + // Create the game surfaces + _foreground.create(640, 320, 1); + _background.create(640, 320, 1); +} + +GraphicsMan::~GraphicsMan() { + // Free the game surfaces + _foreground.free(); + _background.free(); +} + +void GraphicsMan::update() { + if (_fading) { + // Set the start time + uint32 time = _vm->_system->getMillis() - _fadeStartTime; + + // Scale the time + int step = time / 4; + if (step > 256) { + step = 256; + } + + if (_fading == 1) { + // Apply the fade in + applyFading(step); + } else if (_fading == 2) { + // Apply the fade out + applyFading(256 - step); + + // Clear the buffer when ending the fade out + if (step == 256) + _foreground.fillRect(Common::Rect::Rect(640, 320), 0); + } + + // Check for the end + if (step == 256) { + _fading = 0; + } + } + + // Update the screen if needed and reset the status + if (_changed) { + _vm->_system->updateScreen(); + _changed = false; + } +} + +void GraphicsMan::change() { + _changed = true; +} + +void GraphicsMan::mergeFgAndBg() { + uint32 i; + byte *countf, *countb; + + countf = (byte *)_foreground.getBasePtr(0, 0); + countb = (byte *)_background.getBasePtr(0, 0); + for (i = 640 * 320; i; i--) { + if (255 == *(countf)) { + *(countf) = *(countb); + } + countf++; + countb++; + } +} + + +void GraphicsMan::updateScreen(Graphics::Surface *source) { + _vm->_system->copyRectToScreen((byte *)source->getBasePtr(0, 0), 640, 0, 80, 640, 320); + change(); +} + +bool GraphicsMan::isFading() { + return _fading; +} + +void GraphicsMan::fadeIn(byte *pal) { + // Set the start time + _fadeStartTime = _vm->_system->getMillis(); + + // Copy the target palette + for (int i = 0; i < 256; i++) { + _paletteFull[(i * 4) + 0] = pal[(i * 3) + 0]; + _paletteFull[(i * 4) + 1] = pal[(i * 3) + 1]; + _paletteFull[(i * 4) + 2] = pal[(i * 3) + 2]; + } + + // Apply a black palette right now + applyFading(0); + + // Set the current fading + _fading = 1; +} + +void GraphicsMan::fadeOut() { + // Set the start time + _fadeStartTime = _vm->_system->getMillis(); + + // Get the current palette + _vm->_system->grabPalette(_paletteFull, 0, 256); + + // Set the current fading + _fading = 2; +} + +void GraphicsMan::applyFading(int step) { + // Calculate the fade factor for the given step + int factorR = 256 - (256 - step) * 1; + int factorGB = 256 - (256 - step) * 2; + + if (factorR <= 0) factorR = 0; + if (factorGB <= 0) factorGB = 0; + + // Calculate the new palette + byte newpal[256 * 4]; + for (int i = 0; i < 256; i++) { + newpal[(i * 4) + 0] = (_paletteFull[(i * 4) + 0] * factorR) / 256; + newpal[(i * 4) + 1] = (_paletteFull[(i * 4) + 1] * factorGB) / 256; + newpal[(i * 4) + 2] = (_paletteFull[(i * 4) + 2] * factorGB) / 256; + } + + // Set the screen palette + _vm->_system->setPalette(newpal, 0, 256); + + // Request a screen update + change(); +} + +} // End of Groovie namespace |