summaryrefslogtreecommitdiff
path: root/src/util/coloredstring.cpp
diff options
context:
space:
mode:
authorTriBlade9 <triblade9@mail.com>2015-01-16 14:54:26 +0800
committerEkdohibs <nathanael.courant@laposte.net>2016-05-31 17:34:29 +0200
commit1d40385d4aacf0cbea4b19ff06940e8c9bebaf47 (patch)
tree39732d23598a1c14d514ff35d241f9499f0a3c13 /src/util/coloredstring.cpp
parent0e44af9f7056a78a8e561f708751acceacd149c1 (diff)
downloadminetest-1d40385d4aacf0cbea4b19ff06940e8c9bebaf47.tar.gz
minetest-1d40385d4aacf0cbea4b19ff06940e8c9bebaf47.tar.bz2
minetest-1d40385d4aacf0cbea4b19ff06940e8c9bebaf47.zip
Colored chat working as expected for both freetype and non-freetype builds. @nerzhul improvements * Add unit tests * Fix coding style * move guiChatConsole.hpp to client/
Diffstat (limited to 'src/util/coloredstring.cpp')
-rw-r--r--src/util/coloredstring.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/util/coloredstring.cpp b/src/util/coloredstring.cpp
new file mode 100644
index 000000000..7db586550
--- /dev/null
+++ b/src/util/coloredstring.cpp
@@ -0,0 +1,68 @@
+/*
+Copyright (C) 2013 xyz, Ilya Zhuravlev <whatever@xyz.is>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) 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 Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "coloredstring.h"
+#include "util/string.h"
+
+ColoredString::ColoredString()
+{}
+
+ColoredString::ColoredString(const std::wstring &string, const std::vector<SColor> &colors):
+ m_string(string),
+ m_colors(colors)
+{}
+
+ColoredString::ColoredString(const std::wstring &s) {
+ m_string = colorizeText(s, m_colors, SColor(255, 255, 255, 255));
+}
+
+void ColoredString::operator=(const wchar_t *str) {
+ m_string = colorizeText(str, m_colors, SColor(255, 255, 255, 255));
+}
+
+size_t ColoredString::size() const {
+ return m_string.size();
+}
+
+ColoredString ColoredString::substr(size_t pos, size_t len) const {
+ if (pos == m_string.length())
+ return ColoredString();
+ if (len == std::string::npos || pos + len > m_string.length()) {
+ return ColoredString(
+ m_string.substr(pos, std::string::npos),
+ std::vector<SColor>(m_colors.begin() + pos, m_colors.end())
+ );
+ } else {
+ return ColoredString(
+ m_string.substr(pos, len),
+ std::vector<SColor>(m_colors.begin() + pos, m_colors.begin() + pos + len)
+ );
+ }
+}
+
+const wchar_t *ColoredString::c_str() const {
+ return m_string.c_str();
+}
+
+const std::vector<SColor> &ColoredString::getColors() const {
+ return m_colors;
+}
+
+const std::wstring &ColoredString::getString() const {
+ return m_string;
+}