diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-01-14 12:43:28 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-01-14 12:43:28 +0000 |
commit | 5a1007fa3e827c03bb86db71cb26dfd4c485f28d (patch) | |
tree | a8f114d7ae6ccb1806602b89d3ea3cf6bbfe7d83 /src | |
parent | cfac9a371a684a3a6f37bad725094b7e2d80a7d1 (diff) | |
download | Mana-5a1007fa3e827c03bb86db71cb26dfd4c485f28d.tar.gz Mana-5a1007fa3e827c03bb86db71cb26dfd4c485f28d.tar.bz2 Mana-5a1007fa3e827c03bb86db71cb26dfd4c485f28d.tar.xz Mana-5a1007fa3e827c03bb86db71cb26dfd4c485f28d.zip |
Extended Image with methods to get width, height and draw a pattern and made
Window widget use it.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/stats.cpp | 4 | ||||
-rw-r--r-- | src/gui/window.cpp | 29 | ||||
-rw-r--r-- | src/gui/window.h | 7 | ||||
-rw-r--r-- | src/resources/image.cpp | 37 | ||||
-rw-r--r-- | src/resources/image.h | 20 |
5 files changed, 76 insertions, 21 deletions
diff --git a/src/gui/stats.cpp b/src/gui/stats.cpp index 8f2a20f4..3c5bbb3c 100644 --- a/src/gui/stats.cpp +++ b/src/gui/stats.cpp @@ -112,8 +112,8 @@ StatsWindow::~StatsWindow() { } } -StatsWindow * StatsWindow::ptr = NULL; -StatsWindow * StatsWindow::create_statswindow() { +StatsWindow *StatsWindow::ptr = NULL; +StatsWindow *StatsWindow::create_statswindow() { if (ptr == NULL) { ptr = new StatsWindow(); } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 9ab17799..d69dae77 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -24,6 +24,7 @@ #include "window.h" #include "gui.h" #include <guichan/allegro.hpp> +#include "../resources/resourcemanager.h" WindowContainer *Window::windowContainer = NULL; @@ -48,9 +49,10 @@ Window::Window(const std::string& text, bool modal, Window *parent): setBaseColor(gcn::Color(255, 255, 255)); // Load dialog title bar image - dLeft = load_bitmap("data/Skin/dialogLeft.bmp", NULL); - dMid = load_bitmap("data/Skin/dialogMiddle.bmp", NULL); - dRight = load_bitmap("data/Skin/dialogRight.bmp", NULL); + ResourceManager *resman = ResourceManager::getInstance(); + dLeft = resman->createImage("Skin/dialogLeft.bmp"); + dMid = resman->createImage("Skin/dialogMiddle.bmp"); + dRight = resman->createImage("Skin/dialogRight.bmp"); // Register mouse listener addMouseListener(this); @@ -77,9 +79,9 @@ Window::~Window() #endif // Free dialog bitmaps - release_bitmap(dLeft); - release_bitmap(dMid); - release_bitmap(dRight); + //release_bitmap(dLeft); + //release_bitmap(dMid); + //release_bitmap(dRight); delete chrome; } @@ -109,17 +111,16 @@ void Window::draw(gcn::Graphics* graphics) { gcn::AllegroGraphics *gfx = (gcn::AllegroGraphics*)graphics; BITMAP *screen = gfx->getTarget(); - int x, y, i; + int x, y; getAbsolutePosition(x, y); // Draw title bar - masked_blit(dLeft, screen, 0, 0, x, y, 24, 24); - for (i = 24; i < getWidth() - 24; i += 24) - { - blit(dMid, screen, 0, 0, x + i, y, 24, 24); - } - masked_blit(dRight, screen, 0, 0, - x + getWidth() - 24, y, 24, 24); + dLeft->draw(screen, x, y); + dMid->drawPattern(screen, + x + dLeft->getWidth(), y, + getWidth() - dLeft->getWidth() - dRight->getWidth(), + dMid->getHeight()); + dRight->draw(screen, x + getWidth() - dRight->getWidth(), y); } else { // Plain title bar diff --git a/src/gui/window.h b/src/gui/window.h index 39d04ddb..6802ce2d 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -28,6 +28,7 @@ #include <allegro.h> #include <guichan.hpp> #include "windowcontainer.h" +#include "../resources/image.h" /** * A window. This window can be dragged around and has a title bar. @@ -49,9 +50,9 @@ class Window : public gcn::Container, public gcn::MouseListener gcn::Color titlebarColor; /**< Title bar color */ int titlebarHeight; /**< Height of title bar */ - BITMAP *dLeft; /**< Left side of title bar */ - BITMAP *dMid; /**< Middle of title bar */ - BITMAP *dRight; /**< Right side of title bar */ + Image *dLeft; /**< Left side of title bar */ + Image *dMid; /**< Middle of title bar */ + Image *dRight; /**< Right side of title bar */ /** The window container windows add themselves to. */ static WindowContainer* windowContainer; 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; |