aboutsummaryrefslogtreecommitdiff
path: root/graphics/surface.h
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/surface.h')
-rw-r--r--graphics/surface.h105
1 files changed, 103 insertions, 2 deletions
diff --git a/graphics/surface.h b/graphics/surface.h
index 6c9e464657..f1b2aa64ab 100644
--- a/graphics/surface.h
+++ b/graphics/surface.h
@@ -61,11 +61,13 @@ struct Surface {
*/
uint16 pitch;
+protected:
/**
* The surface's pixel data.
*/
void *pixels;
+public:
/**
* The pixel format of the surface.
*/
@@ -78,6 +80,33 @@ struct Surface {
}
/**
+ * Return a pointer to the pixel data.
+ *
+ * @return Pointer to the pixel data.
+ */
+ inline const void *getPixels() const {
+ return pixels;
+ }
+
+ /**
+ * Return a pointer to the pixel data.
+ *
+ * @return Pointer to the pixel data.
+ */
+ inline void *getPixels() {
+ return pixels;
+ }
+
+ /**
+ * Sets the pixel data.
+ *
+ * Note that this is a simply a 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.
*
* @param x The x coordinate of the pixel.
@@ -122,6 +151,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.
*
* Note that this calls free on the current surface, to assure it being
@@ -135,10 +178,66 @@ struct Surface {
void copyFrom(const Surface &surf);
/**
+ * Creates a Surface which represents a sub-area of this Surface object.
+ *
+ * The pixel (0, 0) of the returned Surface will be the same as Pixel
+ * (area.x, area.y) of this Surface. Changes to any of the Surface objects
+ * will change the shared pixel data.
+ *
+ * Note that the Surface returned is only valid as long as this Surface
+ * object is still alive (i.e. its pixel data is not destroyed or
+ * reallocated). Do *never* try to free the returned Surface.
+ *
+ * @param area The area which should be represented. Note that the area
+ * will get clipped in case it does not fit!
+ */
+ Surface getSubArea(const Common::Rect &area);
+
+ /**
+ * Creates a Surface which represents a sub-area of this Surface object.
+ *
+ * The pixel (0, 0) of the returned Surface will be the same as Pixel
+ * (area.x, area.y) of this Surface.
+ *
+ * Note that the Surface returned is only valid as long as this Surface
+ * object is still alive (i.e. its pixel data is not destroyed or
+ * reallocated). Do *never* try to free the returned Surface.
+ *
+ * @param area The area which should be represented. Note that the area
+ * will get clipped in case it does not fit!
+ */
+ const Surface getSubArea(const Common::Rect &area) const;
+
+ /**
+ * Copies a bitmap to the Surface internal buffer. The pixel format
+ * of buffer must match the pixel format of the Surface.
+ *
+ * @param buffer The buffer containing the graphics data source
+ * @param pitch The pitch of the buffer (number of bytes in a scanline)
+ * @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 srcPitch, 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.
*
* This works in-place. This means it will not create an additional buffer
- * for the conversion process. The value of pixels might change though.
+ * for the conversion process. The value of 'pixels' might change though
+ * (that means it might realloc the pixel data).
*
* Note that you should only use this, when you created the Surface data via
* create! Otherwise this function has undefined behavior.
@@ -235,7 +334,9 @@ struct Surface {
*/
struct SharedPtrSurfaceDeleter {
void operator()(Surface *ptr) {
- ptr->free();
+ if (ptr) {
+ ptr->free();
+ }
delete ptr;
}
};