ui_text.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. *** :: UI Text ::
  3. ***
  4. *** A text object in the UI.
  5. ***
  6. *** To change text properties access the struct
  7. *** Then call "ui_text_draw" to redraw the text
  8. *** vertex buffer.
  9. ***
  10. **/
  11. #ifndef ui_text_h
  12. #define ui_text_h
  13. #include "cengine.h"
  14. #include "casset.h"
  15. enum {
  16. TEXT_ALIGN_LEFT = 0,
  17. TEXT_ALIGN_RIGHT = 1,
  18. TEXT_ALIGN_CENTER = 2,
  19. };
  20. enum {
  21. TEXT_ALIGN_TOP = 0,
  22. TEXT_ALIGN_BOTTOM = 1,
  23. };
  24. typedef struct {
  25. /* private */
  26. char* string;
  27. GLuint positions_buffer;
  28. GLuint texcoords_buffer;
  29. GLuint colors_buffer;
  30. int num_positions;
  31. int num_texcoords;
  32. vec2 top_left;
  33. vec2 bottom_right;
  34. /* public */
  35. asset_hndl font;
  36. vec2 position;
  37. vec2 scale;
  38. vec4 color;
  39. int halign;
  40. int valign;
  41. float line_spacing;
  42. float char_spacing;
  43. float rotation;
  44. float line_length;
  45. bool active;
  46. } ui_text;
  47. ui_text* ui_text_new();
  48. ui_text* ui_text_new_string(char* string);
  49. void ui_text_delete(ui_text* text);
  50. void ui_text_move(ui_text* text, vec2 pos);
  51. void ui_text_set_font(ui_text* text, asset_hndl font);
  52. void ui_text_set_color(ui_text* text, vec4 color);
  53. void ui_text_set_scale(ui_text* text, vec2 scale);
  54. void ui_text_align(ui_text* text, int halign, int valign);
  55. void ui_text_draw(ui_text* text);
  56. void ui_text_draw_string(ui_text* text, char* string);
  57. void ui_text_event(ui_text* text, SDL_Event e);
  58. void ui_text_update(ui_text* text);
  59. void ui_text_render(ui_text* text);
  60. bool ui_text_contains_point(ui_text* text, vec2 position);
  61. #endif