[Scummvm-cvs-logs] scummvm master -> 0933325b7cc6d512327a02716f95748fc9a16bba

clone2727 clone2727 at gmail.com
Sun Feb 20 20:23:24 CET 2011


This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
fe250d2755 SCI: Don't error out when a Mac resource has size 0
dceb1391cb SCI: Cache all icon bar images from the start
257bae431a SCI: Fix KQ6 Mac video positioning
0933325b7c SCI: Add support for enabling/disabling Mac icon bar images


Commit: fe250d275564e9dfcfbbf16926852d9cfcf17fc1
    https://github.com/scummvm/scummvm/commit/fe250d275564e9dfcfbbf16926852d9cfcf17fc1
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2011-02-20T09:44:59-08:00

Commit Message:
SCI: Don't error out when a Mac resource has size 0

Changed paths:
    engines/sci/resource.cpp



diff --git a/engines/sci/resource.cpp b/engines/sci/resource.cpp
index f399478..a16f712 100644
--- a/engines/sci/resource.cpp
+++ b/engines/sci/resource.cpp
@@ -428,10 +428,8 @@ void MacResourceForkResourceSource::loadResource(ResourceManager *resMan, Resour
 			stream = _macResMan->getResource(tagArray[i], res->getNumber());
 	}
 
-	if (!stream)
-		error("Could not get Mac resource fork resource: %s", res->_id.toString().c_str());
-
-	decompressResource(stream, res);
+	if (stream)
+		decompressResource(stream, res);
 }
 
 bool MacResourceForkResourceSource::isCompressableResource(ResourceType type) const {


Commit: dceb1391cb92126891b805494b4645272c7fddbe
    https://github.com/scummvm/scummvm/commit/dceb1391cb92126891b805494b4645272c7fddbe
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2011-02-20T09:44:59-08:00

Commit Message:
SCI: Cache all icon bar images from the start

Changed paths:
    engines/sci/graphics/maciconbar.cpp
    engines/sci/graphics/maciconbar.h



diff --git a/engines/sci/graphics/maciconbar.cpp b/engines/sci/graphics/maciconbar.cpp
index d625164..1800f79 100644
--- a/engines/sci/graphics/maciconbar.cpp
+++ b/engines/sci/graphics/maciconbar.cpp
@@ -38,38 +38,74 @@
 
 namespace Sci {
 
+GfxMacIconBar::GfxMacIconBar() {
+	_lastX = 0;
+}
+
+GfxMacIconBar::~GfxMacIconBar() {
+	for (uint32 i = 0; i < _iconBarItems.size(); i++) {
+		if (_iconBarItems[i].nonSelectedImage) {
+			_iconBarItems[i].nonSelectedImage->free();
+			delete _iconBarItems[i].nonSelectedImage;
+		}
+
+		if (_iconBarItems[i].selectedImage) {
+			_iconBarItems[i].selectedImage->free();
+			delete _iconBarItems[i].selectedImage;
+		}
+	}
+}
+
 void GfxMacIconBar::addIcon(reg_t obj) {
-	_iconBarObjects.push_back(obj);
+	IconBarItem item;
+	uint32 iconIndex = readSelectorValue(g_sci->getEngineState()->_segMan, obj, SELECTOR(iconIndex));
+
+	item.object = obj;
+	item.nonSelectedImage = createImage(iconIndex, false);
+	item.selectedImage = createImage(iconIndex, true);
+
+	// Start after the main viewing window and add a two pixel buffer
+	uint16 y = g_sci->_gfxScreen->getHeight() + 2;
+
+	if (item.nonSelectedImage)
+		item.rect = Common::Rect(_lastX, y, MIN<uint32>(_lastX + item.nonSelectedImage->w, 320), y + item.nonSelectedImage->h);
+	else
+		error("Could not find a non-selected image for icon %d", iconIndex);
+
+	_lastX += item.rect.width();
+
+	_iconBarItems.push_back(item);
 }
 
 void GfxMacIconBar::drawIcons() {
 	// Draw the icons to the bottom of the screen
 
-	byte *pal = new byte[256 * 3];
-	Graphics::PictDecoder *pict = new Graphics::PictDecoder(Graphics::PixelFormat::createFormatCLUT8());
-	uint32 lastX = 0;
+	for (uint32 i = 0; i < _iconBarItems.size(); i++) {
+		Graphics::Surface *surface = _iconBarItems[i].nonSelectedImage;
 
-	for (uint32 i = 0; i < _iconBarObjects.size(); i++) {
-		uint32 iconIndex = readSelectorValue(g_sci->getEngineState()->_segMan, _iconBarObjects[i], SELECTOR(iconIndex));
-		Resource *res = g_sci->getResMan()->findResource(ResourceId(kResourceTypeMacIconBarPictN, iconIndex + 1), false);
-		if (!res)
-			continue;
+		if (surface) {
+			g_system->copyRectToScreen((byte *)surface->pixels, surface->pitch, _iconBarItems[i].rect.left,
+				_iconBarItems[i].rect.top, _iconBarItems[i].rect.width(), _iconBarItems[i].rect.height());
+		}
+	}
+}
 
-		Common::SeekableReadStream *stream = new Common::MemoryReadStream(res->data, res->size);
-		Graphics::Surface *surf = pict->decodeImage(stream, pal);
-		remapColors(surf, pal);
+Graphics::Surface *GfxMacIconBar::createImage(uint32 iconIndex, bool isSelected) {
+	Graphics::PictDecoder pictDecoder(Graphics::PixelFormat::createFormatCLUT8());
+	ResourceType type = isSelected ? kResourceTypeMacIconBarPictS : kResourceTypeMacIconBarPictN;
 
-		g_system->copyRectToScreen((byte *)surf->pixels, surf->pitch, lastX,
-				g_sci->_gfxScreen->getHeight() + 2, MIN<uint32>(surf->w, 320 - lastX), surf->h);
+	Resource *res = g_sci->getResMan()->findResource(ResourceId(type, iconIndex + 1), false);
 
-		lastX += surf->w;
-		surf->free();
-		delete surf;
-		delete stream;
-	}
+	if (!res || res->size == 0)
+		return 0;
+
+	byte palette[256 * 3];
+	Common::SeekableReadStream *stream = new Common::MemoryReadStream(res->data, res->size);
+	Graphics::Surface *surface = pictDecoder.decodeImage(stream, palette);
+	remapColors(surface, palette);
 
-	delete pict;
-	delete[] pal;
+	delete stream;
+	return surface;
 }
 
 void GfxMacIconBar::remapColors(Graphics::Surface *surf, byte *palette) {
diff --git a/engines/sci/graphics/maciconbar.h b/engines/sci/graphics/maciconbar.h
index 71e65fc..0731da4 100644
--- a/engines/sci/graphics/maciconbar.h
+++ b/engines/sci/graphics/maciconbar.h
@@ -38,15 +38,24 @@ namespace Sci {
 
 class GfxMacIconBar {
 public:
-	GfxMacIconBar() {}
-	~GfxMacIconBar() {}
+	GfxMacIconBar();
+	~GfxMacIconBar();
 
 	void addIcon(reg_t obj);
 	void drawIcons();
 
 private:
-	Common::Array<reg_t> _iconBarObjects;
+	struct IconBarItem {
+		reg_t object;
+		Graphics::Surface *nonSelectedImage;
+		Graphics::Surface *selectedImage;
+		Common::Rect rect;
+	};
 
+	Common::Array<IconBarItem> _iconBarItems;
+	uint32 _lastX;
+
+	Graphics::Surface *createImage(uint32 iconIndex, bool isSelected);
 	void remapColors(Graphics::Surface *surf, byte *palette);
 };
 


Commit: 257bae431ac7e9a966e0cc1e41c7f10dc0125092
    https://github.com/scummvm/scummvm/commit/257bae431ac7e9a966e0cc1e41c7f10dc0125092
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2011-02-20T09:44:59-08:00

Commit Message:
SCI: Fix KQ6 Mac video positioning

Changed paths:
    engines/sci/engine/kvideo.cpp



diff --git a/engines/sci/engine/kvideo.cpp b/engines/sci/engine/kvideo.cpp
index 0706da0..6a411d8 100644
--- a/engines/sci/engine/kvideo.cpp
+++ b/engines/sci/engine/kvideo.cpp
@@ -48,8 +48,8 @@ void playVideo(Video::VideoDecoder *videoDecoder, VideoState videoState) {
 	uint16 width = videoDecoder->getWidth();
 	uint16 height = videoDecoder->getHeight();
 	uint16 pitch = videoDecoder->getWidth() * bytesPerPixel;
-	uint16 screenWidth = g_system->getWidth();
-	uint16 screenHeight = g_system->getHeight();
+	uint16 screenWidth = g_sci->_gfxScreen->getDisplayWidth();
+	uint16 screenHeight = g_sci->_gfxScreen->getDisplayHeight();
 
 	videoState.fileName.toLowercase();
 	bool isVMD = videoState.fileName.hasSuffix(".vmd");


Commit: 0933325b7cc6d512327a02716f95748fc9a16bba
    https://github.com/scummvm/scummvm/commit/0933325b7cc6d512327a02716f95748fc9a16bba
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2011-02-20T09:44:59-08:00

Commit Message:
SCI: Add support for enabling/disabling Mac icon bar images

Changed paths:
    engines/sci/engine/kmisc.cpp
    engines/sci/graphics/maciconbar.cpp
    engines/sci/graphics/maciconbar.h



diff --git a/engines/sci/engine/kmisc.cpp b/engines/sci/engine/kmisc.cpp
index f95b1dd..6d7c458 100644
--- a/engines/sci/engine/kmisc.cpp
+++ b/engines/sci/engine/kmisc.cpp
@@ -366,8 +366,6 @@ reg_t kIconBar(EngineState *s, int argc, reg_t *argv) {
 		for (int i = 0; i < argv[1].toUint16(); i++)
 			g_sci->_gfxMacIconBar->addIcon(argv[i + 2]);
 
-		g_sci->_gfxMacIconBar->drawIcons();
-
 		// TODO: Should return icon bar handle
 		// Said handle is then used by DisposeIconBar
 		break;
@@ -375,10 +373,12 @@ reg_t kIconBar(EngineState *s, int argc, reg_t *argv) {
 		warning("kIconBar(Dispose)");
 		break;
 	case 2: // EnableIconBar (0xffff = all)
-		warning("kIconBar(Enable, %d)", argv[1].toUint16());
+		debug(0, "kIconBar(Enable, %d)", argv[1].toUint16());
+		g_sci->_gfxMacIconBar->setIconEnabled(argv[1].toUint16(), true);
 		break;
 	case 3: // DisableIconBar (0xffff = all)
-		warning("kIconBar(Disable, %d)", argv[1].toUint16());
+		debug(0, "kIconBar(Disable, %d)", argv[1].toUint16());
+		g_sci->_gfxMacIconBar->setIconEnabled(argv[1].toUint16(), false);
 		break;
 	case 4: // SetIconBarIcon
 		warning("kIconBar(SetIcon, %d, %d)", argv[1].toUint16(), argv[2].toUint16());
@@ -387,6 +387,8 @@ reg_t kIconBar(EngineState *s, int argc, reg_t *argv) {
 		error("Unknown kIconBar(%d)", argv[0].toUint16());
 	}
 
+	g_sci->_gfxMacIconBar->drawIcons();
+
 	return NULL_REG;
 }
 
diff --git a/engines/sci/graphics/maciconbar.cpp b/engines/sci/graphics/maciconbar.cpp
index 1800f79..ea44db6 100644
--- a/engines/sci/graphics/maciconbar.cpp
+++ b/engines/sci/graphics/maciconbar.cpp
@@ -63,6 +63,7 @@ void GfxMacIconBar::addIcon(reg_t obj) {
 	item.object = obj;
 	item.nonSelectedImage = createImage(iconIndex, false);
 	item.selectedImage = createImage(iconIndex, true);
+	item.enabled = true;
 
 	// Start after the main viewing window and add a two pixel buffer
 	uint16 y = g_sci->_gfxScreen->getHeight() + 2;
@@ -80,13 +81,67 @@ void GfxMacIconBar::addIcon(reg_t obj) {
 void GfxMacIconBar::drawIcons() {
 	// Draw the icons to the bottom of the screen
 
-	for (uint32 i = 0; i < _iconBarItems.size(); i++) {
-		Graphics::Surface *surface = _iconBarItems[i].nonSelectedImage;
+	for (uint32 i = 0; i < _iconBarItems.size(); i++)
+		redrawIcon(i);
+}
 
-		if (surface) {
-			g_system->copyRectToScreen((byte *)surface->pixels, surface->pitch, _iconBarItems[i].rect.left,
-				_iconBarItems[i].rect.top, _iconBarItems[i].rect.width(), _iconBarItems[i].rect.height());
-		}
+void GfxMacIconBar::redrawIcon(uint16 iconIndex) {
+	if (iconIndex >= _iconBarItems.size())
+		return;
+
+	if (_iconBarItems[iconIndex].enabled)
+		drawEnabledImage(_iconBarItems[iconIndex].nonSelectedImage, _iconBarItems[iconIndex].rect);
+	else
+		drawDisabledImage(_iconBarItems[iconIndex].nonSelectedImage, _iconBarItems[iconIndex].rect);
+}
+
+void GfxMacIconBar::drawEnabledImage(Graphics::Surface *surface, const Common::Rect &rect) {
+	if (surface)
+		g_system->copyRectToScreen((byte *)surface->pixels, surface->pitch, rect.left, rect.top, rect.width(), rect.height());
+}
+
+void GfxMacIconBar::drawDisabledImage(Graphics::Surface *surface, const Common::Rect &rect) {
+	if (!surface)
+		return;
+
+	// Add a black checkboard pattern to the image before copying it to the screen
+
+	Graphics::Surface newSurf;
+	newSurf.copyFrom(*surface);
+
+	for (int i = 0; i < newSurf.h; i++) {
+		int startX = rect.left & 3;
+
+		if ((i + rect.top) & 1)
+			startX += 2;
+
+		for (int j = startX; j < newSurf.w; j += 4)
+			*((byte *)newSurf.getBasePtr(j, i)) = 0;
+	}
+
+	g_system->copyRectToScreen((byte *)newSurf.pixels, newSurf.pitch, rect.left, rect.top, rect.width(), rect.height());
+	newSurf.free();
+}
+
+void GfxMacIconBar::drawSelectedImage(uint16 iconIndex) {
+	assert(iconIndex <= _iconBarItems.size());
+
+	// TODO
+}
+
+bool GfxMacIconBar::isIconEnabled(uint16 iconIndex) const {
+	if (iconIndex >= _iconBarItems.size())
+		return false;
+
+	return _iconBarItems[iconIndex].enabled;
+}
+
+void GfxMacIconBar::setIconEnabled(uint16 iconIndex, bool enabled) {
+	if (iconIndex == 0xffff) {
+		for (uint32 i = 0; i < _iconBarItems.size(); i++)
+			_iconBarItems[i].enabled = enabled;
+	} else if (iconIndex < _iconBarItems.size()) {
+		_iconBarItems[iconIndex].enabled = enabled;
 	}
 }
 
diff --git a/engines/sci/graphics/maciconbar.h b/engines/sci/graphics/maciconbar.h
index 0731da4..0db9454 100644
--- a/engines/sci/graphics/maciconbar.h
+++ b/engines/sci/graphics/maciconbar.h
@@ -43,6 +43,10 @@ public:
 
 	void addIcon(reg_t obj);
 	void drawIcons();
+	void redrawIcon(uint16 index);
+	void drawSelectedImage(uint16 index);
+	bool isIconEnabled(uint16 index) const;
+	void setIconEnabled(uint16 index, bool enabled);
 
 private:
 	struct IconBarItem {
@@ -50,6 +54,7 @@ private:
 		Graphics::Surface *nonSelectedImage;
 		Graphics::Surface *selectedImage;
 		Common::Rect rect;
+		bool enabled;
 	};
 
 	Common::Array<IconBarItem> _iconBarItems;
@@ -57,6 +62,9 @@ private:
 
 	Graphics::Surface *createImage(uint32 iconIndex, bool isSelected);
 	void remapColors(Graphics::Surface *surf, byte *palette);
+
+	void drawEnabledImage(Graphics::Surface *surface, const Common::Rect &rect);
+	void drawDisabledImage(Graphics::Surface *surface, const Common::Rect &rect);
 };
 
 } // End of namespace Sci






More information about the Scummvm-git-logs mailing list