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:
parent
527a372bd3
commit
6bbdf7e183
|
@ -278,9 +278,21 @@ IntRect Bitmap::rect() const
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bitmap::blt(int x, int y,
|
void Bitmap::blt(int x, int y,
|
||||||
const Bitmap &source, const IntRect &rect,
|
const Bitmap &source, IntRect rect,
|
||||||
int opacity)
|
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),
|
stretchBlt(IntRect(x, y, rect.w, rect.h),
|
||||||
source, rect, opacity);
|
source, rect, opacity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
IntRect rect() const;
|
IntRect rect() const;
|
||||||
|
|
||||||
void blt(int x, int y,
|
void blt(int x, int y,
|
||||||
const Bitmap &source, const IntRect &rect,
|
const Bitmap &source, IntRect rect,
|
||||||
int opacity = 255);
|
int opacity = 255);
|
||||||
|
|
||||||
void stretchBlt(const IntRect &destRect,
|
void stretchBlt(const IntRect &destRect,
|
||||||
|
|
Loading…
Reference in New Issue