MADS: Fix positioning and clipping of flipped scaled images
This commit is contained in:
parent
7d82cac910
commit
8f20ebb610
3 changed files with 23 additions and 22 deletions
|
@ -258,7 +258,7 @@ void MSurface::copyFrom(MSurface *src, const Common::Rect &srcBounds,
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSurface::copyFrom(MSurface *src, const Common::Point &destPos, int depth,
|
void MSurface::copyFrom(MSurface *src, const Common::Point &destPos, int depth,
|
||||||
DepthSurface *depthSurface, int scale, int transparentColor) {
|
DepthSurface *depthSurface, int scale, bool flipped, int transparentColor) {
|
||||||
int destX = destPos.x, destY = destPos.y;
|
int destX = destPos.x, destY = destPos.y;
|
||||||
int frameWidth = src->getWidth();
|
int frameWidth = src->getWidth();
|
||||||
int frameHeight = src->getHeight();
|
int frameHeight = src->getHeight();
|
||||||
|
@ -337,12 +337,12 @@ void MSurface::copyFrom(MSurface *src, const Common::Point &destPos, int depth,
|
||||||
|
|
||||||
int destRight = this->getWidth() - 1;
|
int destRight = this->getWidth() - 1;
|
||||||
int destBottom = this->getHeight() - 1;
|
int destBottom = this->getHeight() - 1;
|
||||||
bool normalFrame = true;
|
|
||||||
|
|
||||||
// Check x bounding area
|
// Check x bounding area
|
||||||
int spriteLeft = 0;
|
int spriteLeft = 0;
|
||||||
int spriteWidth = distXCount;
|
int spriteWidth = distXCount;
|
||||||
int widthAmount = destX + distXCount - 1;
|
int widthAmount = destX + distXCount - 1;
|
||||||
|
int direction = flipped ? -1 : 1;
|
||||||
|
|
||||||
if (destX < 0) {
|
if (destX < 0) {
|
||||||
spriteWidth += destX;
|
spriteWidth += destX;
|
||||||
|
@ -355,7 +355,7 @@ void MSurface::copyFrom(MSurface *src, const Common::Point &destPos, int depth,
|
||||||
int spriteRight = spriteLeft + spriteWidth;
|
int spriteRight = spriteLeft + spriteWidth;
|
||||||
if (spriteWidth <= 0)
|
if (spriteWidth <= 0)
|
||||||
return;
|
return;
|
||||||
if (!normalFrame) {
|
if (flipped) {
|
||||||
destX += distXCount - 1;
|
destX += distXCount - 1;
|
||||||
spriteLeft = -(distXCount - spriteRight);
|
spriteLeft = -(distXCount - spriteRight);
|
||||||
spriteRight = (-spriteLeft + spriteWidth);
|
spriteRight = (-spriteLeft + spriteWidth);
|
||||||
|
@ -380,7 +380,7 @@ void MSurface::copyFrom(MSurface *src, const Common::Point &destPos, int depth,
|
||||||
|
|
||||||
byte *destPixelsP = this->getBasePtr(destX + spriteLeft, destY + spriteTop);
|
byte *destPixelsP = this->getBasePtr(destX + spriteLeft, destY + spriteTop);
|
||||||
|
|
||||||
spriteLeft = (spriteLeft * (normalFrame ? 1 : -1));
|
spriteLeft = spriteLeft * direction;
|
||||||
|
|
||||||
// Loop through the lines of the sprite
|
// Loop through the lines of the sprite
|
||||||
for (int yp = 0, sprY = -1; yp < frameHeight; ++yp, srcPixelsP += src->pitch) {
|
for (int yp = 0, sprY = -1; yp < frameHeight; ++yp, srcPixelsP += src->pitch) {
|
||||||
|
@ -412,7 +412,7 @@ void MSurface::copyFrom(MSurface *src, const Common::Point &destPos, int depth,
|
||||||
if ((*srcP != transparentColor) && (depth <= pixelDepth))
|
if ((*srcP != transparentColor) && (depth <= pixelDepth))
|
||||||
*destP = *srcP;
|
*destP = *srcP;
|
||||||
|
|
||||||
++destP;
|
destP += direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move to the next destination line
|
// Move to the next destination line
|
||||||
|
|
|
@ -162,10 +162,11 @@ public:
|
||||||
* @param depth Depth of sprite
|
* @param depth Depth of sprite
|
||||||
* @param depthSurface Depth surface to use with sprite depth
|
* @param depthSurface Depth surface to use with sprite depth
|
||||||
* @param scale Scale for image
|
* @param scale Scale for image
|
||||||
|
* @param flipped Flag for whether image is to be flipped
|
||||||
* @param transparentColor Transparency palette index
|
* @param transparentColor Transparency palette index
|
||||||
*/
|
*/
|
||||||
void copyFrom(MSurface *src, const Common::Point &destPos, int depth, DepthSurface *depthSurface,
|
void copyFrom(MSurface *src, const Common::Point &destPos, int depth, DepthSurface *depthSurface,
|
||||||
int scale, int transparentColor = -1);
|
int scale, bool flipped, int transparentColor = -1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies the surface to a given destination surface
|
* Copies the surface to a given destination surface
|
||||||
|
|
|
@ -317,16 +317,10 @@ void SpriteSlots::drawSprites(MSurface *s) {
|
||||||
assert(frameNumber > 0);
|
assert(frameNumber > 0);
|
||||||
MSprite *sprite = spriteSet.getFrame(frameNumber - 1);
|
MSprite *sprite = spriteSet.getFrame(frameNumber - 1);
|
||||||
|
|
||||||
MSurface *spr = sprite;
|
|
||||||
if (flipped) {
|
|
||||||
// Create a flipped copy of the sprite temporarily
|
|
||||||
spr = sprite->flipHorizontal();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((slot._scale < 100) && (slot._scale != -1)) {
|
if ((slot._scale < 100) && (slot._scale != -1)) {
|
||||||
// Scaled drawing
|
// Scaled drawing
|
||||||
s->copyFrom(spr, slot._position, slot._depth, &scene._depthSurface,
|
s->copyFrom(sprite, slot._position, slot._depth, &scene._depthSurface,
|
||||||
slot._scale, sprite->getTransparencyIndex());
|
slot._scale, flipped, sprite->getTransparencyIndex());
|
||||||
} else {
|
} else {
|
||||||
int xp, yp;
|
int xp, yp;
|
||||||
|
|
||||||
|
@ -334,23 +328,29 @@ void SpriteSlots::drawSprites(MSurface *s) {
|
||||||
xp = slot._position.x - scene._posAdjust.x;
|
xp = slot._position.x - scene._posAdjust.x;
|
||||||
yp = slot._position.y - scene._posAdjust.y;
|
yp = slot._position.y - scene._posAdjust.y;
|
||||||
} else {
|
} else {
|
||||||
xp = slot._position.x - (spr->w / 2) - scene._posAdjust.x;
|
xp = slot._position.x - (sprite->w / 2) - scene._posAdjust.x;
|
||||||
yp = slot._position.y - spr->h - scene._posAdjust.y + 1;
|
yp = slot._position.y - sprite->h - scene._posAdjust.y + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (slot._depth > 1) {
|
if (slot._depth > 1) {
|
||||||
// Draw the frame with depth processing
|
// Draw the frame with depth processing
|
||||||
s->copyFrom(spr, Common::Point(xp, yp), slot._depth, &scene._depthSurface,
|
s->copyFrom(sprite, Common::Point(xp, yp), slot._depth, &scene._depthSurface,
|
||||||
-1, sprite->getTransparencyIndex());
|
-1, flipped, sprite->getTransparencyIndex());
|
||||||
} else {
|
} else {
|
||||||
|
MSurface *spr = sprite;
|
||||||
|
if (flipped) {
|
||||||
|
// Create a flipped copy of the sprite temporarily
|
||||||
|
spr = sprite->flipHorizontal();
|
||||||
|
}
|
||||||
|
|
||||||
// No depth, so simply draw the image
|
// No depth, so simply draw the image
|
||||||
spr->copyTo(s, Common::Point(xp, yp), sprite->getTransparencyIndex());
|
spr->copyTo(s, Common::Point(xp, yp), sprite->getTransparencyIndex());
|
||||||
|
|
||||||
|
// Free sprite if it was a flipped one
|
||||||
|
if (flipped)
|
||||||
|
delete spr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free sprite if it was a flipped one
|
|
||||||
if (flipped)
|
|
||||||
delete spr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue