From dceb1391cb92126891b805494b4645272c7fddbe Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Sun, 20 Feb 2011 01:20:04 -0500 Subject: SCI: Cache all icon bar images from the start --- engines/sci/graphics/maciconbar.cpp | 78 +++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 21 deletions(-) (limited to 'engines/sci/graphics/maciconbar.cpp') diff --git a/engines/sci/graphics/maciconbar.cpp b/engines/sci/graphics/maciconbar.cpp index d6251641a3..1800f79609 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(_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(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) { -- cgit v1.2.3