From e7fdf567fe53e45c00564dc1b5244e81686e89e6 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 18 Jan 2005 13:48:07 +0000 Subject: Fixed pattern drawing and focus on Ok/Select buttons for first dialogs. --- src/gui/char_select.cpp | 1 + src/gui/char_server.cpp | 1 + src/resources/image.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 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 true if the image was blitted properly + * false 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 true if the image was blitted properly * false otherwise. @@ -136,6 +147,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 true if drawing was succesful -- cgit v1.2.3-70-g09d2