1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/src/lv_misc/lv_anim.h

192 lines
5.1 KiB
C
Raw Normal View History

2017-11-23 20:42:14 +01:00
/**
* @file anim.h
*
*/
#ifndef ANIM_H
#define ANIM_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lv_conf.h"
#else
2019-03-17 08:33:03 +01:00
#include "../../../lv_conf.h"
#endif
#if LV_USE_ANIMATION
2017-11-27 17:48:54 +01:00
2017-11-23 20:42:14 +01:00
#include <stdint.h>
#include <stdbool.h>
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
2017-12-17 01:54:09 +01:00
struct _lv_anim_t;
2017-11-23 20:42:14 +01:00
2019-04-22 08:45:07 +02:00
/*Generic prototype of "animator" functions*/
typedef void (*lv_anim_exec_cb_t)(void *, int32_t);
2017-11-23 20:42:14 +01:00
2019-04-22 08:45:07 +02:00
/*Get the current value in an animation*/
typedef int32_t (*lv_anim_path_cb_t)(const struct _lv_anim_t *);
/*Callback for animation ready*/
typedef void (*lv_anim_ready_cb_t)(struct _lv_anim_t *);
2017-11-23 20:42:14 +01:00
2017-12-17 01:54:09 +01:00
typedef struct _lv_anim_t
2017-11-23 20:42:14 +01:00
{
2019-04-04 07:15:40 +02:00
void * var; /*Variable to animate*/
2019-04-22 08:45:07 +02:00
lv_anim_exec_cb_t exec_cb; /*Function to execute to animate*/
lv_anim_path_cb_t path_cb; /*An array with the steps of animations*/
lv_anim_ready_cb_t ready_cb; /*Call it when the animation is ready*/
2019-04-04 07:15:40 +02:00
int32_t start; /*Start value*/
int32_t end; /*End value*/
uint16_t time; /*Animation time in ms*/
int16_t act_time; /*Current time in animation. Set to negative to make delay.*/
uint16_t playback_pause; /*Wait before play back*/
uint16_t repeat_pause; /*Wait before repeat*/
2019-04-22 08:45:07 +02:00
#if LV_USE_USER_DATA_SINGLE
lv_anim_user_data_t user_data; /*Custom user data*/
#endif
#if LV_USE_USER_DATA_MULTI
lv_anim_user_data_t exec_user_data;
lv_anim_user_data_t path_user_data;
lv_anim_user_data_t ready_user_data;
#endif
2019-04-04 07:15:40 +02:00
uint8_t playback : 1; /*When the animation is ready play it back*/
uint8_t repeat : 1; /*Repeat the animation infinitely*/
2018-06-19 09:49:58 +02:00
/*Animation system use these - user shouldn't set*/
2019-04-04 07:15:40 +02:00
uint8_t playback_now : 1; /*Play back is in progress*/
uint32_t has_run : 1; /*Indicates the animation has run it this round*/
2018-06-19 09:49:58 +02:00
} lv_anim_t;
2017-11-23 20:42:14 +01:00
/*Example initialization
2017-11-23 21:28:36 +01:00
lv_anim_t a;
2017-11-23 20:42:14 +01:00
a.var = obj;
a.start = lv_obj_get_height(obj);
a.end = new_height;
2019-04-22 08:45:07 +02:00
a.exec_cb = (lv_anim_fp_t)lv_obj_set_height;
a.path_cb = lv_anim_path_linear;
a.ready_cb = NULL;
2017-11-23 20:42:14 +01:00
a.act_time = 0;
a.time = 200;
a.playback = 0;
a.playback_pause = 0;
a.repeat = 0;
a.repeat_pause = 0;
2019-04-22 08:45:07 +02:00
a.user_data = NULL;
2018-09-13 22:11:01 +02:00
lv_anim_create(&a);
2017-11-23 20:42:14 +01:00
*/
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Init. the animation module
*/
2017-11-23 21:28:36 +01:00
void lv_anim_init(void);
2017-11-23 20:42:14 +01:00
/**
* Create an animation
* @param anim_p an initialized 'anim_t' variable. Not required after call.
*/
2017-11-23 21:28:36 +01:00
void lv_anim_create(lv_anim_t * anim_p);
2017-11-23 20:42:14 +01:00
/**
* Delete an animation for a variable with a given animatior function
* @param var pointer to variable
* @param fp a function pointer which is animating 'var',
* or NULL to ignore it and delete all animation with 'var
* @return true: at least 1 animation is deleted, false: no animation is deleted
*/
2019-04-22 08:45:07 +02:00
bool lv_anim_del(void * var, lv_anim_exec_cb_t fp);
2017-11-23 20:42:14 +01:00
2018-11-09 12:36:38 +01:00
/**
* Get the number of currently running animations
* @return the number of running animations
*/
uint16_t lv_anim_count_running(void);
2017-11-23 20:42:14 +01:00
/**
* Calculate the time of an animation with a given speed and the start and end values
* @param speed speed of animation in unit/sec
* @param start start value of the animation
* @param end end value of the animation
* @return the required time [ms] for the animation with the given parameters
*/
2017-11-23 21:28:36 +01:00
uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end);
2017-11-23 20:42:14 +01:00
/**
2017-12-17 01:54:09 +01:00
* Calculate the current value of an animation applying linear characteristic
* @param a pointer to an animation
* @return the current value to set
2017-11-23 20:42:14 +01:00
*/
2019-04-04 07:15:40 +02:00
int32_t lv_anim_path_linear(const lv_anim_t * a);
2017-11-23 20:42:14 +01:00
2019-01-22 15:50:00 +01:00
/**
* Calculate the current value of an animation slowing down the start phase
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_in(const lv_anim_t * a);
/**
* Calculate the current value of an animation slowing down the end phase
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_ease_out(const lv_anim_t * a);
2018-06-09 08:45:38 +02:00
/**
* Calculate the current value of an animation applying an "S" characteristic (cosine)
* @param a pointer to an animation
* @return the current value to set
*/
2019-04-04 07:15:40 +02:00
int32_t lv_anim_path_ease_in_out(const lv_anim_t * a);
2018-06-09 08:45:38 +02:00
2018-11-20 14:49:16 +01:00
/**
* Calculate the current value of an animation with overshoot at the end
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_overshoot(const lv_anim_t * a);
2018-11-24 07:38:07 +01:00
/**
* Calculate the current value of an animation with 3 bounces
* @param a pointer to an animation
* @return the current value to set
*/
int32_t lv_anim_path_bounce(const lv_anim_t * a);
2017-12-17 01:54:09 +01:00
/**
* Calculate the current value of an animation applying step characteristic.
* (Set end value on the end of the animation)
* @param a pointer to an animation
* @return the current value to set
*/
2019-04-04 07:15:40 +02:00
int32_t lv_anim_path_step(const lv_anim_t * a);
2019-04-22 08:45:07 +02:00
2017-11-23 20:42:14 +01:00
/**********************
* MACROS
**********************/
#endif /*LV_USE_ANIMATION == 0*/
2017-11-27 17:48:54 +01:00
2017-11-23 20:42:14 +01:00
#ifdef __cplusplus
} /* extern "C" */
#endif
2017-11-27 17:48:54 +01:00
#endif /*LV_ANIM_H*/