summaryrefslogtreecommitdiff
path: root/src/gui/fonts/textchunk.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/fonts/textchunk.cpp
parentfd85f62f2e3003a79e90611e95b09e23710be479 (diff)
downloadmanaverse-e224a077737739a895fe533c9cce93783621d8e9.tar.gz
manaverse-e224a077737739a895fe533c9cce93783621d8e9.tar.bz2
manaverse-e224a077737739a895fe533c9cce93783621d8e9.tar.xz
manaverse-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/fonts/textchunk.cpp')
-rw-r--r--src/gui/fonts/textchunk.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/gui/fonts/textchunk.cpp b/src/gui/fonts/textchunk.cpp
index b0933a3e0..a0c8a39dc 100644
--- a/src/gui/fonts/textchunk.cpp
+++ b/src/gui/fonts/textchunk.cpp
@@ -25,6 +25,8 @@
#include "sdlshared.h"
+#include "gui/fonts/font.h"
+
#include "resources/image.h"
#include "resources/surfaceimagehelper.h"
@@ -45,10 +47,24 @@ char *strBuf = nullptr;
int textChunkCnt = 0;
#endif
+TextChunk::TextChunk() :
+ img(nullptr),
+ textFont(nullptr),
+ text(),
+ color(),
+ color2(),
+ prev(nullptr),
+ next(nullptr)
+{
+#ifdef UNITTESTS
+ textChunkCnt ++;
+#endif
+}
+
TextChunk::TextChunk(const std::string &text0,
const Color &color0,
const Color &color1,
- const Font *const font) :
+ Font *const font) :
img(nullptr),
textFont(font),
text(text0),
@@ -167,3 +183,16 @@ void TextChunk::generate(TTF_Font *const font, const float alpha)
BLOCK_END("TextChunk::generate")
}
+
+void TextChunk::deleteImage()
+{
+ if (textFont)
+ {
+ textFont->insertChunk(this);
+ img = nullptr;
+ }
+ else
+ {
+ delete2(img);
+ }
+}