1
0

text.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #define SETextInput_pos(ti) (ti.bg_mesh.transform.pos)
  9. #define SETextInput_scale(ti) (ti.bg_mesh.transform.scale)
  10. typedef struct {
  11. unsigned int textures[128];
  12. ivec2 sizes[128];
  13. ivec2 bearings[128];
  14. unsigned int advances[128];
  15. int size_x_max;
  16. int size_y_max;
  17. int bearing_y_max;
  18. } SEFont;
  19. typedef struct {
  20. bool active;
  21. size_t cursor;
  22. SEMesh cursor_mesh;
  23. SEMesh bg_mesh;
  24. SCDString text;
  25. vec3 text_color;
  26. } SETextInput;
  27. SEResult se_font_load(
  28. const char *path,
  29. const unsigned int pixel_w,
  30. const unsigned int pixel_h,
  31. size_t *const font_id
  32. );
  33. void se_font_set(const size_t font_id);
  34. SEFont *se_font_current_get();
  35. size_t se_font_current_get_id();
  36. /**
  37. @param x Left edge of text.
  38. @param y Bottom of text. For example, the bottom edge of a '_' character is at y.
  39. @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.
  40. */
  41. int se_text_render(
  42. const char *text,
  43. unsigned int x,
  44. unsigned int y,
  45. unsigned int h,
  46. const vec3 color
  47. );
  48. SETextInput SETextInput_alloc(
  49. const char *text,
  50. const size_t text_len,
  51. vec3 color,
  52. vec4 bg_color
  53. );
  54. void SETextInput_free(SETextInput *const ti);
  55. void SETextInput_scale_set(SETextInput *const ti, const vec2 dims);
  56. void SETextInput_pos_set(SETextInput *const ti, const vec2 pos);
  57. void SETextInput_color_set(SETextInput *const ti, const vec3 color);
  58. void SETextInput_bg_color_set(SETextInput *const ti, const vec4 color);
  59. SCDString *SETextInput_string_get_ref(SETextInput *const ti);
  60. void SETextInput_deactivate();
  61. void SETextInput_activate(SETextInput *const ti);
  62. void SETextInput_bbox_get(
  63. const SETextInput *const ti,
  64. float *const left,
  65. float *const top,
  66. float *const right,
  67. float *const bottom
  68. );
  69. void SETextInput_bbox_get_v(const SETextInput *const ti, vec4 bbox);
  70. SEResult SETextInput_text_copy(const SETextInput *const ti, SCDString *const dst);
  71. const char *SETextInput_c_str(const SETextInput *const ti);
  72. SEResult SETextInput_char_insert_at_cursor(SETextInput *const ti, const char ch);
  73. void SETextInput_char_remove_at_cursor(SETextInput *const ti);
  74. bool SETextInput_is_pos_inside(const SETextInput *const ti, const float x, const float y);
  75. void SETextInput_render_2d(SETextInput *const ti);
  76. void SETextInput_render_multiple_2d(SETextInput *const *const tis, const size_t ti_count);
  77. #endif // SCUFENG_TEXT_H_