1
0

text.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef SCUFENG_TEXT_H_
  2. #define SCUFENG_TEXT_H_
  3. #include <stdint.h>
  4. #include "cglm/types.h"
  5. #include "scufeng/engine.h"
  6. #include "scufeng/Mesh.h"
  7. #include "scufcont/DString.h"
  8. typedef struct {
  9. unsigned int textures[128];
  10. ivec2 sizes[128];
  11. ivec2 bearings[128];
  12. unsigned int advances[128];
  13. int size_x_max;
  14. int size_y_max;
  15. int bearing_y_max;
  16. } SEFont;
  17. typedef enum : uint8_t {
  18. TI_FIXED_WIDTH = 1,
  19. } SETextInputOptions;
  20. typedef struct {
  21. SETextInputOptions opts;
  22. bool active;
  23. size_t cursor;
  24. SEMesh cursor_mesh;
  25. SEMesh bg_mesh;
  26. SCDString text;
  27. int x;
  28. int y;
  29. float scale;
  30. vec3 text_color;
  31. float fixed_width;
  32. } SETextInput;
  33. SEResult se_font_load(
  34. const char *path,
  35. const unsigned int pixel_w,
  36. const unsigned int pixel_h,
  37. size_t *const font_id
  38. );
  39. void se_font_set(const size_t font_id);
  40. SEFont *se_font_current_get();
  41. size_t se_font_current_get_id();
  42. int se_text_render(
  43. const char *text,
  44. int x,
  45. int y,
  46. float scale,
  47. const vec3 color
  48. );
  49. SETextInput SETextInput_alloc(
  50. const char *text,
  51. const size_t text_len,
  52. const int x,
  53. const int y,
  54. vec3 color,
  55. vec4 bg_color,
  56. const SETextInputOptions opts
  57. );
  58. void SETextInput_free(SETextInput *const ti);
  59. void SETextInput_deactivate();
  60. void SETextInput_activate(SETextInput *const ti);
  61. SCDString *SETextInput_string_get_ref(SETextInput *const ti);
  62. SEResult SETextInput_text_copy(const SETextInput *const ti, SCDString *const dst);
  63. const char *SETextInput_c_str(const SETextInput *const ti);
  64. SEResult SETextInput_char_insert_at_cursor(SETextInput *const ti, const char ch);
  65. void SETextInput_char_remove_at_cursor(SETextInput *const ti);
  66. bool SETextInput_is_pos_inside(const SETextInput *const ti, const float x, const float y);
  67. void SETextInput_fixed_width_set(SETextInput *const ti, const float w);
  68. void SETextInput_render_2d(SETextInput *const ti);
  69. void SETextInput_render_multiple_2d(SETextInput *const *const tis, const size_t ti_count);
  70. #endif // SCUFENG_TEXT_H_