scene_manager.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #include <stdint.h>
  6. #include <stdbool.h>
  7. /** Scene Manager events type
  8. */
  9. typedef enum {
  10. SceneManagerEventTypeCustom,
  11. SceneManagerEventTypeNavigation,
  12. SceneManagerEventTypeTick,
  13. } SceneManagerEventType;
  14. /** Scene Manager event
  15. */
  16. typedef struct {
  17. SceneManagerEventType type;
  18. uint32_t event;
  19. } SceneManagerEvent;
  20. /** Prototype for Scene on_enter handler */
  21. typedef void (*AppSceneOnEnterCallback)(void* context);
  22. /** Prototype for Scene on_event handler */
  23. typedef bool (*AppSceneOnEventCallback)(void* context, SceneManagerEvent event);
  24. /** Prototype for Scene on_exit handler */
  25. typedef void (*AppSceneOnExitCallback)(void* context);
  26. /** Scene Manager configuration structure
  27. * Contains array of Scene handlers
  28. */
  29. typedef struct {
  30. const AppSceneOnEnterCallback* on_enter_handlers;
  31. const AppSceneOnEventCallback* on_event_handlers;
  32. const AppSceneOnExitCallback* on_exit_handlers;
  33. const uint32_t scene_num;
  34. } SceneManagerHandlers;
  35. typedef struct SceneManager SceneManager;
  36. /** Set Scene state
  37. * @param scene_manager SceneManager instance
  38. * @param scene_id Scene ID
  39. * @param state Scene new state
  40. */
  41. void scene_manager_set_scene_state(SceneManager* scene_manager, uint32_t scene_id, uint32_t state);
  42. /** Get Scene state
  43. * @param scene_manager SceneManager instance
  44. * @param scene_id Scene ID
  45. * @return Scene state
  46. */
  47. uint32_t scene_manager_get_scene_state(SceneManager* scene_manager, uint32_t scene_id);
  48. /** Scene Manager allocation and configuration
  49. * Scene Manager allocates all scenes internally
  50. * @param app_scene_handlers SceneManagerHandlers instance
  51. * @param context context to be set on Scene handlers calls
  52. * @return SceneManager instance
  53. */
  54. SceneManager* scene_manager_alloc(const SceneManagerHandlers* app_scene_handlers, void* context);
  55. /** Free Scene Manager with allocated Scenes
  56. * @param scene_manager SceneManager instance
  57. */
  58. void scene_manager_free(SceneManager* scene_manager);
  59. /** Custom event handler
  60. * Calls Scene event handler with Custom event parameter
  61. * @param scene_manager SceneManager instance
  62. * @param custom_event Custom event code
  63. * @return true if event was consumed, false otherwise
  64. */
  65. bool scene_manager_handle_custom_event(SceneManager* scene_manager, uint32_t custom_event);
  66. /** Navigation event handler
  67. * Calls Scene event handler with Navigation event parameter
  68. * @param scene_manager SceneManager instance
  69. * @return true if event was consumed, false otherwise
  70. */
  71. bool scene_manager_handle_navigation_event(SceneManager* scene_manager);
  72. /** Tick event handler
  73. * Calls Scene event handler with Tick event parameter
  74. * @param scene_manager SceneManager instance
  75. * @return true if event was consumed, false otherwise
  76. */
  77. void scene_manager_handle_tick_event(SceneManager* scene_manager);
  78. /** Add and run next Scene
  79. * @param scene_manager SceneManager instance
  80. * @param next_scene_id next Scene ID
  81. */
  82. void scene_manager_next_scene(SceneManager* scene_manager, uint32_t next_scene_id);
  83. /** Run previous Scene
  84. * @param scene_manager SceneManager instance
  85. * @return true if previous scene was found, false otherwise
  86. */
  87. bool scene_manager_previous_scene(SceneManager* scene_manager);
  88. /** Search previous Scene by ID
  89. * @param scene_manager SceneManager instance
  90. * @param scene_id Scene ID
  91. * @return true if previous scene was found, false otherwise
  92. */
  93. bool scene_manager_search_previous_scene(SceneManager* scene_manager, uint32_t scene_id);
  94. #ifdef __cplusplus
  95. }
  96. #endif