aboutsummaryrefslogtreecommitdiff
path: root/include/mglpp/graphics/Text.hpp
blob: 648ecac35adce600981e655886afbcfb33604fa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef MGLPP_TEXT_HPP
#define MGLPP_TEXT_HPP

#include <string>
#include "Drawable.hpp"
#include "../system/FloatRect.hpp"

extern "C" {
#include <mgl/graphics/text.h>
}

namespace mgl {
    class Font;
    class Text : public Drawable {
    public:
        Text();
        Text(std::string str, Font &font);
        Text(std::string str, vec2f position, Font &font);
        Text(const Text &other);
        Text& operator=(const Text &other);
        Text(Text &&other);
        ~Text();

        void set_position(vec2f position) override;
        void set_color(Color color) override;
        vec2f get_position() const override;

        FloatRect get_bounds() const;
        void set_string(std::string str);
        const std::string& get_string() const;
        void append_string(const std::string &str);

        // Returns the visual position of a character from its index.
        // If the index is out of range, then the position of the end of the string is returned.
        vec2f find_character_pos(size_t index);

        Font* get_font();
    protected:
        void draw(Window &window) override;
    private:
        mgl_text text;
        Font *font;
        std::string str;
    };
}

#endif /* MGLPP_TEXT_HPP */