2009-06-17 04:48:48 +00:00
|
|
|
/* 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/stream.h"
|
|
|
|
|
|
|
|
#include "draci/draci.h"
|
|
|
|
#include "draci/screen.h"
|
|
|
|
|
|
|
|
namespace Draci {
|
|
|
|
|
|
|
|
Screen::Screen(DraciEngine *vm) : _vm(vm) {
|
|
|
|
_surface = new Graphics::Surface();
|
2009-06-18 00:33:16 +00:00
|
|
|
_surface->create(kScreenWidth, kScreenHeight, 1);
|
2009-06-17 04:48:48 +00:00
|
|
|
this->clearScreen();
|
2009-06-17 23:11:24 +00:00
|
|
|
_palette = new byte[4 * kNumColours];
|
2009-06-17 21:29:05 +00:00
|
|
|
setPaletteEmpty();
|
2009-06-17 04:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Screen::~Screen() {
|
|
|
|
_surface->free();
|
|
|
|
delete[] _surface;
|
|
|
|
delete[] _palette;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::setPaletteEmpty(unsigned int numEntries) {
|
2009-06-17 23:11:24 +00:00
|
|
|
for (unsigned int i = 0; i < 4 * numEntries; ++i) {
|
2009-06-17 04:48:48 +00:00
|
|
|
_palette[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_system->setPalette(_palette, 0, numEntries);
|
|
|
|
_vm->_system->updateScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::setPalette(byte *data, uint16 start, uint16 num) {
|
|
|
|
|
2009-06-17 23:11:24 +00:00
|
|
|
Common::MemoryReadStream pal(data, 3 * kNumColours);
|
2009-06-17 04:48:48 +00:00
|
|
|
pal.seek(start * 4);
|
|
|
|
|
|
|
|
// Copy the palette
|
|
|
|
for (unsigned int i = start; i < start + num; ++i) {
|
|
|
|
_palette[i * 4] = pal.readByte();
|
|
|
|
_palette[i * 4 + 1] = pal.readByte();
|
|
|
|
_palette[i * 4 + 2] = pal.readByte();
|
|
|
|
_palette[i * 4 + 3] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Investigate why this is needed
|
|
|
|
// Shift the palette one bit to the left to make it brighter
|
2009-06-17 23:11:24 +00:00
|
|
|
for (unsigned int i = 0; i < 4 * kNumColours; ++i) {
|
2009-06-17 04:48:48 +00:00
|
|
|
_palette[i] <<= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_system->setPalette(_palette, start, num);
|
|
|
|
_vm->_system->updateScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::copyToScreen() const {
|
|
|
|
byte *ptr = (byte *)_surface->getBasePtr(0, 0);
|
|
|
|
|
2009-06-18 00:33:16 +00:00
|
|
|
_vm->_system->copyRectToScreen(ptr, kScreenWidth, 0, 0,
|
|
|
|
kScreenWidth, kScreenHeight);
|
2009-06-17 04:48:48 +00:00
|
|
|
|
|
|
|
_vm->_system->updateScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Screen::clearScreen() const {
|
|
|
|
byte *ptr = (byte *)_surface->getBasePtr(0, 0);
|
|
|
|
|
2009-06-18 00:33:16 +00:00
|
|
|
memset(ptr, 0, kScreenWidth * kScreenHeight);
|
2009-06-17 04:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::drawSprite(const Sprite &s) const {
|
|
|
|
byte *dst = (byte *)_surface->getBasePtr(s._x, s._y);
|
|
|
|
byte *src = s._data;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < s._height; ++i) {
|
|
|
|
for(unsigned int j = 0; j < s._width; ++j) {
|
|
|
|
dst[j] = *src++;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst += _surface->pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::fillScreen(uint16 colour) const {
|
|
|
|
byte *ptr = (byte *)_surface->getBasePtr(0, 0);
|
|
|
|
|
2009-06-18 00:33:16 +00:00
|
|
|
memset(ptr, colour, kScreenWidth * kScreenHeight);
|
2009-06-17 04:48:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
byte *Screen::getPalette() const {
|
|
|
|
return _palette;
|
|
|
|
}
|
|
|
|
|
|
|
|
Graphics::Surface *Screen::getSurface() {
|
|
|
|
return _surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Draci
|
|
|
|
|
|
|
|
|