2015-03-16 23:52:08 -04: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.
|
2015-05-09 18:04:13 +02:00
|
|
|
*
|
2015-03-16 23:52:08 -04:00
|
|
|
* 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.
|
2015-05-09 18:04:13 +02:00
|
|
|
*
|
2015-03-16 23:52:08 -04: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 "sherlock/screen.h"
|
|
|
|
#include "sherlock/sherlock.h"
|
2015-06-25 20:42:02 -04:00
|
|
|
#include "sherlock/scalpel/scalpel_screen.h"
|
2015-03-16 23:52:08 -04:00
|
|
|
#include "common/system.h"
|
2015-03-24 08:35:08 -04:00
|
|
|
#include "common/util.h"
|
2015-03-16 23:52:08 -04:00
|
|
|
#include "graphics/palette.h"
|
|
|
|
|
|
|
|
namespace Sherlock {
|
|
|
|
|
2015-06-25 20:42:02 -04:00
|
|
|
Screen *Screen::init(SherlockEngine *vm) {
|
|
|
|
if (vm->getGameID() == GType_SerratedScalpel)
|
|
|
|
return new Scalpel::ScalpelScreen(vm);
|
|
|
|
else
|
|
|
|
return new Screen(vm);
|
|
|
|
}
|
|
|
|
|
2015-06-18 19:21:04 -04:00
|
|
|
Screen::Screen(SherlockEngine *vm) : Surface(g_system->getWidth(), g_system->getHeight()), _vm(vm),
|
|
|
|
_backBuffer1(g_system->getWidth(), g_system->getHeight()),
|
|
|
|
_backBuffer2(g_system->getWidth(), g_system->getHeight()),
|
2015-03-28 20:13:57 -04:00
|
|
|
_backBuffer(&_backBuffer1) {
|
2015-03-18 19:02:17 -04:00
|
|
|
_transitionSeed = 1;
|
2015-03-18 22:32:41 -04:00
|
|
|
_fadeStyle = false;
|
2015-03-20 19:44:32 -04:00
|
|
|
Common::fill(&_cMap[0], &_cMap[PALETTE_SIZE], 0);
|
|
|
|
Common::fill(&_sMap[0], &_sMap[PALETTE_SIZE], 0);
|
2015-05-12 22:02:59 -04:00
|
|
|
Common::fill(&_tMap[0], &_tMap[PALETTE_SIZE], 0);
|
2015-06-10 19:46:14 -04:00
|
|
|
|
|
|
|
// Set up the initial font
|
2015-05-24 07:46:25 -04:00
|
|
|
setFont(IS_SERRATED_SCALPEL ? 1 : 4);
|
2015-04-30 11:23:31 -10:00
|
|
|
|
2015-05-12 22:02:59 -04:00
|
|
|
// Rose Tattoo specific fields
|
|
|
|
_fadeBytesRead = _fadeBytesToRead = 0;
|
|
|
|
_oldFadePercent = 0;
|
2015-05-27 22:36:51 -04:00
|
|
|
_flushScreen = false;
|
2015-03-16 23:52:08 -04:00
|
|
|
}
|
|
|
|
|
2015-03-24 08:35:08 -04:00
|
|
|
Screen::~Screen() {
|
2015-06-10 19:46:14 -04:00
|
|
|
Fonts::free();
|
2015-03-16 23:52:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::update() {
|
2015-03-17 00:01:12 -04:00
|
|
|
// Merge the dirty rects
|
|
|
|
mergeDirtyRects();
|
|
|
|
|
|
|
|
// Loop through copying dirty areas to the physical screen
|
|
|
|
Common::List<Common::Rect>::iterator i;
|
|
|
|
for (i = _dirtyRects.begin(); i != _dirtyRects.end(); ++i) {
|
|
|
|
const Common::Rect &r = *i;
|
|
|
|
const byte *srcP = (const byte *)getBasePtr(r.left, r.top);
|
2015-05-19 09:10:35 -04:00
|
|
|
g_system->copyRectToScreen(srcP, _surface.pitch, r.left, r.top,
|
2015-03-17 00:01:12 -04:00
|
|
|
r.width(), r.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Signal the physical screen to update
|
2015-03-16 23:52:08 -04:00
|
|
|
g_system->updateScreen();
|
2015-03-17 00:01:12 -04:00
|
|
|
_dirtyRects.clear();
|
2015-03-16 23:52:08 -04:00
|
|
|
}
|
|
|
|
|
2015-06-13 20:35:00 +02:00
|
|
|
void Screen::makeAllDirty() {
|
|
|
|
addDirtyRect(Common::Rect(0, 0, this->w(), this->h()));
|
|
|
|
}
|
|
|
|
|
2015-03-16 23:52:08 -04:00
|
|
|
void Screen::getPalette(byte palette[PALETTE_SIZE]) {
|
|
|
|
g_system->getPaletteManager()->grabPalette(palette, 0, PALETTE_COUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::setPalette(const byte palette[PALETTE_SIZE]) {
|
|
|
|
g_system->getPaletteManager()->setPalette(palette, 0, PALETTE_COUNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Screen::equalizePalette(const byte palette[PALETTE_SIZE]) {
|
|
|
|
int total = 0;
|
|
|
|
byte tempPalette[PALETTE_SIZE];
|
|
|
|
getPalette(tempPalette);
|
|
|
|
|
|
|
|
// For any palette component that doesn't already match the given destination
|
|
|
|
// palette, change by 1 towards the reference palette component
|
|
|
|
for (int idx = 0; idx < PALETTE_SIZE; ++idx) {
|
2015-05-18 23:23:37 +02:00
|
|
|
if (tempPalette[idx] > palette[idx]) {
|
2015-03-17 08:31:29 -04:00
|
|
|
tempPalette[idx] = MAX((int)palette[idx], (int)tempPalette[idx] - 4);
|
2015-03-16 23:52:08 -04:00
|
|
|
++total;
|
|
|
|
} else if (tempPalette[idx] < palette[idx]) {
|
2015-03-17 08:31:29 -04:00
|
|
|
tempPalette[idx] = MIN((int)palette[idx], (int)tempPalette[idx] + 4);
|
2015-03-16 23:52:08 -04:00
|
|
|
++total;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (total > 0)
|
|
|
|
// Palette changed, so reload it
|
|
|
|
setPalette(tempPalette);
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2015-03-17 23:09:04 -04:00
|
|
|
void Screen::fadeToBlack(int speed) {
|
2015-03-16 23:52:08 -04:00
|
|
|
byte tempPalette[PALETTE_SIZE];
|
2015-03-17 23:09:04 -04:00
|
|
|
Common::fill(&tempPalette[0], &tempPalette[PALETTE_SIZE], 0);
|
2015-03-16 23:52:08 -04:00
|
|
|
|
2015-03-17 23:09:04 -04:00
|
|
|
while (equalizePalette(tempPalette)) {
|
|
|
|
_vm->_events->delay(15 * speed);
|
|
|
|
}
|
2015-03-16 23:52:08 -04:00
|
|
|
|
2015-03-17 23:09:04 -04:00
|
|
|
setPalette(tempPalette);
|
2015-05-19 09:10:35 -04:00
|
|
|
fillRect(Common::Rect(0, 0, _surface.w, _surface.h), 0);
|
2015-03-17 23:09:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::fadeIn(const byte palette[PALETTE_SIZE], int speed) {
|
|
|
|
int count = 50;
|
|
|
|
while (equalizePalette(palette) && --count) {
|
|
|
|
_vm->_events->delay(15 * speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
setPalette(palette);
|
2015-03-16 23:52:08 -04:00
|
|
|
}
|
|
|
|
|
2015-03-17 00:01:12 -04:00
|
|
|
void Screen::addDirtyRect(const Common::Rect &r) {
|
|
|
|
_dirtyRects.push_back(r);
|
2015-05-13 18:08:06 -04:00
|
|
|
assert(r.width() > 0 && r.height() > 0);
|
2015-03-17 00:01:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::mergeDirtyRects() {
|
|
|
|
Common::List<Common::Rect>::iterator rOuter, rInner;
|
|
|
|
|
|
|
|
// Process the dirty rect list to find any rects to merge
|
|
|
|
for (rOuter = _dirtyRects.begin(); rOuter != _dirtyRects.end(); ++rOuter) {
|
|
|
|
rInner = rOuter;
|
|
|
|
while (++rInner != _dirtyRects.end()) {
|
|
|
|
|
|
|
|
if ((*rOuter).intersects(*rInner)) {
|
|
|
|
// these two rectangles overlap or
|
|
|
|
// are next to each other - merge them
|
|
|
|
|
|
|
|
unionRectangle(*rOuter, *rOuter, *rInner);
|
|
|
|
|
|
|
|
// remove the inner rect from the list
|
|
|
|
_dirtyRects.erase(rInner);
|
|
|
|
|
|
|
|
// move back to beginning of list
|
|
|
|
rInner = rOuter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Screen::unionRectangle(Common::Rect &destRect, const Common::Rect &src1, const Common::Rect &src2) {
|
|
|
|
destRect = src1;
|
|
|
|
destRect.extend(src2);
|
|
|
|
|
|
|
|
return !destRect.isEmpty();
|
|
|
|
}
|
|
|
|
|
2015-03-17 23:09:04 -04:00
|
|
|
void Screen::randomTransition() {
|
2015-03-21 20:25:15 -04:00
|
|
|
Events &events = *_vm->_events;
|
2015-03-18 19:02:17 -04:00
|
|
|
const int TRANSITION_MULTIPLIER = 0x15a4e35;
|
|
|
|
_dirtyRects.clear();
|
2015-05-24 23:15:33 -04:00
|
|
|
assert(IS_SERRATED_SCALPEL);
|
2015-03-17 23:09:04 -04:00
|
|
|
|
2015-05-01 20:33:56 -10:00
|
|
|
for (int idx = 0; idx <= 65535 && !_vm->shouldQuit(); ++idx) {
|
2015-03-18 19:02:17 -04:00
|
|
|
_transitionSeed = _transitionSeed * TRANSITION_MULTIPLIER + 1;
|
2015-05-18 23:23:37 +02:00
|
|
|
int offset = _transitionSeed & 0xFFFF;
|
2015-03-18 19:02:17 -04:00
|
|
|
|
2015-05-22 22:31:21 -04:00
|
|
|
if (offset < (this->w() * this->h()))
|
2015-03-28 20:13:57 -04:00
|
|
|
*((byte *)getPixels() + offset) = *((const byte *)_backBuffer->getPixels() + offset);
|
2015-05-07 19:33:44 +02:00
|
|
|
|
2015-05-15 20:44:12 -04:00
|
|
|
if (idx != 0 && (idx % 300) == 0) {
|
2015-03-18 19:02:17 -04:00
|
|
|
// Ensure there's a full screen dirty rect for the next frame update
|
|
|
|
if (_dirtyRects.empty())
|
2015-05-19 09:10:35 -04:00
|
|
|
addDirtyRect(Common::Rect(0, 0, _surface.w, _surface.h));
|
2015-05-07 19:33:44 +02:00
|
|
|
|
2015-03-18 19:02:17 -04:00
|
|
|
events.pollEvents();
|
|
|
|
events.delay(1);
|
2015-03-17 23:09:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure everything has been transferred
|
2015-05-12 19:14:39 -04:00
|
|
|
blitFrom(*_backBuffer);
|
2015-03-17 23:09:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::verticalTransition() {
|
2015-03-21 20:25:15 -04:00
|
|
|
Events &events = *_vm->_events;
|
2015-03-17 23:09:04 -04:00
|
|
|
|
2015-05-12 22:02:59 -04:00
|
|
|
byte table[640];
|
|
|
|
Common::fill(&table[0], &table[640], 0);
|
2015-05-07 19:33:44 +02:00
|
|
|
|
2015-05-22 22:31:21 -04:00
|
|
|
for (int yp = 0; yp < this->h(); ++yp) {
|
|
|
|
for (int xp = 0; xp < this->w(); ++xp) {
|
|
|
|
int temp = (table[xp] >= (this->h() - 3)) ? this->h() - table[xp] :
|
2015-03-17 23:09:04 -04:00
|
|
|
_vm->getRandomNumber(3) + 1;
|
|
|
|
|
|
|
|
if (temp) {
|
2015-03-28 20:13:57 -04:00
|
|
|
blitFrom(_backBuffer1, Common::Point(xp, table[xp]),
|
2015-03-17 23:09:04 -04:00
|
|
|
Common::Rect(xp, table[xp], xp + 1, table[xp] + temp));
|
|
|
|
table[xp] += temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
events.delay(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-09 12:14:41 +02:00
|
|
|
void Screen::fadeIntoScreen3DO(int speed) {
|
|
|
|
Events &events = *_vm->_events;
|
|
|
|
uint16 *currentScreenBasePtr = (uint16 *)getPixels();
|
|
|
|
uint16 *targetScreenBasePtr = (uint16 *)_backBuffer->getPixels();
|
|
|
|
uint16 currentScreenPixel = 0;
|
|
|
|
uint16 targetScreenPixel = 0;
|
|
|
|
|
|
|
|
uint16 currentScreenPixelRed = 0;
|
|
|
|
uint16 currentScreenPixelGreen = 0;
|
|
|
|
uint16 currentScreenPixelBlue = 0;
|
|
|
|
|
|
|
|
uint16 targetScreenPixelRed = 0;
|
|
|
|
uint16 targetScreenPixelGreen = 0;
|
|
|
|
uint16 targetScreenPixelBlue = 0;
|
|
|
|
|
|
|
|
uint16 screenWidth = this->w();
|
|
|
|
uint16 screenHeight = this->h();
|
|
|
|
uint16 screenX = 0;
|
|
|
|
uint16 screenY = 0;
|
|
|
|
uint16 pixelsChanged = 0;
|
|
|
|
|
|
|
|
_dirtyRects.clear();
|
|
|
|
|
|
|
|
do {
|
|
|
|
pixelsChanged = 0;
|
2015-06-13 08:07:34 +02:00
|
|
|
uint16 *currentScreenPtr = currentScreenBasePtr;
|
|
|
|
uint16 *targetScreenPtr = targetScreenBasePtr;
|
2015-06-09 12:14:41 +02:00
|
|
|
|
|
|
|
for (screenY = 0; screenY < screenHeight; screenY++) {
|
|
|
|
for (screenX = 0; screenX < screenWidth; screenX++) {
|
|
|
|
currentScreenPixel = *currentScreenPtr;
|
|
|
|
targetScreenPixel = *targetScreenPtr;
|
|
|
|
|
|
|
|
if (currentScreenPixel != targetScreenPixel) {
|
|
|
|
// pixel doesn't match, adjust accordingly
|
|
|
|
currentScreenPixelRed = currentScreenPixel & 0xF800;
|
|
|
|
currentScreenPixelGreen = currentScreenPixel & 0x07E0;
|
|
|
|
currentScreenPixelBlue = currentScreenPixel & 0x001F;
|
|
|
|
targetScreenPixelRed = targetScreenPixel & 0xF800;
|
|
|
|
targetScreenPixelGreen = targetScreenPixel & 0x07E0;
|
|
|
|
targetScreenPixelBlue = targetScreenPixel & 0x001F;
|
|
|
|
|
|
|
|
if (currentScreenPixelRed != targetScreenPixelRed) {
|
|
|
|
if (currentScreenPixelRed < targetScreenPixelRed) {
|
|
|
|
currentScreenPixelRed += 0x0800;
|
|
|
|
} else {
|
|
|
|
currentScreenPixelRed -= 0x0800;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentScreenPixelGreen != targetScreenPixelGreen) {
|
|
|
|
// Adjust +2/-2 because we are running RGB555 at RGB565
|
|
|
|
if (currentScreenPixelGreen < targetScreenPixelGreen) {
|
|
|
|
currentScreenPixelGreen += 0x0040;
|
|
|
|
} else {
|
|
|
|
currentScreenPixelGreen -= 0x0040;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentScreenPixelBlue != targetScreenPixelBlue) {
|
|
|
|
if (currentScreenPixelBlue < targetScreenPixelBlue) {
|
|
|
|
currentScreenPixelBlue += 0x0001;
|
|
|
|
} else {
|
|
|
|
currentScreenPixelBlue -= 0x0001;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*currentScreenPtr = currentScreenPixelRed | currentScreenPixelGreen | currentScreenPixelBlue;
|
|
|
|
pixelsChanged++;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentScreenPtr++;
|
|
|
|
targetScreenPtr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Too much considered dirty at the moment
|
|
|
|
addDirtyRect(Common::Rect(0, 0, screenWidth, screenHeight));
|
|
|
|
|
|
|
|
events.pollEvents();
|
|
|
|
events.delay(10 * speed);
|
|
|
|
} while ((pixelsChanged) && (!_vm->shouldQuit()));
|
|
|
|
}
|
|
|
|
|
2015-06-09 23:22:52 +02:00
|
|
|
void Screen::blitFrom3DOcolorLimit(uint16 limitColor) {
|
|
|
|
uint16 *currentScreenPtr = (uint16 *)getPixels();
|
|
|
|
uint16 *targetScreenPtr = (uint16 *)_backBuffer->getPixels();
|
|
|
|
uint16 currentScreenPixel = 0;
|
|
|
|
|
|
|
|
uint16 screenWidth = this->w();
|
|
|
|
uint16 screenHeight = this->h();
|
|
|
|
uint16 screenX = 0;
|
|
|
|
uint16 screenY = 0;
|
|
|
|
|
|
|
|
uint16 currentScreenPixelRed = 0;
|
|
|
|
uint16 currentScreenPixelGreen = 0;
|
|
|
|
uint16 currentScreenPixelBlue = 0;
|
|
|
|
|
|
|
|
uint16 limitPixelRed = limitColor & 0xF800;
|
|
|
|
uint16 limitPixelGreen = limitColor & 0x07E0;
|
|
|
|
uint16 limitPixelBlue = limitColor & 0x001F;
|
|
|
|
|
|
|
|
for (screenY = 0; screenY < screenHeight; screenY++) {
|
|
|
|
for (screenX = 0; screenX < screenWidth; screenX++) {
|
|
|
|
currentScreenPixel = *targetScreenPtr;
|
|
|
|
|
|
|
|
currentScreenPixelRed = currentScreenPixel & 0xF800;
|
|
|
|
currentScreenPixelGreen = currentScreenPixel & 0x07E0;
|
|
|
|
currentScreenPixelBlue = currentScreenPixel & 0x001F;
|
|
|
|
|
|
|
|
if (currentScreenPixelRed < limitPixelRed)
|
|
|
|
currentScreenPixelRed = limitPixelRed;
|
|
|
|
if (currentScreenPixelGreen < limitPixelGreen)
|
|
|
|
currentScreenPixelGreen = limitPixelGreen;
|
|
|
|
if (currentScreenPixelBlue < limitPixelBlue)
|
|
|
|
currentScreenPixelBlue = limitPixelBlue;
|
|
|
|
|
|
|
|
*currentScreenPtr = currentScreenPixelRed | currentScreenPixelGreen | currentScreenPixelBlue;
|
|
|
|
currentScreenPtr++;
|
|
|
|
targetScreenPtr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Too much considered dirty at the moment
|
|
|
|
addDirtyRect(Common::Rect(0, 0, screenWidth, screenHeight));
|
|
|
|
}
|
|
|
|
|
2015-03-22 00:52:02 -04:00
|
|
|
void Screen::restoreBackground(const Common::Rect &r) {
|
2015-07-05 22:14:29 -04:00
|
|
|
if (r.width() > 0 && r.height() > 0)
|
|
|
|
_backBuffer1.blitFrom(_backBuffer2, Common::Point(r.left, r.top), r);
|
2015-03-22 00:52:02 -04:00
|
|
|
}
|
|
|
|
|
2015-05-08 18:01:51 +02:00
|
|
|
void Screen::slamArea(int16 xp, int16 yp, int16 width, int16 height) {
|
|
|
|
slamRect(Common::Rect(xp, yp, xp + width, yp + height));
|
2015-03-22 00:52:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Screen::slamRect(const Common::Rect &r) {
|
2015-06-30 08:29:09 -04:00
|
|
|
if (r.width() && r.height() > 0) {
|
|
|
|
Common::Rect srcRect = r, destRect = r;
|
2015-07-04 11:28:55 -04:00
|
|
|
srcRect.translate(_currentScroll.x, _currentScroll.y);
|
2015-06-30 08:29:09 -04:00
|
|
|
|
|
|
|
if (destRect.left < 0) {
|
|
|
|
srcRect.left += -destRect.left;
|
|
|
|
destRect.left = 0;
|
|
|
|
}
|
|
|
|
if (destRect.top < 0) {
|
|
|
|
srcRect.top += -destRect.top;
|
|
|
|
destRect.top = 0;
|
|
|
|
}
|
|
|
|
if (destRect.right > SHERLOCK_SCREEN_WIDTH) {
|
|
|
|
srcRect.right -= (destRect.left - SHERLOCK_SCREEN_WIDTH);
|
|
|
|
destRect.right = SHERLOCK_SCREEN_WIDTH;
|
|
|
|
}
|
|
|
|
if (destRect.bottom > SHERLOCK_SCREEN_HEIGHT) {
|
|
|
|
srcRect.bottom -= (destRect.bottom - SHERLOCK_SCREEN_HEIGHT);
|
|
|
|
destRect.bottom = SHERLOCK_SCREEN_HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srcRect.isValidRect())
|
|
|
|
blitFrom(*_backBuffer, Common::Point(destRect.left, destRect.top), srcRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-28 19:59:03 -04:00
|
|
|
void Screen::flushImage(ImageFrame *frame, const Common::Point &pt, int16 *xp, int16 *yp,
|
|
|
|
int16 *width, int16 *height) {
|
2015-03-22 00:52:02 -04:00
|
|
|
Common::Point imgPos = pt + frame->_offset;
|
|
|
|
Common::Rect newBounds(imgPos.x, imgPos.y, imgPos.x + frame->_frame.w, imgPos.y + frame->_frame.h);
|
2015-05-08 18:01:51 +02:00
|
|
|
Common::Rect oldBounds(*xp, *yp, *xp + *width, *yp + *height);
|
2015-03-22 00:52:02 -04:00
|
|
|
|
2015-05-28 19:59:03 -04:00
|
|
|
if (!_flushScreen) {
|
|
|
|
// See if the areas of the old and new overlap, and if so combine the areas
|
|
|
|
if (newBounds.intersects(oldBounds)) {
|
|
|
|
Common::Rect mergedBounds = newBounds;
|
|
|
|
mergedBounds.extend(oldBounds);
|
|
|
|
mergedBounds.right += 1;
|
|
|
|
mergedBounds.bottom += 1;
|
|
|
|
|
|
|
|
slamRect(mergedBounds);
|
|
|
|
} else {
|
|
|
|
// The two areas are independent, so copy them both
|
|
|
|
slamRect(newBounds);
|
|
|
|
slamRect(oldBounds);
|
|
|
|
}
|
2015-03-22 00:52:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
*xp = newBounds.left;
|
|
|
|
*yp = newBounds.top;
|
2015-05-08 18:01:51 +02:00
|
|
|
*width = newBounds.width();
|
|
|
|
*height = newBounds.height();
|
2015-03-22 00:52:02 -04:00
|
|
|
}
|
|
|
|
|
2015-05-28 19:59:03 -04:00
|
|
|
void Screen::flushScaleImage(ImageFrame *frame, const Common::Point &pt, int16 *xp, int16 *yp,
|
|
|
|
int16 *width, int16 *height, int scaleVal) {
|
2015-05-28 21:47:52 -04:00
|
|
|
Common::Point imgPos = pt + frame->_offset;
|
|
|
|
Common::Rect newBounds(imgPos.x, imgPos.y, imgPos.x + frame->sDrawXSize(scaleVal),
|
|
|
|
imgPos.y + frame->sDrawYSize(scaleVal));
|
|
|
|
Common::Rect oldBounds(*xp, *yp, *xp + *width, *yp + *height);
|
|
|
|
|
|
|
|
if (!_flushScreen) {
|
|
|
|
// See if the areas of the old and new overlap, and if so combine the areas
|
|
|
|
if (newBounds.intersects(oldBounds)) {
|
|
|
|
Common::Rect mergedBounds = newBounds;
|
|
|
|
mergedBounds.extend(oldBounds);
|
|
|
|
mergedBounds.right += 1;
|
|
|
|
mergedBounds.bottom += 1;
|
|
|
|
|
|
|
|
slamRect(mergedBounds);
|
|
|
|
} else {
|
|
|
|
// The two areas are independent, so copy them both
|
|
|
|
slamRect(newBounds);
|
|
|
|
slamRect(oldBounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*xp = newBounds.left;
|
|
|
|
*yp = newBounds.top;
|
|
|
|
*width = newBounds.width();
|
|
|
|
*height = newBounds.height();
|
2015-05-28 19:59:03 -04:00
|
|
|
}
|
|
|
|
|
2015-05-31 17:55:56 -04:00
|
|
|
void Screen::flushImage(ImageFrame *frame, const Common::Point &pt, Common::Rect &newBounds, int scaleVal) {
|
|
|
|
Common::Point newPos, newSize;
|
|
|
|
|
|
|
|
if (scaleVal == 256)
|
|
|
|
flushImage(frame, pt, &newPos.x, &newPos.y, &newSize.x, &newSize.y);
|
|
|
|
else
|
|
|
|
flushScaleImage(frame, pt, &newPos.x, &newPos.y, &newSize.x, &newSize.y, scaleVal);
|
|
|
|
|
|
|
|
// Transfer the pos and size amounts into a single bounds rect
|
|
|
|
newBounds = Common::Rect(newPos.x, newPos.y, newPos.x + newSize.x, newPos.y + newSize.y);
|
|
|
|
}
|
|
|
|
|
2015-07-04 11:28:55 -04:00
|
|
|
void Screen::blockMove(const Common::Rect &r) {
|
2015-05-31 16:28:41 -04:00
|
|
|
Common::Rect bounds = r;
|
|
|
|
slamRect(bounds);
|
|
|
|
}
|
|
|
|
|
2015-07-04 11:28:55 -04:00
|
|
|
void Screen::blockMove() {
|
|
|
|
blockMove(Common::Rect(0, 0, w(), h()));
|
2015-05-31 16:28:41 -04:00
|
|
|
}
|
|
|
|
|
2015-05-08 18:28:45 +02:00
|
|
|
void Screen::print(const Common::Point &pt, byte color, const char *formatStr, ...) {
|
2015-03-24 08:35:08 -04:00
|
|
|
// Create the string to display
|
|
|
|
va_list args;
|
2015-05-08 18:28:45 +02:00
|
|
|
va_start(args, formatStr);
|
2015-05-18 20:57:58 -04:00
|
|
|
Common::String str = Common::String::vformat(formatStr, args);
|
2015-03-24 08:35:08 -04:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
// Figure out area to draw text in
|
|
|
|
Common::Point pos = pt;
|
|
|
|
int width = stringWidth(str);
|
|
|
|
pos.y--; // Font is always drawing one line higher
|
|
|
|
if (!pos.x)
|
|
|
|
// Center text horizontally
|
2015-05-22 22:31:21 -04:00
|
|
|
pos.x = (this->w() - width) / 2;
|
2015-03-24 08:35:08 -04:00
|
|
|
|
|
|
|
Common::Rect textBounds(pos.x, pos.y, pos.x + width, pos.y + _fontHeight);
|
2015-05-22 22:31:21 -04:00
|
|
|
if (textBounds.right > this->w())
|
|
|
|
textBounds.moveTo(this->w() - width, textBounds.top);
|
|
|
|
if (textBounds.bottom > this->h())
|
|
|
|
textBounds.moveTo(textBounds.left, this->h() - _fontHeight);
|
2015-03-24 08:35:08 -04:00
|
|
|
|
|
|
|
// Write out the string at the given position
|
2015-03-26 21:40:24 -04:00
|
|
|
writeString(str, Common::Point(textBounds.left, textBounds.top), color);
|
2015-03-24 08:35:08 -04:00
|
|
|
|
|
|
|
// Copy the affected area to the screen
|
|
|
|
slamRect(textBounds);
|
|
|
|
}
|
|
|
|
|
2015-05-08 18:28:45 +02:00
|
|
|
void Screen::gPrint(const Common::Point &pt, byte color, const char *formatStr, ...) {
|
2015-03-26 21:40:24 -04:00
|
|
|
// Create the string to display
|
|
|
|
va_list args;
|
2015-05-08 18:28:45 +02:00
|
|
|
va_start(args, formatStr);
|
2015-05-18 20:57:58 -04:00
|
|
|
Common::String str = Common::String::vformat(formatStr, args);
|
2015-03-26 21:40:24 -04:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
// Print the text
|
|
|
|
writeString(str, pt, color);
|
|
|
|
}
|
|
|
|
|
2015-06-10 19:46:14 -04:00
|
|
|
void Screen::writeString(const Common::String &str, const Common::Point &pt, byte overrideColor) {
|
|
|
|
Fonts::writeString(_backBuffer, str, pt, overrideColor);
|
2015-03-24 08:35:08 -04:00
|
|
|
}
|
|
|
|
|
2015-03-27 22:12:37 -04:00
|
|
|
void Screen::vgaBar(const Common::Rect &r, int color) {
|
2015-03-28 20:13:57 -04:00
|
|
|
_backBuffer->fillRect(r, color);
|
2015-03-24 20:14:13 -04:00
|
|
|
slamRect(r);
|
|
|
|
}
|
2015-03-24 08:35:08 -04:00
|
|
|
|
2015-03-30 21:07:01 -04:00
|
|
|
void Screen::setDisplayBounds(const Common::Rect &r) {
|
2015-07-03 21:12:14 -04:00
|
|
|
_sceneSurface.setPixels(_backBuffer1.getBasePtr(r.left, r.top), r.width(), r.height(), _backBuffer1.getPixelFormat());
|
2015-04-30 11:23:31 -10:00
|
|
|
|
|
|
|
_backBuffer = &_sceneSurface;
|
2015-03-30 21:07:01 -04:00
|
|
|
}
|
2015-04-30 11:23:31 -10:00
|
|
|
|
2015-03-30 21:07:01 -04:00
|
|
|
void Screen::resetDisplayBounds() {
|
2015-04-30 11:23:31 -10:00
|
|
|
_backBuffer = &_backBuffer1;
|
2015-03-30 21:07:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Rect Screen::getDisplayBounds() {
|
2015-05-19 09:10:35 -04:00
|
|
|
return (_backBuffer == &_sceneSurface) ? Common::Rect(0, 0, _sceneSurface.w(), _sceneSurface.h()) :
|
2015-05-22 22:31:21 -04:00
|
|
|
Common::Rect(0, 0, this->w(), this->h());
|
2015-03-30 21:07:01 -04:00
|
|
|
}
|
|
|
|
|
2015-06-07 19:18:14 -04:00
|
|
|
void Screen::synchronize(Serializer &s) {
|
2015-05-08 18:28:45 +02:00
|
|
|
int fontNumb = _fontNumber;
|
|
|
|
s.syncAsByte(fontNumb);
|
2015-04-21 22:51:03 -05:00
|
|
|
if (s.isLoading())
|
2015-05-08 18:28:45 +02:00
|
|
|
setFont(fontNumb);
|
2015-04-21 22:51:03 -05:00
|
|
|
}
|
|
|
|
|
2015-05-12 22:02:59 -04:00
|
|
|
void Screen::initPaletteFade(int bytesToRead) {
|
|
|
|
Common::copy(&_cMap[0], &_cMap[PALETTE_SIZE], &_sMap[0]);
|
|
|
|
Common::copy(&_cMap[0], &_cMap[PALETTE_SIZE], &_tMap[0]);
|
|
|
|
|
|
|
|
// Set how many bytes need to be read / have been read
|
|
|
|
_fadeBytesRead = 0;
|
|
|
|
_fadeBytesToRead = bytesToRead;
|
|
|
|
_oldFadePercent = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Screen::fadeRead(Common::SeekableReadStream &stream, byte *buf, int totalSize) {
|
|
|
|
warning("TODO: fadeRead");
|
|
|
|
stream.read(buf, totalSize);
|
|
|
|
return totalSize;
|
|
|
|
}
|
|
|
|
|
2015-05-24 07:46:25 -04:00
|
|
|
void Screen::translatePalette(byte palette[PALETTE_SIZE]) {
|
|
|
|
for (int idx = 0; idx < PALETTE_SIZE; ++idx)
|
|
|
|
palette[idx] = VGA_COLOR_TRANS(palette[idx]);
|
|
|
|
}
|
|
|
|
|
2015-03-16 23:52:08 -04:00
|
|
|
} // End of namespace Sherlock
|