aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-07 08:25:36 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-07 08:25:36 +0100
commit01e3403abf86050e4096ecf60466de4139ac78e2 (patch)
tree0e55dfc60060a75f3810e985a8394a41b4012cfd /src
parent29627a93c68b9f3927ee9d1097ed3266777b6a0b (diff)
Fix text rendering getting corrupt at copy/move constructor
Diffstat (limited to 'src')
-rw-r--r--src/graphics/Text.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/graphics/Text.cpp b/src/graphics/Text.cpp
index 49829e6..953833b 100644
--- a/src/graphics/Text.cpp
+++ b/src/graphics/Text.cpp
@@ -18,9 +18,26 @@ namespace mgl {
}
Text::Text(const Text &other) {
+ *this = other;
+ }
+
+ Text& Text::operator=(const Text &other) {
font = other.font;
- mgl_text_init(&text, font ? font->internal_font() : nullptr, other.str.c_str(), other.str.size());
+ str = other.str;
+ mgl_text_init(&text, font ? font->internal_font() : nullptr, str.c_str(), str.size());
mgl_text_set_position(&text, { other.text.position.x, other.text.position.y });
+ return *this;
+ }
+
+ Text::Text(Text &&other) {
+ font = std::move(other.font);
+ str = std::move(other.str);
+ text = std::move(other.text);
+ mgl_text_init(&text, font ? font->internal_font() : nullptr, str.c_str(), str.size());
+
+ other.font = nullptr;
+ other.str.clear();
+ mgl_text_deinit(&other.text);
}
Text::~Text() {
@@ -54,6 +71,11 @@ namespace mgl {
return str;
}
+ void Text::append_string(const std::string &str) {
+ this->str += str;
+ mgl_text_set_string(&text, this->str.c_str(), this->str.size());
+ }
+
// TODO: Implement
vec2f Text::find_character_pos(size_t index) {
return vec2f();