#ifndef SCUFENG_TEXT_H_ #define SCUFENG_TEXT_H_ #include #include "cglm/types.h" #include "scufeng/engine.h" #include "scufeng/Mesh.h" #include "scufcont/DString.h" #define SETextInput_pos(ti) (ti.bg_mesh.transform.pos) #define SETextInput_scale(ti) (ti.bg_mesh.transform.scale) typedef struct { unsigned int textures[128]; ivec2 sizes[128]; ivec2 bearings[128]; unsigned int advances[128]; int size_x_max; int size_y_max; int bearing_y_max; } SEFont; typedef struct { bool active; size_t cursor; SEMesh cursor_mesh; SEMesh bg_mesh; SCDString text; vec3 text_color; } SETextInput; SEResult se_font_load( const char *path, const unsigned int pixel_w, const unsigned int pixel_h, size_t *const font_id ); void se_font_set(const size_t font_id); SEFont *se_font_current_get(); size_t se_font_current_get_id(); /** @param x Left edge of text. @param y Bottom of text. For example, the bottom edge of a '_' character is at y. @param h Height scale. Values above font.size_y_max scale up, values below it scale down. Set to 0 or font.size_y_max for no scaling. */ int se_text_render( const char *text, unsigned int x, unsigned int y, unsigned int h, const vec3 color ); SETextInput SETextInput_alloc( const char *text, const size_t text_len, vec3 color, vec4 bg_color ); void SETextInput_free(SETextInput *const ti); void SETextInput_scale_set(SETextInput *const ti, const vec2 dims); void SETextInput_pos_set(SETextInput *const ti, const vec2 pos); void SETextInput_color_set(SETextInput *const ti, const vec3 color); void SETextInput_bg_color_set(SETextInput *const ti, const vec4 color); SCDString *SETextInput_string_get_ref(SETextInput *const ti); void SETextInput_deactivate(); void SETextInput_activate(SETextInput *const ti); void SETextInput_bbox_get( const SETextInput *const ti, float *const left, float *const top, float *const right, float *const bottom ); void SETextInput_bbox_get_v(const SETextInput *const ti, vec4 bbox); SEResult SETextInput_text_copy(const SETextInput *const ti, SCDString *const dst); const char *SETextInput_c_str(const SETextInput *const ti); SEResult SETextInput_char_insert_at_cursor(SETextInput *const ti, const char ch); void SETextInput_char_remove_at_cursor(SETextInput *const ti); bool SETextInput_is_pos_inside(const SETextInput *const ti, const float x, const float y); void SETextInput_render_2d(SETextInput *const ti); void SETextInput_render_multiple_2d(SETextInput *const *const tis, const size_t ti_count); #endif // SCUFENG_TEXT_H_