aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMatthew Hoops2011-02-20 01:20:04 -0500
committerMatthew Hoops2011-02-20 12:44:59 -0500
commitdceb1391cb92126891b805494b4645272c7fddbe (patch)
treebb1cd4b1215d59f6548209a059893712704b33c1 /engines
parentfe250d275564e9dfcfbbf16926852d9cfcf17fc1 (diff)
downloadscummvm-rg350-dceb1391cb92126891b805494b4645272c7fddbe.tar.gz
scummvm-rg350-dceb1391cb92126891b805494b4645272c7fddbe.tar.bz2
scummvm-rg350-dceb1391cb92126891b805494b4645272c7fddbe.zip
SCI: Cache all icon bar images from the start
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/graphics/maciconbar.cpp78
-rw-r--r--engines/sci/graphics/maciconbar.h15
2 files changed, 69 insertions, 24 deletions
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<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 71e65fcb40..0731da497d 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);
};