animation_manager.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #pragma once
  2. #include "dolphin/dolphin.h"
  3. #include <gui/view.h>
  4. #include <stdint.h>
  5. typedef struct AnimationManager AnimationManager;
  6. typedef struct {
  7. uint8_t x;
  8. uint8_t y;
  9. const char* str;
  10. Align horizontal;
  11. Align vertical;
  12. } Bubble;
  13. typedef struct FrameBubble {
  14. Bubble bubble;
  15. uint8_t starts_at_frame;
  16. uint8_t ends_at_frame;
  17. struct FrameBubble* next_bubble;
  18. } FrameBubble;
  19. typedef struct {
  20. FrameBubble** frame_bubbles;
  21. uint8_t frame_bubbles_count;
  22. const Icon** icons;
  23. uint8_t passive_frames;
  24. uint8_t active_frames;
  25. uint8_t active_cycles;
  26. uint8_t frame_rate;
  27. uint16_t duration;
  28. uint16_t active_cooldown;
  29. } BubbleAnimation;
  30. typedef void (*AnimationManagerSetNewIdleAnimationCallback)(void* context);
  31. typedef void (*AnimationManagerCheckBlockingCallback)(void* context);
  32. typedef void (*AnimationManagerInteractCallback)(void*);
  33. /**
  34. * Allocate Animation Manager
  35. *
  36. * @return animation manager instance
  37. */
  38. AnimationManager* animation_manager_alloc(void);
  39. /**
  40. * Free Animation Manager
  41. *
  42. * @animation_manager instance
  43. */
  44. void animation_manager_free(AnimationManager* animation_manager);
  45. /**
  46. * Get View of Animation Manager
  47. *
  48. * @animation_manager instance
  49. * @return view
  50. */
  51. View* animation_manager_get_animation_view(AnimationManager* animation_manager);
  52. /**
  53. * Set context for all callbacks for Animation Manager
  54. *
  55. * @animation_manager instance
  56. * @context context
  57. */
  58. void animation_manager_set_context(AnimationManager* animation_manager, void* context);
  59. /**
  60. * Set callback for Animation Manager for defered calls
  61. * for animation_manager_new_idle_process().
  62. * Animation Manager doesn't have it's own thread, so main thread gives
  63. * callbacks to A.M. to call when it should perform some inner manipulations.
  64. * This callback is called from other threads and should notify main thread
  65. * when to call animation_manager_new_idle_process().
  66. * So scheme is this:
  67. * A.M. sets callbacks,
  68. * callbacks notifies main thread
  69. * main thread in its own context calls appropriate *_process() function.
  70. *
  71. * @animation_manager instance
  72. * @callback callback
  73. */
  74. void animation_manager_set_new_idle_callback(
  75. AnimationManager* animation_manager,
  76. AnimationManagerSetNewIdleAnimationCallback callback);
  77. /**
  78. * Function to call in main thread as a response to
  79. * set_new_idle_callback's call.
  80. *
  81. * @animation_manager instance
  82. */
  83. void animation_manager_new_idle_process(AnimationManager* animation_manager);
  84. /**
  85. * Set callback for Animation Manager for defered calls
  86. * for animation_manager_check_blocking_process().
  87. *
  88. * @animation_manager instance
  89. * @callback callback
  90. */
  91. void animation_manager_set_check_callback(
  92. AnimationManager* animation_manager,
  93. AnimationManagerCheckBlockingCallback callback);
  94. /**
  95. * Function to call in main thread as a response to
  96. * set_new_idle_callback's call.
  97. *
  98. * @animation_manager instance
  99. */
  100. void animation_manager_check_blocking_process(AnimationManager* animation_manager);
  101. /**
  102. * Set callback for Animation Manager for defered calls
  103. * for animation_manager_interact_process().
  104. *
  105. * @animation_manager instance
  106. * @callback callback
  107. */
  108. void animation_manager_set_interact_callback(
  109. AnimationManager* animation_manager,
  110. AnimationManagerInteractCallback callback);
  111. /**
  112. * Function to call in main thread as a response to
  113. * set_new_idle_callback's call.
  114. *
  115. * @animation_manager instance
  116. */
  117. void animation_manager_interact_process(AnimationManager* animation_manager);
  118. /**
  119. * Unload and Stall animation actions. Draw callback in view
  120. * paints first frame of current animation until
  121. * animation_manager_load_and_continue_animation() is called.
  122. * Can't be called multiple times. Every Stall has to be finished
  123. * with Continue.
  124. *
  125. * @animation_manager instance
  126. */
  127. void animation_manager_unload_and_stall_animation(AnimationManager* animation_manager);
  128. /**
  129. * Load and Contunue execution of animation manager.
  130. *
  131. * @animation_manager instance
  132. */
  133. void animation_manager_load_and_continue_animation(AnimationManager* animation_manager);