diff options
Diffstat (limited to 'engines/neverhood/graphics.cpp')
-rw-r--r-- | engines/neverhood/graphics.cpp | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/engines/neverhood/graphics.cpp b/engines/neverhood/graphics.cpp index 66a7999e59..89792d2659 100644 --- a/engines/neverhood/graphics.cpp +++ b/engines/neverhood/graphics.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -29,7 +29,7 @@ namespace Neverhood { BaseSurface::BaseSurface(NeverhoodEngine *vm, int priority, int16 width, int16 height, Common::String name) : _vm(vm), _priority(priority), _visible(true), _transparent(true), _clipRects(NULL), _clipRectsCount(0), _version(0), _name(name) { - + _drawRect.x = 0; _drawRect.y = 0; _drawRect.width = width; @@ -47,6 +47,7 @@ BaseSurface::BaseSurface(NeverhoodEngine *vm, int priority, int16 width, int16 h } BaseSurface::~BaseSurface() { + _surface->free(); delete _surface; } @@ -68,7 +69,7 @@ void BaseSurface::clear() { } void BaseSurface::drawSpriteResource(SpriteResource &spriteResource) { - if (spriteResource.getDimensions().width <= _drawRect.width && + if (spriteResource.getDimensions().width <= _drawRect.width && spriteResource.getDimensions().height <= _drawRect.height) { clear(); spriteResource.draw(_surface, false, false); @@ -77,7 +78,7 @@ void BaseSurface::drawSpriteResource(SpriteResource &spriteResource) { } void BaseSurface::drawSpriteResourceEx(SpriteResource &spriteResource, bool flipX, bool flipY, int16 width, int16 height) { - if (spriteResource.getDimensions().width <= _sysRect.width && + if (spriteResource.getDimensions().width <= _sysRect.width && spriteResource.getDimensions().height <= _sysRect.height) { if (width > 0 && width <= _sysRect.width) _drawRect.width = width; @@ -113,7 +114,15 @@ void BaseSurface::drawMouseCursorResource(MouseCursorResource &mouseCursorResour } void BaseSurface::copyFrom(Graphics::Surface *sourceSurface, int16 x, int16 y, NDrawRect &sourceRect) { - // Copy a rectangle from sourceSurface, no clipping is performed, 0 is the transparent color + // Copy a rectangle from sourceSurface, 0 is the transparent color + // Clipping is performed against the right/bottom border since x, y will always be >= 0 + + if (x + sourceRect.width > _surface->w) + sourceRect.width = _surface->w - x - 1; + + if (y + sourceRect.height > _surface->h) + sourceRect.height = _surface->h - y - 1; + byte *source = (byte*)sourceSurface->getBasePtr(sourceRect.x, sourceRect.y); byte *dest = (byte*)_surface->getBasePtr(x, y); int height = sourceRect.height; @@ -145,7 +154,7 @@ void ShadowSurface::draw() { FontSurface::FontSurface(NeverhoodEngine *vm, NPointArray *tracking, uint charsPerRow, uint16 numRows, byte firstChar, uint16 charWidth, uint16 charHeight) : BaseSurface(vm, 0, charWidth * charsPerRow, charHeight * numRows, "font"), _charsPerRow(charsPerRow), _numRows(numRows), _firstChar(firstChar), _charWidth(charWidth), _charHeight(charHeight), _tracking(NULL) { - + _tracking = new NPointArray(); *_tracking = *tracking; @@ -154,7 +163,7 @@ FontSurface::FontSurface(NeverhoodEngine *vm, NPointArray *tracking, uint charsP FontSurface::FontSurface(NeverhoodEngine *vm, uint32 fileHash, uint charsPerRow, uint16 numRows, byte firstChar, uint16 charWidth, uint16 charHeight) : BaseSurface(vm, 0, charWidth * charsPerRow, charHeight * numRows, "font"), _charsPerRow(charsPerRow), _numRows(numRows), _firstChar(firstChar), _charWidth(charWidth), _charHeight(charHeight), _tracking(NULL) { - + SpriteResource fontSpriteResource(_vm); fontSpriteResource.load(fileHash, true); drawSpriteResourceEx(fontSpriteResource, false, false, 0, 0); @@ -182,7 +191,7 @@ void FontSurface::drawString(BaseSurface *destSurface, int16 x, int16 y, const b for (; stringLen > 0; --stringLen, ++string) { drawChar(destSurface, x, y, *string); x += _tracking ? (*_tracking)[*string - _firstChar].x : _charWidth; - } + } } @@ -201,7 +210,7 @@ FontSurface *FontSurface::createFontSurface(NeverhoodEngine *vm, uint32 fileHash uint16 charHeight = fontData.getPoint(calcHash("meCharHeight")).x; NPointArray *tracking = fontData.getPointArray(calcHash("meTracking")); fontSprite.load(fileHash, true); - fontSurface = new FontSurface(vm, tracking, 16, numRows, firstChar, charWidth, charHeight); + fontSurface = new FontSurface(vm, tracking, 16, numRows, firstChar, charWidth, charHeight); fontSurface->drawSpriteResourceEx(fontSprite, false, false, 0, 0); return fontSurface; } @@ -219,7 +228,7 @@ enum BitmapFlags { void parseBitmapResource(const byte *sprite, bool *rle, NDimensions *dimensions, NPoint *position, const byte **palette, const byte **pixels) { uint16 flags; - + flags = READ_LE_UINT16(sprite); sprite += 2; @@ -278,7 +287,7 @@ void unpackSpriteRle(const byte *source, int width, int height, byte *dest, int rows = READ_LE_UINT16(source); chunks = READ_LE_UINT16(source + 2); source += 4; - + do { if (chunks == 0) { dest += rows * destPitch; @@ -299,11 +308,11 @@ void unpackSpriteRle(const byte *source, int width, int height, byte *dest, int } source += copy; } - dest += destPitch; if (replaceColors) for (int xc = 0; xc < width; xc++) if (dest[xc] == oldColor) dest[xc] = newColor; + dest += destPitch; } } rows = READ_LE_UINT16(source); @@ -316,7 +325,7 @@ void unpackSpriteRle(const byte *source, int width, int height, byte *dest, int void unpackSpriteNormal(const byte *source, int width, int height, byte *dest, int destPitch, bool flipX, bool flipY) { const int sourcePitch = (width + 3) & 0xFFFC; - + if (flipY) { dest += destPitch * (height - 1); destPitch = -destPitch; |