diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-01-18 13:48:07 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-01-18 13:48:07 +0000 |
commit | e7fdf567fe53e45c00564dc1b5244e81686e89e6 (patch) | |
tree | 29f6bddb541c50d5f3c6b1cd24067d3c6775c869 /src/resources/image.cpp | |
parent | 39ea054b214612ae7d56a01884904dcb63181598 (diff) | |
download | mana-e7fdf567fe53e45c00564dc1b5244e81686e89e6.tar.gz mana-e7fdf567fe53e45c00564dc1b5244e81686e89e6.tar.bz2 mana-e7fdf567fe53e45c00564dc1b5244e81686e89e6.tar.xz mana-e7fdf567fe53e45c00564dc1b5244e81686e89e6.zip |
Fixed pattern drawing and focus on Ok/Select buttons for first dialogs.
Diffstat (limited to 'src/resources/image.cpp')
-rw-r--r-- | src/resources/image.cpp | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 7a06a4cc..15ef6708 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -96,6 +96,26 @@ Image *Image::getScaledInstance(int width, int height) return new ScaledImage(this, image, width, height); } +bool Image::draw(SDL_Surface *screen, int srcX, int srcY, int dstX, int dstY, + int width, int height) +{ + // Check that preconditions for blitting are met. + if (screen == NULL || image == NULL) return false; + + SDL_Rect dstRect; + SDL_Rect srcRect; + dstRect.x = dstX; dstRect.y = dstY; + srcRect.x = srcX; srcRect.y = srcY; + srcRect.w = width; + srcRect.h = height; + + if (SDL_BlitSurface(image, &srcRect, screen, &dstRect) < 0) { + return false; + } + + return true; +} + bool Image::draw(SDL_Surface *screen, int x, int y) { // Check that preconditions for blitting are met. @@ -123,8 +143,9 @@ void Image::drawPattern(SDL_Surface *screen, int x, int y, int w, int h) while (py < h) { while (px < w) { - draw(screen, x + px, y + py); - // TODO: Prevent overdraw + int dw = (px + iw >= w) ? w - px : iw; + int dh = (py + ih >= h) ? h - py : ih; + draw(screen, 0, 0, x + px, y + py, dw, dh); px += iw; } py += ih; @@ -170,6 +191,27 @@ Image *SubImage::getSubImage(int x, int y, int w, int h) return NULL; } +bool SubImage::draw(SDL_Surface *screen, int srcX, int srcY, + int dstX, int dstY, int width, int height) +{ + // Check that preconditions for blitting are met. + if (screen == NULL || image == NULL) return false; + + SDL_Rect dstRect; + SDL_Rect srcRect; + dstRect.x = dstX; dstRect.y = dstY; + srcRect.x = rect.x + srcX; + srcRect.y = rect.y + srcY; + srcRect.w = width; + srcRect.h = height; + + if (SDL_BlitSurface(image, &srcRect, screen, &dstRect) < 0) { + return false; + } + + return true; +} + bool SubImage::draw(SDL_Surface *screen, int x, int y) { // Check that drawing preconditions are satisfied. |