diff --git a/src/bitmap.cpp b/src/bitmap.cpp index b951f52..d023f55 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -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); } diff --git a/src/bitmap.h b/src/bitmap.h index cb491bb..fd4d8c6 100644 --- a/src/bitmap.h +++ b/src/bitmap.h @@ -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,