2009-10-03 20:49:18 +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/timer.h"
|
|
|
|
#include "common/util.h"
|
|
|
|
|
|
|
|
#include "sci/sci.h"
|
|
|
|
#include "sci/engine/state.h"
|
|
|
|
#include "sci/tools.h"
|
|
|
|
#include "sci/gui/gui_screen.h"
|
|
|
|
|
|
|
|
namespace Sci {
|
|
|
|
|
2009-10-07 12:52:21 +00:00
|
|
|
SciGuiScreen::SciGuiScreen(int16 width, int16 height, int16 scaleFactor) :
|
|
|
|
_width(width), _height(height) {
|
2009-10-03 20:49:18 +00:00
|
|
|
|
|
|
|
int i;
|
|
|
|
uint16 base = 0;
|
|
|
|
|
|
|
|
_pixels = _width * _height;
|
|
|
|
|
2009-10-05 07:38:05 +00:00
|
|
|
// if you want to do scaling, adjust putPixel() accordingly
|
2009-10-06 12:26:13 +00:00
|
|
|
_displayWidth = _width * scaleFactor;
|
|
|
|
_displayHeight = _height * scaleFactor;
|
2009-10-03 20:49:18 +00:00
|
|
|
_displayPixels = _displayWidth * _displayHeight;
|
|
|
|
|
2009-10-07 22:53:32 +00:00
|
|
|
_visualScreen = (byte *)calloc(_pixels, 1);
|
|
|
|
_priorityScreen = (byte *)calloc(_pixels, 1);
|
|
|
|
_controlScreen = (byte *)calloc(_pixels, 1);
|
|
|
|
_displayScreen = (byte *)calloc(_displayPixels, 1);
|
2009-10-03 20:49:18 +00:00
|
|
|
|
2009-10-07 15:53:34 +00:00
|
|
|
// Sets display screen to be actually displayed
|
|
|
|
_activeScreen = _displayScreen;
|
|
|
|
|
2009-10-03 20:49:18 +00:00
|
|
|
for (i = 0; i < _height; i++) {
|
|
|
|
_baseTable[i] = base; _baseDisplayTable[i] = base;
|
|
|
|
base += _width;
|
|
|
|
}
|
2009-10-06 19:57:55 +00:00
|
|
|
|
|
|
|
_picNotValid = false;
|
2009-10-07 21:47:34 +00:00
|
|
|
_unditherState = false;
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 12:26:13 +00:00
|
|
|
SciGuiScreen::~SciGuiScreen() {
|
|
|
|
free(_visualScreen);
|
|
|
|
free(_priorityScreen);
|
|
|
|
free(_controlScreen);
|
|
|
|
free(_displayScreen);
|
|
|
|
}
|
|
|
|
|
2009-10-05 12:04:39 +00:00
|
|
|
void SciGuiScreen::copyToScreen() {
|
2009-10-07 15:53:34 +00:00
|
|
|
g_system->copyRectToScreen(_activeScreen, _displayWidth, 0, 0, _displayWidth, _displayHeight);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
|
2009-10-05 07:38:05 +00:00
|
|
|
byte SciGuiScreen::getDrawingMask(byte color, byte prio, byte control) {
|
2009-10-03 20:49:18 +00:00
|
|
|
byte flag = 0;
|
|
|
|
if (color != 255)
|
|
|
|
flag |= SCI_SCREEN_MASK_VISUAL;
|
|
|
|
if (prio != 255)
|
|
|
|
flag |= SCI_SCREEN_MASK_PRIORITY;
|
|
|
|
if (control != 255)
|
|
|
|
flag |= SCI_SCREEN_MASK_CONTROL;
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2009-10-05 07:38:05 +00:00
|
|
|
void SciGuiScreen::putPixel(int x, int y, byte drawMask, byte color, byte priority, byte control) {
|
2009-10-03 20:49:18 +00:00
|
|
|
int offset = _baseTable[y] + x;
|
|
|
|
|
|
|
|
if (drawMask & SCI_SCREEN_MASK_VISUAL) {
|
|
|
|
*(_visualScreen + offset) = color;
|
|
|
|
_displayScreen[_baseDisplayTable[y] + x] = color;
|
|
|
|
}
|
|
|
|
if (drawMask & SCI_SCREEN_MASK_PRIORITY)
|
|
|
|
*(_priorityScreen + offset) = priority;
|
|
|
|
if (drawMask & SCI_SCREEN_MASK_CONTROL)
|
|
|
|
*(_controlScreen + offset) = control;
|
|
|
|
}
|
|
|
|
|
2009-10-05 07:38:05 +00:00
|
|
|
byte SciGuiScreen::getVisual(int x, int y) {
|
2009-10-03 20:49:18 +00:00
|
|
|
return _visualScreen[_baseTable[y] + x];
|
|
|
|
}
|
|
|
|
|
2009-10-05 07:38:05 +00:00
|
|
|
byte SciGuiScreen::getPriority(int x, int y) {
|
2009-10-03 20:49:18 +00:00
|
|
|
return _priorityScreen[_baseTable[y] + x];
|
|
|
|
}
|
|
|
|
|
2009-10-05 07:38:05 +00:00
|
|
|
byte SciGuiScreen::getControl(int x, int y) {
|
2009-10-03 20:49:18 +00:00
|
|
|
return _controlScreen[_baseTable[y] + x];
|
|
|
|
}
|
|
|
|
|
2009-10-05 07:38:05 +00:00
|
|
|
byte SciGuiScreen::isFillMatch(int16 x, int16 y, byte flag, byte t_color, byte t_pri, byte t_con) {
|
2009-10-03 20:49:18 +00:00
|
|
|
int offset = _baseTable[y] + x;
|
|
|
|
byte match = 0;
|
|
|
|
|
|
|
|
if (flag & SCI_SCREEN_MASK_VISUAL && *(_visualScreen + offset) == t_color)
|
|
|
|
match |= SCI_SCREEN_MASK_VISUAL;
|
|
|
|
if (flag & SCI_SCREEN_MASK_PRIORITY && *(_priorityScreen + offset) == t_pri)
|
|
|
|
match |= SCI_SCREEN_MASK_PRIORITY;
|
|
|
|
if (flag & SCI_SCREEN_MASK_CONTROL && *(_controlScreen + offset) == t_con)
|
|
|
|
match |= SCI_SCREEN_MASK_CONTROL;
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2009-10-05 07:38:05 +00:00
|
|
|
int SciGuiScreen::getBitsDataSize(Common::Rect rect, byte mask) {
|
2009-10-03 20:49:18 +00:00
|
|
|
int byteCount = sizeof(rect) + sizeof(mask);
|
|
|
|
int pixels = rect.width() * rect.height();
|
2009-10-05 23:00:48 +00:00
|
|
|
if (mask & SCI_SCREEN_MASK_VISUAL) {
|
|
|
|
byteCount += pixels; // _visualScreen
|
|
|
|
byteCount += pixels; // _displayScreen
|
|
|
|
}
|
|
|
|
if (mask & SCI_SCREEN_MASK_PRIORITY) {
|
|
|
|
byteCount += pixels; // _priorityScreen
|
|
|
|
}
|
|
|
|
if (mask & SCI_SCREEN_MASK_CONTROL) {
|
|
|
|
byteCount += pixels; // _controlScreen
|
|
|
|
}
|
2009-10-05 07:51:31 +00:00
|
|
|
|
2009-10-03 20:49:18 +00:00
|
|
|
return byteCount;
|
|
|
|
}
|
|
|
|
|
2009-10-05 07:38:05 +00:00
|
|
|
void SciGuiScreen::saveBits(Common::Rect rect, byte mask, byte *memoryPtr) {
|
2009-10-03 20:49:18 +00:00
|
|
|
memcpy(memoryPtr, (void *)&rect, sizeof(rect)); memoryPtr += sizeof(rect);
|
|
|
|
memcpy(memoryPtr, (void *)&mask, sizeof(mask)); memoryPtr += sizeof(mask);
|
|
|
|
|
|
|
|
if (mask & SCI_SCREEN_MASK_VISUAL) {
|
2009-10-05 07:38:05 +00:00
|
|
|
saveBitsScreen(rect, _visualScreen, memoryPtr);
|
|
|
|
saveBitsScreen(rect, _displayScreen, memoryPtr);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
if (mask & SCI_SCREEN_MASK_PRIORITY) {
|
2009-10-05 07:38:05 +00:00
|
|
|
saveBitsScreen(rect, _priorityScreen, memoryPtr);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
if (mask & SCI_SCREEN_MASK_CONTROL) {
|
2009-10-05 07:38:05 +00:00
|
|
|
saveBitsScreen(rect, _controlScreen, memoryPtr);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-05 07:38:05 +00:00
|
|
|
void SciGuiScreen::saveBitsScreen(Common::Rect rect, byte *screen, byte *&memoryPtr) {
|
2009-10-03 20:49:18 +00:00
|
|
|
int width = rect.width();
|
|
|
|
int y;
|
|
|
|
|
|
|
|
screen += (rect.top * _width) + rect.left;
|
|
|
|
|
2009-10-04 05:20:56 +00:00
|
|
|
for (y = rect.top; y < rect.bottom; y++) {
|
2009-10-03 20:49:18 +00:00
|
|
|
memcpy(memoryPtr, (void*)screen, width); memoryPtr += width;
|
|
|
|
screen += _width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-05 07:38:05 +00:00
|
|
|
void SciGuiScreen::restoreBits(byte *memoryPtr) {
|
2009-10-03 20:49:18 +00:00
|
|
|
Common::Rect rect;
|
|
|
|
byte mask;
|
|
|
|
|
|
|
|
memcpy((void *)&rect, memoryPtr, sizeof(rect)); memoryPtr += sizeof(rect);
|
|
|
|
memcpy((void *)&mask, memoryPtr, sizeof(mask)); memoryPtr += sizeof(mask);
|
|
|
|
|
|
|
|
if (mask & SCI_SCREEN_MASK_VISUAL) {
|
2009-10-05 07:38:05 +00:00
|
|
|
restoreBitsScreen(rect, memoryPtr, _visualScreen);
|
|
|
|
restoreBitsScreen(rect, memoryPtr, _displayScreen);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
if (mask & SCI_SCREEN_MASK_PRIORITY) {
|
2009-10-05 07:38:05 +00:00
|
|
|
restoreBitsScreen(rect, memoryPtr, _priorityScreen);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
if (mask & SCI_SCREEN_MASK_CONTROL) {
|
2009-10-05 07:38:05 +00:00
|
|
|
restoreBitsScreen(rect, memoryPtr, _controlScreen);
|
2009-10-03 20:49:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-05 07:38:05 +00:00
|
|
|
void SciGuiScreen::restoreBitsScreen(Common::Rect rect, byte *&memoryPtr, byte *screen) {
|
2009-10-03 20:49:18 +00:00
|
|
|
int width = rect.width();
|
|
|
|
int y;
|
|
|
|
|
|
|
|
screen += (rect.top * _width) + rect.left;
|
|
|
|
|
2009-10-04 05:20:56 +00:00
|
|
|
for (y = rect.top; y < rect.bottom; y++) {
|
2009-10-03 20:49:18 +00:00
|
|
|
memcpy((void*) screen, memoryPtr, width); memoryPtr += width;
|
|
|
|
screen += _width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-06 16:14:40 +00:00
|
|
|
void SciGuiScreen::setPalette(GuiPalette*pal) {
|
|
|
|
// just copy palette to system
|
|
|
|
byte bpal[4 * 256];
|
|
|
|
// Get current palette, update it and put back
|
2009-10-07 12:52:21 +00:00
|
|
|
g_system->grabPalette(bpal, 0, 256);
|
2009-10-06 16:14:40 +00:00
|
|
|
for (int16 i = 0; i < 256; i++) {
|
|
|
|
if (!pal->colors[i].used)
|
|
|
|
continue;
|
|
|
|
bpal[i * 4] = pal->colors[i].r * pal->intensity[i] / 100;
|
|
|
|
bpal[i * 4 + 1] = pal->colors[i].g * pal->intensity[i] / 100;
|
|
|
|
bpal[i * 4 + 2] = pal->colors[i].b * pal->intensity[i] / 100;
|
|
|
|
bpal[i * 4 + 3] = 100;
|
|
|
|
}
|
2009-10-07 12:52:21 +00:00
|
|
|
g_system->setPalette(bpal, 0, 256);
|
2009-10-06 16:14:40 +00:00
|
|
|
}
|
|
|
|
|
2009-10-05 21:38:51 +00:00
|
|
|
// Currently not really done, its supposed to be possible to only dither _visualScreen
|
2009-10-09 20:54:02 +00:00
|
|
|
void SciGuiScreen::dither(bool addToFlag) {
|
2009-10-05 21:38:51 +00:00
|
|
|
int y, x;
|
2009-10-07 22:03:17 +00:00
|
|
|
byte color;
|
2009-10-05 21:38:51 +00:00
|
|
|
byte *screenPtr = _visualScreen;
|
|
|
|
byte *displayPtr = _displayScreen;
|
|
|
|
|
2009-10-09 20:21:21 +00:00
|
|
|
if (!_unditherState) {
|
|
|
|
// Do dithering on visual and display-screen
|
|
|
|
for (y = 0; y < _height; y++) {
|
|
|
|
for (x = 0; x < _width; x++) {
|
|
|
|
color = *screenPtr;
|
|
|
|
if (color & 0xF0) {
|
|
|
|
color ^= color << 4;
|
|
|
|
color = ((x^y) & 1) ? color >> 4 : color & 0x0F;
|
|
|
|
*screenPtr = color; *displayPtr = color;
|
|
|
|
}
|
|
|
|
screenPtr++; displayPtr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2009-10-09 20:54:02 +00:00
|
|
|
if (!addToFlag)
|
|
|
|
memset(&_unditherMemorial, 0, sizeof(_unditherMemorial));
|
2009-10-09 20:21:21 +00:00
|
|
|
// Do dithering on visual screen and put decoded but undithered byte onto display-screen
|
|
|
|
for (y = 0; y < _height; y++) {
|
|
|
|
for (x = 0; x < _width; x++) {
|
|
|
|
color = *screenPtr;
|
|
|
|
if (color & 0xF0) {
|
|
|
|
color ^= color << 4;
|
2009-10-09 20:54:02 +00:00
|
|
|
// remember dither combination for cel-undithering
|
|
|
|
_unditherMemorial[color]++;
|
2009-10-09 20:21:21 +00:00
|
|
|
// if decoded color wants do dither with black on left side, we turn it around
|
|
|
|
// otherwise the normal ega color would get used for display
|
|
|
|
if (color & 0xF0) {
|
|
|
|
*displayPtr = color;
|
|
|
|
} else {
|
|
|
|
*displayPtr = color << 4;
|
|
|
|
}
|
|
|
|
color = ((x^y) & 1) ? color >> 4 : color & 0x0F;
|
|
|
|
*screenPtr = color;
|
|
|
|
}
|
|
|
|
screenPtr++; displayPtr++;
|
2009-10-05 22:42:41 +00:00
|
|
|
}
|
2009-10-05 21:38:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-07 21:47:34 +00:00
|
|
|
void SciGuiScreen::unditherSetState(bool flag) {
|
|
|
|
_unditherState = flag;
|
|
|
|
}
|
|
|
|
|
2009-10-09 20:54:02 +00:00
|
|
|
int16 *SciGuiScreen::unditherGetMemorial() {
|
|
|
|
if (_unditherState)
|
|
|
|
return (int16 *)&_unditherMemorial;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-07 15:53:34 +00:00
|
|
|
void SciGuiScreen::debugShowMap(int mapNo) {
|
|
|
|
switch (mapNo) {
|
|
|
|
case 0:
|
|
|
|
_activeScreen = _visualScreen;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
_activeScreen = _priorityScreen;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
_activeScreen = _controlScreen;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
_activeScreen = _displayScreen;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace Sci
|