SHERLOCK: Implement transparent sprite drawing

This commit is contained in:
Paul Gilbert 2015-03-17 08:12:19 -04:00
parent 59c124aa60
commit 51989953b6
3 changed files with 49 additions and 11 deletions

View file

@ -129,7 +129,7 @@ bool Animation::playPrologue(const Common::String &filename, int minDelay, int f
} }
// Draw the sprite // Draw the sprite
screen.copyFrom(sprite[spriteFrame]._frame, pt); screen.transBlitFrom(sprite[spriteFrame]._frame, pt);
} else { } else {
// No sprite to show for this animation frame // No sprite to show for this animation frame
if (fade == 255) { if (fade == 255) {

View file

@ -35,17 +35,10 @@ Surface::~Surface() {
free(); free();
} }
/**
* Draws a surface into another
*/
void Surface::copyFrom(const Graphics::Surface &src) {
copyFrom(src, Common::Point());
}
/** /**
* Draws a surface at a given position within this surface * Draws a surface at a given position within this surface
*/ */
void Surface::copyFrom(const Graphics::Surface &src, const Common::Point &pt) { void Surface::blitFrom(const Graphics::Surface &src, const Common::Point &pt) {
Common::Rect drawRect(0, 0, src.w, src.h); Common::Rect drawRect(0, 0, src.w, src.h);
Common::Point destPt = pt; Common::Point destPt = pt;
@ -73,6 +66,51 @@ void Surface::copyFrom(const Graphics::Surface &src, const Common::Point &pt) {
} }
} }
/**
* Draws a surface at a given position within this surface with transparency
*/
void Surface::transBlitFrom(const Graphics::Surface &src, const Common::Point &pt) {
Common::Rect drawRect(0, 0, src.w, src.h);
Common::Point destPt = pt;
if (destPt.x < 0) {
drawRect.left += -destPt.x;
destPt.x = 0;
}
if (destPt.y < 0) {
drawRect.top += -destPt.y;
destPt.y = 0;
}
int right = destPt.x + src.w;
if (right > this->w) {
drawRect.right -= (right - this->w);
}
int bottom = destPt.y + src.h;
if (bottom > this->h) {
drawRect.bottom -= (bottom - this->h);
}
if (!drawRect.isValidRect())
return;
addDirtyRect(Common::Rect(destPt.x, destPt.y, destPt.x + drawRect.width(),
destPt.y + drawRect.height()));
// Draw loop
const int TRANSPARENCY = 0xFF;
for (int yp = 0; yp < drawRect.height(); ++yp) {
const byte *srcP = (const byte *)src.getBasePtr(drawRect.left, drawRect.top + yp);
byte *destP = (byte *)getBasePtr(destPt.x, destPt.y + yp);
for (int xp = 0; xp < drawRect.width(); ++xp, ++srcP, ++destP) {
if (*srcP != TRANSPARENCY)
*destP = *srcP;
}
}
}
void Surface::fillRect(int x1, int y1, int x2, int y2, byte color) { void Surface::fillRect(int x1, int y1, int x2, int y2, byte color) {
Graphics::Surface::fillRect(Common::Rect(x1, y1, x2, y2), color); Graphics::Surface::fillRect(Common::Rect(x1, y1, x2, y2), color);
} }

View file

@ -35,8 +35,8 @@ public:
Surface(uint16 width, uint16 height); Surface(uint16 width, uint16 height);
~Surface(); ~Surface();
void copyFrom(const Graphics::Surface &src); void blitFrom(const Graphics::Surface &src, const Common::Point &pt);
void copyFrom(const Graphics::Surface &src, const Common::Point &pt); void transBlitFrom(const Graphics::Surface &src, const Common::Point &pt);
void fillRect(int x1, int y1, int x2, int y2, byte color); void fillRect(int x1, int y1, int x2, int y2, byte color);
}; };