lv_anim.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * @file anim.h
  3. *
  4. */
  5. #ifndef ANIM_H
  6. #define ANIM_H
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /*********************
  11. * INCLUDES
  12. *********************/
  13. #include "../../lv_conf.h"
  14. #if USE_LV_ANIMATION
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. /*********************
  18. * DEFINES
  19. *********************/
  20. /**********************
  21. * TYPEDEFS
  22. **********************/
  23. struct _lv_anim_t;
  24. typedef int32_t(*lv_anim_path_t)(const struct _lv_anim_t*);
  25. typedef void (*lv_anim_fp_t)(void *, int32_t);
  26. typedef void (*lv_anim_cb_t)(void *);
  27. typedef struct _lv_anim_t
  28. {
  29. void * var; /*Variable to animate*/
  30. lv_anim_fp_t fp; /*Animator function*/
  31. lv_anim_cb_t end_cb; /*Call it when the animation is ready*/
  32. lv_anim_path_t path; /*An array with the steps of animations*/
  33. int32_t start; /*Start value*/
  34. int32_t end; /*End value*/
  35. uint16_t time; /*Animation time in ms*/
  36. int16_t act_time; /*Current time in animation. Set to negative to make delay.*/
  37. uint16_t playback_pause; /*Wait before play back*/
  38. uint16_t repeat_pause; /*Wait before repeat*/
  39. uint8_t playback :1; /*When the animation is ready play it back*/
  40. uint8_t repeat :1; /*Repeat the animation infinitely*/
  41. /*Animation system use these - user shouldn't set*/
  42. uint8_t playback_now :1; /*Play back is in progress*/
  43. }lv_anim_t;
  44. /*Example initialization
  45. lv_anim_t a;
  46. a.var = obj;
  47. a.start = lv_obj_get_height(obj);
  48. a.end = new_height;
  49. a.fp = (lv_anim_fp_t)lv_obj_set_height;
  50. a.path = lv_anim_path_linear;
  51. a.end_cb = NULL;
  52. a.act_time = 0;
  53. a.time = 200;
  54. a.playback = 0;
  55. a.playback_pause = 0;
  56. a.repeat = 0;
  57. a.repeat_pause = 0;
  58. */
  59. /**********************
  60. * GLOBAL PROTOTYPES
  61. **********************/
  62. /**
  63. * Init. the animation module
  64. */
  65. void lv_anim_init(void);
  66. /**
  67. * Create an animation
  68. * @param anim_p an initialized 'anim_t' variable. Not required after call.
  69. */
  70. void lv_anim_create(lv_anim_t * anim_p);
  71. /**
  72. * Delete an animation for a variable with a given animatior function
  73. * @param var pointer to variable
  74. * @param fp a function pointer which is animating 'var',
  75. * or NULL to ignore it and delete all animation with 'var
  76. * @return true: at least 1 animation is deleted, false: no animation is deleted
  77. */
  78. bool lv_anim_del(void * var, lv_anim_fp_t fp);
  79. /**
  80. * Calculate the time of an animation with a given speed and the start and end values
  81. * @param speed speed of animation in unit/sec
  82. * @param start start value of the animation
  83. * @param end end value of the animation
  84. * @return the required time [ms] for the animation with the given parameters
  85. */
  86. uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end);
  87. /**
  88. * Calculate the current value of an animation applying linear characteristic
  89. * @param a pointer to an animation
  90. * @return the current value to set
  91. */
  92. int32_t lv_anim_path_linear(const lv_anim_t *a);
  93. /**
  94. * Calculate the current value of an animation applying step characteristic.
  95. * (Set end value on the end of the animation)
  96. * @param a pointer to an animation
  97. * @return the current value to set
  98. */
  99. int32_t lv_anim_path_step(const lv_anim_t *a);
  100. /**********************
  101. * MACROS
  102. **********************/
  103. #endif /*USE_LV_ANIMATION == 0*/
  104. #ifdef __cplusplus
  105. } /* extern "C" */
  106. #endif
  107. #endif /*LV_ANIM_H*/