diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-05-26 14:38:25 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-05-26 14:38:25 +0300 |
commit | 055345145f35286b3f45ed05d5a80d118a1ab8f4 (patch) | |
tree | 6b6ab1ddcf335ad6025a752abde126cb1c2fcb8a | |
parent | de328959771fcc5f992f13517ea7adacdda61550 (diff) | |
download | manaverse-055345145f35286b3f45ed05d5a80d118a1ab8f4.tar.gz manaverse-055345145f35286b3f45ed05d5a80d118a1ab8f4.tar.bz2 manaverse-055345145f35286b3f45ed05d5a80d118a1ab8f4.tar.xz manaverse-055345145f35286b3f45ed05d5a80d118a1ab8f4.zip |
Use local TextChunk in text class.
-rw-r--r-- | src/text.cpp | 27 | ||||
-rw-r--r-- | src/text.h | 10 |
2 files changed, 28 insertions, 9 deletions
diff --git a/src/text.cpp b/src/text.cpp index 4f56f7cdf..0331b5263 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -46,6 +46,7 @@ Text::Text(const std::string &text, const int x, const int y, const Color *const color, const bool isSpeech, Font *const font) : mFont(font ? font : (gui ? gui->getFont() : nullptr)), + mTextChunk(), mX(x), mY(y), mWidth(mFont ? mFont->getWidth(text) : 1), @@ -53,8 +54,9 @@ Text::Text(const std::string &text, const int x, const int y, mXOffset(0), mText(text), mColor(color), - mOutlineColor(isSpeech ? color : theme->getColor(Theme::OUTLINE, 255)), - mIsSpeech(isSpeech) + mOutlineColor(isSpeech ? *color : theme->getColor(Theme::OUTLINE, 255)), + mIsSpeech(isSpeech), + mTextChanged(true) { if (!textManager) { @@ -117,10 +119,11 @@ Text::~Text() void Text::setColor(const Color *const color) { + mTextChanged = true; if (mIsSpeech) { mColor = color; - mOutlineColor = color; + mOutlineColor = *color; } else { @@ -153,9 +156,21 @@ void Text::draw(Graphics *const graphics, const int xOff, const int yOff) mBubble); } - mFont->drawString(graphics, - *mColor, mOutlineColor, - mText, mX - xOff, mY - yOff); + if (mTextChanged) + { + mTextChunk.textFont = mFont; + mTextChunk.deleteImage(); + mTextChunk.text = mText; + mTextChunk.color = *mColor; + mTextChunk.color2 = mOutlineColor; + mFont->generate(mTextChunk); + mTextChanged = false; + } + + const Image *const image = mTextChunk.img; + if (image) + graphics->drawImage(image, mX - xOff, mY - yOff); + BLOCK_END("Text::draw") } diff --git a/src/text.h b/src/text.h index fbb36050b..845b96353 100644 --- a/src/text.h +++ b/src/text.h @@ -24,6 +24,8 @@ #ifndef TEXT_H #define TEXT_H +#include "gui/fonts/textchunk.h" + #include "render/graphics.h" #include "localconsts.h" @@ -70,7 +72,8 @@ class Text notfinal const int xOff, const int yOff); private: - Font *mFont; /**< The font of the text */ + Font *mFont; /**< The font of the text */ + TextChunk mTextChunk; int mX; /**< Actual x-value of left of text written. */ int mY; /**< Actual y-value of top of text written. */ int mWidth; /**< The width of the text. */ @@ -78,9 +81,10 @@ class Text notfinal int mXOffset; /**< The offset of mX from the desired x. */ static int mInstances; /**< Instances of text. */ std::string mText; /**< The text to display. */ - const Color *mColor; /**< The color of the text. */ - const Color mOutlineColor; + const Color *mColor; /**< The color of the text. */ + Color mOutlineColor; bool mIsSpeech; /**< Is this text a speech bubble? */ + bool mTextChanged; protected: static ImageRect mBubble; /**< Speech bubble graphic */ |