#ifndef MGL_TEXT_H #define MGL_TEXT_H /* TODO: Do not render text outside the window and start from the visible part. Support 64-bit text length on 32-bit systems, and use mmap to optimize loading very large files, and munmap the text parts that are not visible on the screen. */ #include "../system/vec.h" #include "color.h" #include #include typedef struct mgl_font mgl_font; typedef struct mgl_context mgl_context; typedef struct { mgl_font *font; /* nullable */ const char *text; /* nullable */ size_t text_size; mgl_color color; mgl_vec2f position; mgl_vec2f bounds; bool bounds_dirty; } mgl_text; /* Note: keeps a reference to |text|. |text| needs to be valid as long as |self| is used. |font| and |text| may be NULL. */ void mgl_text_init(mgl_text *self, mgl_font *font, const char *str, size_t str_size); void mgl_text_deinit(mgl_text *self); /* Note: keeps a reference to |text|. |text| needs to be valid as long as |self| is used. |text| may be NULL. */ void mgl_text_set_string(mgl_text *self, const char *str, size_t str_size); /* |font| may be NULL */ void mgl_text_set_font(mgl_text *self, mgl_font *font); void mgl_text_set_position(mgl_text *self, mgl_vec2f position); void mgl_text_set_color(mgl_text *self, mgl_color color); mgl_vec2f mgl_text_get_bounds(mgl_text *self); /* Returns the position of the character on the screen (relative to the current mgl_view) */ mgl_vec2f mgl_text_find_character_pos(mgl_text *self, size_t index); void mgl_text_draw(mgl_context *context, mgl_text *text); #endif /* MGL_TEXT_H */