From 6c7bf198fa165c971565f069081c603f068014b1 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 10 Feb 2010 14:51:28 -0700 Subject: Improve look and utility of the SkillDialog --- src/gui/widgets/progressbar.cpp | 61 ++++++++++++++++++++++++++--------------- src/gui/widgets/progressbar.h | 8 ++++++ 2 files changed, 47 insertions(+), 22 deletions(-) (limited to 'src/gui/widgets') diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index cb064899..98c31873 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -141,31 +141,14 @@ void ProgressBar::draw(gcn::Graphics *graphics) { updateAlpha(); - static_cast(graphics)-> - drawImageRect(0, 0, getWidth(), getHeight(), mBorder); - mColor.a = (int) (mAlpha * 255); - // The bar - if (mProgress > 0) - { - graphics->setColor(mColor); - graphics->fillRectangle(gcn::Rectangle(4, 4, - (int) (mProgress * (getWidth() - 8)), - getHeight() - 8)); - } - - // The label - if (!mText.empty()) - { - const int textX = getWidth() / 2; - const int textY = (getHeight() - boldFont->getHeight()) / 2; + gcn::Rectangle rect = getDimension(); + rect.x = 0; + rect.y = 0; - TextRenderer::renderText(graphics, mText, textX, textY, - gcn::Graphics::CENTER, - guiPalette->getColor(Palette::PROGRESS_BAR), - gui->getFont(), true, false); - } + render(static_cast(graphics), rect, mColor, + mProgress, mText); } void ProgressBar::setProgress(float progress) @@ -184,3 +167,37 @@ void ProgressBar::setColor(const gcn::Color &color) if (!mSmoothColorChange) mColor = color; } + +void ProgressBar::render(Graphics *graphics, const gcn::Rectangle &area, + const gcn::Color &color, float progress, + const std::string &text) +{ + gcn::Font *oldFont = graphics->getFont(); + gcn::Color oldColor = graphics->getColor(); + + graphics->drawImageRect(area, mBorder); + + // The bar + if (progress > 0) + { + graphics->setColor(color); + graphics->fillRectangle(gcn::Rectangle(area.x + 4, area.y + 4, + (int) (progress * (area.width - 8)), + area.height - 8)); + } + + // The label + if (!text.empty()) + { + const int textX = area.x + area.width / 2; + const int textY = area.y + (area.height - boldFont->getHeight()) / 2; + + TextRenderer::renderText(graphics, text, textX, textY, + gcn::Graphics::CENTER, + guiPalette->getColor(Palette::PROGRESS_BAR), + gui->getFont(), true, false); + } + + graphics->setFont(oldFont); + graphics->setColor(oldColor); +} diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h index 4a314690..daa872a1 100644 --- a/src/gui/widgets/progressbar.h +++ b/src/gui/widgets/progressbar.h @@ -26,6 +26,7 @@ #include +class Graphics; class ImageRect; /** @@ -112,6 +113,13 @@ class ProgressBar : public gcn::Widget void setSmoothColorChange(bool smoothColorChange) { mSmoothColorChange = smoothColorChange; } + /** + * Renders a progressbar with the given properties. + */ + static void render(Graphics *graphics, const gcn::Rectangle &area, + const gcn::Color &color, float progress, + const std::string &text = ""); + private: float mProgress, mProgressToGo; bool mSmoothProgress; -- cgit v1.2.3-70-g09d2