From 8d525bc1c3506f15a5f68672245f845cebe18eef Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 28 Oct 2021 17:33:57 +0200 Subject: More, todo interfaces --- src/graphics/Text.cpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/graphics/Text.cpp') diff --git a/src/graphics/Text.cpp b/src/graphics/Text.cpp index 7d08c22..dbaa7c1 100644 --- a/src/graphics/Text.cpp +++ b/src/graphics/Text.cpp @@ -6,12 +6,21 @@ extern "C" { } namespace mgl { - Text::Text(std::string str, Font &font) : Text(std::move(str), mgl::vec2f(0.0f, 0.0f), font){} + Text::Text() : font(nullptr) { + mgl_text_init(&text, nullptr, nullptr, 0.0f, 0.0f); + } + + Text::Text(std::string str, Font &font) : Text(std::move(str), vec2f(0.0f, 0.0f), font) {} - Text::Text(std::string str, vec2f position, Font &font) : font(font), str(std::move(str)) { + Text::Text(std::string str, vec2f position, Font &font) : font(&font), str(std::move(str)) { mgl_text_init(&text, font.internal_font(), this->str.c_str(), position.x, position.y); } + Text::Text(const Text &other) { + font = other.font; + mgl_text_init(&text, font ? font->internal_font() : nullptr, other.str.c_str(), other.text.position.x, other.text.position.y); + } + Text::~Text() { mgl_text_deinit(&text); } @@ -28,6 +37,29 @@ namespace mgl { return { text.position.x, text.position.y }; } + // TODO: Implement + FloatRect Text::get_local_bounds() { + return FloatRect(); + } + + void Text::set_string(std::string str) { + this->str = std::move(str); + mgl_text_set_string(&text, this->str.c_str()); + } + + const std::string& Text::get_string() const { + return str; + } + + // TODO: Implement + vec2f Text::find_character_pos(size_t index) { + return vec2f(); + } + + Font* Text::get_font() { + return font; + } + void Text::draw(Window&) { mgl_text_draw(mgl_get_context(), &text); } -- cgit v1.2.3