2011-02-20 02:31:34 -05: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.
|
|
|
|
*
|
2011-09-09 14:02:23 -04:00
|
|
|
* Additional copyright for this file:
|
|
|
|
* Copyright (C) 1995-1997 Presto Studios, Inc.
|
|
|
|
*
|
2011-02-20 02:31:34 -05: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.
|
|
|
|
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
2011-09-09 14:02:23 -04:00
|
|
|
|
2011-09-21 21:33:33 -04:00
|
|
|
#include "common/events.h"
|
2011-02-20 02:31:34 -05:00
|
|
|
#include "common/file.h"
|
2011-05-03 17:17:27 -04:00
|
|
|
#include "common/textconsole.h"
|
2011-02-20 02:31:34 -05:00
|
|
|
#include "engines/util.h"
|
|
|
|
|
2011-09-10 10:41:36 -04:00
|
|
|
#include "pegasus/elements.h"
|
|
|
|
#include "pegasus/graphics.h"
|
2011-09-09 14:02:23 -04:00
|
|
|
|
2011-09-10 10:41:36 -04:00
|
|
|
namespace Pegasus {
|
2011-09-09 14:02:23 -04:00
|
|
|
|
2011-02-20 02:31:34 -05:00
|
|
|
GraphicsManager::GraphicsManager(PegasusEngine *vm) : _vm(vm) {
|
|
|
|
initGraphics(640, 480, true, NULL);
|
2011-09-09 14:02:23 -04:00
|
|
|
|
2011-09-15 20:50:21 -04:00
|
|
|
if (_vm->_system->getScreenFormat().bytesPerPixel == 1)
|
|
|
|
error("No true color mode available");
|
|
|
|
|
2011-09-09 14:02:23 -04:00
|
|
|
_backLayer = kMinAvailableOrder;
|
|
|
|
_frontLayer = kMaxAvailableOrder;
|
|
|
|
_firstDisplayElement = _lastDisplayElement = 0;
|
2011-09-15 20:50:21 -04:00
|
|
|
_workArea.create(640, 480, _vm->_system->getScreenFormat());
|
2011-09-26 00:17:21 -04:00
|
|
|
_modifiedScreen = false;
|
2011-02-20 02:31:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsManager::~GraphicsManager() {
|
2011-09-15 20:50:21 -04:00
|
|
|
_workArea.free();
|
2011-02-20 02:31:34 -05:00
|
|
|
}
|
|
|
|
|
2011-09-09 14:02:23 -04:00
|
|
|
void GraphicsManager::invalRect(const Common::Rect &rect) {
|
|
|
|
// We're using a simpler algorithm for dirty rect handling than the original
|
|
|
|
// The original was way too overcomplicated for what we need here now.
|
|
|
|
|
|
|
|
if (_dirtyRect.width() == 0 || _dirtyRect.height() == 0) {
|
|
|
|
// We have no dirty rect, so this is now our dirty rect
|
|
|
|
_dirtyRect = rect;
|
|
|
|
} else {
|
|
|
|
// Expand our dirty rect to include rect
|
2011-09-19 19:07:11 -04:00
|
|
|
_dirtyRect.extend(rect);
|
2011-09-09 14:02:23 -04:00
|
|
|
}
|
2011-09-21 21:09:58 -04:00
|
|
|
|
|
|
|
// Sanity check: clip our rect to the screen
|
|
|
|
_dirtyRect.right = MIN<int>(640, _dirtyRect.right);
|
|
|
|
_dirtyRect.bottom = MIN<int>(480, _dirtyRect.bottom);
|
2011-09-09 14:02:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsManager::addDisplayElement(DisplayElement *newElement) {
|
|
|
|
newElement->_elementOrder = CLIP<int>(newElement->_elementOrder, kMinAvailableOrder, kMaxAvailableOrder);
|
|
|
|
|
|
|
|
if (_firstDisplayElement) {
|
|
|
|
DisplayElement *runner = _firstDisplayElement;
|
|
|
|
DisplayElement *lastRunner = 0;
|
|
|
|
|
|
|
|
// Search for first element whose display order is greater than
|
|
|
|
// the new element's and add the new element just before it.
|
|
|
|
while (runner) {
|
|
|
|
if (newElement->_elementOrder < runner->_elementOrder) {
|
|
|
|
if (lastRunner) {
|
|
|
|
lastRunner->_nextElement = newElement;
|
|
|
|
newElement->_nextElement = runner;
|
|
|
|
} else {
|
|
|
|
newElement->_nextElement = _firstDisplayElement;
|
|
|
|
_firstDisplayElement = newElement;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lastRunner = runner;
|
|
|
|
runner = runner->_nextElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If got here and runner == NULL, we ran through the whole list without
|
|
|
|
// inserting, so add at the end.
|
|
|
|
if (!runner) {
|
|
|
|
_lastDisplayElement->_nextElement = newElement;
|
|
|
|
_lastDisplayElement = newElement;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_firstDisplayElement = newElement;
|
|
|
|
_lastDisplayElement = newElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
newElement->_elementIsDisplaying = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsManager::removeDisplayElement(DisplayElement *oldElement) {
|
|
|
|
if (!_firstDisplayElement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (oldElement == _firstDisplayElement) {
|
|
|
|
if (oldElement == _lastDisplayElement) {
|
|
|
|
_firstDisplayElement = 0;
|
|
|
|
_lastDisplayElement = 0;
|
|
|
|
} else {
|
|
|
|
_firstDisplayElement = oldElement->_nextElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
invalRect(oldElement->_bounds);
|
|
|
|
} else {
|
|
|
|
// Scan list for element.
|
|
|
|
// If we get here, we know that the list has at least one item, and it
|
|
|
|
// is not the first item, so we can skip it.
|
|
|
|
DisplayElement *runner = _firstDisplayElement->_nextElement;
|
|
|
|
DisplayElement *lastRunner = _firstDisplayElement;
|
|
|
|
|
|
|
|
while (runner) {
|
|
|
|
if (runner == oldElement) {
|
|
|
|
lastRunner->_nextElement = runner->_nextElement;
|
|
|
|
|
|
|
|
if (oldElement == _lastDisplayElement)
|
|
|
|
_lastDisplayElement = lastRunner;
|
|
|
|
|
|
|
|
invalRect(oldElement->_bounds);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastRunner = runner;
|
|
|
|
runner = runner->_nextElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
oldElement->_nextElement = 0;
|
|
|
|
oldElement->_elementIsDisplaying = false;
|
|
|
|
}
|
2011-09-15 20:50:21 -04:00
|
|
|
|
|
|
|
void GraphicsManager::updateDisplay() {
|
|
|
|
bool screenDirty = false;
|
|
|
|
|
|
|
|
if (!_dirtyRect.isEmpty()) {
|
|
|
|
for (DisplayElement *runner = _firstDisplayElement; runner != 0; runner = runner->_nextElement) {
|
|
|
|
Common::Rect bounds;
|
|
|
|
runner->getBounds(bounds);
|
|
|
|
|
|
|
|
// TODO: Better logic; it does a bit more work than it probably needs to
|
|
|
|
// but it should work fine for now.
|
2011-09-26 00:17:21 -04:00
|
|
|
if (bounds.intersects(_dirtyRect) && runner->validToDraw(_backLayer, _frontLayer)) {
|
2011-09-15 20:50:21 -04:00
|
|
|
runner->draw(bounds);
|
2011-09-26 00:17:21 -04:00
|
|
|
screenDirty = true;
|
|
|
|
}
|
2011-09-15 20:50:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy only the dirty rect to the screen
|
2011-09-26 00:17:21 -04:00
|
|
|
if (screenDirty)
|
|
|
|
g_system->copyRectToScreen((byte *)_workArea.getBasePtr(_dirtyRect.left, _dirtyRect.top), _workArea.pitch, _dirtyRect.left, _dirtyRect.top, _dirtyRect.width(), _dirtyRect.height());
|
2011-09-15 20:50:21 -04:00
|
|
|
|
|
|
|
// Clear the dirty rect
|
|
|
|
_dirtyRect = Common::Rect();
|
|
|
|
}
|
|
|
|
|
2011-09-26 00:17:21 -04:00
|
|
|
if (screenDirty || _modifiedScreen)
|
2011-09-15 20:50:21 -04:00
|
|
|
g_system->updateScreen();
|
2011-09-26 00:17:21 -04:00
|
|
|
|
|
|
|
_modifiedScreen = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsManager::clearScreen() {
|
|
|
|
Graphics::Surface *screen = g_system->lockScreen();
|
|
|
|
screen->fillRect(Common::Rect(0, 0, 640, 480), g_system->getScreenFormat().RGBToColor(0, 0, 0));
|
|
|
|
g_system->unlockScreen();
|
|
|
|
_modifiedScreen = true;
|
2011-09-15 20:50:21 -04:00
|
|
|
}
|
2011-09-28 14:25:55 -04:00
|
|
|
|
|
|
|
DisplayElement *GraphicsManager::findDisplayElement(const tDisplayElementID id) {
|
|
|
|
DisplayElement *runner = _firstDisplayElement;
|
|
|
|
|
|
|
|
while (runner) {
|
|
|
|
if (runner->getObjectID() == id)
|
|
|
|
return runner;
|
|
|
|
runner = runner->_nextElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-09-29 20:12:51 -04:00
|
|
|
|
2011-10-02 20:52:09 -04:00
|
|
|
void GraphicsManager::doFadeOutSync(const TimeValue, const TimeValue, uint32 color) {
|
|
|
|
if (color == 0)
|
|
|
|
color = g_system->getScreenFormat().RGBToColor(0, 0, 0);
|
|
|
|
|
|
|
|
// HACK: Until fading out is done, white-out the screen here
|
|
|
|
Graphics::Surface *screen = g_system->lockScreen();
|
|
|
|
screen->fillRect(Common::Rect(0, 0, 640, 480), color);
|
|
|
|
g_system->unlockScreen();
|
|
|
|
g_system->updateScreen();
|
2011-09-29 20:12:51 -04:00
|
|
|
}
|
|
|
|
|
2011-10-02 20:52:09 -04:00
|
|
|
void GraphicsManager::doFadeInSync(const TimeValue, const TimeValue, uint32) {
|
2011-09-29 20:12:51 -04:00
|
|
|
// TODO
|
|
|
|
}
|
2011-09-30 01:14:11 -04:00
|
|
|
|
|
|
|
void GraphicsManager::markCursorAsDirty() {
|
|
|
|
_modifiedScreen = true;
|
|
|
|
}
|
2011-02-20 02:31:34 -05:00
|
|
|
|
|
|
|
} // End of namespace Pegasus
|