scummvm/engines/xeen/screen.cpp

173 lines
4.3 KiB
C++
Raw Normal View History

/* 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 "common/system.h"
#include "graphics/palette.h"
2014-12-31 08:50:24 +00:00
#include "graphics/surface.h"
#include "xeen/screen.h"
#include "xeen/resources.h"
#include "xeen/window.h"
#include "xeen/xeen.h"
namespace Xeen {
Screen::Screen(XeenEngine *vm) : _vm(vm) {
_fadeIn = false;
create(SCREEN_WIDTH, SCREEN_HEIGHT);
Common::fill(&_tempPalette[0], &_tempPalette[PALETTE_SIZE], 0);
Common::fill(&_mainPalette[0], &_mainPalette[PALETTE_SIZE], 0);
}
void Screen::loadPalette(const Common::String &name) {
File f(name);
for (int i = 0; i < PALETTE_SIZE; ++i)
_tempPalette[i] = f.readByte() << 2;
}
void Screen::loadBackground(const Common::String &name) {
File f(name);
assert(f.size() == (SCREEN_WIDTH * SCREEN_HEIGHT));
f.read((byte *)getPixels(), SCREEN_WIDTH * SCREEN_HEIGHT);
2015-01-01 21:46:22 +00:00
addDirtyRect(Common::Rect(0, 0, this->w, this->h));
}
void Screen::loadPage(int pageNum) {
assert(pageNum == 0 || pageNum == 1);
if (_pages[0].empty()) {
_pages[0].create(SCREEN_WIDTH, SCREEN_HEIGHT);
_pages[1].create(SCREEN_WIDTH, SCREEN_HEIGHT);
}
_pages[pageNum].blitFrom(*this);
}
void Screen::freePages() {
_pages[0].free();
_pages[1].free();
}
void Screen::horizMerge(int xp) {
if (_pages[0].empty())
return;
for (int y = 0; y < SCREEN_HEIGHT; ++y) {
byte *destP = (byte *)getBasePtr(0, y);
const byte *srcP = (const byte *)_pages[0].getBasePtr(xp, y);
Common::copy(srcP, srcP + SCREEN_WIDTH - xp, destP);
if (xp != 0) {
destP = (byte *)getBasePtr(SCREEN_WIDTH - xp, y);
2014-12-26 07:57:58 +00:00
srcP = (const byte *)_pages[1].getBasePtr(0, y);
Common::copy(srcP, srcP + xp, destP);
}
}
markAllDirty();
}
void Screen::vertMerge(int yp) {
if (_pages[0].empty())
return;
for (int y = 0; y < SCREEN_HEIGHT - yp; ++y) {
2016-09-21 00:56:32 +00:00
const byte *srcP = (const byte *)_pages[0].getBasePtr(0, yp + y);
byte *destP = (byte *)getBasePtr(0, y);
Common::copy(srcP, srcP + SCREEN_WIDTH, destP);
}
2016-09-21 00:56:32 +00:00
for (int y = 0; y < yp; ++y) {
const byte *srcP = (const byte *)_pages[1].getBasePtr(0, y);
byte *destP = (byte *)getBasePtr(0, SCREEN_HEIGHT - yp + y);
Common::copy(srcP, srcP + SCREEN_WIDTH, destP);
}
markAllDirty();
}
void Screen::draw(void *data) {
// TODO: Figure out data structure that can be passed to method
assert(!data);
drawScreen();
}
void Screen::drawScreen() {
addDirtyRect(Common::Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
}
void Screen::fadeIn(int step) {
_fadeIn = true;
fadeInner(step);
}
void Screen::fadeOut(int step) {
_fadeIn = false;
fadeInner(step);
}
void Screen::fadeInner(int step) {
for (int idx = 128; idx >= 0 && !_vm->shouldQuit(); idx -= step) {
int val = MAX(idx, 0);
bool flag = !_fadeIn;
if (!flag) {
val = -(val - 128);
flag = step != 0x81;
}
if (!flag) {
step = 0x80;
} else {
// Create a scaled palette from the temporary one
for (int i = 0; i < PALETTE_SIZE; ++i) {
_mainPalette[i] = (_tempPalette[i] * val * 2) >> 8;
}
updatePalette();
}
_vm->_events->pollEventsAndWait();
}
update();
}
void Screen::updatePalette() {
updatePalette(_mainPalette, 0, 16);
}
void Screen::updatePalette(const byte *pal, int start, int count16) {
g_system->getPaletteManager()->setPalette(pal, start, count16 * 16);
}
void Screen::saveBackground(int slot) {
assert(slot > 0 && slot < 10);
_savedScreens[slot - 1].copyFrom(*this);
}
void Screen::restoreBackground(int slot) {
assert(slot > 0 && slot < 10);
blitFrom(_savedScreens[slot - 1]);
}
} // End of namespace Xeen