From 260ec7a430b34f75ec6c30f0f8f444bb7397341e Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sat, 3 Aug 2013 03:42:37 +0200 Subject: GRAPHICS: Add two new methods to change 'pixels' of a Surface. One method is a simpler setter for 'pixels'. The other one can be used to setup a Surface with custom data. --- graphics/surface.cpp | 8 ++++++++ graphics/surface.h | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'graphics') diff --git a/graphics/surface.cpp b/graphics/surface.cpp index 010389c9fa..728c6db12c 100644 --- a/graphics/surface.cpp +++ b/graphics/surface.cpp @@ -82,6 +82,14 @@ void Surface::free() { format = PixelFormat(); } +void Surface::init(uint16 width, uint16 height, uint16 newPitch, void *newPixels, const PixelFormat &f) { + w = width; + h = height; + pitch = newPitch; + pixels = newPixels; + format = f; +} + void Surface::copyFrom(const Surface &surf) { create(surf.w, surf.h, surf.format); if (surf.pitch == pitch) { diff --git a/graphics/surface.h b/graphics/surface.h index d685853009..8ce2cf3ecc 100644 --- a/graphics/surface.h +++ b/graphics/surface.h @@ -95,6 +95,15 @@ struct Surface { return pixels; } + /** + * Sets the pixel data. + * + * Note that this is a simply setter. Be careful what you are doing! + * + * @param newPixels The new pixel data. + */ + void setPixels(void *newPixels) { pixels = newPixels; } + /** * Return a pointer to the pixel at the specified point. * @@ -139,6 +148,20 @@ struct Surface { */ void free(); + /** + * Set up the Surface with user specified data. + * + * Note that this simply sets the 'internal' attributes of the Surface. It + * will not take care of freeing old data via free or similar! + * + * @param width Width of the pixel data. + * @param height Height of the pixel data. + * @param pitch The pitch of the pixel data. + * @param pixels The pixel data itself. + * @param format The pixel format of the pixel data. + */ + void init(uint16 width, uint16 height, uint16 pitch, void *pixels, const PixelFormat &format); + /** * Copy the data from another Surface. * -- cgit v1.2.3