animation_manager.h 4.3 KB

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