From e224a077737739a895fe533c9cce93783621d8e9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 19 May 2015 14:49:19 +0300 Subject: 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. --- src/gui/fonts/textchunk.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/gui/fonts/textchunk.cpp') 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); + } +} -- cgit v1.2.3-70-g09d2