From 8765ee0f90be145ad73a6a912c8df6ebb16dd963 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 18 Nov 2021 06:20:56 +0100 Subject: Fix corrupt reactions in matrix (use of deleted vertex buffer) --- depends/mglpp | 2 +- include/Text.hpp | 5 ++++- src/Text.cpp | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/depends/mglpp b/depends/mglpp index 870f3ac..3f8099b 160000 --- a/depends/mglpp +++ b/depends/mglpp @@ -1 +1 @@ -Subproject commit 870f3ac7f31fd4056f95ebec1844a22ef64c7472 +Subproject commit 3f8099b9b5c64e912a2ca227a9e3b2ce774f5ff3 diff --git a/include/Text.hpp b/include/Text.hpp index dc3a0f7..a8a17be 100644 --- a/include/Text.hpp +++ b/include/Text.hpp @@ -55,6 +55,8 @@ namespace QuickMedia { public: Text(std::string str, bool bold_font, unsigned int characterSize, float maxWidth, bool highlight_urls = false); + Text(const Text &other); + Text& operator=(const Text&); void setString(std::string str); const std::string& getString() const; @@ -112,6 +114,7 @@ namespace QuickMedia RIGHT_WORD }; + Text(); void updateCaret(); int getStartOfLine(int startIndex) const; int getEndOfLine(int startIndex) const; @@ -135,7 +138,7 @@ namespace QuickMedia size_t get_string_index_from_caret_index(size_t caret_index) const; private: std::string str; // TODO: Remove this for non-editable text??? also replace with std::string? then we get more efficient editing of text - const bool bold_font; + bool bold_font; unsigned int characterSize; std::array, 4> vertices; std::array vertex_buffers; diff --git a/src/Text.cpp b/src/Text.cpp index 18a87f4..39e5bc4 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -21,6 +21,26 @@ namespace QuickMedia static const size_t FONT_INDEX_SYMBOLS = 2; static const size_t FONT_INDEX_EMOJI = 3; static const size_t FONT_ARRAY_SIZE = 4; + + Text::Text() : + bold_font(false), + characterSize(12), + maxWidth(0.0f), + color(get_theme().text_color), + dirty(true), + dirtyText(true), + dirtyCaret(true), + editable(false), + highlight_urls(false), + caretMoveDirection(CaretMoveDirection::NONE), + num_lines(1), + lineSpacing(0.0f), + characterSpacing(0.0f), + caretIndex(0), + caret_offset_x(0.0f) + { + + } Text::Text(std::string _str, bool bold_font, unsigned int characterSize, float maxWidth, bool highlight_urls) : bold_font(bold_font), @@ -28,8 +48,8 @@ namespace QuickMedia maxWidth(maxWidth), color(get_theme().text_color), dirty(true), - dirtyText(false), - dirtyCaret(false), + dirtyText(true), + dirtyCaret(true), editable(false), highlight_urls(highlight_urls), caretMoveDirection(CaretMoveDirection::NONE), @@ -41,6 +61,21 @@ namespace QuickMedia { setString(std::move(_str)); } + + Text::Text(const Text &other) : Text(other.str, other.bold_font, other.characterSize, other.maxWidth, other.highlight_urls) { + + } + + Text& Text::operator=(const Text &other) { + str = other.str; + bold_font = other.bold_font; + characterSize = other.characterSize; + maxWidth = other.maxWidth; + highlight_urls = other.highlight_urls; + caretIndex = other.caretIndex; + position = other.position; + return *this; + } void Text::setString(std::string str) { -- cgit v1.2.3