cui.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. *** :: UI ::
  3. ***
  4. *** Interface to create and manager UI data.
  5. ***
  6. *** Acts much like the entity manager.
  7. *** UI elements can be created, destroyed and
  8. *** accessed from anywhere in the engine.
  9. ***
  10. **/
  11. #ifndef cui_h
  12. #define cui_h
  13. #include "ui/ui_style.h"
  14. #include "cengine.h"
  15. typedef void ui_elem;
  16. void ui_init(void);
  17. void ui_finish(void);
  18. void ui_set_style(ui_style* s);
  19. /* Pass Event, Update, and Render whole UI */
  20. void ui_event(SDL_Event e);
  21. void ui_update(void);
  22. void ui_render(void);
  23. /* Register new UI type */
  24. #define ui_handler(type, new, delete, event, update, render) \
  25. ui_handler_cast(typeid(type), \
  26. (ui_elem*(*)())new, \
  27. (void(*)(ui_elem*))delete, \
  28. (void(*)(ui_elem*,SDL_Event))event, \
  29. (void(*)(ui_elem*))update, \
  30. (void(*)(ui_elem*))render)
  31. void ui_handler_cast(int type_id,
  32. void* (*ui_elem_new_func)(),
  33. void (*ui_elem_del_func)(ui_elem*),
  34. void (*ui_elem_event_func)(ui_elem*, SDL_Event),
  35. void (*ui_elem_update_func)(ui_elem*),
  36. void (*ui_elem_render_func)(ui_elem*));
  37. /* Create, add and get UI elements */
  38. #define ui_elem_new(fmt, type, ...) (type*)ui_elem_new_type_id(fmt, typeid(type), ##__VA_ARGS__)
  39. #define ui_elem_get_as(fmt, type, ...) ((type*)ui_elem_get_as_type_id(fmt, typeid(type), ##__VA_ARGS__))
  40. bool ui_elem_exists(char* fmt, ...);
  41. ui_elem* ui_elem_get(char* fmt, ...);
  42. ui_elem* ui_elem_get_as_type_id(char* fmt, int type_id, ...);
  43. ui_elem* ui_elem_new_type_id(char* fmt, int type_id, ...);
  44. void ui_elem_delete(char* fmt, ...);
  45. void ui_elem_event(char* fmt, SDL_Event e, ...);
  46. void ui_elem_update(char* fmt, ...);
  47. void ui_elem_render(char* fmt, ...);
  48. /* Get UI element name or type name */
  49. char* ui_elem_name(ui_elem* e);
  50. char* ui_elem_typename(ui_elem* e);
  51. #endif