Minetest 5.9.0-dev
 
Loading...
Searching...
No Matches
enriched_string.h
Go to the documentation of this file.
1/*
2Copyright (C) 2013 xyz, Ilya Zhuravlev <whatever@xyz.is>
3Copyright (C) 2016 Nore, Nathanaƫlle Courant <nore@mesecons.net>
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU Lesser General Public License as published by
7the Free Software Foundation; either version 2.1 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU Lesser General Public License for more details.
14
15You should have received a copy of the GNU Lesser General Public License along
16with this program; if not, write to the Free Software Foundation, Inc.,
1751 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18*/
19
20#pragma once
21
22#include <string>
23#include <vector>
24#include <SColor.h>
25
26using namespace irr;
27
29public:
31 EnrichedString(const std::wstring &s,
32 const video::SColor &color = video::SColor(255, 255, 255, 255));
33 EnrichedString(const wchar_t *str,
34 const video::SColor &color = video::SColor(255, 255, 255, 255));
35 EnrichedString(const std::wstring &string,
36 const std::vector<video::SColor> &colors);
37 EnrichedString &operator=(const wchar_t *str);
38
39 void clear();
40
41 void addAtEnd(const std::wstring &s, video::SColor color);
42
43 // Adds the character source[i] at the end.
44 // An EnrichedString should always be able to be copied
45 // to the end of an existing EnrichedString that way.
46 void addChar(const EnrichedString &source, size_t i);
47
48 // Adds a single character at the end, without specifying its
49 // color. The color used will be the one from the last character.
50 void addCharNoColor(wchar_t c);
51
52 EnrichedString getNextLine(size_t *pos) const;
53 EnrichedString substr(size_t pos = 0, size_t len = std::string::npos) const;
54 EnrichedString operator+(const EnrichedString &other) const;
55 void operator+=(const EnrichedString &other);
56 const wchar_t *c_str() const;
57 const std::vector<video::SColor> &getColors() const;
58 const std::wstring &getString() const;
59
60 inline void setDefaultColor(video::SColor color)
61 {
62 m_default_color = color;
64 }
65 void updateDefaultColor();
66 inline const video::SColor &getDefaultColor() const
67 {
68 return m_default_color;
69 }
70
71 inline bool operator==(const EnrichedString &other) const
72 {
73 return (m_string == other.m_string && m_colors == other.m_colors);
74 }
75 inline bool operator!=(const EnrichedString &other) const
76 {
77 return !(*this == other);
78 }
79 inline bool empty() const
80 {
81 return m_string.empty();
82 }
83 inline size_t size() const
84 {
85 return m_string.size();
86 }
87
88 inline bool hasBackground() const
89 {
90 return m_has_background;
91 }
92 inline video::SColor getBackground() const
93 {
94 return m_background;
95 }
96 inline void setBackground(video::SColor color)
97 {
98 m_background = color;
99 m_has_background = true;
100 }
101
102private:
103 std::wstring m_string;
104 std::vector<video::SColor> m_colors;
106 video::SColor m_default_color;
107 video::SColor m_background;
108 // This variable defines the length of the default-colored text.
109 // Change this to a std::vector if an "end coloring" tag is wanted.
111};
Definition: enriched_string.h:28
video::SColor getBackground() const
Definition: enriched_string.h:92
EnrichedString getNextLine(size_t *pos) const
Definition: enriched_string.cpp:169
EnrichedString & operator=(const wchar_t *str)
Definition: enriched_string.cpp:62
void setBackground(video::SColor color)
Definition: enriched_string.h:96
bool empty() const
Definition: enriched_string.h:79
void addChar(const EnrichedString &source, size_t i)
Definition: enriched_string.cpp:133
EnrichedString(const std::wstring &string, const std::vector< video::SColor > &colors)
void clear()
Definition: enriched_string.cpp:52
bool operator!=(const EnrichedString &other) const
Definition: enriched_string.h:75
EnrichedString(const wchar_t *str, const video::SColor &color=video::SColor(255, 255, 255, 255))
const std::vector< video::SColor > & getColors() const
Definition: enriched_string.cpp:211
EnrichedString(const std::wstring &s, const video::SColor &color=video::SColor(255, 255, 255, 255))
bool operator==(const EnrichedString &other) const
Definition: enriched_string.h:71
void addAtEnd(const std::wstring &s, video::SColor color)
Definition: enriched_string.cpp:69
bool hasBackground() const
Definition: enriched_string.h:88
const std::wstring & getString() const
Definition: enriched_string.cpp:216
std::wstring m_string
Definition: enriched_string.h:103
const wchar_t * c_str() const
Definition: enriched_string.cpp:206
video::SColor m_default_color
Definition: enriched_string.h:106
std::vector< video::SColor > m_colors
Definition: enriched_string.h:104
void operator+=(const EnrichedString &other)
Definition: enriched_string.cpp:156
const video::SColor & getDefaultColor() const
Definition: enriched_string.h:66
void addCharNoColor(wchar_t c)
Definition: enriched_string.cpp:139
size_t size() const
Definition: enriched_string.h:83
bool m_has_background
Definition: enriched_string.h:105
EnrichedString operator+(const EnrichedString &other) const
Definition: enriched_string.cpp:149
EnrichedString()
Definition: enriched_string.cpp:27
void updateDefaultColor()
Definition: enriched_string.cpp:221
size_t m_default_length
Definition: enriched_string.h:110
EnrichedString substr(size_t pos=0, size_t len=std::string::npos) const
Definition: enriched_string.cpp:184
void setDefaultColor(video::SColor color)
Definition: enriched_string.h:60
video::SColor m_background
Definition: enriched_string.h:107
Definition: shader.h:61