diff options
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/image.cpp | 37 | ||||
-rw-r--r-- | src/resources/image.h | 20 |
2 files changed, 55 insertions, 2 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 8a37a4e1..fb36f400 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -63,6 +63,23 @@ void Image::unload() } } + +int Image::getWidth() +{ + if (image != NULL) { + return image->w; + } + return 0; +} + +int Image::getHeight() +{ + if (image != NULL) { + return image->h; + } + return 0; +} + Image* Image::createSubImage(int x, int y, int width, int height) { // Create a new clipped sub-image @@ -83,6 +100,26 @@ bool Image::draw(BITMAP *screen, int x, int y) return true; } +void Image::drawPattern(BITMAP *screen, int x, int y, int w, int h) +{ + int iw = getWidth(); // Width of image + int ih = getHeight(); // Height of image + if (iw == 0 || ih == 0) return; + + int px = 0; // X position on pattern plane + int py = 0; // Y position on pattern plane + + while (py < h) { + while (px < w) { + draw(screen, x + px, y + py); + // TODO: Prevent overdraw + px += iw; + } + py += ih; + px = x; + } +} + SubImage::SubImage(Image *parent, BITMAP *image, int x, int y, int width, int height): Image(create_sub_bitmap(image, x, y, width, height)), diff --git a/src/resources/image.h b/src/resources/image.h index 363dabde..8f956324 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -63,6 +63,16 @@ class Image : public Resource void unload(); /** + * Returns the width of the image. + */ + int getWidth(); + + /** + * Returns the height of the image. + */ + int getHeight(); + + /** * Creates a new image with the desired clipping rectangle. * @return <code>NULL</code> if creation failed and a valid * object otherwise. @@ -70,12 +80,18 @@ class Image : public Resource Image* createSubImage(int x, int y, int width, int height); /** - * Attempts to blit the internal image onto the screen. + * Blits the internal image onto the screen. + * * @return <code>true</code> if the image was blitted properly - * <code>false</code> otherwise. + * <code>false</code> otherwise. */ bool draw(BITMAP *screen, int x, int y); + /** + * Does a pattern fill on the given area. + */ + void drawPattern(BITMAP *screen, int x, int y, int w, int h); + protected: //SDL_Rect screenRect; //SDL_Surface *image; |