diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-05-18 20:26:49 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-05-18 21:45:18 +0300 |
commit | 031f32210799807411af4fb9a40793d4f26febe7 (patch) | |
tree | a9ad02433e05c3f004ce192f8e47572a3795fd48 /src | |
parent | fbbf87a36f5f27851a2e2d17b95a0f17dd82624b (diff) | |
download | manaverse-031f32210799807411af4fb9a40793d4f26febe7.tar.gz manaverse-031f32210799807411af4fb9a40793d4f26febe7.tar.bz2 manaverse-031f32210799807411af4fb9a40793d4f26febe7.tar.xz manaverse-031f32210799807411af4fb9a40793d4f26febe7.zip |
Add font field into textchunk class. For now unused.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/fonts/font.cpp | 2 | ||||
-rw-r--r-- | src/gui/fonts/font_unittest.cc | 64 | ||||
-rw-r--r-- | src/gui/fonts/textchunk.cpp | 7 | ||||
-rw-r--r-- | src/gui/fonts/textchunk.h | 5 |
4 files changed, 43 insertions, 35 deletions
diff --git a/src/gui/fonts/font.cpp b/src/gui/fonts/font.cpp index d689ef88c..27628aec5 100644 --- a/src/gui/fonts/font.cpp +++ b/src/gui/fonts/font.cpp @@ -249,7 +249,7 @@ void Font::drawString(Graphics *const graphics, #ifdef DEBUG_FONT_COUNTERS mCreateCounter ++; #endif - TextChunk *chunk2 = new TextChunk(text, col, col2); + TextChunk *chunk2 = new TextChunk(text, col, col2, this); chunk2->generate(mFont, alpha); cache->insertFirst(chunk2); diff --git a/src/gui/fonts/font_unittest.cc b/src/gui/fonts/font_unittest.cc index b5b589e72..8b8d027c5 100644 --- a/src/gui/fonts/font_unittest.cc +++ b/src/gui/fonts/font_unittest.cc @@ -46,7 +46,7 @@ TEST(TextChunkList, add1) TextChunkList list; TextChunk *chunk = new TextChunk("test", - Color(1, 2, 3), Color(2, 3, 4)); + Color(1, 2, 3), Color(2, 3, 4), nullptr); list.insertFirst(chunk); @@ -69,9 +69,9 @@ TEST(TextChunkList, add2) TextChunkList list; TextChunk *chunk1 = new TextChunk("test", - Color(1, 2, 3), Color(3, 4, 5)); + Color(1, 2, 3), Color(3, 4, 5), nullptr); TextChunk *chunk2 = new TextChunk("test", - Color(2, 3, 4), Color(4, 5, 6)); + Color(2, 3, 4), Color(4, 5, 6), nullptr); list.insertFirst(chunk2); list.insertFirst(chunk1); @@ -99,7 +99,7 @@ TEST(TextChunkList, addRemoveBack1) TextChunkList list; TextChunk *chunk = new TextChunk("test", - Color(1, 2, 3), Color(1, 2, 3)); + Color(1, 2, 3), Color(1, 2, 3), nullptr); list.insertFirst(chunk); list.removeBack(); @@ -116,9 +116,9 @@ TEST(TextChunkList, addRemoveBack2) TextChunkList list; TextChunk *chunk1 = new TextChunk("test", - Color(1, 2, 3), Color(1, 2, 3)); + Color(1, 2, 3), Color(1, 2, 3), nullptr); TextChunk *chunk2 = new TextChunk("test2", - Color(1, 2, 4), Color(1, 2, 5)); + Color(1, 2, 4), Color(1, 2, 5), nullptr); list.insertFirst(chunk2); list.insertFirst(chunk1); @@ -143,9 +143,9 @@ TEST(TextChunkList, addRemoveBack3) TextChunkList list; TextChunk *chunk1 = new TextChunk("test", - Color(1, 2, 3), Color(1, 2, 3)); + Color(1, 2, 3), Color(1, 2, 3), nullptr); TextChunk *chunk2 = new TextChunk("test2", - Color(2, 3, 4), Color(2, 3, 4)); + Color(2, 3, 4), Color(2, 3, 4), nullptr); list.insertFirst(chunk2); list.insertFirst(chunk1); @@ -164,11 +164,11 @@ TEST(TextChunkList, addRemoveBack4) TextChunkList list; TextChunk *chunk1 = new TextChunk("test", - Color(1, 2, 3), Color(1, 2, 3)); + Color(1, 2, 3), Color(1, 2, 3), nullptr); TextChunk *chunk2 = new TextChunk("test2", - Color(2, 3, 4), Color(2, 3, 4)); + Color(2, 3, 4), Color(2, 3, 4), nullptr); TextChunk *chunk3 = new TextChunk("test", - Color(3, 4, 5), Color(3, 4, 5)); + Color(3, 4, 5), Color(3, 4, 5), nullptr); list.insertFirst(chunk3); list.insertFirst(chunk2); @@ -194,7 +194,7 @@ TEST(TextChunkList, moveToFirst1) TextChunkList list; TextChunk *chunk = new TextChunk("test", - Color(1, 2, 3), Color(2, 3, 4)); + Color(1, 2, 3), Color(2, 3, 4), nullptr); list.insertFirst(chunk); list.moveToFirst(chunk); @@ -211,9 +211,9 @@ TEST(TextChunkList, moveToFirst2) TextChunkList list; TextChunk *chunk1 = new TextChunk("test", - Color(1, 2, 3), Color(1, 2, 3)); + Color(1, 2, 3), Color(1, 2, 3), nullptr); TextChunk *chunk2 = new TextChunk("test", - Color(2, 3, 4), Color(1, 2, 3)); + Color(2, 3, 4), Color(1, 2, 3), nullptr); list.insertFirst(chunk1); list.insertFirst(chunk2); @@ -233,11 +233,11 @@ TEST(TextChunkList, moveToFirst3) TextChunkList list; TextChunk *chunk1 = new TextChunk("test", - Color(1, 2, 3), Color(1, 2, 3)); + Color(1, 2, 3), Color(1, 2, 3), nullptr); TextChunk *chunk2 = new TextChunk("test", - Color(1, 2, 4), Color(1, 2, 3)); + Color(1, 2, 4), Color(1, 2, 3), nullptr); TextChunk *chunk3 = new TextChunk("test", - Color(1, 2, 5), Color(1, 2, 3)); + Color(1, 2, 5), Color(1, 2, 3), nullptr); list.insertFirst(chunk3); list.insertFirst(chunk1); @@ -260,11 +260,11 @@ TEST(TextChunkList, moveToFirst4) TextChunkList list; TextChunk *chunk1 = new TextChunk("test", - Color(), Color()); + Color(), Color(), nullptr); TextChunk *chunk2 = new TextChunk("test2", - Color(), Color()); + Color(), Color(), nullptr); TextChunk *chunk3 = new TextChunk("test3", - Color(), Color()); + Color(), Color(), nullptr); list.insertFirst(chunk1); list.insertFirst(chunk3); @@ -287,7 +287,8 @@ TEST(TextChunkList, clear1) TextChunkList list; int chunksLeft = textChunkCnt; - TextChunk *chunk = new TextChunk("test", Color(), Color()); + TextChunk *chunk = new TextChunk("test", + Color(), Color(), nullptr); list.insertFirst(chunk); list.clear(); @@ -306,11 +307,11 @@ TEST(TextChunkList, clear2) int chunksLeft = textChunkCnt; TextChunk *chunk1 = new TextChunk("test", - Color(1, 2, 3), Color(2, 0, 0)); + Color(1, 2, 3), Color(2, 0, 0), nullptr); TextChunk *chunk2 = new TextChunk("test", - Color(1, 2, 3), Color(2, 0, 1)); + Color(1, 2, 3), Color(2, 0, 1), nullptr); TextChunk *chunk3 = new TextChunk("test", - Color(1, 2, 3), Color(2, 0, 2)); + Color(1, 2, 3), Color(2, 0, 2), nullptr); list.insertFirst(chunk1); list.insertFirst(chunk2); @@ -331,11 +332,11 @@ TEST(TextChunkList, clear3) int chunksLeft = textChunkCnt; TextChunk *chunk1 = new TextChunk("test", - Color(1, 2, 3), Color(2, 0, 0)); + Color(1, 2, 3), Color(2, 0, 0), nullptr); TextChunk *chunk2 = new TextChunk("test", - Color(1, 2, 3), Color(2, 0, 1)); + Color(1, 2, 3), Color(2, 0, 1), nullptr); TextChunk *chunk3 = new TextChunk("test", - Color(1, 2, 3), Color(2, 0, 2)); + Color(1, 2, 3), Color(2, 0, 2), nullptr); list.insertFirst(chunk1); list.insertFirst(chunk2); @@ -356,18 +357,19 @@ TEST(TextChunkList, clear3) EXPECT_EQ(0, list.searchWidth.size()); } -TEST(TextChunkList, clear4) +TEST(TextChunkList, clear5) { TextChunkList list; int chunksLeft = textChunkCnt; TextChunk *chunk1 = new TextChunk("test", - Color(1, 2, 3), Color(2, 0, 0)); + Color(1, 2, 3), Color(2, 0, 0), nullptr); TextChunk *chunk2 = new TextChunk("test", - Color(1, 2, 3), Color(2, 0, 1)); + Color(1, 2, 3), Color(2, 0, 1), nullptr); TextChunk *chunk3 = new TextChunk("test3", - Color(1, 2, 3), Color(2, 0, 2)); + Color(1, 2, 3), Color(2, 0, 2), nullptr); + chunk1->refCount = 1; list.insertFirst(chunk1); list.insertFirst(chunk2); list.insertFirst(chunk3); diff --git a/src/gui/fonts/textchunk.cpp b/src/gui/fonts/textchunk.cpp index 2cb7b2641..b0933a3e0 100644 --- a/src/gui/fonts/textchunk.cpp +++ b/src/gui/fonts/textchunk.cpp @@ -45,9 +45,12 @@ char *strBuf = nullptr; int textChunkCnt = 0; #endif -TextChunk::TextChunk(const std::string &text0, const Color &color0, - const Color &color1) : +TextChunk::TextChunk(const std::string &text0, + const Color &color0, + const Color &color1, + const Font *const font) : img(nullptr), + textFont(font), text(text0), color(color0), color2(color1), diff --git a/src/gui/fonts/textchunk.h b/src/gui/fonts/textchunk.h index 9e9e36827..13187473d 100644 --- a/src/gui/fonts/textchunk.h +++ b/src/gui/fonts/textchunk.h @@ -32,6 +32,7 @@ #include "localconsts.h" +class Font; class Image; class TextChunk final @@ -39,7 +40,8 @@ class TextChunk final public: TextChunk(const std::string &text0, const Color &color0, - const Color &color1); + const Color &color1, + const Font *const font); A_DELETE_COPY(TextChunk) @@ -50,6 +52,7 @@ class TextChunk final void generate(TTF_Font *const font, const float alpha); Image *img; + const Font *textFont; std::string text; Color color; Color color2; |