forked from Guillem96/argon-nx
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
97 changed files
with
34,811 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
/** | ||
* @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 | ||
#include "../../lv_conf.h" | ||
#endif | ||
|
||
#if USE_LV_ANIMATION | ||
|
||
#include <stdint.h> | ||
|
||
/********************* | ||
* DEFINES | ||
*********************/ | ||
|
||
/********************** | ||
* TYPEDEFS | ||
**********************/ | ||
|
||
struct _lv_anim_t; | ||
|
||
typedef int32_t(*lv_anim_path_t)(const struct _lv_anim_t*); | ||
|
||
typedef void (*lv_anim_fp_t)(void *, int32_t); | ||
typedef void (*lv_anim_cb_t)(void *); | ||
|
||
typedef struct _lv_anim_t | ||
{ | ||
void * var; /*Variable to animate*/ | ||
lv_anim_fp_t fp; /*Animator function*/ | ||
lv_anim_cb_t end_cb; /*Call it when the animation is ready*/ | ||
lv_anim_path_t path; /*An array with the steps of animations*/ | ||
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*/ | ||
uint8_t playback :1; /*When the animation is ready play it back*/ | ||
uint8_t repeat :1; /*Repeat the animation infinitely*/ | ||
/*Animation system use these - user shouldn't set*/ | ||
uint8_t playback_now :1; /*Play back is in progress*/ | ||
uint32_t has_run :1; /*Indicates the animation has run it this round*/ | ||
} lv_anim_t; | ||
|
||
/*Example initialization | ||
lv_anim_t a; | ||
a.var = obj; | ||
a.start = lv_obj_get_height(obj); | ||
a.end = new_height; | ||
a.fp = (lv_anim_fp_t)lv_obj_set_height; | ||
a.path = lv_anim_path_linear; | ||
a.end_cb = NULL; | ||
a.act_time = 0; | ||
a.time = 200; | ||
a.playback = 0; | ||
a.playback_pause = 0; | ||
a.repeat = 0; | ||
a.repeat_pause = 0; | ||
lv_anim_create(&a); | ||
*/ | ||
/********************** | ||
* GLOBAL PROTOTYPES | ||
**********************/ | ||
|
||
/** | ||
* Init. the animation module | ||
*/ | ||
void lv_anim_init(void); | ||
|
||
/** | ||
* Create an animation | ||
* @param anim_p an initialized 'anim_t' variable. Not required after call. | ||
*/ | ||
void lv_anim_create(lv_anim_t * anim_p); | ||
|
||
/** | ||
* 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 | ||
*/ | ||
bool lv_anim_del(void * var, lv_anim_fp_t fp); | ||
|
||
/** | ||
* Get the number of currently running animations | ||
* @return the number of running animations | ||
*/ | ||
uint16_t lv_anim_count_running(void); | ||
|
||
/** | ||
* 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 | ||
*/ | ||
uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end); | ||
|
||
/** | ||
* Calculate the current value of an animation applying linear characteristic | ||
* @param a pointer to an animation | ||
* @return the current value to set | ||
*/ | ||
int32_t lv_anim_path_linear(const lv_anim_t *a); | ||
|
||
/** | ||
* 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); | ||
|
||
/** | ||
* Calculate the current value of an animation applying an "S" characteristic (cosine) | ||
* @param a pointer to an animation | ||
* @return the current value to set | ||
*/ | ||
int32_t lv_anim_path_ease_in_out(const lv_anim_t *a); | ||
|
||
/** | ||
* 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); | ||
|
||
/** | ||
* 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); | ||
|
||
/** | ||
* 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 | ||
*/ | ||
int32_t lv_anim_path_step(const lv_anim_t *a); | ||
/********************** | ||
* MACROS | ||
**********************/ | ||
|
||
#endif /*USE_LV_ANIMATION == 0*/ | ||
|
||
#ifdef __cplusplus | ||
} /* extern "C" */ | ||
#endif | ||
|
||
#endif /*LV_ANIM_H*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
/** | ||
* @file lv_area.c | ||
* | ||
*/ | ||
|
||
/********************* | ||
* INCLUDES | ||
*********************/ | ||
#include "lv_area.h" | ||
#include "lv_math.h" | ||
|
||
/********************* | ||
* DEFINES | ||
*********************/ | ||
|
||
/********************** | ||
* TYPEDEFS | ||
**********************/ | ||
|
||
/********************** | ||
* STATIC PROTOTYPES | ||
**********************/ | ||
|
||
/********************** | ||
* STATIC VARIABLES | ||
**********************/ | ||
|
||
/********************** | ||
* MACROS | ||
**********************/ | ||
|
||
/********************** | ||
* GLOBAL FUNCTIONS | ||
**********************/ | ||
|
||
/** | ||
* Initialize an area | ||
* @param area_p pointer to an area | ||
* @param x1 left coordinate of the area | ||
* @param y1 top coordinate of the area | ||
* @param x2 right coordinate of the area | ||
* @param y2 bottom coordinate of the area | ||
*/ | ||
void lv_area_set(lv_area_t * area_p, lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2) | ||
{ | ||
area_p->x1 = x1; | ||
area_p->y1 = y1; | ||
area_p->x2 = x2; | ||
area_p->y2 = y2; | ||
} | ||
|
||
/** | ||
* Set the width of an area | ||
* @param area_p pointer to an area | ||
* @param w the new width of the area (w == 1 makes x1 == x2) | ||
*/ | ||
void lv_area_set_width(lv_area_t * area_p, lv_coord_t w) | ||
{ | ||
area_p->x2 = area_p->x1 + w - 1; | ||
} | ||
|
||
/** | ||
* Set the height of an area | ||
* @param area_p pointer to an area | ||
* @param h the new height of the area (h == 1 makes y1 == y2) | ||
*/ | ||
void lv_area_set_height(lv_area_t * area_p, lv_coord_t h) | ||
{ | ||
area_p->y2 = area_p->y1 + h - 1; | ||
} | ||
|
||
/** | ||
* Set the position of an area (width and height will be kept) | ||
* @param area_p pointer to an area | ||
* @param x the new x coordinate of the area | ||
* @param y the new y coordinate of the area | ||
*/ | ||
void lv_area_set_pos(lv_area_t * area_p, lv_coord_t x, lv_coord_t y) | ||
{ | ||
lv_coord_t w = lv_area_get_width(area_p); | ||
lv_coord_t h = lv_area_get_height(area_p); | ||
area_p->x1 = x; | ||
area_p->y1 = y; | ||
lv_area_set_width(area_p, w); | ||
lv_area_set_height(area_p, h); | ||
} | ||
|
||
/** | ||
* Return with area of an area (x * y) | ||
* @param area_p pointer to an area | ||
* @return size of area | ||
*/ | ||
uint32_t lv_area_get_size(const lv_area_t * area_p) | ||
{ | ||
uint32_t size; | ||
|
||
size = (uint32_t)(area_p->x2 - area_p->x1 + 1) * | ||
(area_p->y2 - area_p->y1 + 1); | ||
|
||
return size; | ||
} | ||
|
||
/** | ||
* Get the common parts of two areas | ||
* @param res_p pointer to an area, the result will be stored here | ||
* @param a1_p pointer to the first area | ||
* @param a2_p pointer to the second area | ||
* @return false: the two area has NO common parts, res_p is invalid | ||
*/ | ||
bool lv_area_intersect(lv_area_t * res_p, const lv_area_t * a1_p, const lv_area_t * a2_p) | ||
{ | ||
/* Get the smaller area from 'a1_p' and 'a2_p' */ | ||
res_p->x1 = LV_MATH_MAX(a1_p->x1, a2_p->x1); | ||
res_p->y1 = LV_MATH_MAX(a1_p->y1, a2_p->y1); | ||
res_p->x2 = LV_MATH_MIN(a1_p->x2, a2_p->x2); | ||
res_p->y2 = LV_MATH_MIN(a1_p->y2, a2_p->y2); | ||
|
||
/*If x1 or y1 greater then x2 or y2 then the areas union is empty*/ | ||
bool union_ok = true; | ||
if((res_p->x1 > res_p->x2) || | ||
(res_p->y1 > res_p->y2)) { | ||
union_ok = false; | ||
} | ||
|
||
return union_ok; | ||
} | ||
/** | ||
* Join two areas into a third which involves the other two | ||
* @param res_p pointer to an area, the result will be stored here | ||
* @param a1_p pointer to the first area | ||
* @param a2_p pointer to the second area | ||
*/ | ||
void lv_area_join(lv_area_t * a_res_p, const lv_area_t * a1_p, const lv_area_t * a2_p) | ||
{ | ||
a_res_p->x1 = LV_MATH_MIN(a1_p->x1, a2_p->x1); | ||
a_res_p->y1 = LV_MATH_MIN(a1_p->y1, a2_p->y1); | ||
a_res_p->x2 = LV_MATH_MAX(a1_p->x2, a2_p->x2); | ||
a_res_p->y2 = LV_MATH_MAX(a1_p->y2, a2_p->y2); | ||
} | ||
|
||
/** | ||
* Check if a point is on an area | ||
* @param a_p pointer to an area | ||
* @param p_p pointer to a point | ||
* @return false:the point is out of the area | ||
*/ | ||
bool lv_area_is_point_on(const lv_area_t * a_p, const lv_point_t * p_p) | ||
{ | ||
bool is_on = false; | ||
|
||
if((p_p->x >= a_p->x1 && p_p->x <= a_p->x2) && | ||
((p_p->y >= a_p->y1 && p_p->y <= a_p->y2))) { | ||
is_on = true; | ||
} | ||
|
||
return is_on; | ||
} | ||
|
||
/** | ||
* Check if two area has common parts | ||
* @param a1_p pointer to an area. | ||
* @param a2_p pointer to an other area | ||
* @return false: a1_p and a2_p has no common parts | ||
*/ | ||
bool lv_area_is_on(const lv_area_t * a1_p, const lv_area_t * a2_p) | ||
{ | ||
if((a1_p->x1 <= a2_p->x2) && | ||
(a1_p->x2 >= a2_p->x1) && | ||
(a1_p->y1 <= a2_p->y2) && | ||
(a1_p->y2 >= a2_p->y1)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Check if an area is fully on an other | ||
* @param ain_p pointer to an area which could be in 'aholder_p' | ||
* @param aholder pointer to an area which could involve 'ain_p' | ||
* @return | ||
*/ | ||
bool lv_area_is_in(const lv_area_t * ain_p, const lv_area_t * aholder_p) | ||
{ | ||
bool is_in = false; | ||
|
||
if(ain_p->x1 >= aholder_p->x1 && | ||
ain_p->y1 >= aholder_p->y1 && | ||
ain_p->x2 <= aholder_p->x2 && | ||
ain_p->y2 <= aholder_p->y2) { | ||
is_in = true; | ||
} | ||
|
||
return is_in; | ||
} | ||
|
||
/********************** | ||
* STATIC FUNCTIONS | ||
**********************/ |
Oops, something went wrong.