diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-01-04 21:57:32 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-01-04 21:57:32 +0300 |
commit | 8a5603e487f682f5f67bc2cedae81249aa138f5b (patch) | |
tree | 697535ca4d8e50ee6da8cf364cad814fa5f7603a /src/gui/widgets/progressbar.cpp | |
parent | 80f7177ea4ce0185e1ef3355e91dcf14617d0f09 (diff) | |
parent | f2d1d2b43a0ebdb625aea94cb4b8ff7fce6bf8f4 (diff) | |
download | plus-8a5603e487f682f5f67bc2cedae81249aa138f5b.tar.gz plus-8a5603e487f682f5f67bc2cedae81249aa138f5b.tar.bz2 plus-8a5603e487f682f5f67bc2cedae81249aa138f5b.tar.xz plus-8a5603e487f682f5f67bc2cedae81249aa138f5b.zip |
Merge branch 'master' into stable
Diffstat (limited to 'src/gui/widgets/progressbar.cpp')
-rw-r--r-- | src/gui/widgets/progressbar.cpp | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index 33011f9fc..97c29bd8c 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -2,7 +2,7 @@ * The ManaPlus Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 The ManaPlus Developers + * Copyright (C) 2011-2014 The ManaPlus Developers * * This file is part of The ManaPlus Client. * @@ -37,10 +37,12 @@ float ProgressBar::mAlpha = 1.0; ProgressBar::ProgressBar(const Widget2 *const widget, float progress, const int width, const int height, - const int backColor): + const int backColor, + const std::string &skin, const std::string &skinFill): gcn::Widget(), Widget2(widget), gcn::WidgetListener(), + mFillRect(), mSkin(nullptr), mProgress(progress), mProgressToGo(progress), @@ -53,6 +55,7 @@ ProgressBar::ProgressBar(const Widget2 *const widget, float progress, mProgressPalette(backColor), mPadding(2), mFillPadding(3), + mFillImage(false), mSmoothProgress(true), mSmoothColorChange(true), mRedraw(true) @@ -68,11 +71,14 @@ ProgressBar::ProgressBar(const Widget2 *const widget, float progress, Theme *const theme = Theme::instance(); if (theme) { - mSkin = theme->load("progressbar.xml", ""); + mSkin = theme->load(skin, "progressbar.xml"); if (mSkin) { setPadding(mSkin->getPadding()); mFillPadding = mSkin->getOption("fillPadding"); + mFillImage = mSkin->getOption("fillImage") != 0; + if (mFillImage) + theme->loadRect(mFillRect, skinFill, "progressbar_fill.xml"); } setHeight(2 * mPadding + getFont()->getHeight() + 2); } @@ -86,13 +92,15 @@ ProgressBar::~ProgressBar() gui->removeDragged(this); mInstances--; + Theme *const theme = Theme::instance(); if (mSkin) { - Theme *const theme = Theme::instance(); if (theme) theme->unload(mSkin); mSkin = nullptr; } + if (theme) + theme->unloadRect(mFillRect); delete mVertexes; mVertexes = nullptr; } @@ -115,6 +123,7 @@ void ProgressBar::logic() mBackgroundColor.g--; if (mBackgroundColorToGo.b < mBackgroundColor.b) mBackgroundColor.b--; + mRedraw = true; } if (mSmoothProgress && mProgressToGo != mProgress) @@ -124,6 +133,7 @@ void ProgressBar::logic() mProgress = std::min(1.0F, mProgress + 0.005F); if (mProgressToGo < mProgress) mProgress = std::max(0.0F, mProgress - 0.005F); + mRedraw = true; } BLOCK_END("ProgressBar::logic") } @@ -148,6 +158,7 @@ void ProgressBar::setProgress(const float progress) { const float p = std::min(1.0F, std::max(0.0F, progress)); mProgressToGo = p; + mRedraw = true; if (!mSmoothProgress) mProgress = p; @@ -163,6 +174,7 @@ void ProgressBar::setProgressPalette(const int progressPalette) { const int oldPalette = mProgressPalette; mProgressPalette = progressPalette; + mRedraw = true; if (mProgressPalette != oldPalette && mProgressPalette >= 0) { @@ -173,6 +185,7 @@ void ProgressBar::setProgressPalette(const int progressPalette) void ProgressBar::setBackgroundColor(const gcn::Color &color) { + mRedraw = true; mBackgroundColorToGo = color; if (!mSmoothColorChange) @@ -198,6 +211,20 @@ void ProgressBar::render(Graphics *graphics) mVertexes->clear(); graphics->calcWindow(mVertexes, 0, 0, mDimension.width, mDimension.height, mSkin->getBorder()); + if (mFillImage) + { + const unsigned int pad = 2 * mFillPadding; + const int maxWidth = mDimension.width - pad; + int width = static_cast<int>(mProgress + * static_cast<float>(maxWidth)); + if (width > 0) + { + if (width > maxWidth) + width = maxWidth; + graphics->calcWindow(mVertexes, mFillPadding, mFillPadding, + width, mDimension.height - pad, mFillRect); + } + } } graphics->drawTileCollection(mVertexes); @@ -206,10 +233,24 @@ void ProgressBar::render(Graphics *graphics) { graphics->drawImageRect(0, 0, mDimension.width, mDimension.height, mSkin->getBorder()); + if (mFillImage) + { + const unsigned int pad = 2 * mFillPadding; + const int maxWidth = mDimension.width - pad; + int width = static_cast<int>(mProgress + * static_cast<float>(maxWidth)); + if (width > 0) + { + if (width > maxWidth) + width = maxWidth; + graphics->drawImageRect(mFillPadding, mFillPadding, + width, mDimension.height - pad, mFillRect); + } + } } // The bar - if (mProgress > 0) + if (!mFillImage && mProgress > 0) { graphics->setColor(mBackgroundColor); const unsigned int pad = 2 * mFillPadding; |