From 6f4e80e36e7729bd2137a1a2bde712521861b0b3 Mon Sep 17 00:00:00 2001 From: RichieSams Date: Thu, 12 Sep 2013 09:30:28 -0500 Subject: ZVISION: Add wrapper function for copyRectToSurface Also rename some arguments to make them more clear --- graphics/surface.cpp | 18 ++++++++++++------ graphics/surface.h | 17 ++++++++++++++--- 2 files changed, 26 insertions(+), 9 deletions(-) (limited to 'graphics') diff --git a/graphics/surface.cpp b/graphics/surface.cpp index d808121c87..a8173f0e9c 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -133,17 +133,17 @@ const Surface Surface::getSubArea(const Common::Rect &area) const { return subSurface; } -void Surface::copyRectToSurface(const void *buffer, int pitch, int x, int y, int width, int height) { +void Surface::copyRectToSurface(const void *buffer, int pitch, int destX, int destY, int width, int height) { assert(buffer); - assert(x >= 0 && x < w); - assert(y >= 0 && y < h); - assert(height > 0 && y + height <= h); - assert(width > 0 && x + width <= w); + assert(destX >= 0 && destX < w); + assert(destY >= 0 && destY < h); + assert(height > 0 && destY + height <= h); + assert(width > 0 && destX + width <= w); // Copy buffer data to internal buffer const byte *src = (const byte *)buffer; - byte *dst = (byte *)getBasePtr(x, y); + byte *dst = (byte *)getBasePtr(destX, destY); for (int i = 0; i < height; i++) { memcpy(dst, src, width * format.bytesPerPixel); src += pitch; @@ -151,6 +151,12 @@ void Surface::copyRectToSurface(const void *buffer, int pitch, int x, int y, int } } +void Surface::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect) { + assert(srcSurface.format == format); + + copyRectToSurface(srcSurface.getBasePtr(subRect.left, subRect.top), srcSurface.pitch, destX, destY, subRect.width(), subRect.height()); +} + void Surface::hLine(int x, int y, int x2, uint32 color) { // Clipping if (y < 0 || y >= h) diff --git a/graphics/surface.h b/graphics/surface.h index ad52ed8238..1492e71e68 100644 --- a/graphics/surface.h +++ b/graphics/surface.h @@ -214,12 +214,23 @@ public: * * @param buffer The buffer containing the graphics data source * @param pitch The pitch of the buffer (number of bytes in a scanline) - * @param x The x coordinate of the destination rectangle - * @param y The y coordinate of the destination rectangle + * @param destX The x coordinate of the destination rectangle + * @param destY The y coordinate of the destination rectangle * @param width The width of the destination rectangle * @param height The height of the destination rectangle */ - void copyRectToSurface(const void *buffer, int pitch, int x, int y, int width, int height); + void copyRectToSurface(const void *buffer, int pitch, int destX, int destY, int width, int height); + /** + * Copies a bitmap to the Surface internal buffer. The pixel format + * of buffer must match the pixel format of the Surface. + * + * @param srcSurface The source of the bitmap data + * @param destX The x coordinate of the destination rectangle + * @param destY The y coordinate of the destination rectangle + * @param subRect The subRect of surface to be blitted + * @return + */ + void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect); /** * Convert the data to another pixel format. -- cgit v1.2.3