summaryrefslogtreecommitdiff
path: root/src/gui/widgets/progressbar.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-09-06 15:41:27 +0300
committerAndrei Karas <akaras@inbox.ru>2015-09-06 15:41:27 +0300
commit893df56fe05fb0e865fda77477c37200bbab018b (patch)
tree8922c463869a9b5486609d1bec7b1bda28f8c88b /src/gui/widgets/progressbar.cpp
parentd4841f5ec6d954bce7f628a33b8394550e32a057 (diff)
downloadmanaverse-893df56fe05fb0e865fda77477c37200bbab018b.tar.gz
manaverse-893df56fe05fb0e865fda77477c37200bbab018b.tar.bz2
manaverse-893df56fe05fb0e865fda77477c37200bbab018b.tar.xz
manaverse-893df56fe05fb0e865fda77477c37200bbab018b.zip
Use cached image for drawing text in progressbar.
Diffstat (limited to 'src/gui/widgets/progressbar.cpp')
-rw-r--r--src/gui/widgets/progressbar.cpp79
1 files changed, 54 insertions, 25 deletions
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp
index 59951c960..294a8f610 100644
--- a/src/gui/widgets/progressbar.cpp
+++ b/src/gui/widgets/progressbar.cpp
@@ -47,6 +47,7 @@ ProgressBar::ProgressBar(const Widget2 *const widget,
Widget(widget),
WidgetListener(),
mFillRect(),
+ mTextChunk(),
mSkin(nullptr),
mProgress(progress),
mProgressToGo(progress),
@@ -58,7 +59,8 @@ ProgressBar::ProgressBar(const Widget2 *const widget,
mFillPadding(3),
mFillImage(false),
mSmoothProgress(true),
- mSmoothColorChange(true)
+ mSmoothColorChange(true),
+ mTextChanged(true)
{
mBackgroundColor = Theme::getProgressColor(
backColor >= ProgressColorId::PROG_HP
@@ -106,6 +108,7 @@ ProgressBar::~ProgressBar()
}
Theme::unloadRect(mFillRect);
delete2(mVertexes);
+ mTextChunk.deleteImage();
}
void ProgressBar::logic()
@@ -204,20 +207,25 @@ void ProgressBar::draw(Graphics *graphics)
// The label
if (!mText.empty())
{
- const Color oldColor = graphics->getColor();
-
Font *const font = gui->getFont();
- const int textX = mDimension.width / 2;
- const int textY = (mDimension.height - font->getHeight()) / 2;
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- mText,
- textX - font->getWidth(mText) / 2,
- textY);
+ if (mTextChanged)
+ {
+ mTextChunk.textFont = font;
+ mTextChunk.deleteImage();
+ mTextChunk.text = mText;
+ mTextChunk.color = mForegroundColor;
+ mTextChunk.color2 = mForegroundColor2;
+ font->generate(mTextChunk);
+ mTextChanged = false;
+ }
- graphics->setColor(oldColor);
+ const Image *const image = mTextChunk.img;
+ if (image)
+ {
+ const int textX = (mDimension.width - font->getWidth(mText)) / 2;
+ const int textY = (mDimension.height - font->getHeight()) / 2;
+ graphics->drawImage(image, textX, textY);
+ }
}
BLOCK_END("ProgressBar::draw")
}
@@ -270,20 +278,25 @@ void ProgressBar::safeDraw(Graphics *graphics)
// The label
if (!mText.empty())
{
- const Color oldColor = graphics->getColor();
-
Font *const font = gui->getFont();
- const int textX = mDimension.width / 2;
- const int textY = (mDimension.height - font->getHeight()) / 2;
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- mText,
- textX - font->getWidth(mText) / 2,
- textY);
+ if (mTextChanged)
+ {
+ mTextChunk.textFont = font;
+ mTextChunk.deleteImage();
+ mTextChunk.text = mText;
+ mTextChunk.color = mForegroundColor;
+ mTextChunk.color2 = mForegroundColor2;
+ font->generate(mTextChunk);
+ mTextChanged = false;
+ }
- graphics->setColor(oldColor);
+ const Image *const image = mTextChunk.img;
+ if (image)
+ {
+ const int textX = (mDimension.width - font->getWidth(mText)) / 2;
+ const int textY = (mDimension.height - font->getHeight()) / 2;
+ graphics->drawImage(image, textX, textY);
+ }
}
BLOCK_END("ProgressBar::safeDraw")
}
@@ -331,6 +344,7 @@ void ProgressBar::setColor(const Color &color1, const Color &color2)
{
mForegroundColor = color1;
mForegroundColor2 = color2;
+ mTextChanged = true;
}
void ProgressBar::widgetResized(const Event &event A_UNUSED)
@@ -342,3 +356,18 @@ void ProgressBar::widgetMoved(const Event &event A_UNUSED)
{
mRedraw = true;
}
+
+void ProgressBar::setText(const std::string &str)
+{
+ if (mText != str)
+ {
+ mText = str;
+ mTextChanged = true;
+ }
+}
+
+void ProgressBar::widgetHidden(const Event &event A_UNUSED)
+{
+ mTextChanged = true;
+ mTextChunk.deleteImage();
+}