summaryrefslogtreecommitdiff
path: root/src/gui/widgets/label.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-19 14:49:19 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-20 00:02:36 +0300
commite224a077737739a895fe533c9cce93783621d8e9 (patch)
tree28194260919ffcc8aa77f52caf45cbf3a1747334 /src/gui/widgets/label.cpp
parentfd85f62f2e3003a79e90611e95b09e23710be479 (diff)
downloadmanaplus-e224a077737739a895fe533c9cce93783621d8e9.tar.gz
manaplus-e224a077737739a895fe533c9cce93783621d8e9.tar.bz2
manaplus-e224a077737739a895fe533c9cce93783621d8e9.tar.xz
manaplus-e224a077737739a895fe533c9cce93783621d8e9.zip
Add fast way for draw not changed text strings.
TextChunk with colors and image stored inside draw object. If string or color changed old string image moved to cache. New string image generated or moved from cache. Use new way in drawing string in label.
Diffstat (limited to 'src/gui/widgets/label.cpp')
-rw-r--r--src/gui/widgets/label.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
index 8b074a0b1..65e7f86d0 100644
--- a/src/gui/widgets/label.cpp
+++ b/src/gui/widgets/label.cpp
@@ -78,8 +78,10 @@ Label::Label(const Widget2 *const widget) :
Widget(widget),
ToolTipListener(),
mCaption(),
+ mTextChunk(),
mAlignment(Graphics::LEFT),
- mPadding(0)
+ mPadding(0),
+ mTextChanged(true)
{
init();
}
@@ -89,8 +91,10 @@ Label::Label(const Widget2 *const widget,
Widget(widget),
ToolTipListener(),
mCaption(caption),
+ mTextChunk(),
mAlignment(Graphics::LEFT),
- mPadding(0)
+ mPadding(0),
+ mTextChanged(true)
{
const Font *const font = getFont();
if (font)
@@ -113,6 +117,7 @@ Label::~Label()
theme->unload(mSkin);
}
removeMouseListener(this);
+ mTextChunk.deleteImage();
}
void Label::init()
@@ -160,7 +165,21 @@ void Label::draw(Graphics* graphics)
}
graphics->setColorAll(mForegroundColor, mForegroundColor2);
- font->drawString(graphics, mCaption, textX, textY);
+ if (mTextChanged)
+ {
+ mTextChunk.textFont = font;
+ mTextChunk.deleteImage();
+ mTextChunk.text = mCaption;
+ mTextChunk.color = mForegroundColor;
+ mTextChunk.color2 = mForegroundColor2;
+ font->generate(mTextChunk);
+ mTextChanged = false;
+ }
+
+ const Image *const image = mTextChunk.img;
+ if (image)
+ graphics->drawImage(image, textX, textY);
+// font->drawString(graphics, mCaption, textX, textY);
BLOCK_END("Label::draw")
}
@@ -174,6 +193,9 @@ void Label::adjustSize()
void Label::setForegroundColor(const Color &color)
{
+ if (mForegroundColor != color || mForegroundColor2 != color)
+ mTextChanged = true;
+// logger->log("Label::setForegroundColor: " + mCaption);
mForegroundColor = color;
mForegroundColor2 = color;
}
@@ -181,6 +203,9 @@ void Label::setForegroundColor(const Color &color)
void Label::setForegroundColorAll(const Color &color1,
const Color &color2)
{
+ if (mForegroundColor != color1 || mForegroundColor2 != color2)
+ mTextChanged = true;
+// logger->log("Label::setForegroundColorAll: " + mCaption);
mForegroundColor = color1;
mForegroundColor2 = color2;
}
@@ -221,3 +246,10 @@ void Label::resizeTo(const int maxSize, const int minSize)
setWidth(sz);
}
}
+
+void Label::setCaption(const std::string& caption)
+{
+ if (caption != mCaption)
+ mTextChanged = true;
+ mCaption = caption;
+}