diff options
Diffstat (limited to 'src/gui/widgets/progressbar.cpp')
-rw-r--r-- | src/gui/widgets/progressbar.cpp | 199 |
1 files changed, 121 insertions, 78 deletions
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp index 9acb8386c..da11c779d 100644 --- a/src/gui/widgets/progressbar.cpp +++ b/src/gui/widgets/progressbar.cpp @@ -151,105 +151,103 @@ void ProgressBar::updateAlpha() void ProgressBar::draw(Graphics *graphics) { BLOCK_START("ProgressBar::draw") + if (!mSkin) + { + BLOCK_END("ProgressBar::draw") + return; + } + updateAlpha(); mBackgroundColor.a = static_cast<int>(mAlpha * 255); - render(graphics); - BLOCK_END("ProgressBar::draw") -} - -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; - if (mProgressPalette >= 0) + if (mRedraw || graphics->getRedraw()) { - mBackgroundColorToGo = Theme::getProgressColor( - mProgressPalette, progress); + mRedraw = false; + 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->finalize(mVertexes); } -} -void ProgressBar::setProgressPalette(const int progressPalette) -{ - const int oldPalette = mProgressPalette; - mProgressPalette = progressPalette; - mRedraw = true; + graphics->drawTileCollection(mVertexes); - if (mProgressPalette != oldPalette && mProgressPalette >= 0) + // The bar + if (!mFillImage && mProgress > 0) { - mBackgroundColorToGo = Theme::getProgressColor( - mProgressPalette, mProgressToGo); + graphics->setColor(mBackgroundColor); + 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->fillRectangle(Rect(mFillPadding, mFillPadding, + width, mDimension.height - pad)); + } } -} -void ProgressBar::setBackgroundColor(const Color &color) -{ - mRedraw = true; - mBackgroundColorToGo = color; + // The label + if (!mText.empty()) + { + const Color oldColor = graphics->getColor(); - if (!mSmoothColorChange) - mBackgroundColor = color; -} + Font *const font = gui->getFont(); + const int textX = mDimension.width / 2; + const int textY = (mDimension.height - font->getHeight()) / 2; -void ProgressBar::setColor(const Color &color1, const Color &color2) -{ - mForegroundColor = color1; - mForegroundColor2 = color2; + font->drawString(graphics, + mForegroundColor, + mForegroundColor2, + mText, + textX - font->getWidth(mText) / 2, + textY); + + graphics->setColor(oldColor); + } + BLOCK_END("ProgressBar::draw") } -void ProgressBar::render(Graphics *graphics) +void ProgressBar::safeDraw(Graphics *graphics) { + BLOCK_START("ProgressBar::safeDraw") if (!mSkin) + { + BLOCK_END("ProgressBar::safeDraw") return; + } - if (isBatchDrawRenders(openGLMode)) - { - if (mRedraw || graphics->getRedraw()) - { - mRedraw = false; - 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->finalize(mVertexes); - } + updateAlpha(); + mBackgroundColor.a = static_cast<int>(mAlpha * 255); - graphics->drawTileCollection(mVertexes); - } - else + graphics->drawImageRect(0, 0, mDimension.width, mDimension.height, + mSkin->getBorder()); + if (mFillImage) { - 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) { - 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); - } + if (width > maxWidth) + width = maxWidth; + graphics->drawImageRect(mFillPadding, mFillPadding, + width, mDimension.height - pad, mFillRect); } } @@ -287,6 +285,51 @@ void ProgressBar::render(Graphics *graphics) graphics->setColor(oldColor); } + BLOCK_END("ProgressBar::safeDraw") +} + +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; + + if (mProgressPalette >= 0) + { + mBackgroundColorToGo = Theme::getProgressColor( + mProgressPalette, progress); + } +} + +void ProgressBar::setProgressPalette(const int progressPalette) +{ + const int oldPalette = mProgressPalette; + mProgressPalette = progressPalette; + mRedraw = true; + + if (mProgressPalette != oldPalette && mProgressPalette >= 0) + { + mBackgroundColorToGo = Theme::getProgressColor( + mProgressPalette, mProgressToGo); + } +} + +void ProgressBar::setBackgroundColor(const Color &color) +{ + mRedraw = true; + mBackgroundColorToGo = color; + + if (!mSmoothColorChange) + mBackgroundColor = color; +} + +void ProgressBar::setColor(const Color &color1, const Color &color2) +{ + mForegroundColor = color1; + mForegroundColor2 = color2; } void ProgressBar::widgetResized(const Event &event A_UNUSED) |