2007-05-30 21:56:52 +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.
|
2006-02-11 12:54:56 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2014-02-18 01:34:22 +00:00
|
|
|
*
|
2006-02-11 12:54:56 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2006-02-11 12:54:56 +00:00
|
|
|
* GNU General Public License for more details.
|
2014-02-18 01:34:22 +00:00
|
|
|
*
|
2006-02-11 12:54:56 +00:00
|
|
|
* 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 "lure/screen.h"
|
|
|
|
#include "lure/luredefs.h"
|
|
|
|
#include "lure/memory.h"
|
|
|
|
#include "lure/disk.h"
|
|
|
|
#include "lure/decode.h"
|
2007-07-26 10:11:31 +00:00
|
|
|
#include "lure/events.h"
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "graphics/palette.h"
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
namespace Lure {
|
|
|
|
|
|
|
|
static Screen *int_disk = NULL;
|
|
|
|
|
|
|
|
Screen &Screen::getReference() {
|
|
|
|
return *int_disk;
|
|
|
|
}
|
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
Screen::Screen(OSystem &system): _system(system),
|
|
|
|
_screen(new Surface(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT)),
|
2006-02-11 12:54:56 +00:00
|
|
|
_disk(Disk::getReference()),
|
2007-12-31 05:58:22 +00:00
|
|
|
_palette(new Palette(GAME_PALETTE_RESOURCE_ID, RGB64)) {
|
2006-02-11 12:54:56 +00:00
|
|
|
int_disk = this;
|
|
|
|
_screen->empty();
|
2011-04-14 12:12:27 +00:00
|
|
|
_system.getPaletteManager()->setPalette(_palette->data(), 0, GAME_COLORS);
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Screen::~Screen() {
|
|
|
|
delete _screen;
|
|
|
|
delete _palette;
|
|
|
|
}
|
|
|
|
|
2011-02-13 15:34:30 +00:00
|
|
|
void Screen::setSystemPalette(Palette *p, uint16 start, uint16 num) {
|
|
|
|
byte pal[3 * 256];
|
|
|
|
assert(start + num <= 256);
|
|
|
|
|
|
|
|
const byte *rawData = p->data();
|
|
|
|
for (uint i = 0; i < num; ++i) {
|
|
|
|
pal[i * 3 + 0] = rawData[(i + start) * 4 + 0];
|
|
|
|
pal[i * 3 + 1] = rawData[(i + start) * 4 + 1];
|
|
|
|
pal[i * 3 + 2] = rawData[(i + start) * 4 + 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
_system.getPaletteManager()->setPalette(pal, start, num);
|
|
|
|
}
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
// setPaletteEmpty
|
|
|
|
// Defaults the palette to an empty set
|
|
|
|
|
2007-08-25 06:06:18 +00:00
|
|
|
void Screen::setPaletteEmpty(int numEntries) {
|
2007-10-28 04:27:18 +00:00
|
|
|
Palette emptyPalette(numEntries, NULL, RGB64);
|
2011-02-13 15:34:30 +00:00
|
|
|
setSystemPalette(&emptyPalette, 0, numEntries);
|
2007-10-28 04:27:18 +00:00
|
|
|
_palette->copyFrom(&emptyPalette);
|
|
|
|
/*
|
2006-02-11 12:54:56 +00:00
|
|
|
delete _palette;
|
|
|
|
_palette = new Palette();
|
|
|
|
|
2011-02-07 17:52:38 +00:00
|
|
|
_system.getPaletteManager()->setPalette(_palette->data(), 0, numEntries);
|
2007-10-28 04:27:18 +00:00
|
|
|
*/
|
2006-02-11 12:54:56 +00:00
|
|
|
_system.updateScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
// setPalette
|
|
|
|
// Sets the current palette to the passed palette
|
|
|
|
|
|
|
|
void Screen::setPalette(Palette *p) {
|
|
|
|
_palette->copyFrom(p);
|
2011-04-14 12:12:27 +00:00
|
|
|
setSystemPalette(_palette, 0, GAME_COLORS);
|
2006-02-11 12:54:56 +00:00
|
|
|
_system.updateScreen();
|
|
|
|
}
|
|
|
|
|
2007-07-26 10:11:31 +00:00
|
|
|
// setPalette
|
|
|
|
// Variation that allows the specification of a subset of a palette passed in to be copied
|
|
|
|
|
|
|
|
void Screen::setPalette(Palette *p, uint16 start, uint16 num) {
|
2007-08-25 06:06:18 +00:00
|
|
|
_palette->palette()->copyFrom(p->palette(), start * 4, start * 4, num * 4);
|
2011-02-13 15:34:30 +00:00
|
|
|
setSystemPalette(_palette, start, num);
|
2007-07-26 10:11:31 +00:00
|
|
|
_system.updateScreen();
|
|
|
|
}
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
// paletteFadeIn
|
|
|
|
// Fades in the palette. For proper operation, the palette should have been
|
|
|
|
// previously set to empty
|
|
|
|
|
|
|
|
void Screen::paletteFadeIn(Palette *p) {
|
2007-07-26 10:11:31 +00:00
|
|
|
assert(p->numEntries() <= _palette->numEntries());
|
|
|
|
Events &events = Events::getReference();
|
2006-02-11 12:54:56 +00:00
|
|
|
bool changed;
|
|
|
|
|
|
|
|
do {
|
|
|
|
changed = false;
|
2007-07-26 10:11:31 +00:00
|
|
|
byte *pFinal = p->data();
|
|
|
|
byte *pCurrent = _palette->data();
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2007-09-10 13:17:20 +00:00
|
|
|
for (int palCtr = 0; palCtr < p->numEntries() * PALETTE_FADE_INC_SIZE; ++palCtr, ++pCurrent, ++pFinal) {
|
2006-02-11 12:54:56 +00:00
|
|
|
if (palCtr % PALETTE_FADE_INC_SIZE == (PALETTE_FADE_INC_SIZE - 1)) continue;
|
2007-07-26 10:11:31 +00:00
|
|
|
bool isDifferent = *pCurrent < *pFinal;
|
|
|
|
|
2006-02-11 12:54:56 +00:00
|
|
|
if (isDifferent) {
|
2008-01-27 19:47:41 +00:00
|
|
|
if ((*pFinal - *pCurrent) < PALETTE_FADE_INC_SIZE)
|
2007-07-26 10:11:31 +00:00
|
|
|
*pCurrent = *pFinal;
|
|
|
|
else
|
|
|
|
*pCurrent += PALETTE_FADE_INC_SIZE;
|
2006-02-11 12:54:56 +00:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed) {
|
2011-02-13 15:34:30 +00:00
|
|
|
setSystemPalette(_palette, 0, p->numEntries());
|
2006-02-11 12:54:56 +00:00
|
|
|
_system.updateScreen();
|
|
|
|
_system.delayMillis(20);
|
2007-11-17 10:47:37 +00:00
|
|
|
while (events.pollEvent())
|
|
|
|
;
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
} while (changed);
|
|
|
|
}
|
|
|
|
|
|
|
|
// paletteFadeOut
|
2011-04-14 12:12:27 +00:00
|
|
|
// Fades the screen to black by gradually decreasing the palette colors
|
2006-02-11 12:54:56 +00:00
|
|
|
|
2007-07-26 10:11:31 +00:00
|
|
|
void Screen::paletteFadeOut(int numEntries) {
|
|
|
|
assert((uint32)numEntries <= _palette->palette()->size());
|
|
|
|
Events &events = Events::getReference();
|
2006-02-11 12:54:56 +00:00
|
|
|
bool changed;
|
|
|
|
|
|
|
|
do {
|
|
|
|
byte *pTemp = _palette->data();
|
|
|
|
changed = false;
|
|
|
|
|
2007-07-26 10:11:31 +00:00
|
|
|
for (uint32 palCtr = 0; palCtr < (uint32)(numEntries * PALETTE_FADE_INC_SIZE); ++palCtr, ++pTemp) {
|
2008-01-27 19:47:41 +00:00
|
|
|
if (palCtr % PALETTE_FADE_INC_SIZE == (PALETTE_FADE_INC_SIZE - 1))
|
2006-02-11 12:54:56 +00:00
|
|
|
continue;
|
|
|
|
bool isDifferent = *pTemp > 0;
|
|
|
|
if (isDifferent) {
|
|
|
|
if (*pTemp < PALETTE_FADE_INC_SIZE) *pTemp = 0;
|
|
|
|
else *pTemp -= PALETTE_FADE_INC_SIZE;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed) {
|
2011-02-13 15:34:30 +00:00
|
|
|
setSystemPalette(_palette, 0, numEntries);
|
2006-02-11 12:54:56 +00:00
|
|
|
_system.updateScreen();
|
|
|
|
_system.delayMillis(20);
|
2007-11-17 10:47:37 +00:00
|
|
|
while (events.pollEvent())
|
|
|
|
;
|
2006-02-11 12:54:56 +00:00
|
|
|
}
|
|
|
|
} while (changed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::resetPalette() {
|
|
|
|
Palette p(GAME_PALETTE_RESOURCE_ID);
|
|
|
|
setPalette(&p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::empty() {
|
|
|
|
_screen->empty();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::update() {
|
|
|
|
_system.copyRectToScreen(screen_raw(), FULL_SCREEN_WIDTH, 0, 0, FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
|
|
|
|
_system.updateScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::updateArea(uint16 x, uint16 y, uint16 w, uint16 h) {
|
|
|
|
_system.copyRectToScreen(screen_raw(), FULL_SCREEN_WIDTH, x, y, w, h);
|
|
|
|
_system.updateScreen();
|
|
|
|
}
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Lure
|