From b32d0f2ad99b526d72d47523eb642f8bc70fc91a Mon Sep 17 00:00:00 2001 From: Scott Percival Date: Sat, 4 Jan 2020 22:04:43 +0800 Subject: DIRECTOR: Render shapes with transparency --- engines/director/cast.cpp | 4 ++-- engines/director/frame.cpp | 22 +++++++++++++++------- engines/director/frame.h | 2 +- engines/director/sprite.h | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/engines/director/cast.cpp b/engines/director/cast.cpp index dc1170b611..1d22da7228 100644 --- a/engines/director/cast.cpp +++ b/engines/director/cast.cpp @@ -288,8 +288,8 @@ ShapeCast::ShapeCast(Common::ReadStreamEndian &stream, uint16 version) { _shapeType = static_cast(stream.readByte()); _initialRect = Score::readRect(stream); _pattern = stream.readUint16BE(); - _fgCol = (uint8)stream.readByte(); - _bgCol = (uint8)stream.readByte(); + _fgCol = (127 - stream.readByte()) & 0xff; // -128 -> 0, 127 -> 256 + _bgCol = (127 - stream.readByte()) & 0xff; _fillType = stream.readByte(); _ink = static_cast(_fillType & 0x3f); _lineThickness = stream.readByte(); diff --git a/engines/director/frame.cpp b/engines/director/frame.cpp index b73146a771..fe332ad4a4 100644 --- a/engines/director/frame.cpp +++ b/engines/director/frame.cpp @@ -309,7 +309,7 @@ void Frame::readMainChannels(Common::SeekableSubReadStreamEndian &stream, uint16 _soundType2 = stream.readByte(); offset += 1; break; - case kPaletePosition: + case kPalettePosition: if (stream.readUint16()) readPaletteInfo(stream); offset += 16; @@ -644,7 +644,7 @@ void Frame::renderSprites(Graphics::ManagedSurface &surface, bool renderTrail) { int width = _vm->getVersion() > 4 ? bc->_initialRect.width() : _sprites[i]->_width; Common::Rect drawRect(x, y, x + width, y + height); addDrawRect(i, drawRect); - inkBasedBlit(surface, *(bc->_surface), i, drawRect); + inkBasedBlit(surface, *(bc->_surface), _sprites[i]->_ink, drawRect); } } } @@ -660,6 +660,7 @@ void Frame::addDrawRect(uint16 spriteId, Common::Rect &rect) { void Frame::renderShape(Graphics::ManagedSurface &surface, uint16 spriteId) { Sprite *sp = _sprites[spriteId]; + InkType ink = sp->_ink; byte spriteType = sp->_spriteType; byte foreColor = sp->_foreColor; byte backColor = sp->_backColor; @@ -688,6 +689,11 @@ void Frame::renderShape(Graphics::ManagedSurface &surface, uint16 spriteId) { foreColor = sc->_fgCol; backColor = sc->_bgCol; lineSize = sc->_lineThickness; + ink = sc->_ink; + // shapes should be rendered with transparency by default + if (ink == kInkTypeCopy) { + ink = kInkTypeTransparent; + } } break; default: @@ -703,6 +709,7 @@ void Frame::renderShape(Graphics::ManagedSurface &surface, uint16 spriteId) { Graphics::ManagedSurface tmpSurface; tmpSurface.create(shapeRect.width(), shapeRect.height(), Graphics::PixelFormat::createFormatCLUT8()); + tmpSurface.clear(255); // No minus one on the pattern here! MacPlotData will do that for us! //Graphics::MacPlotData pd(&tmpSurface, &_vm->getPatterns(), 1, 1, sp->_backColor); @@ -743,7 +750,8 @@ void Frame::renderShape(Graphics::ManagedSurface &surface, uint16 spriteId) { } addDrawRect(spriteId, shapeRect); - inkBasedBlit(surface, tmpSurface, spriteId, shapeRect); + inkBasedBlit(surface, tmpSurface, ink, shapeRect); + } void Frame::renderButton(Graphics::ManagedSurface &surface, uint16 spriteId) { @@ -910,16 +918,16 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteId, Commo textWithFeatures.transBlitFrom(textSurface->rawSurface(), Common::Point(textX, textY), 0xff); - inkBasedBlit(surface, textWithFeatures, spriteId, Common::Rect(x, y, x + width, y + height)); + inkBasedBlit(surface, textWithFeatures, _sprites[spriteId]->_ink, Common::Rect(x, y, x + width, y + height)); } -void Frame::inkBasedBlit(Graphics::ManagedSurface &targetSurface, const Graphics::Surface &spriteSurface, uint16 spriteId, Common::Rect drawRect) { +void Frame::inkBasedBlit(Graphics::ManagedSurface &targetSurface, const Graphics::Surface &spriteSurface, InkType ink, Common::Rect drawRect) { // drawRect could be bigger than the spriteSurface. Clip it Common::Rect t(spriteSurface.w, spriteSurface.h); t.moveTo(drawRect.left, drawRect.top); drawRect.clip(t); - switch (_sprites[spriteId]->_ink) { + switch (ink) { case kInkTypeCopy: targetSurface.blitFrom(spriteSurface, Common::Point(drawRect.left, drawRect.top)); break; @@ -940,7 +948,7 @@ void Frame::inkBasedBlit(Graphics::ManagedSurface &targetSurface, const Graphics drawReverseSprite(targetSurface, spriteSurface, drawRect); break; default: - warning("Frame::inkBasedBlit(): Unhandled ink type %d", _sprites[spriteId]->_ink); + warning("Frame::inkBasedBlit(): Unhandled ink type %d", ink); targetSurface.blitFrom(spriteSurface, Common::Point(drawRect.left, drawRect.top)); break; } diff --git a/engines/director/frame.h b/engines/director/frame.h index 3c20dea822..25192af05e 100644 --- a/engines/director/frame.h +++ b/engines/director/frame.h @@ -147,7 +147,7 @@ private: void drawMatteSprite(Graphics::ManagedSurface &target, const Graphics::Surface &sprite, Common::Rect &drawRect); void drawGhostSprite(Graphics::ManagedSurface &target, const Graphics::Surface &sprite, Common::Rect &drawRect); void drawReverseSprite(Graphics::ManagedSurface &target, const Graphics::Surface &sprite, Common::Rect &drawRect); - void inkBasedBlit(Graphics::ManagedSurface &targetSurface, const Graphics::Surface &spriteSurface, uint16 spriteId, Common::Rect drawRect); + void inkBasedBlit(Graphics::ManagedSurface &targetSurface, const Graphics::Surface &spriteSurface, InkType ink, Common::Rect drawRect); void addDrawRect(uint16 entityId, Common::Rect &rect); public: diff --git a/engines/director/sprite.h b/engines/director/sprite.h index 0c12a0d234..8ac0dcbb8a 100644 --- a/engines/director/sprite.h +++ b/engines/director/sprite.h @@ -54,7 +54,7 @@ enum MainChannelsPosition { kBlendPosition, kSound2Position, kSound2TypePosition = 11, - kPaletePosition = 15 + kPalettePosition = 15 }; class Sprite { -- cgit v1.2.3