summaryrefslogtreecommitdiff
path: root/src/gui/widgets/button.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-19 22:17:53 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-20 00:02:36 +0300
commit12478121f86ea50672f5e392bc2b1e29c7fac700 (patch)
treeaa328efcc7dc8444e4b412518f6187ce41d69855 /src/gui/widgets/button.cpp
parente224a077737739a895fe533c9cce93783621d8e9 (diff)
downloadplus-12478121f86ea50672f5e392bc2b1e29c7fac700.tar.gz
plus-12478121f86ea50672f5e392bc2b1e29c7fac700.tar.bz2
plus-12478121f86ea50672f5e392bc2b1e29c7fac700.tar.xz
plus-12478121f86ea50672f5e392bc2b1e29c7fac700.zip
Use fast draw way in drawing string in buttons.
Diffstat (limited to 'src/gui/widgets/button.cpp')
-rw-r--r--src/gui/widgets/button.cpp41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index 3d05584d9..1a8c613ba 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -106,6 +106,7 @@ Button::Button(const Widget2 *const widget) :
WidgetListener(),
mCaption(),
mDescription(),
+ mTextChunk(),
mVertexes2(new ImageCollection),
mEnabledColor(getThemeColor(Theme::BUTTON)),
mEnabledColor2(getThemeColor(Theme::BUTTON_OUTLINE)),
@@ -130,7 +131,8 @@ Button::Button(const Widget2 *const widget) :
mKeyPressed(false),
mMousePressed(false),
mStick(false),
- mPressed(false)
+ mPressed(false),
+ mTextChanged(true)
{
init();
adjustSize();
@@ -147,6 +149,7 @@ Button::Button(const Widget2 *const widget,
WidgetListener(),
mCaption(caption),
mDescription(),
+ mTextChunk(),
mVertexes2(new ImageCollection),
mEnabledColor(getThemeColor(Theme::BUTTON)),
mEnabledColor2(getThemeColor(Theme::BUTTON_OUTLINE)),
@@ -171,7 +174,8 @@ Button::Button(const Widget2 *const widget,
mKeyPressed(false),
mMousePressed(false),
mStick(false),
- mPressed(false)
+ mPressed(false),
+ mTextChanged(true)
{
init();
adjustSize();
@@ -194,6 +198,7 @@ Button::Button(const Widget2 *const widget,
WidgetListener(),
mCaption(caption),
mDescription(),
+ mTextChunk(),
mVertexes2(new ImageCollection),
mEnabledColor(getThemeColor(Theme::BUTTON)),
mEnabledColor2(getThemeColor(Theme::BUTTON_OUTLINE)),
@@ -218,7 +223,8 @@ Button::Button(const Widget2 *const widget,
mKeyPressed(false),
mMousePressed(false),
mStick(false),
- mPressed(false)
+ mPressed(false),
+ mTextChanged(true)
{
init();
loadImageSet(imageName);
@@ -241,6 +247,7 @@ Button::Button(const Widget2 *const widget,
WidgetListener(),
mCaption(),
mDescription(),
+ mTextChunk(),
mVertexes2(new ImageCollection),
mEnabledColor(getThemeColor(Theme::BUTTON)),
mEnabledColor2(getThemeColor(Theme::BUTTON_OUTLINE)),
@@ -265,7 +272,8 @@ Button::Button(const Widget2 *const widget,
mKeyPressed(false),
mMousePressed(false),
mStick(false),
- mPressed(false)
+ mPressed(false),
+ mTextChanged(true)
{
init();
loadImageSet(imageName);
@@ -288,6 +296,7 @@ Button::Button(const Widget2 *const widget,
WidgetListener(),
mCaption(caption),
mDescription(),
+ mTextChunk(),
mVertexes2(new ImageCollection),
mEnabledColor(getThemeColor(Theme::BUTTON)),
mEnabledColor2(getThemeColor(Theme::BUTTON_OUTLINE)),
@@ -312,7 +321,8 @@ Button::Button(const Widget2 *const widget,
mKeyPressed(false),
mMousePressed(false),
mStick(false),
- mPressed(false)
+ mPressed(false),
+ mTextChanged(true)
{
init();
loadImage(imageName);
@@ -380,6 +390,7 @@ Button::~Button()
delete [] mImages;
mImages = nullptr;
}
+ mTextChunk.deleteImage();
}
void Button::loadImage(const std::string &imageName)
@@ -511,6 +522,8 @@ void Button::draw(Graphics *graphics)
graphics->setColorAll(mEnabledColor, mEnabledColor2);
break;
}
+ if (recalc)
+ mTextChanged = true;
int imageX = 0;
int imageY = 0;
@@ -614,7 +627,23 @@ void Button::draw(Graphics *graphics)
textX ++;
textY ++;
}
- font->drawString(graphics, mCaption, textX, textY);
+
+ if (mTextChanged)
+ {
+ mTextChunk.textFont = font;
+ mTextChunk.deleteImage();
+ mTextChunk.text = mCaption;
+ mTextChunk.color = graphics->getColor();
+ mTextChunk.color2 = graphics->getColor2();
+ 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("Button::draw")
}