Bitmap#blt: Clamp source rect to source bitmap bounds

RGSS allows the source rectangle in both `blt` and
`stretch_blt` to lie outside the source bitmap bounds
(treating the missing data as (0, 0, 0, 0)) and to be
inverted (in which case the blitted image is also inverted).

This commit only hanldes a corner case that
arises in the game "Last Scenario"; emulating the full
RGSS behavior is however desirable.
This commit is contained in:
Jonas Kulla 2014-07-09 02:56:35 +02:00
parent 527a372bd3
commit 6bbdf7e183
2 changed files with 14 additions and 2 deletions

View File

@ -278,9 +278,21 @@ IntRect Bitmap::rect() const
}
void Bitmap::blt(int x, int y,
const Bitmap &source, const IntRect &rect,
const Bitmap &source, IntRect rect,
int opacity)
{
// FIXME: RGSS allows the source rect to both lie outside
// the bitmap rect and be inverted in both directions;
// clamping only covers a subset of these cases (and
// doesn't fix anything for a direct stretch_blt call).
/* Clamp rect to source bitmap size */
if (rect.x + rect.w > source.width())
rect.w = source.width() - rect.x;
if (rect.y + rect.h > source.height())
rect.h = source.height() - rect.y;
stretchBlt(IntRect(x, y, rect.w, rect.h),
source, rect, opacity);
}

View File

@ -49,7 +49,7 @@ public:
IntRect rect() const;
void blt(int x, int y,
const Bitmap &source, const IntRect &rect,
const Bitmap &source, IntRect rect,
int opacity = 255);
void stretchBlt(const IntRect &destRect,