summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/fonts/font.cpp130
-rw-r--r--src/gui/fonts/font.h25
-rw-r--r--src/gui/fonts/textchunk.cpp165
-rw-r--r--src/gui/fonts/textchunk.h65
6 files changed, 238 insertions, 151 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3742b845f..e8689d753 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -427,6 +427,8 @@ SET(SRCS
gui/setupactiondata.h
gui/fonts/font.cpp
gui/fonts/font.h
+ gui/fonts/textchunk.cpp
+ gui/fonts/textchunk.h
gui/fonts/textchunksmall.cpp
gui/fonts/textchunksmall.h
gui/windows/shopwindow.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index bd172ca87..8e325261f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -524,6 +524,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
gui/setupactiondata.h \
gui/fonts/font.cpp \
gui/fonts/font.h \
+ gui/fonts/textchunk.cpp \
+ gui/fonts/textchunk.h \
gui/fonts/textchunksmall.cpp \
gui/fonts/textchunksmall.h \
gui/windows/shopwindow.cpp \
diff --git a/src/gui/fonts/font.cpp b/src/gui/fonts/font.cpp
index a8f636862..485d1a84e 100644
--- a/src/gui/fonts/font.cpp
+++ b/src/gui/fonts/font.cpp
@@ -69,6 +69,8 @@
#include "logger.h"
#include "main.h"
+#include "gui/fonts/textchunk.h"
+
#include "render/sdlgraphics.h"
#include "resources/image.h"
@@ -89,136 +91,10 @@ const unsigned int CACHE_SIZE_SMALL1 = 2;
const unsigned int CACHE_SIZE_SMALL2 = 50;
const unsigned int CACHE_SIZE_SMALL3 = 170;
const unsigned int CLEAN_TIME = 7;
-const int OUTLINE_SIZE = 1;
bool Font::mSoftMode(false);
-char *strBuf = nullptr;
-
-#ifdef UNITTESTS
-int sdlTextChunkCnt = 0;
-#endif
-
-TextChunk::TextChunk(const std::string &text0, const Color &color0,
- const Color &color1) :
- img(nullptr),
- text(text0),
- color(color0),
- color2(color1),
- prev(nullptr),
- next(nullptr)
-{
-#ifdef UNITTESTS
- sdlTextChunkCnt ++;
-#endif
-}
-
-TextChunk::~TextChunk()
-{
- delete2(img);
-#ifdef UNITTESTS
- sdlTextChunkCnt --;
-#endif
-}
-
-bool TextChunk::operator==(const TextChunk &chunk) const
-{
- return (chunk.text == text && chunk.color == color
- && chunk.color2 == color2);
-}
-
-void TextChunk::generate(TTF_Font *const font, const float alpha)
-{
- BLOCK_START("TextChunk::generate")
- SDL_Color sdlCol;
- sdlCol.b = static_cast<uint8_t>(color.b);
- sdlCol.r = static_cast<uint8_t>(color.r);
- sdlCol.g = static_cast<uint8_t>(color.g);
-#ifdef USE_SDL2
- sdlCol.a = 255;
-#else
- sdlCol.unused = 0;
-#endif
-
- getSafeUtf8String(text, strBuf);
-
- SDL_Surface *surface = MTTF_RenderUTF8_Blended(
- font, strBuf, sdlCol);
-
- if (!surface)
- {
- img = nullptr;
- BLOCK_END("TextChunk::generate")
- return;
- }
-
- const int width = surface->w;
- const int height = surface->h;
-
- if (color.r != color2.r || color.g != color2.g
- || color.b != color2.b)
- { // outlining
- SDL_Color sdlCol2;
- SDL_Surface *const background = imageHelper->create32BitSurface(
- width, height);
- if (!background)
- {
- img = nullptr;
- MSDL_FreeSurface(surface);
- BLOCK_END("TextChunk::generate")
- return;
- }
- sdlCol2.b = static_cast<uint8_t>(color2.b);
- sdlCol2.r = static_cast<uint8_t>(color2.r);
- sdlCol2.g = static_cast<uint8_t>(color2.g);
-#ifdef USE_SDL2
- sdlCol2.a = 255;
-#else
- sdlCol2.unused = 0;
-#endif
- SDL_Surface *const surface2 = MTTF_RenderUTF8_Blended(
- font, strBuf, sdlCol2);
- if (!surface2)
- {
- img = nullptr;
- MSDL_FreeSurface(surface);
- BLOCK_END("TextChunk::generate")
- return;
- }
- SDL_Rect rect =
- {
- OUTLINE_SIZE,
- 0,
- static_cast<Uint16>(surface->w),
- static_cast<Uint16>(surface->h)
- };
- SurfaceImageHelper::combineSurface(surface2, nullptr,
- background, &rect);
- rect.x = -OUTLINE_SIZE;
- SurfaceImageHelper::combineSurface(surface2, nullptr,
- background, &rect);
- rect.x = 0;
- rect.y = -OUTLINE_SIZE;
- SurfaceImageHelper::combineSurface(surface2, nullptr,
- background, &rect);
- rect.y = OUTLINE_SIZE;
- SurfaceImageHelper::combineSurface(surface2, nullptr,
- background, &rect);
- rect.x = 0;
- rect.y = 0;
- SurfaceImageHelper::combineSurface(surface, nullptr,
- background, &rect);
- MSDL_FreeSurface(surface);
- MSDL_FreeSurface(surface2);
- surface = background;
- }
- img = imageHelper->createTextSurface(
- surface, width, height, alpha);
- MSDL_FreeSurface(surface);
-
- BLOCK_END("TextChunk::generate")
-}
-
+extern char *strBuf;
TextChunkList::TextChunkList() :
start(nullptr),
diff --git a/src/gui/fonts/font.h b/src/gui/fonts/font.h
index 551800bdb..7ed400ff4 100644
--- a/src/gui/fonts/font.h
+++ b/src/gui/fonts/font.h
@@ -81,33 +81,10 @@
class Color;
class Graphics;
class Image;
+class TextChunk;
const unsigned int CACHES_NUMBER = 256;
-class TextChunk final
-{
- public:
- TextChunk(const std::string &text0,
- const Color &color0,
- const Color &color1);
-
- A_DELETE_COPY(TextChunk)
-
- ~TextChunk();
-
- bool operator==(const TextChunk &chunk) const;
-
- void generate(TTF_Font *const font, const float alpha);
-
- Image *img;
- std::string text;
- Color color;
- Color color2;
- TextChunk *prev;
- TextChunk *next;
-};
-
-
class TextChunkList final
{
public:
diff --git a/src/gui/fonts/textchunk.cpp b/src/gui/fonts/textchunk.cpp
new file mode 100644
index 000000000..632dfaf7b
--- /dev/null
+++ b/src/gui/fonts/textchunk.cpp
@@ -0,0 +1,165 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2009 Aethyra Development Team
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/fonts/textchunk.h"
+
+#include "sdlshared.h"
+
+#include "resources/image.h"
+#include "resources/surfaceimagehelper.h"
+
+#include "utils/delete2.h"
+#include "utils/stringutils.h"
+
+#include "debug.h"
+
+namespace
+{
+ const int OUTLINE_SIZE = 1;
+} // namespace
+
+char *strBuf = nullptr;
+
+#ifdef UNITTESTS
+int sdlTextChunkCnt = 0;
+#endif
+
+TextChunk::TextChunk(const std::string &text0, const Color &color0,
+ const Color &color1) :
+ img(nullptr),
+ text(text0),
+ color(color0),
+ color2(color1),
+ prev(nullptr),
+ next(nullptr)
+{
+#ifdef UNITTESTS
+ sdlTextChunkCnt ++;
+#endif
+}
+
+TextChunk::~TextChunk()
+{
+ delete2(img);
+#ifdef UNITTESTS
+ sdlTextChunkCnt --;
+#endif
+}
+
+bool TextChunk::operator==(const TextChunk &chunk) const
+{
+ return (chunk.text == text && chunk.color == color
+ && chunk.color2 == color2);
+}
+
+void TextChunk::generate(TTF_Font *const font, const float alpha)
+{
+ BLOCK_START("TextChunk::generate")
+ SDL_Color sdlCol;
+ sdlCol.b = static_cast<uint8_t>(color.b);
+ sdlCol.r = static_cast<uint8_t>(color.r);
+ sdlCol.g = static_cast<uint8_t>(color.g);
+#ifdef USE_SDL2
+ sdlCol.a = 255;
+#else
+ sdlCol.unused = 0;
+#endif
+
+ getSafeUtf8String(text, strBuf);
+
+ SDL_Surface *surface = MTTF_RenderUTF8_Blended(
+ font, strBuf, sdlCol);
+
+ if (!surface)
+ {
+ img = nullptr;
+ BLOCK_END("TextChunk::generate")
+ return;
+ }
+
+ const int width = surface->w;
+ const int height = surface->h;
+
+ if (color.r != color2.r || color.g != color2.g
+ || color.b != color2.b)
+ { // outlining
+ SDL_Color sdlCol2;
+ SDL_Surface *const background = imageHelper->create32BitSurface(
+ width, height);
+ if (!background)
+ {
+ img = nullptr;
+ MSDL_FreeSurface(surface);
+ BLOCK_END("TextChunk::generate")
+ return;
+ }
+ sdlCol2.b = static_cast<uint8_t>(color2.b);
+ sdlCol2.r = static_cast<uint8_t>(color2.r);
+ sdlCol2.g = static_cast<uint8_t>(color2.g);
+#ifdef USE_SDL2
+ sdlCol2.a = 255;
+#else
+ sdlCol2.unused = 0;
+#endif
+ SDL_Surface *const surface2 = MTTF_RenderUTF8_Blended(
+ font, strBuf, sdlCol2);
+ if (!surface2)
+ {
+ img = nullptr;
+ MSDL_FreeSurface(surface);
+ BLOCK_END("TextChunk::generate")
+ return;
+ }
+ SDL_Rect rect =
+ {
+ OUTLINE_SIZE,
+ 0,
+ static_cast<Uint16>(surface->w),
+ static_cast<Uint16>(surface->h)
+ };
+ SurfaceImageHelper::combineSurface(surface2, nullptr,
+ background, &rect);
+ rect.x = -OUTLINE_SIZE;
+ SurfaceImageHelper::combineSurface(surface2, nullptr,
+ background, &rect);
+ rect.x = 0;
+ rect.y = -OUTLINE_SIZE;
+ SurfaceImageHelper::combineSurface(surface2, nullptr,
+ background, &rect);
+ rect.y = OUTLINE_SIZE;
+ SurfaceImageHelper::combineSurface(surface2, nullptr,
+ background, &rect);
+ rect.x = 0;
+ rect.y = 0;
+ SurfaceImageHelper::combineSurface(surface, nullptr,
+ background, &rect);
+ MSDL_FreeSurface(surface);
+ MSDL_FreeSurface(surface2);
+ surface = background;
+ }
+ img = imageHelper->createTextSurface(
+ surface, width, height, alpha);
+ MSDL_FreeSurface(surface);
+
+ BLOCK_END("TextChunk::generate")
+}
diff --git a/src/gui/fonts/textchunk.h b/src/gui/fonts/textchunk.h
new file mode 100644
index 000000000..f83472f07
--- /dev/null
+++ b/src/gui/fonts/textchunk.h
@@ -0,0 +1,65 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ * Copyright (C) 2009 Aethyra Development Team
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_FONTS_TEXTCHUNK_H
+#define GUI_FONTS_TEXTCHUNK_H
+
+#include "gui/color.h"
+
+#include <string>
+
+#include <SDL_ttf.h>
+
+#include "localconsts.h"
+
+class Color;
+class Image;
+
+class TextChunk final
+{
+ public:
+ TextChunk(const std::string &text0,
+ const Color &color0,
+ const Color &color1);
+
+ A_DELETE_COPY(TextChunk)
+
+ ~TextChunk();
+
+ bool operator==(const TextChunk &chunk) const;
+
+ void generate(TTF_Font *const font, const float alpha);
+
+ Image *img;
+ std::string text;
+ Color color;
+ Color color2;
+ TextChunk *prev;
+ TextChunk *next;
+};
+
+#ifdef UNITTESTS
+extern int sdlTextChunkCnt;
+#endif
+
+#endif // GUI_FONTS_TEXTCHUNK_H