00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef GRAPHICS_SURFACE_H
00024 #define GRAPHICS_SURFACE_H
00025
00026 #include "common/scummsys.h"
00027 #include "common/list.h"
00028
00029 namespace Common {
00030 struct Rect;
00031 struct Point;
00032 }
00033
00034 #include "graphics/pixelformat.h"
00035
00036 namespace Graphics {
00037
00042 struct Surface {
00043
00044
00045
00046
00047
00048
00049
00053 uint16 w;
00054
00058 uint16 h;
00059
00065 uint16 pitch;
00066
00067 protected:
00071 void *pixels;
00072
00073 public:
00077 PixelFormat format;
00078
00082 Surface() : w(0), h(0), pitch(0), pixels(0), format() {
00083 }
00084
00090 inline const void *getPixels() const {
00091 return pixels;
00092 }
00093
00099 inline void *getPixels() {
00100 return pixels;
00101 }
00102
00110 void setPixels(void *newPixels) { pixels = newPixels; }
00111
00119 inline const void *getBasePtr(int x, int y) const {
00120 return (const byte *)(pixels) + y * pitch + x * format.bytesPerPixel;
00121 }
00122
00130 inline void *getBasePtr(int x, int y) {
00131 return static_cast<byte *>(pixels) + y * pitch + x * format.bytesPerPixel;
00132 }
00133
00144 void create(uint16 width, uint16 height, const PixelFormat &format);
00145
00154 void free();
00155
00168 void init(uint16 width, uint16 height, uint16 pitch, void *pixels, const PixelFormat &format);
00169
00181 void copyFrom(const Surface &surf);
00182
00197 Surface getSubArea(const Common::Rect &area);
00198
00212 const Surface getSubArea(const Common::Rect &area) const;
00213
00225 void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height);
00235 void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect);
00236
00250 void convertToInPlace(const PixelFormat &dstFormat, const byte *palette = 0);
00251
00261 Graphics::Surface *convertTo(const PixelFormat &dstFormat, const byte *palette = 0) const;
00262
00273 void drawLine(int x0, int y0, int x1, int y1, uint32 color);
00274
00288 void drawThickLine(int x0, int y0, int x1, int y1, int penX, int penY, uint32 color);
00289
00299 void hLine(int x, int y, int x2, uint32 color);
00300
00310 void vLine(int x, int y, int y2, uint32 color);
00311
00318 void fillRect(Common::Rect r, uint32 color);
00319
00326 void frameRect(const Common::Rect &r, uint32 color);
00327
00328
00329 void move(int dx, int dy, int height);
00330 };
00331
00337 struct SurfaceDeleter {
00338 void operator()(Surface *ptr) {
00339 if (ptr) {
00340 ptr->free();
00341 }
00342 delete ptr;
00343 }
00344 };
00345
00356 class FloodFill {
00357 public:
00365 FloodFill(Surface *surface, uint32 oldColor, uint32 fillColor, bool maskMode = false);
00366 ~FloodFill();
00367
00374 void addSeed(int x, int y);
00375
00383 void fill();
00384
00393 void fillMask();
00394
00400 Surface *getMask() { return _mask; }
00401
00402 private:
00403 Common::List<Common::Point *> _queue;
00404 Surface *_surface;
00405 Surface *_mask;
00406 uint32 _oldColor, _fillColor;
00407 byte *_visited;
00408 int _w, _h;
00409
00410 bool _maskMode;
00411 };
00412
00413 }
00414
00415
00416 #endif