aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/mohawk/console.cpp2
-rw-r--r--engines/mohawk/graphics.cpp190
-rw-r--r--engines/mohawk/graphics.h15
-rw-r--r--engines/mohawk/livingbooks.cpp6
4 files changed, 114 insertions, 99 deletions
diff --git a/engines/mohawk/console.cpp b/engines/mohawk/console.cpp
index 2709cac52b..65479c555c 100644
--- a/engines/mohawk/console.cpp
+++ b/engines/mohawk/console.cpp
@@ -690,7 +690,7 @@ bool LivingBooksConsole::Cmd_DrawImage(int argc, const char **argv) {
return true;
}
- _vm->_gfx->copyImageToScreen((uint16)atoi(argv[1]));
+ _vm->_gfx->copyAnimImageToScreen((uint16)atoi(argv[1]));
_vm->_system->updateScreen();
return false;
}
diff --git a/engines/mohawk/graphics.cpp b/engines/mohawk/graphics.cpp
index 8ffbe2f81b..8812b2edb2 100644
--- a/engines/mohawk/graphics.cpp
+++ b/engines/mohawk/graphics.cpp
@@ -117,6 +117,99 @@ MohawkSurface *GraphicsManager::findImage(uint16 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) {
_bmpDecoder = new MystBitmap();
@@ -784,85 +877,13 @@ MohawkSurface *LBGraphics::decodeImage(uint16 id) {
return _bmpDecoder->decodeImage(_vm->getResource(ID_TBMP, id));
}
-void LBGraphics::preloadImage(uint16 image) {
- 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) {
+void LBGraphics::copyOffsetAnimImageToScreen(uint16 image, int left, int top) {
MohawkSurface *mhkSurface = findImage(image);
- 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 >= _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();
+ left -= mhkSurface->getOffsetX();
+ top -= mhkSurface->getOffsetY();
- // 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();
+ GraphicsManager::copyAnimImageToScreen(image, left, top);
}
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);
delete[] palette;
} else {
- Common::SeekableReadStream *tpalStream = _vm->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;
-
- _vm->_system->setPalette(palette, colorStart, colorCount);
- delete[] palette;
+ GraphicsManager::setPalette(id);
}
}
diff --git a/engines/mohawk/graphics.h b/engines/mohawk/graphics.h
index ffb7143686..e872291d4d 100644
--- a/engines/mohawk/graphics.h
+++ b/engines/mohawk/graphics.h
@@ -35,6 +35,7 @@
namespace Mohawk {
+class MohawkEngine;
class MohawkEngine_Myst;
class MohawkEngine_Riven;
class MohawkEngine_LivingBooks;
@@ -83,6 +84,11 @@ public:
// Free all surfaces in the cache
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:
// findImage will search the cache to find the image.
// If not found, it will call decodeImage to get a new one.
@@ -91,6 +97,8 @@ protected:
// decodeImage will always return a new image.
virtual MohawkSurface *decodeImage(uint16 id) = 0;
+ virtual MohawkEngine *getVM() = 0;
+
private:
// An image cache that stores images until clearCache() is called
Common::HashMap<uint16, MohawkSurface*> _cache;
@@ -110,6 +118,7 @@ public:
protected:
MohawkSurface *decodeImage(uint16 id);
+ MohawkEngine *getVM() { return (MohawkEngine *)_vm; }
private:
MohawkEngine_Myst *_vm;
@@ -177,6 +186,7 @@ public:
protected:
MohawkSurface *decodeImage(uint16 id);
+ MohawkEngine *getVM() { return (MohawkEngine *)_vm; }
private:
MohawkEngine_Riven *_vm;
@@ -205,14 +215,13 @@ public:
LBGraphics(MohawkEngine_LivingBooks *vm, uint16 width, uint16 height);
~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 copyOffsetAnimImageToScreen(uint16 image, int left = 0, int top = 0);
bool imageIsTransparentAt(uint16 image, bool useOffsets, int x, int y);
protected:
MohawkSurface *decodeImage(uint16 id);
+ MohawkEngine *getVM() { return (MohawkEngine *)_vm; }
private:
MohawkBitmap *_bmpDecoder;
diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp
index cfc4b67071..d081343ad3 100644
--- a/engines/mohawk/livingbooks.cpp
+++ b/engines/mohawk/livingbooks.cpp
@@ -1030,7 +1030,7 @@ void LBAnimationNode::draw(const Common::Rect &_bounds) {
yOffset -= offset.y;
}
- _vm->_gfx->copyImageToScreen(resourceId, true, xOffset, yOffset);
+ _vm->_gfx->copyOffsetAnimImageToScreen(resourceId, xOffset, yOffset);
}
void LBAnimationNode::reset() {
@@ -2289,7 +2289,7 @@ void LBLiveTextItem::drawWord(uint word, uint yPos) {
yPos + _words[word].bounds.bottom - _words[word].bounds.top);
Common::Rect dstRect = _words[word].bounds;
dstRect.translate(_rect.left, _rect.top);
- _vm->_gfx->copyImageSectionToScreen(_resourceId, srcRect, dstRect);
+ _vm->_gfx->copyAnimImageSectionToScreen(_resourceId, srcRect, dstRect);
}
void LBLiveTextItem::handleMouseDown(Common::Point pos) {
@@ -2412,7 +2412,7 @@ void LBPictureItem::draw() {
if (!_visible)
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) {