diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-07-14 12:16:56 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-07-14 12:16:56 +0000 |
commit | ef3069f212029c4ca277c2dc369d5f04066ef186 (patch) | |
tree | 13541f4b2268750ea96e9178b9799609a6a84aad /src/gui/progressbar.cpp | |
parent | 92ff85076658f0bd2d175b53e4ee1d03b9437aa3 (diff) | |
download | mana-client-ef3069f212029c4ca277c2dc369d5f04066ef186.tar.gz mana-client-ef3069f212029c4ca277c2dc369d5f04066ef186.tar.bz2 mana-client-ef3069f212029c4ca277c2dc369d5f04066ef186.tar.xz mana-client-ef3069f212029c4ca277c2dc369d5f04066ef186.zip |
Code duplication reduction by Doener, instance counting by me, and a small
improvement to the s character in the font.
Diffstat (limited to 'src/gui/progressbar.cpp')
-rw-r--r-- | src/gui/progressbar.cpp | 98 |
1 files changed, 57 insertions, 41 deletions
diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index 25a3da01..34c164d1 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -25,38 +25,56 @@ #include "../graphics.h" #include "../resources/resourcemanager.h" +ImageRect ProgressBar::mBorder; +int ProgressBar::mInstances = 0; + ProgressBar::ProgressBar(float progress, int x, int y, int width, int height, int red, int green, int blue): gcn::Widget(), - red(red), green(green), blue(blue) + red(red), green(green), blue(blue), + redToGo(red), greenToGo(green), blueToGo(blue) { setProgress(progress); setX(x); setY(y); setWidth(width); setHeight(height); - redToGo = red; - greenToGo = green; - blueToGo = blue; - - // Load dialog title bar image - ResourceManager *resman = ResourceManager::getInstance(); - Image *dBorders = resman->getImage("graphics/gui/vscroll_grey.png"); - dBackground = resman->getImage("graphics/gui/bg_quad_dis.png"); - - dTopBorder = dBorders->getSubImage(4, 0, 3, 4); - dLeftBorder = dBorders->getSubImage(0, 4, 4, 10); - dRightBorder = dBorders->getSubImage(7, 4, 4, 10); - dBottomBorder = dBorders->getSubImage(4, 15, 3, 4); - - dTopLeftBorder = dBorders->getSubImage(0, 0, 4, 4); - dTopRightBorder = dBorders->getSubImage(7, 0, 4, 4); - dBottomRightBorder = dBorders->getSubImage(7, 15, 4, 4); - dBottomLeftBorder = dBorders->getSubImage(0, 15, 4, 4); + + if (mInstances == 0) + { + ResourceManager *resman = ResourceManager::getInstance(); + Image *dBorders = resman->getImage("graphics/gui/vscroll_grey.png"); + mBorder.grid[0] = dBorders->getSubImage(0, 0, 4, 4); + mBorder.grid[1] = dBorders->getSubImage(4, 0, 3, 4); + mBorder.grid[2] = dBorders->getSubImage(7, 0, 4, 4); + mBorder.grid[3] = dBorders->getSubImage(0, 4, 4, 10); + mBorder.grid[4] = resman->getImage("graphics/gui/bg_quad_dis.png"); + mBorder.grid[5] = dBorders->getSubImage(7, 4, 4, 10); + mBorder.grid[6] = dBorders->getSubImage(0, 15, 4, 4); + mBorder.grid[7] = dBorders->getSubImage(4, 15, 3, 4); + mBorder.grid[8] = dBorders->getSubImage(7, 15, 4, 4); + dBorders->decRef(); + } + + mInstances++; } ProgressBar::~ProgressBar() { + mInstances--; + + if (mInstances == 0) + { + delete mBorder.grid[0]; + delete mBorder.grid[1]; + delete mBorder.grid[2]; + delete mBorder.grid[3]; + mBorder.grid[4]->decRef(); + delete mBorder.grid[5]; + delete mBorder.grid[6]; + delete mBorder.grid[7]; + delete mBorder.grid[8]; + } } void ProgressBar::logic() @@ -72,28 +90,11 @@ void ProgressBar::logic() void ProgressBar::draw(gcn::Graphics *graphics) { - int absx, absy; - getAbsolutePosition(absx, absy); - - // Background - dBackground->drawPattern(screen, - absx + 4, absy + 4, - getWidth() - 8, getHeight() - 8); - - // The corners - dTopLeftBorder->draw(screen, absx, absy); - dTopRightBorder->draw(screen, absx + getWidth() - 4, absy); - dBottomLeftBorder->draw(screen, absx, absy + getHeight() - 4); - dBottomRightBorder->draw(screen, - absx+getWidth() - 4, absy+getHeight() - 4); - - // The borders - dTopBorder->drawPattern(screen, absx + 4, absy, getWidth() - 8, 4); - dBottomBorder->drawPattern(screen, absx + 4, absy + getHeight() - 4, - getWidth() - 8, 4); - dLeftBorder->drawPattern(screen, absx, absy + 4, 4, getHeight() - 8); - dRightBorder->drawPattern(screen, absx + getWidth() - 4, absy + 4, - 4, getHeight() - 8); + int x, y; + getAbsolutePosition(x, y); + + ((Graphics*)graphics)->drawImageRect(x, y, getWidth(), getHeight(), + mBorder); // The bar if (progress > 0) @@ -122,3 +123,18 @@ void ProgressBar::setColor(int red, int green, int blue) this->greenToGo = green; this->blueToGo = blue; } + +unsigned char ProgressBar::getRed() +{ + return red; +} + +unsigned char ProgressBar::getGreen() +{ + return green; +} + +unsigned char ProgressBar::getBlue() +{ + return blue; +} |