[Scummvm-cvs-logs] SF.net SVN: scummvm:[54743] scummvm/trunk/engines/mohawk
fuzzie at users.sourceforge.net
fuzzie at users.sourceforge.net
Thu Dec 2 22:25:15 CET 2010
Revision: 54743
http://scummvm.svn.sourceforge.net/scummvm/?rev=54743&view=rev
Author: fuzzie
Date: 2010-12-02 21:25:15 +0000 (Thu, 02 Dec 2010)
Log Message:
-----------
MOHAWK: move shared setPalette/copyImage routines into GraphicsManager
Modified Paths:
--------------
scummvm/trunk/engines/mohawk/console.cpp
scummvm/trunk/engines/mohawk/graphics.cpp
scummvm/trunk/engines/mohawk/graphics.h
scummvm/trunk/engines/mohawk/livingbooks.cpp
Modified: scummvm/trunk/engines/mohawk/console.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/console.cpp 2010-12-02 21:24:55 UTC (rev 54742)
+++ scummvm/trunk/engines/mohawk/console.cpp 2010-12-02 21:25:15 UTC (rev 54743)
@@ -690,7 +690,7 @@
return true;
}
- _vm->_gfx->copyImageToScreen((uint16)atoi(argv[1]));
+ _vm->_gfx->copyAnimImageToScreen((uint16)atoi(argv[1]));
_vm->_system->updateScreen();
return false;
}
Modified: scummvm/trunk/engines/mohawk/graphics.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/graphics.cpp 2010-12-02 21:24:55 UTC (rev 54742)
+++ scummvm/trunk/engines/mohawk/graphics.cpp 2010-12-02 21:25:15 UTC (rev 54743)
@@ -117,6 +117,99 @@
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,87 +877,15 @@
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) {
+void LBGraphics::copyOffsetAnimImageToScreen(uint16 image, int left, int top) {
MohawkSurface *mhkSurface = findImage(image);
- Graphics::Surface *surface = mhkSurface->getSurface();
- if (useOffsets) {
- left -= mhkSurface->getOffsetX();
- top -= mhkSurface->getOffsetY();
- }
+ 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);
+ GraphicsManager::copyAnimImageToScreen(image, left, top);
}
-void LBGraphics::copyImageSectionToScreen(uint16 image, Common::Rect srcRect, Common::Rect dstRect) {
- 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();
-
- // 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) {
MohawkSurface *mhkSurface = findImage(image);
@@ -903,22 +924,7 @@
_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);
}
}
Modified: scummvm/trunk/engines/mohawk/graphics.h
===================================================================
--- scummvm/trunk/engines/mohawk/graphics.h 2010-12-02 21:24:55 UTC (rev 54742)
+++ scummvm/trunk/engines/mohawk/graphics.h 2010-12-02 21:25:15 UTC (rev 54743)
@@ -35,6 +35,7 @@
namespace Mohawk {
+class MohawkEngine;
class MohawkEngine_Myst;
class MohawkEngine_Riven;
class MohawkEngine_LivingBooks;
@@ -83,6 +84,11 @@
// 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 @@
// 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 @@
protected:
MohawkSurface *decodeImage(uint16 id);
+ MohawkEngine *getVM() { return (MohawkEngine *)_vm; }
private:
MohawkEngine_Myst *_vm;
@@ -177,6 +186,7 @@
protected:
MohawkSurface *decodeImage(uint16 id);
+ MohawkEngine *getVM() { return (MohawkEngine *)_vm; }
private:
MohawkEngine_Riven *_vm;
@@ -205,14 +215,13 @@
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;
Modified: scummvm/trunk/engines/mohawk/livingbooks.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/livingbooks.cpp 2010-12-02 21:24:55 UTC (rev 54742)
+++ scummvm/trunk/engines/mohawk/livingbooks.cpp 2010-12-02 21:25:15 UTC (rev 54743)
@@ -1030,7 +1030,7 @@
yOffset -= offset.y;
}
- _vm->_gfx->copyImageToScreen(resourceId, true, xOffset, yOffset);
+ _vm->_gfx->copyOffsetAnimImageToScreen(resourceId, xOffset, yOffset);
}
void LBAnimationNode::reset() {
@@ -2289,7 +2289,7 @@
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 @@
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) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list