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