diff options
-rw-r--r-- | src/gui/char_select.cpp | 1 | ||||
-rw-r--r-- | src/gui/char_server.cpp | 1 | ||||
-rw-r--r-- | src/resources/image.cpp | 46 | ||||
-rw-r--r-- | src/resources/image.h | 19 |
4 files changed, 64 insertions, 3 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 3e509727..5032b196 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -99,6 +99,7 @@ CharSelectDialog::CharSelectDialog(): newCharButton->addActionListener(this); delCharButton->addActionListener(this); + selectButton->requestFocus(); setLocationRelativeTo(getParent()); } diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index 5b3992f1..cb1d3659 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -75,6 +75,7 @@ ServerSelectDialog::ServerSelectDialog(): serverList->setSelected(1); } + okButton->requestFocus(); setLocationRelativeTo(getParent()); } 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. diff --git a/src/resources/image.h b/src/resources/image.h index d5c98c5d..1c2b58cf 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -83,7 +83,18 @@ class Image : public Resource virtual Image* getScaledInstance(int width, int height); /** - * Blits the internal image onto the screen. + * Blits the image onto the screen. + * + * @return <code>true</code> if the image was blitted properly + * <code>false</code> otherwise. + */ + virtual bool draw(SDL_Surface *screen, + int srcX, int srcY, + int dstX, int dstY, + int width, int height); + + /** + * Blits the image onto the screen. * * @return <code>true</code> if the image was blitted properly * <code>false</code> otherwise. @@ -137,6 +148,12 @@ class SubImage : public Image Image* getSubImage(int x, int y, int width, int height); /** + * Draws this image. + */ + bool draw(SDL_Surface *screen, int srcX, int srcY, + int dstX, int dstY, int width, int height); + + /** * Draws the clipped image onto the screen. * @return <code>true</code> if drawing was succesful * <code>false</code> otherwise. |