summaryrefslogtreecommitdiff
path: root/src/gui/widgets
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
parentfd85f62f2e3003a79e90611e95b09e23710be479 (diff)
downloadplus-e224a077737739a895fe533c9cce93783621d8e9.tar.gz
plus-e224a077737739a895fe533c9cce93783621d8e9.tar.bz2
plus-e224a077737739a895fe533c9cce93783621d8e9.tar.xz
plus-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')
-rw-r--r--src/gui/widgets/label.cpp38
-rw-r--r--src/gui/widgets/label.h9
-rw-r--r--src/gui/widgets/tabs/tab.cpp57
-rw-r--r--src/gui/widgets/tabs/tab.h1
4 files changed, 81 insertions, 24 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;
+}
diff --git a/src/gui/widgets/label.h b/src/gui/widgets/label.h
index 681908b71..9e82f0a5d 100644
--- a/src/gui/widgets/label.h
+++ b/src/gui/widgets/label.h
@@ -65,6 +65,8 @@
#ifndef GUI_WIDGETS_LABEL_H
#define GUI_WIDGETS_LABEL_H
+#include "gui/fonts/textchunk.h"
+
#include "gui/widgets/widget.h"
#include "listeners/tooltiplistener.h"
@@ -132,8 +134,7 @@ class Label final : public Widget,
* @param caption The caption of the label.
* @see getCaption, adjustSize
*/
- void setCaption(const std::string& caption)
- { mCaption = caption; }
+ void setCaption(const std::string& caption);
/**
* Sets the alignment of the caption. The alignment is relative
@@ -165,12 +166,16 @@ class Label final : public Widget,
*/
std::string mCaption;
+ TextChunk mTextChunk;
+
/**
* Holds the alignment of the caption.
*/
Graphics::Alignment mAlignment;
int mPadding;
+
+ bool mTextChanged;
};
#endif // GUI_WIDGETS_LABEL_H
diff --git a/src/gui/widgets/tabs/tab.cpp b/src/gui/widgets/tabs/tab.cpp
index 2f300fb5f..e361c78ff 100644
--- a/src/gui/widgets/tabs/tab.cpp
+++ b/src/gui/widgets/tabs/tab.cpp
@@ -120,6 +120,7 @@ Tab::Tab(const Widget2 *const widget) :
mVertexes(new ImageCollection),
mImage(nullptr),
mMode(0),
+ mLabelMode(-1),
mHasMouse(false)
{
init();
@@ -211,37 +212,55 @@ void Tab::draw(Graphics *graphics)
// check which type of tab to draw
if (mTabbedArea)
{
+ int labelMode = mFlash;
+
if (mTabbedArea->isTabSelected(this))
{
- mLabel->setForegroundColorAll(*mTabSelectedColor,
- *mTabSelectedOutlineColor);
+ labelMode = 3;
mode = TAB_SELECTED;
// if tab is selected, it doesnt need to highlight activity
mFlash = 0;
}
- else if (mHasMouse)
+ else if (!labelMode)
{
- mLabel->setForegroundColorAll(*mTabHighlightedColor,
- *mTabHighlightedOutlineColor);
- mode = TAB_HIGHLIGHTED;
+ if (mHasMouse)
+ {
+ labelMode = 4;
+ mode = TAB_HIGHLIGHTED;
+ }
}
- else
+ else if (mHasMouse)
{
- mLabel->setForegroundColorAll(*mTabColor, *mTabOutlineColor);
+ mode = TAB_HIGHLIGHTED;
}
- switch (mFlash)
+ if (labelMode != mLabelMode)
{
- case 1:
- mLabel->setForegroundColorAll(*mFlashColor,
- *mFlashOutlineColor);
- break;
- case 2:
- mLabel->setForegroundColorAll(*mPlayerFlashColor,
- *mPlayerFlashOutlineColor);
- break;
- default:
- break;
+ mLabelMode = labelMode;
+ switch (labelMode)
+ {
+ case 0: // default state
+ default:
+ mLabel->setForegroundColorAll(*mTabColor,
+ *mTabOutlineColor);
+ break;
+ case 1: // mFlash == 1
+ mLabel->setForegroundColorAll(*mFlashColor,
+ *mFlashOutlineColor);
+ break;
+ case 2: // mFlash == 2
+ mLabel->setForegroundColorAll(*mPlayerFlashColor,
+ *mPlayerFlashOutlineColor);
+ break;
+ case 3: //mTabbedArea->isTabSelected(this)
+ mLabel->setForegroundColorAll(*mTabSelectedColor,
+ *mTabSelectedOutlineColor);
+ break;
+ case 4: // mHasMouse
+ mLabel->setForegroundColorAll(*mTabHighlightedColor,
+ *mTabHighlightedOutlineColor);
+ break;
+ }
}
}
diff --git a/src/gui/widgets/tabs/tab.h b/src/gui/widgets/tabs/tab.h
index 06b5a3d18..8b26ee3d4 100644
--- a/src/gui/widgets/tabs/tab.h
+++ b/src/gui/widgets/tabs/tab.h
@@ -228,6 +228,7 @@ class Tab notfinal : public BasicContainer,
ImageCollection *mVertexes;
Image *mImage;
int mMode;
+ int mLabelMode;
protected:
bool mHasMouse;