summaryrefslogtreecommitdiff
path: root/src/gui/widgets
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
parente224a077737739a895fe533c9cce93783621d8e9 (diff)
downloadmanaverse-12478121f86ea50672f5e392bc2b1e29c7fac700.tar.gz
manaverse-12478121f86ea50672f5e392bc2b1e29c7fac700.tar.bz2
manaverse-12478121f86ea50672f5e392bc2b1e29c7fac700.tar.xz
manaverse-12478121f86ea50672f5e392bc2b1e29c7fac700.zip
Use fast draw way in drawing string in buttons.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/button.cpp41
-rw-r--r--src/gui/widgets/button.h8
2 files changed, 42 insertions, 7 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")
}
diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h
index e568f8131..c97741548 100644
--- a/src/gui/widgets/button.h
+++ b/src/gui/widgets/button.h
@@ -66,6 +66,8 @@
#ifndef GUI_WIDGETS_BUTTON_H
#define GUI_WIDGETS_BUTTON_H
+#include "gui/fonts/textchunk.h"
+
#include "gui/widgets/widget.h"
#include "listeners/focuslistener.h"
@@ -204,7 +206,7 @@ class Button final : public Widget,
* @see getCaption, adjustSize
*/
void setCaption(const std::string& caption)
- { mCaption = caption; }
+ { mCaption = caption; mTextChanged = true;}
/**
* Gets the caption of the button.
@@ -273,6 +275,9 @@ class Button final : public Widget,
std::string mCaption;
std::string mDescription;
+
+ TextChunk mTextChunk;
+
ImageCollection *mVertexes2;
Color mEnabledColor;
Color mEnabledColor2;
@@ -320,6 +325,7 @@ class Button final : public Widget,
bool mStick;
bool mPressed;
+ bool mTextChanged;
};
#endif // GUI_WIDGETS_BUTTON_H