From fcdb7807a456f5a6cb94932977a1b0e4f0e11089 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 20 Jun 2010 07:04:58 +0000 Subject: Implemented explicit transparency index support - the previous hardcoded index of 0 wasn't correct, since some sprites need that index svn-id: r50070 --- engines/m4/console.cpp | 2 +- engines/m4/events.cpp | 3 ++- engines/m4/graphics.cpp | 2 +- engines/m4/graphics.h | 1 + engines/m4/mads_anim.cpp | 2 +- engines/m4/mads_menus.cpp | 12 +++++++----- engines/m4/mads_scene.cpp | 2 +- engines/m4/mads_views.cpp | 8 +++++--- engines/m4/sprite.cpp | 15 ++++++++------- engines/m4/sprite.h | 2 +- 10 files changed, 28 insertions(+), 21 deletions(-) (limited to 'engines/m4') diff --git a/engines/m4/console.cpp b/engines/m4/console.cpp index 4e14afdfaf..19fbf6e852 100644 --- a/engines/m4/console.cpp +++ b/engines/m4/console.cpp @@ -196,7 +196,7 @@ bool Console::cmdShowSprite(int argc, const char **argv) { if (y >= bg->height()) break; - spr->copyTo(bg, x, y, (int)spr->getTransparentColor()); + spr->copyTo(bg, x, y, (int)spr->getTransparencyIndex()); x += spr->width(); yMax = MAX(yMax, spr->height()); diff --git a/engines/m4/events.cpp b/engines/m4/events.cpp index 65378c5d6a..c66609844a 100644 --- a/engines/m4/events.cpp +++ b/engines/m4/events.cpp @@ -256,7 +256,8 @@ bool Mouse::setCursorNum(int cursorIndex) { _cursor = _cursorSprites->getFrame(cursorIndex); // Set the cursor to the sprite - CursorMan.replaceCursor((const byte *)_cursor->getBasePtr(), _cursor->width(), _cursor->height(), _cursor->xOffset, _cursor->yOffset, 0); + CursorMan.replaceCursor((const byte *)_cursor->getBasePtr(), _cursor->width(), _cursor->height(), + _cursor->xOffset, _cursor->yOffset, TRANSPARENT_COLOUR_INDEX); return true; } diff --git a/engines/m4/graphics.cpp b/engines/m4/graphics.cpp index d7a0c9edfc..b0bc8bbc0c 100644 --- a/engines/m4/graphics.cpp +++ b/engines/m4/graphics.cpp @@ -919,7 +919,7 @@ void M4Surface::translate(RGBList *list, bool isTransparent) { byte *palIndexes = list->palIndexes(); for (int i = 0; i < width() * height(); ++i, ++p) { - if (!isTransparent || (*p != 0)) { + if (!isTransparent || (*p != TRANSPARENT_COLOUR_INDEX)) { assert(*p < list->size()); *p = palIndexes[*p]; } diff --git a/engines/m4/graphics.h b/engines/m4/graphics.h index 24c0edf223..96cd039e27 100644 --- a/engines/m4/graphics.h +++ b/engines/m4/graphics.h @@ -40,6 +40,7 @@ namespace M4 { #define MADS_SCREEN_HEIGHT 200 #define MADS_Y_OFFSET ((MADS_SCREEN_HEIGHT - MADS_SURFACE_HEIGHT) / 2) +#define TRANSPARENT_COLOUR_INDEX 0xFF struct BGR8 { uint8 b, g, r; diff --git a/engines/m4/mads_anim.cpp b/engines/m4/mads_anim.cpp index c2e9ea4eee..fb565a927c 100644 --- a/engines/m4/mads_anim.cpp +++ b/engines/m4/mads_anim.cpp @@ -547,7 +547,7 @@ void AnimviewView::updateState() { } void AnimviewView::readNextCommand() { -static bool tempFlag = true;//****DEBUG - Temporarily allow me to skip several intro scenes **** +static bool tempFlag = false;//****DEBUG - Temporarily allow me to skip several intro scenes **** while (!_script->eos() && !_script->err()) { if (!tempFlag) { diff --git a/engines/m4/mads_menus.cpp b/engines/m4/mads_menus.cpp index 43b9031692..d7d9cf4150 100644 --- a/engines/m4/mads_menus.cpp +++ b/engines/m4/mads_menus.cpp @@ -163,7 +163,7 @@ bool RexMainMenuView::onEvent(M4EventType eventType, int32 param, int x, int y, if (_highlightedIndex != -1) { M4Sprite *spr = _menuItem->getFrame(_highlightedIndex); const Common::Point &pt = _menuItemPosList[_highlightedIndex]; - spr->copyTo(this, pt.x, row + pt.y, 0); + spr->copyTo(this, pt.x, row + pt.y, spr->getTransparencyIndex()); } } } else { @@ -211,10 +211,12 @@ void RexMainMenuView::updateState() { M4Sprite *spr = _menuItem->getFrame(0); itemSize = _menuItem->getFrame(0)->height(); spr->copyTo(this, _menuItemPosList[_menuItemIndex - 1].x, - _menuItemPosList[_menuItemIndex - 1].y + row + (itemSize / 2) - (spr->height() / 2), 0); + _menuItemPosList[_menuItemIndex - 1].y + row + (itemSize / 2) - (spr->height() / 2), + spr->getTransparencyIndex()); delete _menuItem; - copyTo(_bgSurface, Common::Rect(0, row, width(), row + MADS_SURFACE_HEIGHT), 0, 0); + copyTo(_bgSurface, Common::Rect(0, row, width(), row + MADS_SURFACE_HEIGHT), 0, 0, + spr->getTransparencyIndex()); } // Get the next sprite set @@ -275,7 +277,7 @@ void RexMainMenuView::updateState() { _bgSurface->copyTo(this, 0, row); M4Sprite *spr = _menuItem->getFrame(_frameIndex); spr->copyTo(this, _menuItemPosList[_menuItemIndex - 1].x, _menuItemPosList[_menuItemIndex - 1].y + - row + (itemSize / 2) - (spr->height() / 2), 0); + row + (itemSize / 2) - (spr->height() / 2), spr->getTransparencyIndex()); } int RexMainMenuView::getHighlightedItem(int x, int y) { @@ -531,7 +533,7 @@ void DragonMainMenuView::updateState() { _itemPalData.push_back(palData); spr = _menuItem->getFrame(1); - spr->copyTo(this, spr->xOffset - 140, spr->yOffset - spr->height(), (int)spr->getTransparentColor()); + spr->copyTo(this, spr->xOffset - 140, spr->yOffset - spr->height(), spr->getTransparencyIndex()); _vm->_mouse->cursorOn(); } diff --git a/engines/m4/mads_scene.cpp b/engines/m4/mads_scene.cpp index 8a33424602..7e45b5f1f7 100644 --- a/engines/m4/mads_scene.cpp +++ b/engines/m4/mads_scene.cpp @@ -927,7 +927,7 @@ void MadsInterfaceView::onRefresh(RectList *rects, M4Surface *destSurface) { // Display object sprite. Note that the frame number isn't used directly, because it would result // in too fast an animation M4Sprite *spr = _objectSprites->getFrame(_objectFrameNumber / INV_ANIM_FRAME_SPEED); - spr->copyTo(destSurface, INVENTORY_X, INVENTORY_Y, 0); + spr->copyTo(destSurface, INVENTORY_X, INVENTORY_Y, TRANSPARENT_COLOUR_INDEX); if (!_madsVm->globals()->_config.invObjectsStill && !dialogVisible) { // If objects need to be animated, move to the next frame diff --git a/engines/m4/mads_views.cpp b/engines/m4/mads_views.cpp index 5a7abcf484..a644e81d51 100644 --- a/engines/m4/mads_views.cpp +++ b/engines/m4/mads_views.cpp @@ -196,7 +196,8 @@ void MadsSpriteSlots::drawForeground(View *view, int yOffset) { // Minimalised drawing assert(slot.spriteListIndex < (int)_sprites.size()); M4Sprite *spr = spriteSet.getFrame((slot.frameNumber & 0x7fff) - 1); - view->copyFrom(spr, slot.xp, slot.yp, Common::Point(0, yOffset), slot.depth, _owner._depthSurface, slot.scale, 0); + view->copyFrom(spr, slot.xp, slot.yp, Common::Point(0, yOffset), slot.depth, _owner._depthSurface, + slot.scale, spr->getTransparencyIndex()); } else { int xp, yp; M4Sprite *spr = spriteSet.getFrame(slot.frameNumber - 1); @@ -211,10 +212,11 @@ void MadsSpriteSlots::drawForeground(View *view, int yOffset) { if (slot.depth > 1) { // Draw the frame with depth processing - view->copyFrom(spr, xp, yp, Common::Point(0, yOffset), slot.depth, _owner._depthSurface, 100, 0); + view->copyFrom(spr, xp, yp, Common::Point(0, yOffset), slot.depth, _owner._depthSurface, 100, + spr->getTransparencyIndex()); } else { // No depth, so simply draw the image - spr->copyTo(view, xp, yp + yOffset, 0); + spr->copyTo(view, xp, yp + yOffset, spr->getTransparencyIndex()); } } } diff --git a/engines/m4/sprite.cpp b/engines/m4/sprite.cpp index 0ff4bec855..da043c695f 100644 --- a/engines/m4/sprite.cpp +++ b/engines/m4/sprite.cpp @@ -131,6 +131,9 @@ void M4Sprite::loadMadsSprite(Common::SeekableReadStream* source) { byte cmd1, cmd2, count, pixel; if (newLine) { + if (outp < (lineStart + w)) + Common::set_to(outp, lineStart + w, TRANSPARENT_COLOUR_INDEX); + outp = lineStart + w; lineStart = outp; newLine = false; @@ -150,7 +153,7 @@ void M4Sprite::loadMadsSprite(Common::SeekableReadStream* source) { } else { pixel = source->readByte(); while (count--) - *outp++ = (pixel == 0xFD) ? 0 : pixel; + *outp++ = (pixel == 0xFD) ? TRANSPARENT_COLOUR_INDEX : pixel; } } } else { @@ -162,19 +165,17 @@ void M4Sprite::loadMadsSprite(Common::SeekableReadStream* source) { count = source->readByte(); pixel = source->readByte(); while (count--) - *outp++ = (pixel == 0xFD) ? 0 : pixel; + *outp++ = (pixel == 0xFD) ? TRANSPARENT_COLOUR_INDEX : pixel; } else { - *outp++ = (cmd2 == 0xFD) ? 0 : cmd2; + *outp++ = (cmd2 == 0xFD) ? TRANSPARENT_COLOUR_INDEX : cmd2; } } } } } -byte M4Sprite::getTransparentColor() const { - // FIXME: We assume that the transparent color is the color of the - // top left pixel. - return *getBasePtr(0, 0); +byte M4Sprite::getTransparencyIndex() const { + return TRANSPARENT_COLOUR_INDEX; } } // End of namespace M4 diff --git a/engines/m4/sprite.h b/engines/m4/sprite.h index 49a96a6c4a..d4e5502efd 100644 --- a/engines/m4/sprite.h +++ b/engines/m4/sprite.h @@ -115,7 +115,7 @@ public: void loadDeltaRle(Common::SeekableReadStream* rleData, int destX, int destY); void loadMadsSprite(Common::SeekableReadStream* source); - byte getTransparentColor() const; + byte getTransparencyIndex() const; protected: }; -- cgit v1.2.3