MOHAWK: move shared setPalette/copyImage routines into GraphicsManager
svn-id: r54743
This commit is contained in:
parent
eb729b5f2e
commit
27799e354e
4 changed files with 114 additions and 99 deletions
|
@ -690,7 +690,7 @@ bool LivingBooksConsole::Cmd_DrawImage(int argc, const char **argv) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_vm->_gfx->copyImageToScreen((uint16)atoi(argv[1]));
|
_vm->_gfx->copyAnimImageToScreen((uint16)atoi(argv[1]));
|
||||||
_vm->_system->updateScreen();
|
_vm->_system->updateScreen();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,99 @@ MohawkSurface *GraphicsManager::findImage(uint16 id) {
|
||||||
return _cache[id];
|
return _cache[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GraphicsManager::preloadImage(uint16 image) {
|
||||||
|
findImage(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsManager::setPalette(uint16 id) {
|
||||||
|
Common::SeekableReadStream *tpalStream = getVM()->getResource(ID_TPAL, id);
|
||||||
|
|
||||||
|
uint16 colorStart = tpalStream->readUint16BE();
|
||||||
|
uint16 colorCount = tpalStream->readUint16BE();
|
||||||
|
byte *palette = new byte[colorCount * 4];
|
||||||
|
|
||||||
|
for (uint16 i = 0; i < colorCount; i++) {
|
||||||
|
palette[i * 4] = tpalStream->readByte();
|
||||||
|
palette[i * 4 + 1] = tpalStream->readByte();
|
||||||
|
palette[i * 4 + 2] = tpalStream->readByte();
|
||||||
|
palette[i * 4 + 3] = tpalStream->readByte();
|
||||||
|
}
|
||||||
|
|
||||||
|
delete tpalStream;
|
||||||
|
|
||||||
|
getVM()->_system->setPalette(palette, colorStart, colorCount);
|
||||||
|
delete[] palette;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsManager::copyAnimImageToScreen(uint16 image, int left, int top) {
|
||||||
|
Graphics::Surface *surface = findImage(image)->getSurface();
|
||||||
|
|
||||||
|
Common::Rect srcRect(0, 0, surface->w, surface->h);
|
||||||
|
Common::Rect dstRect(left, top, left + surface->w, top + surface->h);
|
||||||
|
copyAnimImageSectionToScreen(image, srcRect, dstRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphicsManager::copyAnimImageSectionToScreen(uint16 image, Common::Rect srcRect, Common::Rect dstRect) {
|
||||||
|
uint16 startX = 0;
|
||||||
|
uint16 startY = 0;
|
||||||
|
|
||||||
|
assert(srcRect.isValidRect() && dstRect.isValidRect());
|
||||||
|
assert(srcRect.left >= 0 && srcRect.top >= 0);
|
||||||
|
|
||||||
|
// TODO: clip rect
|
||||||
|
if (dstRect.left < 0) {
|
||||||
|
startX -= dstRect.left;
|
||||||
|
dstRect.left = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dstRect.top < 0) {
|
||||||
|
startY -= dstRect.top;
|
||||||
|
dstRect.top = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dstRect.left >= getVM()->_system->getWidth())
|
||||||
|
return;
|
||||||
|
if (dstRect.top >= getVM()->_system->getHeight())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Graphics::Surface *surface = findImage(image)->getSurface();
|
||||||
|
if (startX >= surface->w)
|
||||||
|
return;
|
||||||
|
if (startY >= surface->h)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (srcRect.left > surface->w)
|
||||||
|
return;
|
||||||
|
if (srcRect.top > surface->h)
|
||||||
|
return;
|
||||||
|
if (srcRect.right > surface->w)
|
||||||
|
srcRect.right = surface->w;
|
||||||
|
if (srcRect.bottom > surface->h)
|
||||||
|
srcRect.bottom = surface->h;
|
||||||
|
|
||||||
|
uint16 width = MIN<int>(srcRect.right - srcRect.left - startX, getVM()->_system->getWidth() - dstRect.left);
|
||||||
|
uint16 height = MIN<int>(srcRect.bottom - srcRect.top - startY, getVM()->_system->getHeight() - dstRect.top);
|
||||||
|
|
||||||
|
byte *surf = (byte *)surface->getBasePtr(0, srcRect.top + startY);
|
||||||
|
Graphics::Surface *screen = getVM()->_system->lockScreen();
|
||||||
|
|
||||||
|
// image and screen should always be 8bpp
|
||||||
|
for (uint16 y = 0; y < height; y++) {
|
||||||
|
byte *dest = (byte *)screen->getBasePtr(dstRect.left, dstRect.top + y);
|
||||||
|
byte *src = surf + srcRect.left + startX;
|
||||||
|
// blit, with 0 being transparent
|
||||||
|
for (uint16 x = 0; x < width; x++) {
|
||||||
|
if (*src)
|
||||||
|
*dest = *src;
|
||||||
|
src++;
|
||||||
|
dest++;
|
||||||
|
}
|
||||||
|
surf += surface->pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
getVM()->_system->unlockScreen();
|
||||||
|
}
|
||||||
|
|
||||||
MystGraphics::MystGraphics(MohawkEngine_Myst* vm) : GraphicsManager(), _vm(vm) {
|
MystGraphics::MystGraphics(MohawkEngine_Myst* vm) : GraphicsManager(), _vm(vm) {
|
||||||
_bmpDecoder = new MystBitmap();
|
_bmpDecoder = new MystBitmap();
|
||||||
|
|
||||||
|
@ -784,85 +877,13 @@ MohawkSurface *LBGraphics::decodeImage(uint16 id) {
|
||||||
return _bmpDecoder->decodeImage(_vm->getResource(ID_TBMP, id));
|
return _bmpDecoder->decodeImage(_vm->getResource(ID_TBMP, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBGraphics::preloadImage(uint16 image) {
|
void LBGraphics::copyOffsetAnimImageToScreen(uint16 image, int left, int top) {
|
||||||
findImage(image);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LBGraphics::copyImageToScreen(uint16 image, bool useOffsets, int left, int top) {
|
|
||||||
MohawkSurface *mhkSurface = findImage(image);
|
|
||||||
Graphics::Surface *surface = mhkSurface->getSurface();
|
|
||||||
|
|
||||||
if (useOffsets) {
|
|
||||||
left -= mhkSurface->getOffsetX();
|
|
||||||
top -= mhkSurface->getOffsetY();
|
|
||||||
}
|
|
||||||
|
|
||||||
Common::Rect srcRect(0, 0, surface->w, surface->h);
|
|
||||||
Common::Rect dstRect(left, top, left + surface->w, top + surface->h);
|
|
||||||
copyImageSectionToScreen(image, srcRect, dstRect);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LBGraphics::copyImageSectionToScreen(uint16 image, Common::Rect srcRect, Common::Rect dstRect) {
|
|
||||||
MohawkSurface *mhkSurface = findImage(image);
|
MohawkSurface *mhkSurface = findImage(image);
|
||||||
|
|
||||||
uint16 startX = 0;
|
left -= mhkSurface->getOffsetX();
|
||||||
uint16 startY = 0;
|
top -= mhkSurface->getOffsetY();
|
||||||
|
|
||||||
assert(srcRect.isValidRect() && dstRect.isValidRect());
|
GraphicsManager::copyAnimImageToScreen(image, left, top);
|
||||||
assert(srcRect.left >= 0 && srcRect.top >= 0);
|
|
||||||
|
|
||||||
// TODO: clip rect
|
|
||||||
if (dstRect.left < 0) {
|
|
||||||
startX -= dstRect.left;
|
|
||||||
dstRect.left = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dstRect.top < 0) {
|
|
||||||
startY -= dstRect.top;
|
|
||||||
dstRect.top = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dstRect.left >= _vm->_system->getWidth())
|
|
||||||
return;
|
|
||||||
if (dstRect.top >= _vm->_system->getHeight())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Graphics::Surface *surface = mhkSurface->getSurface();
|
|
||||||
if (startX >= surface->w)
|
|
||||||
return;
|
|
||||||
if (startY >= surface->h)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (srcRect.left > surface->w)
|
|
||||||
return;
|
|
||||||
if (srcRect.top > surface->h)
|
|
||||||
return;
|
|
||||||
if (srcRect.right > surface->w)
|
|
||||||
srcRect.right = surface->w;
|
|
||||||
if (srcRect.bottom > surface->h)
|
|
||||||
srcRect.bottom = surface->h;
|
|
||||||
|
|
||||||
uint16 width = MIN<int>(srcRect.right - srcRect.left - startX, _vm->_system->getWidth() - dstRect.left);
|
|
||||||
uint16 height = MIN<int>(srcRect.bottom - srcRect.top - startY, _vm->_system->getHeight() - dstRect.top);
|
|
||||||
|
|
||||||
byte *surf = (byte *)surface->getBasePtr(0, srcRect.top + startY);
|
|
||||||
Graphics::Surface *screen = _vm->_system->lockScreen();
|
|
||||||
|
|
||||||
// image and screen are always 8bpp for LB
|
|
||||||
for (uint16 y = 0; y < height; y++) {
|
|
||||||
byte *dest = (byte *)screen->getBasePtr(dstRect.left, dstRect.top + y);
|
|
||||||
byte *src = surf + srcRect.left + startX;
|
|
||||||
// blit, with 0 being transparent
|
|
||||||
for (uint16 x = 0; x < width; x++) {
|
|
||||||
if (*src)
|
|
||||||
*dest = *src;
|
|
||||||
src++;
|
|
||||||
dest++;
|
|
||||||
}
|
|
||||||
surf += surface->pitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
_vm->_system->unlockScreen();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LBGraphics::imageIsTransparentAt(uint16 image, bool useOffsets, int x, int y) {
|
bool LBGraphics::imageIsTransparentAt(uint16 image, bool useOffsets, int x, int y) {
|
||||||
|
@ -903,22 +924,7 @@ void LBGraphics::setPalette(uint16 id) {
|
||||||
_vm->_system->setPalette(palette, 0, colorCount);
|
_vm->_system->setPalette(palette, 0, colorCount);
|
||||||
delete[] palette;
|
delete[] palette;
|
||||||
} else {
|
} else {
|
||||||
Common::SeekableReadStream *tpalStream = _vm->getResource(ID_TPAL, id);
|
GraphicsManager::setPalette(id);
|
||||||
uint16 colorStart = tpalStream->readUint16BE();
|
|
||||||
uint16 colorCount = tpalStream->readUint16BE();
|
|
||||||
byte *palette = new byte[colorCount * 4];
|
|
||||||
|
|
||||||
for (uint16 i = 0; i < colorCount; i++) {
|
|
||||||
palette[i * 4] = tpalStream->readByte();
|
|
||||||
palette[i * 4 + 1] = tpalStream->readByte();
|
|
||||||
palette[i * 4 + 2] = tpalStream->readByte();
|
|
||||||
palette[i * 4 + 3] = tpalStream->readByte();
|
|
||||||
}
|
|
||||||
|
|
||||||
delete tpalStream;
|
|
||||||
|
|
||||||
_vm->_system->setPalette(palette, colorStart, colorCount);
|
|
||||||
delete[] palette;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
namespace Mohawk {
|
namespace Mohawk {
|
||||||
|
|
||||||
|
class MohawkEngine;
|
||||||
class MohawkEngine_Myst;
|
class MohawkEngine_Myst;
|
||||||
class MohawkEngine_Riven;
|
class MohawkEngine_Riven;
|
||||||
class MohawkEngine_LivingBooks;
|
class MohawkEngine_LivingBooks;
|
||||||
|
@ -83,6 +84,11 @@ public:
|
||||||
// Free all surfaces in the cache
|
// Free all surfaces in the cache
|
||||||
void clearCache();
|
void clearCache();
|
||||||
|
|
||||||
|
void preloadImage(uint16 image);
|
||||||
|
virtual void setPalette(uint16 id);
|
||||||
|
void copyAnimImageToScreen(uint16 image, int left = 0, int top = 0);
|
||||||
|
void copyAnimImageSectionToScreen(uint16 image, Common::Rect src, Common::Rect dest);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// findImage will search the cache to find the image.
|
// findImage will search the cache to find the image.
|
||||||
// If not found, it will call decodeImage to get a new one.
|
// If not found, it will call decodeImage to get a new one.
|
||||||
|
@ -91,6 +97,8 @@ protected:
|
||||||
// decodeImage will always return a new image.
|
// decodeImage will always return a new image.
|
||||||
virtual MohawkSurface *decodeImage(uint16 id) = 0;
|
virtual MohawkSurface *decodeImage(uint16 id) = 0;
|
||||||
|
|
||||||
|
virtual MohawkEngine *getVM() = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// An image cache that stores images until clearCache() is called
|
// An image cache that stores images until clearCache() is called
|
||||||
Common::HashMap<uint16, MohawkSurface*> _cache;
|
Common::HashMap<uint16, MohawkSurface*> _cache;
|
||||||
|
@ -110,6 +118,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MohawkSurface *decodeImage(uint16 id);
|
MohawkSurface *decodeImage(uint16 id);
|
||||||
|
MohawkEngine *getVM() { return (MohawkEngine *)_vm; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MohawkEngine_Myst *_vm;
|
MohawkEngine_Myst *_vm;
|
||||||
|
@ -177,6 +186,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MohawkSurface *decodeImage(uint16 id);
|
MohawkSurface *decodeImage(uint16 id);
|
||||||
|
MohawkEngine *getVM() { return (MohawkEngine *)_vm; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MohawkEngine_Riven *_vm;
|
MohawkEngine_Riven *_vm;
|
||||||
|
@ -205,14 +215,13 @@ public:
|
||||||
LBGraphics(MohawkEngine_LivingBooks *vm, uint16 width, uint16 height);
|
LBGraphics(MohawkEngine_LivingBooks *vm, uint16 width, uint16 height);
|
||||||
~LBGraphics();
|
~LBGraphics();
|
||||||
|
|
||||||
void preloadImage(uint16 image);
|
|
||||||
void copyImageToScreen(uint16 image, bool useOffsets = false, int left = 0, int top = 0);
|
|
||||||
void copyImageSectionToScreen(uint16 image, Common::Rect src, Common::Rect dest);
|
|
||||||
void setPalette(uint16 id);
|
void setPalette(uint16 id);
|
||||||
|
void copyOffsetAnimImageToScreen(uint16 image, int left = 0, int top = 0);
|
||||||
bool imageIsTransparentAt(uint16 image, bool useOffsets, int x, int y);
|
bool imageIsTransparentAt(uint16 image, bool useOffsets, int x, int y);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MohawkSurface *decodeImage(uint16 id);
|
MohawkSurface *decodeImage(uint16 id);
|
||||||
|
MohawkEngine *getVM() { return (MohawkEngine *)_vm; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MohawkBitmap *_bmpDecoder;
|
MohawkBitmap *_bmpDecoder;
|
||||||
|
|
|
@ -1030,7 +1030,7 @@ void LBAnimationNode::draw(const Common::Rect &_bounds) {
|
||||||
yOffset -= offset.y;
|
yOffset -= offset.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
_vm->_gfx->copyImageToScreen(resourceId, true, xOffset, yOffset);
|
_vm->_gfx->copyOffsetAnimImageToScreen(resourceId, xOffset, yOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBAnimationNode::reset() {
|
void LBAnimationNode::reset() {
|
||||||
|
@ -2289,7 +2289,7 @@ void LBLiveTextItem::drawWord(uint word, uint yPos) {
|
||||||
yPos + _words[word].bounds.bottom - _words[word].bounds.top);
|
yPos + _words[word].bounds.bottom - _words[word].bounds.top);
|
||||||
Common::Rect dstRect = _words[word].bounds;
|
Common::Rect dstRect = _words[word].bounds;
|
||||||
dstRect.translate(_rect.left, _rect.top);
|
dstRect.translate(_rect.left, _rect.top);
|
||||||
_vm->_gfx->copyImageSectionToScreen(_resourceId, srcRect, dstRect);
|
_vm->_gfx->copyAnimImageSectionToScreen(_resourceId, srcRect, dstRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LBLiveTextItem::handleMouseDown(Common::Point pos) {
|
void LBLiveTextItem::handleMouseDown(Common::Point pos) {
|
||||||
|
@ -2412,7 +2412,7 @@ void LBPictureItem::draw() {
|
||||||
if (!_visible)
|
if (!_visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_vm->_gfx->copyImageToScreen(_resourceId, false, _rect.left, _rect.top);
|
_vm->_gfx->copyAnimImageToScreen(_resourceId, _rect.left, _rect.top);
|
||||||
}
|
}
|
||||||
|
|
||||||
LBAnimationItem::LBAnimationItem(MohawkEngine_LivingBooks *vm, Common::Rect rect) : LBItem(vm, rect) {
|
LBAnimationItem::LBAnimationItem(MohawkEngine_LivingBooks *vm, Common::Rect rect) : LBItem(vm, rect) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue