diff options
author | Kari Salminen | 2008-08-07 19:31:12 +0000 |
---|---|---|
committer | Kari Salminen | 2008-08-07 19:31:12 +0000 |
commit | 853f4dbbe00afb8d857c821dd6c0ef3aed4733f2 (patch) | |
tree | 74a97c7029c3b095e8bbe9cb14bddbbc01d58bec /engines | |
parent | b8bfd5d04f0436b685ea36a845439e20bb756766 (diff) | |
download | scummvm-rg350-853f4dbbe00afb8d857c821dd6c0ef3aed4733f2.tar.gz scummvm-rg350-853f4dbbe00afb8d857c821dd6c0ef3aed4733f2.tar.bz2 scummvm-rg350-853f4dbbe00afb8d857c821dd6c0ef3aed4733f2.zip |
Made drawPlainBox handle border cases so it won't corrupt memory so easily. This may help with some memory corruption issues when for an example trying to draw the player's command string out of screen.
svn-id: r33687
Diffstat (limited to 'engines')
-rw-r--r-- | engines/cine/gfx.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/engines/cine/gfx.cpp b/engines/cine/gfx.cpp index 3d0ad278b9..bbd79aa391 100644 --- a/engines/cine/gfx.cpp +++ b/engines/cine/gfx.cpp @@ -282,20 +282,43 @@ void FWRenderer::drawMessage(const char *str, int x, int y, int width, byte colo */ void FWRenderer::drawPlainBox(int x, int y, int width, int height, byte color) { int i; - byte *dest = _backBuffer + y * 320 + x; + // Handle horizontally flipped boxes if (width < 0) { x += width; - width = -width; + width = ABS(width); } + // Handle vertically flipped boxes if (height < 0) { y += height; - height = -height; + height = ABS(height); } - for (i = 0; i < height; i++) { - memset(dest + i * 320, color, width); + // Handle horizontal boundaries + if (x < 0) { + width += x; // Remove invisible columns + x = 0; // Start drawing at the screen's left border + } else if (x > 319) { + // Nothing left to draw as we're over the screen's right border + width = 0; + } + + // Handle vertical boundaries + if (y < 0) { + height += y; // Remove invisible rows + y = 0; // Start drawing at the screen's top border + } else if (y > 199) { + // Nothing left to draw as we're below the screen's bottom border + height = 0; + } + + // Draw the box if it's not empty + if (width > 0 && height > 0) { + byte *dest = _backBuffer + y * 320 + x; + for (i = 0; i < height; i++) { + memset(dest + i * 320, color, width); + } } } |