diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-12-22 20:03:20 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-12-22 20:03:20 +0300 |
commit | 15309c3bb75a5d5d1b56171fe1bd91b96e1735b8 (patch) | |
tree | 456439afcc908a50360bb8968f143dab32a4251e /src/gui/widgets | |
parent | 2425f9821deb57ceab2f6e6a5aa01a0784e07148 (diff) | |
download | plus-15309c3bb75a5d5d1b56171fe1bd91b96e1735b8.tar.gz plus-15309c3bb75a5d5d1b56171fe1bd91b96e1735b8.tar.bz2 plus-15309c3bb75a5d5d1b56171fe1bd91b96e1735b8.tar.xz plus-15309c3bb75a5d5d1b56171fe1bd91b96e1735b8.zip |
allow fill complete part of progress bar with images.
For this need add in progress bar theme file option fillImage and set it to 1.
Then add progress bar xml file for image with name: name_fill.xml.
Default is: progressbar_fill.xml
New theme option: fillImage
New theme file (default name): progressbar_fill.xml
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/progressbar.cpp | 49 | ||||
-rw-r--r-- | src/gui/widgets/progressbar.h | 5 |
2 files changed, 50 insertions, 4 deletions
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index e8f3b5947..5d776fa1a 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -37,11 +37,14 @@ float ProgressBar::mAlpha = 1.0; ProgressBar::ProgressBar(const Widget2 *const widget, float progress, const int width, const int height, - const int backColor, const std::string &skin): + const int backColor, + const std::string &skin, const std::string &skinFill): gcn::Widget(), Widget2(widget), gcn::WidgetListener(), + mFillRect(), mSkin(nullptr), + mSkinFill(nullptr), mProgress(progress), mProgressToGo(progress), mBackgroundColor(Theme::getProgressColor(backColor >= 0 @@ -53,6 +56,7 @@ ProgressBar::ProgressBar(const Widget2 *const widget, float progress, mProgressPalette(backColor), mPadding(2), mFillPadding(3), + mFillImage(false), mSmoothProgress(true), mSmoothColorChange(true), mRedraw(true) @@ -73,6 +77,9 @@ ProgressBar::ProgressBar(const Widget2 *const widget, float progress, { 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 +93,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 +124,7 @@ void ProgressBar::logic() mBackgroundColor.g--; if (mBackgroundColorToGo.b < mBackgroundColor.b) mBackgroundColor.b--; + mRedraw = true; } if (mSmoothProgress && mProgressToGo != mProgress) @@ -124,6 +134,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 +159,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 +175,7 @@ void ProgressBar::setProgressPalette(const int progressPalette) { const int oldPalette = mProgressPalette; mProgressPalette = progressPalette; + mRedraw = true; if (mProgressPalette != oldPalette && mProgressPalette >= 0) { @@ -173,6 +186,7 @@ void ProgressBar::setProgressPalette(const int progressPalette) void ProgressBar::setBackgroundColor(const gcn::Color &color) { + mRedraw = true; mBackgroundColorToGo = color; if (!mSmoothColorChange) @@ -198,6 +212,21 @@ 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; + logger->log("calc fill: %d, %d", mFillPadding, width); + graphics->calcWindow(mVertexes, mFillPadding, mFillPadding, + width, mDimension.height - pad, mFillRect); + } + } } graphics->drawTileCollection(mVertexes); @@ -206,10 +235,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; diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h index 3bfceab18..9b2ab353a 100644 --- a/src/gui/widgets/progressbar.h +++ b/src/gui/widgets/progressbar.h @@ -52,7 +52,7 @@ class ProgressBar final : public gcn::Widget, ProgressBar(const Widget2 *const widget, float progress, const int width, const int height, const int backColor, - const std::string &skin); + const std::string &skin, const std::string &skinFill); A_DELETE_COPY(ProgressBar) @@ -140,7 +140,9 @@ class ProgressBar final : public gcn::Widget, { mPadding = padding; } private: + ImageRect mFillRect; Skin *mSkin; + Skin *mSkinFill; float mProgress; float mProgressToGo; @@ -157,6 +159,7 @@ class ProgressBar final : public gcn::Widget, static int mInstances; static float mAlpha; + bool mFillImage; bool mSmoothProgress; bool mSmoothColorChange; bool mRedraw; |