run astyle code formatter

This commit is contained in:
Gabor Kiss-Vamosi
2020-02-26 19:48:27 +01:00
parent 9d1a1d51d0
commit 41907f9f3c
149 changed files with 5105 additions and 4367 deletions

View File

@@ -77,7 +77,8 @@ static inline void lv_bar_set_sym(lv_obj_t * bar, bool en)
* @return true: symmetric is enabled; false: disable * @return true: symmetric is enabled; false: disable
* @deprecated As of v7.0, you should use `lv_bar_get_type` instead. * @deprecated As of v7.0, you should use `lv_bar_get_type` instead.
*/ */
static inline bool lv_bar_get_sym(lv_obj_t * bar) { static inline bool lv_bar_get_sym(lv_obj_t * bar)
{
return lv_bar_get_type(bar) == LV_BAR_TYPE_SYM; return lv_bar_get_type(bar) == LV_BAR_TYPE_SYM;
} }
@@ -103,7 +104,8 @@ static inline void lv_slider_set_sym(lv_obj_t * slider, bool en)
* @return true: symmetric is enabled; false: disable * @return true: symmetric is enabled; false: disable
* @deprecated As of v7.0, you should use `lv_slider_get_type` instead. * @deprecated As of v7.0, you should use `lv_slider_get_type` instead.
*/ */
static inline bool lv_slider_get_sym(lv_obj_t * slider) { static inline bool lv_slider_get_sym(lv_obj_t * slider)
{
return lv_bar_get_sym(slider); return lv_bar_get_sym(slider);
} }

View File

@@ -15,11 +15,11 @@
* DEFINES * DEFINES
*********************/ *********************/
#ifndef LV_DEBUG_STR_MAX_LENGTH #ifndef LV_DEBUG_STR_MAX_LENGTH
#define LV_DEBUG_STR_MAX_LENGTH (1024 * 8) #define LV_DEBUG_STR_MAX_LENGTH (1024 * 8)
#endif #endif
#ifndef LV_DEBUG_STR_MAX_REPEAT #ifndef LV_DEBUG_STR_MAX_REPEAT
#define LV_DEBUG_STR_MAX_REPEAT 8 #define LV_DEBUG_STR_MAX_REPEAT 8
#endif #endif
/********************** /**********************
* TYPEDEFS * TYPEDEFS
@@ -126,7 +126,8 @@ bool lv_debug_check_str(const void * str)
if(s[i] != last_byte) { if(s[i] != last_byte) {
last_byte = s[i]; last_byte = s[i];
rep = 1; rep = 1;
} else if(s[i] > 0x7F){ }
else if(s[i] > 0x7F) {
rep++; rep++;
if(rep > LV_DEBUG_STR_MAX_REPEAT) { if(rep > LV_DEBUG_STR_MAX_REPEAT) {
LV_LOG_WARN("lv_debug_check_str: a non-ASCII char has repeated more than LV_DEBUG_STR_MAX_REPEAT times)"); LV_LOG_WARN("lv_debug_check_str: a non-ASCII char has repeated more than LV_DEBUG_STR_MAX_REPEAT times)");
@@ -184,7 +185,8 @@ void lv_debug_log_error(const char * msg, uint64_t value)
*bufp = '\0'; *bufp = '\0';
LV_LOG_ERROR(buf); LV_LOG_ERROR(buf);
} else { }
else {
LV_LOG_ERROR(msg); LV_LOG_ERROR(msg);
} }
} }

View File

@@ -50,13 +50,13 @@ void lv_debug_log_error(const char * msg, uint64_t value);
#ifndef LV_DEBUG_ASSERT #ifndef LV_DEBUG_ASSERT
#define LV_DEBUG_ASSERT(expr, msg, value) \ #define LV_DEBUG_ASSERT(expr, msg, value) \
do { \ do { \
if(!(expr)) { \ if(!(expr)) { \
LV_LOG_ERROR(__func__); \ LV_LOG_ERROR(__func__); \
lv_debug_log_error(msg, (uint64_t)((uintptr_t)value)); \ lv_debug_log_error(msg, (uint64_t)((uintptr_t)value)); \
while(1); \ while(1); \
} \ } \
} while(0) } while(0)
#endif #endif
/*---------------- /*----------------

View File

@@ -14,7 +14,7 @@
#include "../lv_misc/lv_gc.h" #include "../lv_misc/lv_gc.h"
#if defined(LV_GC_INCLUDE) #if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE #include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
/********************* /*********************
@@ -93,8 +93,7 @@ void lv_group_del(lv_group_t * group)
/*Remove the objects from the group*/ /*Remove the objects from the group*/
lv_obj_t ** obj; lv_obj_t ** obj;
LV_LL_READ(group->obj_ll, obj) LV_LL_READ(group->obj_ll, obj) {
{
(*obj)->group_p = NULL; (*obj)->group_p = NULL;
} }
@@ -114,8 +113,7 @@ void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj)
/*Do not add the object twice*/ /*Do not add the object twice*/
lv_obj_t ** obj_i; lv_obj_t ** obj_i;
LV_LL_READ(group->obj_ll, obj_i) LV_LL_READ(group->obj_ll, obj_i) {
{
if((*obj_i) == obj) { if((*obj_i) == obj) {
LV_LOG_INFO("lv_group_add_obj: the object is already added to this group"); LV_LOG_INFO("lv_group_add_obj: the object is already added to this group");
return; return;
@@ -175,8 +173,7 @@ void lv_group_remove_obj(lv_obj_t * obj)
/*Search the object and remove it from its group */ /*Search the object and remove it from its group */
lv_obj_t ** i; lv_obj_t ** i;
LV_LL_READ(g->obj_ll, i) LV_LL_READ(g->obj_ll, i) {
{
if(*i == obj) { if(*i == obj) {
lv_ll_remove(&g->obj_ll, i); lv_ll_remove(&g->obj_ll, i);
lv_mem_free(i); lv_mem_free(i);
@@ -201,8 +198,7 @@ void lv_group_remove_all_objs(lv_group_t * group)
/*Remove the objects from the group*/ /*Remove the objects from the group*/
lv_obj_t ** obj; lv_obj_t ** obj;
LV_LL_READ(group->obj_ll, obj) LV_LL_READ(group->obj_ll, obj) {
{
(*obj)->group_p = NULL; (*obj)->group_p = NULL;
} }
@@ -227,8 +223,7 @@ void lv_group_focus_obj(lv_obj_t * obj)
lv_group_set_editing(g, false); lv_group_set_editing(g, false);
lv_obj_t ** i; lv_obj_t ** i;
LV_LL_READ(g->obj_ll, i) LV_LL_READ(g->obj_ll, i) {
{
if(*i == obj) { if(*i == obj) {
if(g->obj_focus != NULL) { if(g->obj_focus != NULL) {
(*g->obj_focus)->signal_cb(*g->obj_focus, LV_SIGNAL_DEFOCUS, NULL); (*g->obj_focus)->signal_cb(*g->obj_focus, LV_SIGNAL_DEFOCUS, NULL);
@@ -400,7 +395,8 @@ lv_style_t * lv_group_mod_style(lv_group_t * group, const lv_style_t * style)
if(group->editing) { if(group->editing) {
if(group->style_mod_edit_cb) group->style_mod_edit_cb(group, &group->style_tmp); if(group->style_mod_edit_cb) group->style_mod_edit_cb(group, &group->style_tmp);
} else { }
else {
if(group->style_mod_cb) group->style_mod_cb(group, &group->style_tmp); if(group->style_mod_cb) group->style_mod_cb(group, &group->style_tmp);
} }
return &group->style_tmp; return &group->style_tmp;
@@ -532,7 +528,8 @@ static void focus_next_core(lv_group_t * group, void * (*begin)(const lv_ll_t *)
obj_next = begin(&group->obj_ll); obj_next = begin(&group->obj_ll);
can_move = false; can_move = false;
can_begin = false; can_begin = false;
} else { }
else {
/*Currently focused object is the last/first in the group, keep it that way*/ /*Currently focused object is the last/first in the group, keep it that way*/
return; return;
} }

View File

@@ -51,8 +51,7 @@ typedef void (*lv_group_focus_cb_t)(struct _lv_group_t *);
* Groups can be used to logically hold objects so that they can be individually focused. * Groups can be used to logically hold objects so that they can be individually focused.
* They are NOT for laying out objects on a screen (try `lv_cont` for that). * They are NOT for laying out objects on a screen (try `lv_cont` for that).
*/ */
typedef struct _lv_group_t typedef struct _lv_group_t {
{
lv_ll_t obj_ll; /**< Linked list to store the objects in the group */ lv_ll_t obj_ll; /**< Linked list to store the objects in the group */
lv_obj_t ** obj_focus; /**< The object in focus*/ lv_obj_t ** obj_focus; /**< The object in focus*/

View File

@@ -21,7 +21,7 @@
*********************/ *********************/
#if LV_INDEV_DEF_DRAG_THROW <= 0 #if LV_INDEV_DEF_DRAG_THROW <= 0
#warning "LV_INDEV_DRAG_THROW must be greater than 0" #warning "LV_INDEV_DRAG_THROW must be greater than 0"
#endif #endif
/********************** /**********************
@@ -101,17 +101,21 @@ void lv_indev_read_task(lv_task_t * task)
/*Save the last activity time*/ /*Save the last activity time*/
if(indev_act->proc.state == LV_INDEV_STATE_PR) { if(indev_act->proc.state == LV_INDEV_STATE_PR) {
indev_act->driver.disp->last_activity_time = lv_tick_get(); indev_act->driver.disp->last_activity_time = lv_tick_get();
} else if(indev_act->driver.type == LV_INDEV_TYPE_ENCODER && data.enc_diff) { }
else if(indev_act->driver.type == LV_INDEV_TYPE_ENCODER && data.enc_diff) {
indev_act->driver.disp->last_activity_time = lv_tick_get(); indev_act->driver.disp->last_activity_time = lv_tick_get();
} }
if(indev_act->driver.type == LV_INDEV_TYPE_POINTER) { if(indev_act->driver.type == LV_INDEV_TYPE_POINTER) {
indev_pointer_proc(indev_act, &data); indev_pointer_proc(indev_act, &data);
} else if(indev_act->driver.type == LV_INDEV_TYPE_KEYPAD) { }
else if(indev_act->driver.type == LV_INDEV_TYPE_KEYPAD) {
indev_keypad_proc(indev_act, &data); indev_keypad_proc(indev_act, &data);
} else if(indev_act->driver.type == LV_INDEV_TYPE_ENCODER) { }
else if(indev_act->driver.type == LV_INDEV_TYPE_ENCODER) {
indev_encoder_proc(indev_act, &data); indev_encoder_proc(indev_act, &data);
} else if(indev_act->driver.type == LV_INDEV_TYPE_BUTTON) { }
else if(indev_act->driver.type == LV_INDEV_TYPE_BUTTON) {
indev_button_proc(indev_act, &data); indev_button_proc(indev_act, &data);
} }
/*Handle reset query if it happened in during processing*/ /*Handle reset query if it happened in during processing*/
@@ -159,7 +163,8 @@ void lv_indev_reset(lv_indev_t * indev, lv_obj_t * obj)
if(obj == NULL || indev->proc.types.pointer.last_pressed == obj) { if(obj == NULL || indev->proc.types.pointer.last_pressed == obj) {
indev->proc.types.pointer.last_pressed = NULL; indev->proc.types.pointer.last_pressed = NULL;
} }
} else { }
else {
lv_indev_t * i = lv_indev_get_next(NULL); lv_indev_t * i = lv_indev_get_next(NULL);
while(i) { while(i) {
i->proc.reset_query = 1; i->proc.reset_query = 1;
@@ -245,7 +250,8 @@ void lv_indev_get_point(const lv_indev_t * indev, lv_point_t * point)
if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) { if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) {
point->x = -1; point->x = -1;
point->y = -1; point->y = -1;
} else { }
else {
point->x = indev->proc.types.pointer.act_point.x; point->x = indev->proc.types.pointer.act_point.x;
point->y = indev->proc.types.pointer.act_point.y; point->y = indev->proc.types.pointer.act_point.y;
} }
@@ -304,7 +310,8 @@ void lv_indev_get_vect(const lv_indev_t * indev, lv_point_t * point)
if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) { if(indev->driver.type != LV_INDEV_TYPE_POINTER && indev->driver.type != LV_INDEV_TYPE_BUTTON) {
point->x = 0; point->x = 0;
point->y = 0; point->y = 0;
} else { }
else {
point->x = indev->proc.types.pointer.vect.x; point->x = indev->proc.types.pointer.vect.x;
point->y = indev->proc.types.pointer.vect.y; point->y = indev->proc.types.pointer.vect.y;
} }
@@ -396,7 +403,8 @@ static void indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data)
if(i->proc.state == LV_INDEV_STATE_PR) { if(i->proc.state == LV_INDEV_STATE_PR) {
indev_proc_press(&i->proc); indev_proc_press(&i->proc);
} else { }
else {
indev_proc_release(&i->proc); indev_proc_release(&i->proc);
} }
@@ -453,7 +461,8 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data)
if(indev_reset_check(&i->proc)) return; if(indev_reset_check(&i->proc)) return;
lv_event_send(indev_obj_act, LV_EVENT_PRESSED, NULL); lv_event_send(indev_obj_act, LV_EVENT_PRESSED, NULL);
if(indev_reset_check(&i->proc)) return; if(indev_reset_check(&i->proc)) return;
} else if(data->key == LV_KEY_ESC) { }
else if(data->key == LV_KEY_ESC) {
/*Send the ESC as a normal KEY*/ /*Send the ESC as a normal KEY*/
lv_group_send_data(g, LV_KEY_ESC); lv_group_send_data(g, LV_KEY_ESC);
@@ -589,7 +598,8 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data)
int32_t s; int32_t s;
if(data->enc_diff < 0) { if(data->enc_diff < 0) {
for(s = 0; s < -data->enc_diff; s++) lv_group_send_data(g, LV_KEY_LEFT); for(s = 0; s < -data->enc_diff; s++) lv_group_send_data(g, LV_KEY_LEFT);
} else if(data->enc_diff > 0) { }
else if(data->enc_diff > 0) {
for(s = 0; s < data->enc_diff; s++) lv_group_send_data(g, LV_KEY_RIGHT); for(s = 0; s < data->enc_diff; s++) lv_group_send_data(g, LV_KEY_RIGHT);
} }
} }
@@ -598,7 +608,8 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data)
int32_t s; int32_t s;
if(data->enc_diff < 0) { if(data->enc_diff < 0) {
for(s = 0; s < -data->enc_diff; s++) lv_group_focus_prev(g); for(s = 0; s < -data->enc_diff; s++) lv_group_focus_prev(g);
} else if(data->enc_diff > 0) { }
else if(data->enc_diff > 0) {
for(s = 0; s < data->enc_diff; s++) lv_group_focus_next(g); for(s = 0; s < data->enc_diff; s++) lv_group_focus_next(g);
} }
} }
@@ -715,7 +726,8 @@ static void indev_button_proc(lv_indev_t * i, lv_indev_data_t * data)
if(i->proc.types.pointer.last_point.x == i->proc.types.pointer.act_point.x && if(i->proc.types.pointer.last_point.x == i->proc.types.pointer.act_point.x &&
i->proc.types.pointer.last_point.y == i->proc.types.pointer.act_point.y && data->state == LV_INDEV_STATE_PR) { i->proc.types.pointer.last_point.y == i->proc.types.pointer.act_point.y && data->state == LV_INDEV_STATE_PR) {
indev_proc_press(&i->proc); indev_proc_press(&i->proc);
} else { }
else {
/*If a new point comes always make a release*/ /*If a new point comes always make a release*/
indev_proc_release(&i->proc); indev_proc_release(&i->proc);
} }
@@ -741,16 +753,20 @@ static void indev_proc_press(lv_indev_proc_t * proc)
/*If there is no last object then search*/ /*If there is no last object then search*/
if(indev_obj_act == NULL) { if(indev_obj_act == NULL) {
indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_sys(disp), &proc->types.pointer.act_point); indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_sys(disp), &proc->types.pointer.act_point);
if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_top(disp), &proc->types.pointer.act_point); if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_top(disp),
if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_scr_act(disp), &proc->types.pointer.act_point); &proc->types.pointer.act_point);
if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_scr_act(disp),
&proc->types.pointer.act_point);
new_obj_searched = true; new_obj_searched = true;
} }
/*If there is last object but it is not dragged and not protected also search*/ /*If there is last object but it is not dragged and not protected also search*/
else if(proc->types.pointer.drag_in_prog == 0 && else if(proc->types.pointer.drag_in_prog == 0 &&
lv_obj_is_protected(indev_obj_act, LV_PROTECT_PRESS_LOST) == false) { lv_obj_is_protected(indev_obj_act, LV_PROTECT_PRESS_LOST) == false) {
indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_sys(disp), &proc->types.pointer.act_point); indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_sys(disp), &proc->types.pointer.act_point);
if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_top(disp), &proc->types.pointer.act_point); if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_top(disp),
if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_scr_act(disp), &proc->types.pointer.act_point); &proc->types.pointer.act_point);
if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_scr_act(disp),
&proc->types.pointer.act_point);
new_obj_searched = true; new_obj_searched = true;
} }
/*If a dragable or a protected object was the last then keep it*/ /*If a dragable or a protected object was the last then keep it*/
@@ -1009,7 +1025,7 @@ static void indev_proc_reset_query_handler(lv_indev_t * indev)
* @param point pointer to a point for searhing the most top child * @param point pointer to a point for searhing the most top child
* @return pointer to the found object or NULL if there was no suitable object * @return pointer to the found object or NULL if there was no suitable object
*/ */
lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t *point) lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t * point)
{ {
lv_obj_t * found_p = NULL; lv_obj_t * found_p = NULL;
@@ -1017,8 +1033,7 @@ lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t *point)
if(lv_obj_hittest(obj, point)) { if(lv_obj_hittest(obj, point)) {
lv_obj_t * i; lv_obj_t * i;
LV_LL_READ(obj->child_ll, i) LV_LL_READ(obj->child_ll, i) {
{
found_p = lv_indev_search_obj(i, point); found_p = lv_indev_search_obj(i, point);
/*If a child was found then break*/ /*If a child was found then break*/
@@ -1029,7 +1044,8 @@ lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t *point)
/*If then the children was not ok, and this obj is clickable /*If then the children was not ok, and this obj is clickable
* and it or its parent is not hidden then save this object*/ * and it or its parent is not hidden then save this object*/
if(found_p == NULL && lv_obj_get_click(obj) != false && (lv_obj_get_state(obj, LV_OBJ_PART_MAIN) & LV_STATE_DISABLED) == 0) { if(found_p == NULL && lv_obj_get_click(obj) != false &&
(lv_obj_get_state(obj, LV_OBJ_PART_MAIN) & LV_STATE_DISABLED) == 0) {
lv_obj_t * hidden_i = obj; lv_obj_t * hidden_i = obj;
while(hidden_i != NULL) { while(hidden_i != NULL) {
if(lv_obj_get_hidden(hidden_i) == true) break; if(lv_obj_get_hidden(hidden_i) == true) break;
@@ -1170,7 +1186,8 @@ static void indev_drag(lv_indev_proc_t * proc)
if(allowed_dirs == LV_DRAG_DIR_ONE) { if(allowed_dirs == LV_DRAG_DIR_ONE) {
if(LV_MATH_ABS(proc->types.pointer.drag_sum.x) > LV_MATH_ABS(proc->types.pointer.drag_sum.y)) { if(LV_MATH_ABS(proc->types.pointer.drag_sum.x) > LV_MATH_ABS(proc->types.pointer.drag_sum.y)) {
hor_en = true; hor_en = true;
} else { }
else {
ver_en = true; ver_en = true;
} }
} }
@@ -1203,25 +1220,29 @@ static void indev_drag(lv_indev_proc_t * proc)
act_x += proc->types.pointer.drag_sum.x; act_x += proc->types.pointer.drag_sum.x;
act_y += proc->types.pointer.drag_sum.y; act_y += proc->types.pointer.drag_sum.y;
} }
} else if(allowed_dirs == LV_DRAG_DIR_HOR) { }
else if(allowed_dirs == LV_DRAG_DIR_HOR) {
if(drag_just_started) { if(drag_just_started) {
proc->types.pointer.drag_dir = LV_DRAG_DIR_HOR; proc->types.pointer.drag_dir = LV_DRAG_DIR_HOR;
proc->types.pointer.drag_sum.y = 0; proc->types.pointer.drag_sum.y = 0;
act_x += proc->types.pointer.drag_sum.x; act_x += proc->types.pointer.drag_sum.x;
} }
} else if(allowed_dirs == LV_DRAG_DIR_VER) { }
else if(allowed_dirs == LV_DRAG_DIR_VER) {
if(drag_just_started) { if(drag_just_started) {
proc->types.pointer.drag_dir = LV_DRAG_DIR_VER; proc->types.pointer.drag_dir = LV_DRAG_DIR_VER;
proc->types.pointer.drag_sum.x = 0; proc->types.pointer.drag_sum.x = 0;
act_y += proc->types.pointer.drag_sum.y; act_y += proc->types.pointer.drag_sum.y;
} }
} else if(allowed_dirs == LV_DRAG_DIR_ONE) { }
else if(allowed_dirs == LV_DRAG_DIR_ONE) {
if(drag_just_started) { if(drag_just_started) {
if(LV_MATH_ABS(proc->types.pointer.drag_sum.x) > LV_MATH_ABS(proc->types.pointer.drag_sum.y)) { if(LV_MATH_ABS(proc->types.pointer.drag_sum.x) > LV_MATH_ABS(proc->types.pointer.drag_sum.y)) {
proc->types.pointer.drag_dir = LV_DRAG_DIR_HOR; proc->types.pointer.drag_dir = LV_DRAG_DIR_HOR;
proc->types.pointer.drag_sum.y = 0; proc->types.pointer.drag_sum.y = 0;
act_x += proc->types.pointer.drag_sum.x; act_x += proc->types.pointer.drag_sum.x;
} else { }
else {
proc->types.pointer.drag_dir = LV_DRAG_DIR_VER; proc->types.pointer.drag_dir = LV_DRAG_DIR_VER;
proc->types.pointer.drag_sum.x = 0; proc->types.pointer.drag_sum.x = 0;
act_y += proc->types.pointer.drag_sum.y; act_y += proc->types.pointer.drag_sum.y;
@@ -1374,19 +1395,19 @@ static lv_obj_t * get_dragged_obj(lv_obj_t * obj)
static void indev_gesture(lv_indev_proc_t * proc) static void indev_gesture(lv_indev_proc_t * proc)
{ {
if (proc->types.pointer.drag_in_prog) return; if(proc->types.pointer.drag_in_prog) return;
if (proc->types.pointer.gesture_sent) return; if(proc->types.pointer.gesture_sent) return;
lv_obj_t * gesture_obj = proc->types.pointer.act_obj; lv_obj_t * gesture_obj = proc->types.pointer.act_obj;
/*If gesture parent is active check recursively the drag_parent attribute*/ /*If gesture parent is active check recursively the drag_parent attribute*/
while (gesture_obj && lv_obj_get_gesture_parent(gesture_obj)) { while(gesture_obj && lv_obj_get_gesture_parent(gesture_obj)) {
gesture_obj = lv_obj_get_parent(gesture_obj); gesture_obj = lv_obj_get_parent(gesture_obj);
} }
if (gesture_obj == NULL) return; if(gesture_obj == NULL) return;
if ((LV_MATH_ABS(proc->types.pointer.vect.x) < indev_act->driver.gesture_min_velocity) && if((LV_MATH_ABS(proc->types.pointer.vect.x) < indev_act->driver.gesture_min_velocity) &&
(LV_MATH_ABS(proc->types.pointer.vect.y) < indev_act->driver.gesture_min_velocity)) { (LV_MATH_ABS(proc->types.pointer.vect.y) < indev_act->driver.gesture_min_velocity)) {
proc->types.pointer.gesture_sum.x = 0; proc->types.pointer.gesture_sum.x = 0;
proc->types.pointer.gesture_sum.y = 0; proc->types.pointer.gesture_sum.y = 0;
@@ -1396,28 +1417,28 @@ static void indev_gesture(lv_indev_proc_t * proc)
proc->types.pointer.gesture_sum.x += proc->types.pointer.vect.x; proc->types.pointer.gesture_sum.x += proc->types.pointer.vect.x;
proc->types.pointer.gesture_sum.y += proc->types.pointer.vect.y; proc->types.pointer.gesture_sum.y += proc->types.pointer.vect.y;
if ((LV_MATH_ABS(proc->types.pointer.gesture_sum.x) > indev_act->driver.gesture_limit) || if((LV_MATH_ABS(proc->types.pointer.gesture_sum.x) > indev_act->driver.gesture_limit) ||
(LV_MATH_ABS(proc->types.pointer.gesture_sum.y) > indev_act->driver.gesture_limit)){ (LV_MATH_ABS(proc->types.pointer.gesture_sum.y) > indev_act->driver.gesture_limit)) {
proc->types.pointer.gesture_sent = 1; proc->types.pointer.gesture_sent = 1;
if (LV_MATH_ABS(proc->types.pointer.gesture_sum.x) > LV_MATH_ABS(proc->types.pointer.gesture_sum.y)){ if(LV_MATH_ABS(proc->types.pointer.gesture_sum.x) > LV_MATH_ABS(proc->types.pointer.gesture_sum.y)) {
if (proc->types.pointer.gesture_sum.x > 0) if(proc->types.pointer.gesture_sum.x > 0)
proc->types.pointer.gesture_dir = LV_GESTURE_DIR_RIGHT; proc->types.pointer.gesture_dir = LV_GESTURE_DIR_RIGHT;
else else
proc->types.pointer.gesture_dir = LV_GESTURE_DIR_LEFT; proc->types.pointer.gesture_dir = LV_GESTURE_DIR_LEFT;
} }
else{ else {
if (proc->types.pointer.gesture_sum.y > 0) if(proc->types.pointer.gesture_sum.y > 0)
proc->types.pointer.gesture_dir = LV_GESTURE_DIR_BOTTOM; proc->types.pointer.gesture_dir = LV_GESTURE_DIR_BOTTOM;
else else
proc->types.pointer.gesture_dir = LV_GESTURE_DIR_TOP; proc->types.pointer.gesture_dir = LV_GESTURE_DIR_TOP;
} }
gesture_obj->signal_cb(gesture_obj, LV_SIGNAL_GESTURE, indev_act); gesture_obj->signal_cb(gesture_obj, LV_SIGNAL_GESTURE, indev_act);
if (indev_reset_check(proc)) return; if(indev_reset_check(proc)) return;
lv_event_send(gesture_obj, LV_EVENT_GESTURE, NULL); lv_event_send(gesture_obj, LV_EVENT_GESTURE, NULL);
if (indev_reset_check(proc)) return; if(indev_reset_check(proc)) return;
} }
} }

View File

@@ -170,7 +170,7 @@ lv_obj_t * lv_indev_get_obj_act(void);
* @param point pointer to a point for searhing the most top child * @param point pointer to a point for searhing the most top child
* @return pointer to the found object or NULL if there was no suitable object * @return pointer to the found object or NULL if there was no suitable object
*/ */
lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t *point); lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t * point);
/********************** /**********************
* MACROS * MACROS

View File

@@ -28,12 +28,12 @@
#include <string.h> #include <string.h>
#if defined(LV_GC_INCLUDE) #if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE #include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
#if defined(LV_USER_DATA_FREE_INCLUDE) #if defined(LV_USER_DATA_FREE_INCLUDE)
#include LV_USER_DATA_FREE_INCLUDE #include LV_USER_DATA_FREE_INCLUDE
#endif /* LV_USE_USER_DATA_FREE */ #endif /* LV_USE_USER_DATA_FREE */
/********************* /*********************
@@ -47,8 +47,7 @@
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
typedef struct _lv_event_temp_data typedef struct _lv_event_temp_data {
{
lv_obj_t * obj; lv_obj_t * obj;
bool deleted; bool deleted;
struct _lv_event_temp_data * prev; struct _lv_event_temp_data * prev;
@@ -63,14 +62,14 @@ typedef struct {
lv_style_int_t _int; lv_style_int_t _int;
lv_opa_t _opa; lv_opa_t _opa;
const void * _ptr; const void * _ptr;
}start_value; } start_value;
union { union {
lv_color_t _color; lv_color_t _color;
lv_style_int_t _int; lv_style_int_t _int;
lv_opa_t _opa; lv_opa_t _opa;
const void * _ptr; const void * _ptr;
}end_value; } end_value;
}lv_style_trans_t; } lv_style_trans_t;
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
@@ -83,12 +82,13 @@ static void refresh_children_style(lv_obj_t * obj);
static void delete_children(lv_obj_t * obj); static void delete_children(lv_obj_t * obj);
static void base_dir_refr_children(lv_obj_t * obj); static void base_dir_refr_children(lv_obj_t * obj);
#if LV_USE_ANIMATION #if LV_USE_ANIMATION
static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop, uint8_t part, lv_state_t prev_state, lv_state_t new_state); static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop, uint8_t part, lv_state_t prev_state,
static void trans_del(lv_obj_t * obj, uint8_t part, lv_style_property_t prop); lv_state_t new_state);
static void trans_anim_cb(lv_style_trans_t * tr, lv_anim_value_t v); static void trans_del(lv_obj_t * obj, uint8_t part, lv_style_property_t prop);
static void trans_anim_start_cb(lv_anim_t * a); static void trans_anim_cb(lv_style_trans_t * tr, lv_anim_value_t v);
static void trans_anim_ready_cb(lv_anim_t * a); static void trans_anim_start_cb(lv_anim_t * a);
static void opa_scale_anim(lv_obj_t * obj, lv_anim_value_t v); static void trans_anim_ready_cb(lv_anim_t * a);
static void opa_scale_anim(lv_obj_t * obj, lv_anim_value_t v);
#endif #endif
static void lv_event_mark_deleted(lv_obj_t * obj); static void lv_event_mark_deleted(lv_obj_t * obj);
static void lv_obj_del_async_cb(void * obj); static void lv_obj_del_async_cb(void * obj);
@@ -234,7 +234,8 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
if(lv_obj_get_base_dir(new_obj) == LV_BIDI_DIR_RTL) { if(lv_obj_get_base_dir(new_obj) == LV_BIDI_DIR_RTL) {
new_obj->coords.x2 = parent->coords.x2; new_obj->coords.x2 = parent->coords.x2;
new_obj->coords.x1 = parent->coords.x2 - LV_OBJ_DEF_WIDTH; new_obj->coords.x1 = parent->coords.x2 - LV_OBJ_DEF_WIDTH;
} else { }
else {
new_obj->coords.x1 = parent->coords.x1; new_obj->coords.x1 = parent->coords.x1;
new_obj->coords.x2 = parent->coords.x1 + LV_OBJ_DEF_WIDTH; new_obj->coords.x2 = parent->coords.x1 + LV_OBJ_DEF_WIDTH;
} }
@@ -304,7 +305,8 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
if(copy == NULL) { if(copy == NULL) {
if(parent != NULL) lv_theme_apply(new_obj, LV_THEME_OBJ); if(parent != NULL) lv_theme_apply(new_obj, LV_THEME_OBJ);
else lv_theme_apply(new_obj, LV_THEME_SCR); else lv_theme_apply(new_obj, LV_THEME_SCR);
} else { }
else {
lv_style_list_copy(&new_obj->style_list, &copy->style_list); lv_style_list_copy(&new_obj->style_list, &copy->style_list);
} }
/*Copy the attributes if required*/ /*Copy the attributes if required*/
@@ -451,7 +453,8 @@ lv_res_t lv_obj_del(lv_obj_t * obj)
if(par == NULL) { /*It is a screen*/ if(par == NULL) { /*It is a screen*/
lv_disp_t * d = lv_obj_get_disp(obj); lv_disp_t * d = lv_obj_get_disp(obj);
lv_ll_remove(&d->scr_ll, obj); lv_ll_remove(&d->scr_ll, obj);
} else { }
else {
lv_ll_remove(&(par->child_ll), obj); lv_ll_remove(&(par->child_ll), obj);
} }
@@ -613,7 +616,8 @@ void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent)
if(new_base_dir != LV_BIDI_DIR_RTL) { if(new_base_dir != LV_BIDI_DIR_RTL) {
old_pos.x = lv_obj_get_x(obj); old_pos.x = lv_obj_get_x(obj);
} else { }
else {
old_pos.x = old_par->coords.x2 - obj->coords.x2; old_pos.x = old_par->coords.x2 - obj->coords.x2;
} }
@@ -623,10 +627,11 @@ void lv_obj_set_parent(lv_obj_t * obj, lv_obj_t * parent)
if(new_base_dir != LV_BIDI_DIR_RTL) { if(new_base_dir != LV_BIDI_DIR_RTL) {
lv_obj_set_pos(obj, old_pos.x, old_pos.y); lv_obj_set_pos(obj, old_pos.x, old_pos.y);
} else { }
else {
/*Align to the right in case of RTL base dir*/ /*Align to the right in case of RTL base dir*/
lv_coord_t new_x = lv_obj_get_width(parent) - old_pos.x - lv_obj_get_width(obj); lv_coord_t new_x = lv_obj_get_width(parent) - old_pos.x - lv_obj_get_width(obj);
lv_obj_set_pos(obj, new_x , old_pos.y); lv_obj_set_pos(obj, new_x, old_pos.y);
} }
/*Notify the original parent because one of its children is lost*/ /*Notify the original parent because one of its children is lost*/
@@ -795,7 +800,8 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h)
obj->coords.y2 = obj->coords.y1 + h - 1; obj->coords.y2 = obj->coords.y1 + h - 1;
if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL) { if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL) {
obj->coords.x1 = obj->coords.x2 - w + 1; obj->coords.x1 = obj->coords.x2 - w + 1;
} else { }
else {
obj->coords.x2 = obj->coords.x1 + w - 1; obj->coords.x2 = obj->coords.x1 + w - 1;
} }
@@ -1303,8 +1309,7 @@ void lv_obj_report_style_mod(lv_style_t * style)
while(d) { while(d) {
lv_obj_t * i; lv_obj_t * i;
LV_LL_READ(d->scr_ll, i) LV_LL_READ(d->scr_ll, i) {
{
report_style_mod_core(style, i); report_style_mod_core(style, i);
} }
d = lv_disp_get_next(d); d = lv_disp_get_next(d);
@@ -1339,7 +1344,8 @@ void lv_obj_set_hidden(lv_obj_t * obj, bool en)
* @param obj pointer to an object * @param obj pointer to an object
* @param en true: advanced hit-testing is enabled * @param en true: advanced hit-testing is enabled
*/ */
void lv_obj_set_adv_hittest(lv_obj_t * obj, bool en) { void lv_obj_set_adv_hittest(lv_obj_t * obj, bool en)
{
LV_ASSERT_OBJ(obj, LV_OBJX_NAME); LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
obj->adv_hittest = en == false ? 0 : 1; obj->adv_hittest = en == false ? 0 : 1;
@@ -1545,7 +1551,8 @@ void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state)
if(time == 0) { if(time == 0) {
trans_anim_cb(tr, 255); trans_anim_cb(tr, 255);
} else { }
else {
lv_anim_t a; lv_anim_t a;
lv_anim_init(&a); lv_anim_init(&a);
lv_anim_set_var(&a, tr); lv_anim_set_var(&a, tr);
@@ -1847,11 +1854,9 @@ lv_disp_t * lv_obj_get_disp(const lv_obj_t * obj)
scr = lv_obj_get_screen(obj); /*get the screen of `obj`*/ scr = lv_obj_get_screen(obj); /*get the screen of `obj`*/
lv_disp_t * d; lv_disp_t * d;
LV_LL_READ(LV_GC_ROOT(_lv_disp_ll), d) LV_LL_READ(LV_GC_ROOT(_lv_disp_ll), d) {
{
lv_obj_t * s; lv_obj_t * s;
LV_LL_READ(d->scr_ll, s) LV_LL_READ(d->scr_ll, s) {
{
if(s == scr) return d; if(s == scr) return d;
} }
} }
@@ -1891,7 +1896,8 @@ lv_obj_t * lv_obj_get_child(const lv_obj_t * obj, const lv_obj_t * child)
if(child == NULL) { if(child == NULL) {
result = lv_ll_get_head(&obj->child_ll); result = lv_ll_get_head(&obj->child_ll);
} else { }
else {
result = lv_ll_get_next(&obj->child_ll, child); result = lv_ll_get_next(&obj->child_ll, child);
} }
@@ -1913,7 +1919,8 @@ lv_obj_t * lv_obj_get_child_back(const lv_obj_t * obj, const lv_obj_t * child)
if(child == NULL) { if(child == NULL) {
result = lv_ll_get_tail(&obj->child_ll); result = lv_ll_get_tail(&obj->child_ll);
} else { }
else {
result = lv_ll_get_prev(&obj->child_ll, child); result = lv_ll_get_prev(&obj->child_ll, child);
} }
@@ -1948,8 +1955,7 @@ uint16_t lv_obj_count_children_recursive(const lv_obj_t * obj)
lv_obj_t * i; lv_obj_t * i;
uint16_t cnt = 0; uint16_t cnt = 0;
LV_LL_READ(obj->child_ll, i) LV_LL_READ(obj->child_ll, i) {
{
cnt++; /*Count the child*/ cnt++; /*Count the child*/
cnt += lv_obj_count_children_recursive(i); /*recursively count children's children*/ cnt += lv_obj_count_children_recursive(i); /*recursively count children's children*/
} }
@@ -2007,7 +2013,8 @@ lv_coord_t lv_obj_get_x(const lv_obj_t * obj)
lv_obj_t * parent = lv_obj_get_parent(obj); lv_obj_t * parent = lv_obj_get_parent(obj);
if(parent) { if(parent) {
rel_x = obj->coords.x1 - parent->coords.x1; rel_x = obj->coords.x1 - parent->coords.x1;
} else { }
else {
rel_x = obj->coords.x1; rel_x = obj->coords.x1;
} }
return rel_x; return rel_x;
@@ -2026,7 +2033,8 @@ lv_coord_t lv_obj_get_y(const lv_obj_t * obj)
lv_obj_t * parent = lv_obj_get_parent(obj); lv_obj_t * parent = lv_obj_get_parent(obj);
if(parent) { if(parent) {
rel_y = obj->coords.y1 - parent->coords.y1; rel_y = obj->coords.y1 - parent->coords.y1;
} else { }
else {
rel_y = obj->coords.y1; rel_y = obj->coords.y1;
} }
return rel_y; return rel_y;
@@ -2197,14 +2205,14 @@ lv_coord_t lv_obj_get_ext_draw_pad(const lv_obj_t * obj)
lv_style_list_t * lv_obj_get_style_list(const lv_obj_t * obj, uint8_t part) lv_style_list_t * lv_obj_get_style_list(const lv_obj_t * obj, uint8_t part)
{ {
if(part == LV_OBJ_PART_MAIN) return &((lv_obj_t*)obj)->style_list; if(part == LV_OBJ_PART_MAIN) return &((lv_obj_t *)obj)->style_list;
lv_get_style_info_t info; lv_get_style_info_t info;
info.part = part; info.part = part;
info.result = NULL; info.result = NULL;
lv_res_t res; lv_res_t res;
res = lv_signal_send((lv_obj_t*)obj, LV_SIGNAL_GET_STYLE, &info); res = lv_signal_send((lv_obj_t *)obj, LV_SIGNAL_GET_STYLE, &info);
if(res != LV_RES_OK) return NULL; if(res != LV_RES_OK) return NULL;
@@ -2627,7 +2635,7 @@ lv_state_t lv_obj_get_state(const lv_obj_t * obj, uint8_t part)
{ {
LV_ASSERT_OBJ(obj, LV_OBJX_NAME); LV_ASSERT_OBJ(obj, LV_OBJX_NAME);
if(part < _LV_OBJ_PART_REAL_LAST) return ((lv_obj_t*)obj)->state; if(part < _LV_OBJ_PART_REAL_LAST) return ((lv_obj_t *)obj)->state;
/*If a real part is asked, then use the object's signal to get its state. /*If a real part is asked, then use the object's signal to get its state.
* A real object can be in different state then the main part * A real object can be in different state then the main part
@@ -2635,7 +2643,7 @@ lv_state_t lv_obj_get_state(const lv_obj_t * obj, uint8_t part)
lv_get_state_info_t info; lv_get_state_info_t info;
info.part = part; info.part = part;
info.result = LV_STATE_DEFAULT; info.result = LV_STATE_DEFAULT;
lv_signal_send((lv_obj_t*)obj, LV_SIGNAL_GET_STATE_DSC, &info); lv_signal_send((lv_obj_t *)obj, LV_SIGNAL_GET_STATE_DSC, &info);
return info.result; return info.result;
@@ -2806,7 +2814,8 @@ bool lv_obj_is_focused(const lv_obj_t * obj)
* @param obj object to check * @param obj object to check
* @param point screen-space point * @param point screen-space point
*/ */
bool lv_obj_is_point_on_coords(lv_obj_t * obj, const lv_point_t * point) { bool lv_obj_is_point_on_coords(lv_obj_t * obj, const lv_point_t * point)
{
#if LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_TINY #if LV_USE_EXT_CLICK_AREA == LV_EXT_CLICK_AREA_TINY
lv_area_t ext_area; lv_area_t ext_area;
ext_area.x1 = obj->coords.x1 - obj->ext_click_pad_hor; ext_area.x1 = obj->coords.x1 - obj->ext_click_pad_hor;
@@ -2837,14 +2846,16 @@ bool lv_obj_is_point_on_coords(lv_obj_t * obj, const lv_point_t * point) {
* @param point screen-space point * @param point screen-space point
* @return true if the object is considered under the point * @return true if the object is considered under the point
*/ */
bool lv_obj_hittest(lv_obj_t * obj, lv_point_t * point) { bool lv_obj_hittest(lv_obj_t * obj, lv_point_t * point)
{
if(obj->adv_hittest) { if(obj->adv_hittest) {
lv_hit_test_info_t hit_info; lv_hit_test_info_t hit_info;
hit_info.point = point; hit_info.point = point;
hit_info.result = true; hit_info.result = true;
obj->signal_cb(obj, LV_SIGNAL_HIT_TEST, &hit_info); obj->signal_cb(obj, LV_SIGNAL_HIT_TEST, &hit_info);
return hit_info.result; return hit_info.result;
} else }
else
return lv_obj_is_point_on_coords(obj, point); return lv_obj_is_point_on_coords(obj, point);
} }
@@ -2946,7 +2957,8 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t
if(lv_img_src_get_type(draw_dsc->pattern_image) == LV_IMG_SRC_SYMBOL) { if(lv_img_src_get_type(draw_dsc->pattern_image) == LV_IMG_SRC_SYMBOL) {
draw_dsc->pattern_recolor = lv_obj_get_style_pattern_recolor(obj, part); draw_dsc->pattern_recolor = lv_obj_get_style_pattern_recolor(obj, part);
draw_dsc->pattern_font = lv_obj_get_style_text_font(obj, part); draw_dsc->pattern_font = lv_obj_get_style_text_font(obj, part);
} else if(draw_dsc->pattern_recolor_opa > LV_OPA_MIN ) { }
else if(draw_dsc->pattern_recolor_opa > LV_OPA_MIN) {
draw_dsc->pattern_recolor = lv_obj_get_style_pattern_recolor(obj, part); draw_dsc->pattern_recolor = lv_obj_get_style_pattern_recolor(obj, part);
} }
#if LV_USE_BLEND_MODES #if LV_USE_BLEND_MODES
@@ -3344,7 +3356,8 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
if(sign == LV_SIGNAL_CHILD_CHG) { if(sign == LV_SIGNAL_CHILD_CHG) {
/*Return 'invalid' if the child change signal is not enabled*/ /*Return 'invalid' if the child change signal is not enabled*/
if(lv_obj_is_protected(obj, LV_PROTECT_CHILD_CHG) != false) res = LV_RES_INV; if(lv_obj_is_protected(obj, LV_PROTECT_CHILD_CHG) != false) res = LV_RES_INV;
} else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { }
else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
obj->ext_draw_pad = LV_MATH_MAX(obj->ext_draw_pad, lv_obj_get_draw_rect_ext_pad_size(obj, LV_OBJ_PART_MAIN)); obj->ext_draw_pad = LV_MATH_MAX(obj->ext_draw_pad, lv_obj_get_draw_rect_ext_pad_size(obj, LV_OBJ_PART_MAIN));
} }
#if LV_USE_OBJ_REALIGN #if LV_USE_OBJ_REALIGN
@@ -3369,11 +3382,13 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
uint8_t state = LV_STATE_FOCUSED; uint8_t state = LV_STATE_FOCUSED;
state |= LV_STATE_EDITED; state |= LV_STATE_EDITED;
lv_obj_add_state(obj, state); lv_obj_add_state(obj, state);
} else { }
else {
lv_obj_add_state(obj, LV_STATE_FOCUSED); lv_obj_add_state(obj, LV_STATE_FOCUSED);
lv_obj_clear_state(obj, LV_STATE_EDITED); lv_obj_clear_state(obj, LV_STATE_EDITED);
} }
} else if(sign == LV_SIGNAL_DEFOCUS) { }
else if(sign == LV_SIGNAL_DEFOCUS) {
lv_obj_clear_state(obj, LV_STATE_FOCUSED | LV_STATE_EDITED); lv_obj_clear_state(obj, LV_STATE_FOCUSED | LV_STATE_EDITED);
} }
#endif #endif
@@ -3393,8 +3408,7 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff) static void refresh_children_position(lv_obj_t * obj, lv_coord_t x_diff, lv_coord_t y_diff)
{ {
lv_obj_t * i; lv_obj_t * i;
LV_LL_READ(obj->child_ll, i) LV_LL_READ(obj->child_ll, i) {
{
i->coords.x1 += x_diff; i->coords.x1 += x_diff;
i->coords.y1 += y_diff; i->coords.y1 += y_diff;
i->coords.x2 += x_diff; i->coords.x2 += x_diff;
@@ -3556,7 +3570,8 @@ static void base_dir_refr_children(lv_obj_t * obj)
* @param new_state the new state of the object * @param new_state the new state of the object
* @return pointer to the allocated `the transaction` variable or `NULL` if no transtion created * @return pointer to the allocated `the transaction` variable or `NULL` if no transtion created
*/ */
static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop, uint8_t part, lv_state_t prev_state, lv_state_t new_state) static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop, uint8_t part, lv_state_t prev_state,
lv_state_t new_state)
{ {
lv_style_trans_t * tr; lv_style_trans_t * tr;
lv_style_list_t * style_list = lv_obj_get_style_list(obj, part); lv_style_list_t * style_list = lv_obj_get_style_list(obj, part);
@@ -3630,9 +3645,10 @@ static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop,
tr = lv_ll_ins_head(&LV_GC_ROOT(_lv_obj_style_trans_ll)); tr = lv_ll_ins_head(&LV_GC_ROOT(_lv_obj_style_trans_ll));
LV_ASSERT_MEM(tr); LV_ASSERT_MEM(tr);
if(tr == NULL) return NULL; if(tr == NULL) return NULL;
tr->start_value._opa= o1; tr->start_value._opa = o1;
tr->end_value._opa = o2; tr->end_value._opa = o2;
} else { /*Ptr*/ }
else { /*Ptr*/
obj->state = prev_state; obj->state = prev_state;
style_list->skip_trans = 1; style_list->skip_trans = 1;
const void * p1 = _lv_obj_get_style_ptr(obj, part, prop); const void * p1 = _lv_obj_get_style_ptr(obj, part, prop);
@@ -3649,7 +3665,7 @@ static lv_style_trans_t * trans_create(lv_obj_t * obj, lv_style_property_t prop,
tr = lv_ll_ins_head(&LV_GC_ROOT(_lv_obj_style_trans_ll)); tr = lv_ll_ins_head(&LV_GC_ROOT(_lv_obj_style_trans_ll));
LV_ASSERT_MEM(tr); LV_ASSERT_MEM(tr);
if(tr == NULL) return NULL; if(tr == NULL) return NULL;
tr->start_value._ptr= p1; tr->start_value._ptr = p1;
tr->end_value._ptr = p2; tr->end_value._ptr = p2;
} }
@@ -3707,7 +3723,8 @@ static void trans_anim_cb(lv_style_trans_t * tr, lv_anim_value_t v)
else if(v >= 255) x = tr->end_value._opa; else if(v >= 255) x = tr->end_value._opa;
else x = tr->start_value._opa + (((tr->end_value._opa - tr->start_value._opa) * v) >> 8); else x = tr->start_value._opa + (((tr->end_value._opa - tr->start_value._opa) * v) >> 8);
_lv_style_set_opa(style, tr->prop, x); _lv_style_set_opa(style, tr->prop, x);
} else { }
else {
const void * x; const void * x;
if(v < 128) x = tr->start_value._ptr; if(v < 128) x = tr->start_value._ptr;
else x = tr->end_value._ptr; else x = tr->end_value._ptr;
@@ -3738,8 +3755,9 @@ static void trans_anim_start_cb(lv_anim_t * a)
} }
else if((prop_tmp & 0xF) < LV_STYLE_ID_PTR) { /*Opa*/ else if((prop_tmp & 0xF) < LV_STYLE_ID_PTR) { /*Opa*/
tr->start_value._opa = _lv_obj_get_style_opa(tr->obj, tr->part, prop_tmp); tr->start_value._opa = _lv_obj_get_style_opa(tr->obj, tr->part, prop_tmp);
} else { /*Ptr*/ }
tr->start_value._ptr= _lv_obj_get_style_ptr(tr->obj, tr->part, prop_tmp); else { /*Ptr*/
tr->start_value._ptr = _lv_obj_get_style_ptr(tr->obj, tr->part, prop_tmp);
} }

View File

@@ -155,8 +155,7 @@ typedef uint8_t lv_signal_t;
typedef lv_res_t (*lv_signal_cb_t)(struct _lv_obj_t * obj, lv_signal_t sign, void * param); typedef lv_res_t (*lv_signal_cb_t)(struct _lv_obj_t * obj, lv_signal_t sign, void * param);
#if LV_USE_OBJ_REALIGN #if LV_USE_OBJ_REALIGN
typedef struct typedef struct {
{
const struct _lv_obj_t * base; const struct _lv_obj_t * base;
lv_coord_t xofs; lv_coord_t xofs;
lv_coord_t yofs; lv_coord_t yofs;
@@ -193,8 +192,7 @@ enum {
typedef uint8_t lv_state_t; typedef uint8_t lv_state_t;
typedef struct _lv_obj_t typedef struct _lv_obj_t {
{
struct _lv_obj_t * parent; /**< Pointer to the parent object*/ struct _lv_obj_t * parent; /**< Pointer to the parent object*/
lv_ll_t child_ll; /**< Linked list to store the children objects*/ lv_ll_t child_ll; /**< Linked list to store the children objects*/
@@ -217,18 +215,18 @@ typedef struct _lv_obj_t
lv_coord_t ext_draw_pad; /**< EXTtend the size in every direction for drawing. */ lv_coord_t ext_draw_pad; /**< EXTtend the size in every direction for drawing. */
/*Attributes and states*/ /*Attributes and states*/
uint8_t click :1; /**< 1: Can be pressed by an input device*/ uint8_t click : 1; /**< 1: Can be pressed by an input device*/
uint8_t drag :1; /**< 1: Enable the dragging*/ uint8_t drag : 1; /**< 1: Enable the dragging*/
uint8_t drag_throw :1; /**< 1: Enable throwing with drag*/ uint8_t drag_throw : 1; /**< 1: Enable throwing with drag*/
uint8_t drag_parent :1; /**< 1: Parent will be dragged instead*/ uint8_t drag_parent : 1; /**< 1: Parent will be dragged instead*/
uint8_t hidden :1; /**< 1: Object is hidden*/ uint8_t hidden : 1; /**< 1: Object is hidden*/
uint8_t top :1; /**< 1: If the object or its children is clicked it goes to the foreground*/ uint8_t top : 1; /**< 1: If the object or its children is clicked it goes to the foreground*/
uint8_t parent_event :1; /**< 1: Send the object's events to the parent too. */ uint8_t parent_event : 1; /**< 1: Send the object's events to the parent too. */
uint8_t adv_hittest :1; /**< 1: Use advanced hit-testing (slower) */ uint8_t adv_hittest : 1; /**< 1: Use advanced hit-testing (slower) */
uint8_t gesture_parent : 1; /**< 1: Parent will be gesture instead*/ uint8_t gesture_parent : 1; /**< 1: Parent will be gesture instead*/
lv_drag_dir_t drag_dir :3; /**< Which directions the object can be dragged in */ lv_drag_dir_t drag_dir : 3; /**< Which directions the object can be dragged in */
lv_bidi_dir_t base_dir :2; /**< Base direction of texts related to this object */ lv_bidi_dir_t base_dir : 2; /**< Base direction of texts related to this object */
#if LV_USE_GROUP != 0 #if LV_USE_GROUP != 0
void * group_p; void * group_p;
@@ -258,26 +256,22 @@ enum {
typedef uint8_t lv_obj_part_t; typedef uint8_t lv_obj_part_t;
/** Used by `lv_obj_get_type()`. The object's and its ancestor types are stored here*/ /** Used by `lv_obj_get_type()`. The object's and its ancestor types are stored here*/
typedef struct typedef struct {
{
const char * type[LV_MAX_ANCESTOR_NUM]; /**< [0]: the actual type, [1]: ancestor, [2] #1's ancestor const char * type[LV_MAX_ANCESTOR_NUM]; /**< [0]: the actual type, [1]: ancestor, [2] #1's ancestor
... [x]: "lv_obj" */ ... [x]: "lv_obj" */
} lv_obj_type_t; } lv_obj_type_t;
typedef struct typedef struct {
{ lv_point_t * point;
lv_point_t *point;
bool result; bool result;
} lv_hit_test_info_t; } lv_hit_test_info_t;
typedef struct typedef struct {
{
uint8_t part; uint8_t part;
lv_style_list_t * result; lv_style_list_t * result;
} lv_get_style_info_t; } lv_get_style_info_t;
typedef struct typedef struct {
{
uint8_t part; uint8_t part;
lv_state_t result; lv_state_t result;
} lv_get_state_info_t; } lv_get_state_info_t;
@@ -334,7 +328,7 @@ void lv_obj_del_anim_ready_cb(lv_anim_t * a);
* @param obj object to delete * @param obj object to delete
* @see lv_async_call * @see lv_async_call
*/ */
void lv_obj_del_async(struct _lv_obj_t *obj); void lv_obj_del_async(struct _lv_obj_t * obj);
/** /**
* Delete all children of an object * Delete all children of an object

View File

@@ -60,41 +60,41 @@ extern "C" {
#define _LV_OBJ_STYLE_DECLARE_GET_scalar(prop_name, func_name, value_type, style_type) \ #define _LV_OBJ_STYLE_DECLARE_GET_scalar(prop_name, func_name, value_type, style_type) \
static inline value_type lv_obj_get_style_##func_name (const lv_obj_t * obj, uint8_t part) \ static inline value_type lv_obj_get_style_##func_name (const lv_obj_t * obj, uint8_t part) \
{ \ { \
return (value_type) _lv_obj_get_style##style_type (obj, part, LV_STYLE_##prop_name); \ return (value_type) _lv_obj_get_style##style_type (obj, part, LV_STYLE_##prop_name); \
} }
#define _LV_OBJ_STYLE_DECLARE_GET_nonscalar(prop_name, func_name, value_type, style_type) \ #define _LV_OBJ_STYLE_DECLARE_GET_nonscalar(prop_name, func_name, value_type, style_type) \
static inline value_type lv_obj_get_style_##func_name (const lv_obj_t * obj, uint8_t part) \ static inline value_type lv_obj_get_style_##func_name (const lv_obj_t * obj, uint8_t part) \
{ \ { \
return _lv_obj_get_style##style_type (obj, part, LV_STYLE_##prop_name); \ return _lv_obj_get_style##style_type (obj, part, LV_STYLE_##prop_name); \
} }
#define _LV_OBJ_STYLE_SET_GET_DECLARE(prop_name, func_name, value_type, style_type, scalar) \ #define _LV_OBJ_STYLE_SET_GET_DECLARE(prop_name, func_name, value_type, style_type, scalar) \
_LV_OBJ_STYLE_DECLARE_GET_##scalar(prop_name, func_name, value_type, style_type) \ _LV_OBJ_STYLE_DECLARE_GET_##scalar(prop_name, func_name, value_type, style_type) \
static inline void lv_obj_set_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state, value_type value) \ static inline void lv_obj_set_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state, value_type value) \
{ \ { \
_lv_obj_set_style_local##style_type (obj, part, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), value); \ _lv_obj_set_style_local##style_type (obj, part, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), value); \
} \ } \
static inline void lv_obj_get_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state, void * res) \ static inline void lv_obj_get_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state, void * res) \
{ \ { \
_lv_style_get##style_type (lv_obj_get_local_style(obj, part), LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), res); \ _lv_style_get##style_type (lv_obj_get_local_style(obj, part), LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), res); \
} \ } \
static inline void lv_obj_remove_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state) \ static inline void lv_obj_remove_style_local_##func_name (lv_obj_t * obj, uint8_t part, lv_state_t state) \
{ \ { \
_lv_obj_remove_style_local_prop(obj, part, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS)); \ _lv_obj_remove_style_local_prop(obj, part, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS)); \
} \ } \
static inline int16_t lv_style_get_##func_name (lv_style_t * style, lv_state_t state, void * res) \ static inline int16_t lv_style_get_##func_name (lv_style_t * style, lv_state_t state, void * res) \
{ \ { \
return _lv_style_get##style_type (style, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), res); \ return _lv_style_get##style_type (style, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), res); \
} \ } \
static inline void lv_style_set_##func_name (lv_style_t * style, lv_state_t state, value_type value) \ static inline void lv_style_set_##func_name (lv_style_t * style, lv_state_t state, value_type value) \
{ \ { \
_lv_style_set##style_type (style, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), value); \ _lv_style_set##style_type (style, LV_STYLE_##prop_name | (state << LV_STYLE_STATE_POS), value); \
} }
_LV_OBJ_STYLE_SET_GET_DECLARE(RADIUS, radius, lv_style_int_t,_int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(RADIUS, radius, lv_style_int_t, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(CLIP_CORNER, clip_corner, bool, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(CLIP_CORNER, clip_corner, bool, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(SIZE, size, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(SIZE, size, lv_style_int_t, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSFORM_WIDTH, transform_width, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSFORM_WIDTH, transform_width, lv_style_int_t, _int, scalar)
@@ -111,7 +111,7 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(BG_GRAD_STOP, bg_grad_stop, lv_style_int_t, _int,
_LV_OBJ_STYLE_SET_GET_DECLARE(BG_GRAD_DIR, bg_grad_dir, lv_grad_dir_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BG_GRAD_DIR, bg_grad_dir, lv_grad_dir_t, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(BG_COLOR, bg_color, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BG_COLOR, bg_color, lv_color_t, _color, nonscalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(BG_GRAD_COLOR, bg_grad_color, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BG_GRAD_COLOR, bg_grad_color, lv_color_t, _color, nonscalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(BG_OPA, bg_opa, lv_opa_t , _opa, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BG_OPA, bg_opa, lv_opa_t, _opa, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(BORDER_WIDTH, border_width, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BORDER_WIDTH, border_width, lv_style_int_t, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(BORDER_SIDE, border_side, lv_border_side_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BORDER_SIDE, border_side, lv_border_side_t, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(BORDER_BLEND_MODE, border_blend_mode, lv_blend_mode_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(BORDER_BLEND_MODE, border_blend_mode, lv_blend_mode_t, _int, scalar)
@@ -144,8 +144,8 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_OFS_Y, value_ofs_y, lv_style_int_t, _int, sc
_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_ALIGN, value_align, lv_align_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_ALIGN, value_align, lv_align_t, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_COLOR, value_color, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_COLOR, value_color, lv_color_t, _color, nonscalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_OPA, value_opa, lv_opa_t, _opa, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_OPA, value_opa, lv_opa_t, _opa, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_FONT, value_font, const lv_font_t * , _ptr, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_FONT, value_font, const lv_font_t *, _ptr, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_STR, value_str, const char * , _ptr, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(VALUE_STR, value_str, const char *, _ptr, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_LETTER_SPACE, text_letter_space, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_LETTER_SPACE, text_letter_space, lv_style_int_t, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_LINE_SPACE, text_line_space, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_LINE_SPACE, text_line_space, lv_style_int_t, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_DECOR, text_decor, lv_text_decor_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_DECOR, text_decor, lv_text_decor_t, _int, scalar)
@@ -153,7 +153,7 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_BLEND_MODE, text_blend_mode, lv_blend_mode_t,
_LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_COLOR, text_color, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_COLOR, text_color, lv_color_t, _color, nonscalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_SEL_COLOR, text_sel_color, lv_color_t, _color, nonscalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_SEL_COLOR, text_sel_color, lv_color_t, _color, nonscalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_OPA, text_opa, lv_opa_t, _opa, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_OPA, text_opa, lv_opa_t, _opa, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_FONT, text_font, const lv_font_t * , _ptr, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TEXT_FONT, text_font, const lv_font_t *, _ptr, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(LINE_WIDTH, line_width, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(LINE_WIDTH, line_width, lv_style_int_t, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(LINE_BLEND_MODE, line_blend_mode, lv_blend_mode_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(LINE_BLEND_MODE, line_blend_mode, lv_blend_mode_t, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(LINE_DASH_WIDTH, line_dash_width, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(LINE_DASH_WIDTH, line_dash_width, lv_style_int_t, _int, scalar)
@@ -174,9 +174,9 @@ _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PROP_4, transition_prop_4, lv_style_int
_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PROP_5, transition_prop_5, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PROP_5, transition_prop_5, lv_style_int_t, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PROP_6, transition_prop_6, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PROP_6, transition_prop_6, lv_style_int_t, _int, scalar)
#if LV_USE_ANIMATION #if LV_USE_ANIMATION
_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, lv_anim_path_cb_t , _ptr, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, lv_anim_path_cb_t, _ptr, scalar)
#else #else
_LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, void * , _ptr, scalar) /*For compatibility*/ _LV_OBJ_STYLE_SET_GET_DECLARE(TRANSITION_PATH, transition_path, void *, _ptr, scalar) /*For compatibility*/
#endif #endif
_LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_WIDTH, scale_width, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_WIDTH, scale_width, lv_style_int_t, _int, scalar)
_LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_BORDER_WIDTH, scale_border_width, lv_style_int_t, _int, scalar) _LV_OBJ_STYLE_SET_GET_DECLARE(SCALE_BORDER_WIDTH, scale_border_width, lv_style_int_t, _int, scalar)

View File

@@ -17,7 +17,7 @@
#include "../lv_draw/lv_draw.h" #include "../lv_draw/lv_draw.h"
#if defined(LV_GC_INCLUDE) #if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE #include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
/********************* /*********************
@@ -79,7 +79,8 @@ void lv_refr_now(lv_disp_t * disp)
if(disp) { if(disp) {
lv_disp_refr_task(disp->refr_task); lv_disp_refr_task(disp->refr_task);
} else { }
else {
lv_disp_t * d; lv_disp_t * d;
d = lv_disp_get_next(NULL); d = lv_disp_get_next(NULL);
while(d) { while(d) {
@@ -130,7 +131,8 @@ void lv_inv_area(lv_disp_t * disp, const lv_area_t * area_p)
/*Save the area*/ /*Save the area*/
if(disp->inv_p < LV_INV_BUF_SIZE) { if(disp->inv_p < LV_INV_BUF_SIZE) {
lv_area_copy(&disp->inv_areas[disp->inv_p], &com_area); lv_area_copy(&disp->inv_areas[disp->inv_p], &com_area);
} else { /*If no place for the area add the screen*/ }
else { /*If no place for the area add the screen*/
disp->inv_p = 0; disp->inv_p = 0;
lv_area_copy(&disp->inv_areas[disp->inv_p], &scr_area); lv_area_copy(&disp->inv_areas[disp->inv_p], &scr_area);
} }
@@ -177,8 +179,8 @@ void lv_disp_refr_task(lv_task_t * task)
disp_refr = task->user_data; disp_refr = task->user_data;
// extern rect_cache_t cache[]; // extern rect_cache_t cache[];
// extern uint32_t cp; // extern uint32_t cp;
lv_refr_join_area(); lv_refr_join_area();
@@ -348,7 +350,8 @@ static void lv_refr_area(const lv_area_t * area_p)
LV_LOG_WARN("Can't set VDB height using the round function. (Wrong round_cb or to " LV_LOG_WARN("Can't set VDB height using the round function. (Wrong round_cb or to "
"small VDB)"); "small VDB)");
return; return;
} else { }
else {
max_row = tmp.y2 + 1; max_row = tmp.y2 + 1;
} }
} }
@@ -433,12 +436,12 @@ static lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj)
/*If this object is fully cover the draw area check the children too */ /*If this object is fully cover the draw area check the children too */
if(lv_area_is_in(area_p, &obj->coords, 0) && obj->hidden == 0) { if(lv_area_is_in(area_p, &obj->coords, 0) && obj->hidden == 0) {
lv_design_res_t design_res = obj->design_cb ? obj->design_cb(obj, area_p, LV_DESIGN_COVER_CHK) : LV_DESIGN_RES_NOT_COVER; lv_design_res_t design_res = obj->design_cb ? obj->design_cb(obj, area_p,
LV_DESIGN_COVER_CHK) : LV_DESIGN_RES_NOT_COVER;
if(design_res == LV_DESIGN_RES_MASKED) return NULL; if(design_res == LV_DESIGN_RES_MASKED) return NULL;
lv_obj_t * i; lv_obj_t * i;
LV_LL_READ(obj->child_ll, i) LV_LL_READ(obj->child_ll, i) {
{
found_p = lv_refr_get_top_obj(area_p, i); found_p = lv_refr_get_top_obj(area_p, i);
/*If a children is ok then break*/ /*If a children is ok then break*/
@@ -555,8 +558,7 @@ static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p)
lv_area_t mask_child; /*Mask from obj and its child*/ lv_area_t mask_child; /*Mask from obj and its child*/
lv_obj_t * child_p; lv_obj_t * child_p;
lv_area_t child_area; lv_area_t child_area;
LV_LL_READ_BACK(obj->child_ll, child_p) LV_LL_READ_BACK(obj->child_ll, child_p) {
{
lv_obj_get_coords(child_p, &child_area); lv_obj_get_coords(child_p, &child_area);
ext_size = child_p->ext_draw_pad; ext_size = child_p->ext_draw_pad;
child_area.x1 -= ext_size; child_area.x1 -= ext_size;

View File

@@ -106,8 +106,7 @@ bool lv_style_remove_prop(lv_style_t * style, lv_style_property_t prop)
attr_found.full = *(style->map + id + 1); attr_found.full = *(style->map + id + 1);
attr_goal.full = (prop >> 8) & 0xFFU; attr_goal.full = (prop >> 8) & 0xFFU;
if(attr_found.bits.state == attr_goal.bits.state) if(attr_found.bits.state == attr_goal.bits.state) {
{
uint32_t map_size = lv_style_get_mem_size(style); uint32_t map_size = lv_style_get_mem_size(style);
uint8_t prop_size = sizeof(lv_style_property_t); uint8_t prop_size = sizeof(lv_style_property_t);
if((prop & 0xF) < LV_STYLE_ID_COLOR) prop_size += sizeof(lv_style_int_t); if((prop & 0xF) < LV_STYLE_ID_COLOR) prop_size += sizeof(lv_style_int_t);
@@ -162,17 +161,20 @@ void lv_style_list_copy(lv_style_list_t * list_dest, const lv_style_list_t * lis
list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 1) * sizeof(lv_style_t *)); list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 1) * sizeof(lv_style_t *));
memcpy(list_dest->style_list, list_src->style_list + 1, (list_src->style_cnt - 1) * sizeof(lv_style_t *)); memcpy(list_dest->style_list, list_src->style_list + 1, (list_src->style_cnt - 1) * sizeof(lv_style_t *));
list_dest->style_cnt = list_src->style_cnt - 1; list_dest->style_cnt = list_src->style_cnt - 1;
} else { }
else {
list_dest->style_list = lv_mem_alloc(list_src->style_cnt * sizeof(lv_style_t *)); list_dest->style_list = lv_mem_alloc(list_src->style_cnt * sizeof(lv_style_t *));
memcpy(list_dest->style_list, list_src->style_list, list_src->style_cnt * sizeof(lv_style_t *)); memcpy(list_dest->style_list, list_src->style_list, list_src->style_cnt * sizeof(lv_style_t *));
list_dest->style_cnt = list_src->style_cnt; list_dest->style_cnt = list_src->style_cnt;
} }
} else { }
else {
if(list_src->has_trans) { if(list_src->has_trans) {
list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 2) * sizeof(lv_style_t *)); list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 2) * sizeof(lv_style_t *));
memcpy(list_dest->style_list, list_src->style_list + 2, (list_src->style_cnt - 2) * sizeof(lv_style_t *)); memcpy(list_dest->style_list, list_src->style_list + 2, (list_src->style_cnt - 2) * sizeof(lv_style_t *));
list_dest->style_cnt = list_src->style_cnt - 2; list_dest->style_cnt = list_src->style_cnt - 2;
} else { }
else {
list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 1) * sizeof(lv_style_t *)); list_dest->style_list = lv_mem_alloc((list_src->style_cnt - 1) * sizeof(lv_style_t *));
memcpy(list_dest->style_list, list_src->style_list + 1, (list_src->style_cnt - 1) * sizeof(lv_style_t *)); memcpy(list_dest->style_list, list_src->style_list + 1, (list_src->style_cnt - 1) * sizeof(lv_style_t *));
list_dest->style_cnt = list_src->style_cnt - 1; list_dest->style_cnt = list_src->style_cnt - 1;
@@ -336,10 +338,10 @@ uint16_t lv_style_get_mem_size(const lv_style_t * style)
size_t i = 0; size_t i = 0;
while(style->map[i] != _LV_STYLE_CLOSEING_PROP) { while(style->map[i] != _LV_STYLE_CLOSEING_PROP) {
/*Go to the next property*/ /*Go to the next property*/
if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i+= sizeof(lv_style_int_t); if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i += sizeof(lv_style_int_t);
else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i+= sizeof(lv_color_t); else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i += sizeof(lv_color_t);
else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i+= sizeof(lv_opa_t); else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i += sizeof(lv_opa_t);
else i+= sizeof(void*); else i += sizeof(void *);
i += sizeof(lv_style_property_t); i += sizeof(lv_style_property_t);
} }
@@ -388,7 +390,7 @@ void _lv_style_set_int(lv_style_t * style, lv_style_property_t prop, lv_style_in
LV_ASSERT_MEM(style->map); LV_ASSERT_MEM(style->map);
if(style == NULL) return; if(style == NULL) return;
memcpy(style->map + size - new_prop_size - end_mark_size , &prop, sizeof(lv_style_property_t)); memcpy(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t));
memcpy(style->map + size - sizeof(lv_style_int_t) - end_mark_size, &value, sizeof(lv_style_int_t)); memcpy(style->map + size - sizeof(lv_style_int_t) - end_mark_size, &value, sizeof(lv_style_int_t));
memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark)); memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark));
} }
@@ -529,8 +531,8 @@ void _lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, const void
LV_ASSERT_MEM(style->map); LV_ASSERT_MEM(style->map);
if(style == NULL) return; if(style == NULL) return;
memcpy(style->map + size - new_prop_size - end_mark_size , &prop, sizeof(lv_style_property_t)); memcpy(style->map + size - new_prop_size - end_mark_size, &prop, sizeof(lv_style_property_t));
memcpy(style->map + size - sizeof(void *) - end_mark_size , &p, sizeof(void *)); memcpy(style->map + size - sizeof(void *) - end_mark_size, &p, sizeof(void *));
memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark)); memcpy(style->map + size - end_mark_size, &end_mark, sizeof(end_mark));
} }
@@ -554,7 +556,8 @@ int16_t _lv_style_get_int(const lv_style_t * style, lv_style_property_t prop, vo
int32_t id = get_property_index(style, prop); int32_t id = get_property_index(style, prop);
if(id < 0) { if(id < 0) {
return -1; return -1;
} else { }
else {
memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_style_int_t)); memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_style_int_t));
lv_style_attr_t attr_act; lv_style_attr_t attr_act;
attr_act.full = style->map[id + 1]; attr_act.full = style->map[id + 1];
@@ -589,7 +592,8 @@ int16_t _lv_style_get_opa(const lv_style_t * style, lv_style_property_t prop, vo
int32_t id = get_property_index(style, prop); int32_t id = get_property_index(style, prop);
if(id < 0) { if(id < 0) {
return -1; return -1;
} else { }
else {
memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_opa_t)); memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_opa_t));
lv_style_attr_t attr_act; lv_style_attr_t attr_act;
attr_act.full = style->map[id + 1]; attr_act.full = style->map[id + 1];
@@ -622,7 +626,8 @@ int16_t _lv_style_get_color(const lv_style_t * style, lv_style_property_t prop,
int32_t id = get_property_index(style, prop); int32_t id = get_property_index(style, prop);
if(id < 0) { if(id < 0) {
return -1; return -1;
} else { }
else {
memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_color_t)); memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(lv_color_t));
lv_style_attr_t attr_act; lv_style_attr_t attr_act;
attr_act.full = style->map[id + 1]; attr_act.full = style->map[id + 1];
@@ -649,14 +654,15 @@ int16_t _lv_style_get_color(const lv_style_t * style, lv_style_property_t prop,
*/ */
int16_t _lv_style_get_ptr(const lv_style_t * style, lv_style_property_t prop, void * v_res) int16_t _lv_style_get_ptr(const lv_style_t * style, lv_style_property_t prop, void * v_res)
{ {
void **res = (void *)v_res; void ** res = (void *)v_res;
if(style == NULL) return -1; if(style == NULL) return -1;
if(style->map == NULL) return -1; if(style->map == NULL) return -1;
int32_t id = get_property_index(style, prop); int32_t id = get_property_index(style, prop);
if(id < 0) { if(id < 0) {
return -1; return -1;
} else { }
memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(void*)); else {
memcpy(res, &style->map[id + sizeof(lv_style_property_t)], sizeof(void *));
lv_style_attr_t attr_act; lv_style_attr_t attr_act;
attr_act.full = style->map[id + 1]; attr_act.full = style->map[id + 1];
@@ -1041,10 +1047,10 @@ static inline int32_t get_property_index(const lv_style_t * style, lv_style_prop
} }
/*Go to the next property*/ /*Go to the next property*/
if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i+= sizeof(lv_style_int_t); if((style->map[i] & 0xF) < LV_STYLE_ID_COLOR) i += sizeof(lv_style_int_t);
else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i+= sizeof(lv_color_t); else if((style->map[i] & 0xF) < LV_STYLE_ID_OPA) i += sizeof(lv_color_t);
else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i+= sizeof(lv_opa_t); else if((style->map[i] & 0xF) < LV_STYLE_ID_PTR) i += sizeof(lv_opa_t);
else i+= sizeof(void*); else i += sizeof(void *);
i += sizeof(lv_style_property_t); i += sizeof(lv_style_property_t);
} }

View File

@@ -79,11 +79,11 @@ typedef uint8_t lv_text_decor_t;
typedef union { typedef union {
struct { struct {
uint8_t state :7; /* To which state the property refers to*/ uint8_t state : 7; /* To which state the property refers to*/
uint8_t inherit :1; /*1: The property can be inherited*/ uint8_t inherit : 1; /*1: The property can be inherited*/
}bits; } bits;
uint8_t full; uint8_t full;
}lv_style_attr_t; } lv_style_attr_t;
#define LV_STYLE_ID_VALUE 0x0 /*max 8 pcs*/ #define LV_STYLE_ID_VALUE 0x0 /*max 8 pcs*/
@@ -205,7 +205,7 @@ typedef struct {
#if LV_USE_ASSERT_STYLE #if LV_USE_ASSERT_STYLE
uint32_t sentinel; uint32_t sentinel;
#endif #endif
}lv_style_t; } lv_style_t;
typedef int16_t lv_style_int_t; typedef int16_t lv_style_int_t;
@@ -216,11 +216,11 @@ typedef struct {
uint32_t sentinel; uint32_t sentinel;
#endif #endif
uint8_t style_cnt; uint8_t style_cnt;
uint8_t has_local :1; uint8_t has_local : 1;
uint8_t has_trans :1; uint8_t has_trans : 1;
uint8_t skip_trans :1; /*1: Temporally skip the transition style if any*/ uint8_t skip_trans : 1; /*1: Temporally skip the transition style if any*/
uint8_t ignore_trans :1; /*1: Mark that this style list shouldn't receive transitions at all*/ uint8_t ignore_trans : 1; /*1: Mark that this style list shouldn't receive transitions at all*/
}lv_style_list_t; } lv_style_list_t;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES

View File

@@ -32,16 +32,16 @@ typedef struct {
lv_draw_rect_dsc_t * draw_dsc; lv_draw_rect_dsc_t * draw_dsc;
const lv_area_t * draw_area; const lv_area_t * draw_area;
const lv_area_t * clip_area; const lv_area_t * clip_area;
}quarter_draw_dsc_t; } quarter_draw_dsc_t;
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void draw_quarter_0(quarter_draw_dsc_t* q); static void draw_quarter_0(quarter_draw_dsc_t * q);
static void draw_quarter_1(quarter_draw_dsc_t* q); static void draw_quarter_1(quarter_draw_dsc_t * q);
static void draw_quarter_2(quarter_draw_dsc_t* q); static void draw_quarter_2(quarter_draw_dsc_t * q);
static void draw_quarter_3(quarter_draw_dsc_t* q); static void draw_quarter_3(quarter_draw_dsc_t * q);
static void get_rounded_area(int16_t angle, lv_coord_t radius, uint8_t tickness, lv_area_t * res_area); static void get_rounded_area(int16_t angle, lv_coord_t radius, uint8_t tickness, lv_area_t * res_area);
@@ -68,7 +68,8 @@ static void get_rounded_area(int16_t angle, lv_coord_t radius, uint8_t tickness,
* @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used) * @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used)
* @param opa_scale scale down all opacities by the factor * @param opa_scale scale down all opacities by the factor
*/ */
void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, const lv_area_t * clip_area, lv_draw_line_dsc_t * dsc) void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uint16_t start_angle, uint16_t end_angle,
const lv_area_t * clip_area, lv_draw_line_dsc_t * dsc)
{ {
if(dsc->opa <= LV_OPA_MIN) return; if(dsc->opa <= LV_OPA_MIN) return;
if(dsc->width == 0) return; if(dsc->width == 0) return;
@@ -104,7 +105,8 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin
int32_t angle_gap; int32_t angle_gap;
if(end_angle > start_angle) { if(end_angle > start_angle) {
angle_gap = 360 - (end_angle - start_angle); angle_gap = 360 - (end_angle - start_angle);
} else { }
else {
angle_gap = start_angle - end_angle; angle_gap = start_angle - end_angle;
} }
if(angle_gap > SPLIT_ANGLE_GAP_LIMIT && radius > SPLIT_RADIUS_LIMIT) { if(angle_gap > SPLIT_ANGLE_GAP_LIMIT && radius > SPLIT_RADIUS_LIMIT) {
@@ -115,7 +117,7 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin
q_dsc.radius = radius; q_dsc.radius = radius;
q_dsc.start_angle = start_angle; q_dsc.start_angle = start_angle;
q_dsc.end_angle = end_angle; q_dsc.end_angle = end_angle;
q_dsc.start_quarter= (start_angle / 90) & 0x3; q_dsc.start_quarter = (start_angle / 90) & 0x3;
q_dsc.end_quarter = (end_angle / 90) & 0x3; q_dsc.end_quarter = (end_angle / 90) & 0x3;
q_dsc.width = dsc->width; q_dsc.width = dsc->width;
q_dsc.draw_dsc = &cir_dsc; q_dsc.draw_dsc = &cir_dsc;
@@ -126,7 +128,8 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin
draw_quarter_1(&q_dsc); draw_quarter_1(&q_dsc);
draw_quarter_2(&q_dsc); draw_quarter_2(&q_dsc);
draw_quarter_3(&q_dsc); draw_quarter_3(&q_dsc);
} else { }
else {
lv_draw_rect(&area, clip_area, &cir_dsc); lv_draw_rect(&area, clip_area, &cir_dsc);
} }
lv_draw_mask_remove_id(mask_angle_id); lv_draw_mask_remove_id(mask_angle_id);
@@ -248,8 +251,8 @@ static void draw_quarter_1(quarter_draw_dsc_t * q)
quarter_area.x2 = q->center_x - 1; quarter_area.x2 = q->center_x - 1;
quarter_area.y2 = q->center_y + q->radius; quarter_area.y2 = q->center_y + q->radius;
quarter_area.y1 = q->center_y + ((lv_trigo_sin(q->end_angle) * (q->radius- q->width)) >> LV_TRIGO_SHIFT); quarter_area.y1 = q->center_y + ((lv_trigo_sin(q->end_angle) * (q->radius - q->width)) >> LV_TRIGO_SHIFT);
quarter_area.x1 = q->center_x + ((lv_trigo_sin(q->end_angle + 90) * (q->radius )) >> LV_TRIGO_SHIFT); quarter_area.x1 = q->center_x + ((lv_trigo_sin(q->end_angle + 90) * (q->radius)) >> LV_TRIGO_SHIFT);
bool ok = lv_area_intersect(&quarter_area, &quarter_area, q->clip_area); bool ok = lv_area_intersect(&quarter_area, &quarter_area, q->clip_area);
if(ok) lv_draw_rect(q->draw_area, &quarter_area, q->draw_dsc); if(ok) lv_draw_rect(q->draw_area, &quarter_area, q->draw_dsc);
@@ -291,8 +294,8 @@ static void draw_quarter_2(quarter_draw_dsc_t * q)
quarter_area.x2 = q->center_x - 1; quarter_area.x2 = q->center_x - 1;
quarter_area.y1 = q->center_y - q->radius; quarter_area.y1 = q->center_y - q->radius;
quarter_area.x1 = q->center_x + ((lv_trigo_sin(q->start_angle + 90) * (q->radius )) >> LV_TRIGO_SHIFT); quarter_area.x1 = q->center_x + ((lv_trigo_sin(q->start_angle + 90) * (q->radius)) >> LV_TRIGO_SHIFT);
quarter_area.y2 = q->center_y + ((lv_trigo_sin(q->start_angle) * (q->radius- q->width)) >> LV_TRIGO_SHIFT); quarter_area.y2 = q->center_y + ((lv_trigo_sin(q->start_angle) * (q->radius - q->width)) >> LV_TRIGO_SHIFT);
bool ok = lv_area_intersect(&quarter_area, &quarter_area, q->clip_area); bool ok = lv_area_intersect(&quarter_area, &quarter_area, q->clip_area);
if(ok) lv_draw_rect(q->draw_area, &quarter_area, q->draw_dsc); if(ok) lv_draw_rect(q->draw_area, &quarter_area, q->draw_dsc);

View File

@@ -38,7 +38,8 @@ extern "C" {
* @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used) * @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used)
* @param opa_scale scale down all opacities by the factor * @param opa_scale scale down all opacities by the factor
*/ */
void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uint16_t start_angle, uint16_t end_angle, const lv_area_t * clip_area, lv_draw_line_dsc_t * dsc); void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uint16_t start_angle, uint16_t end_angle,
const lv_area_t * clip_area, lv_draw_line_dsc_t * dsc);
/********************** /**********************
* MACROS * MACROS

View File

@@ -112,7 +112,7 @@ void lv_blend_fill(const lv_area_t * clip_area, const lv_area_t * fill_area,
if(mask && disp->driver.antialiasing == 0) { if(mask && disp->driver.antialiasing == 0) {
int32_t mask_w = lv_area_get_width(&draw_area); int32_t mask_w = lv_area_get_width(&draw_area);
int32_t i; int32_t i;
for (i = 0; i < mask_w; i++) mask[i] = mask[i] > 128 ? LV_OPA_COVER : LV_OPA_TRANSP; for(i = 0; i < mask_w; i++) mask[i] = mask[i] > 128 ? LV_OPA_COVER : LV_OPA_TRANSP;
} }
if(disp->driver.set_px_cb) { if(disp->driver.set_px_cb) {
@@ -158,14 +158,15 @@ void lv_blend_map(const lv_area_t * clip_area, const lv_area_t * map_area, const
if(mask && disp->driver.antialiasing == 0) { if(mask && disp->driver.antialiasing == 0) {
int32_t mask_w = lv_area_get_width(&draw_area); int32_t mask_w = lv_area_get_width(&draw_area);
int32_t i; int32_t i;
for (i = 0; i < mask_w; i++) mask[i] = mask[i] > 128 ? LV_OPA_COVER : LV_OPA_TRANSP; for(i = 0; i < mask_w; i++) mask[i] = mask[i] > 128 ? LV_OPA_COVER : LV_OPA_TRANSP;
} }
if(disp->driver.set_px_cb) { if(disp->driver.set_px_cb) {
map_set_px(disp_area, disp_buf, &draw_area, map_area, map_buf, opa, mask, mask_res); map_set_px(disp_area, disp_buf, &draw_area, map_area, map_buf, opa, mask, mask_res);
} }
else if(mode == LV_BLEND_MODE_NORMAL) { else if(mode == LV_BLEND_MODE_NORMAL) {
map_normal(disp_area, disp_buf, &draw_area, map_area, map_buf, opa, mask, mask_res); map_normal(disp_area, disp_buf, &draw_area, map_area, map_buf, opa, mask, mask_res);
} else { }
else {
map_blended(disp_area, disp_buf, &draw_area, map_area, map_buf, opa, mask, mask_res, mode); map_blended(disp_area, disp_buf, &draw_area, map_area, map_buf, opa, mask, mask_res, mode);
} }
} }
@@ -191,10 +192,11 @@ static void fill_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, con
if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) { if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) {
for(y = draw_area->y1; y <= draw_area->y2; y++) { for(y = draw_area->y1; y <= draw_area->y2; y++) {
for(x = draw_area->x1; x <= draw_area->x2; x++) { for(x = draw_area->x1; x <= draw_area->x2; x++) {
disp->driver.set_px_cb(&disp->driver, (void*)disp_buf, disp_w, x, y, color, opa); disp->driver.set_px_cb(&disp->driver, (void *)disp_buf, disp_w, x, y, color, opa);
} }
} }
} else { }
else {
/* The mask is relative to the clipped area. /* The mask is relative to the clipped area.
* In the cycles below mask will be indexed from `draw_area.x1` * In the cycles below mask will be indexed from `draw_area.x1`
* but it corresponds to zero index. So prepare `mask_tmp` accordingly. */ * but it corresponds to zero index. So prepare `mask_tmp` accordingly. */
@@ -205,7 +207,8 @@ static void fill_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, con
for(y = draw_area->y1; y <= draw_area->y2; y++) { for(y = draw_area->y1; y <= draw_area->y2; y++) {
for(x = draw_area->x1; x <= draw_area->x2; x++) { for(x = draw_area->x1; x <= draw_area->x2; x++) {
disp->driver.set_px_cb(&disp->driver, (void*)disp_buf, disp_w, x, y, color, (uint32_t)((uint32_t)opa * mask_tmp[x]) >> 8); disp->driver.set_px_cb(&disp->driver, (void *)disp_buf, disp_w, x, y, color,
(uint32_t)((uint32_t)opa * mask_tmp[x]) >> 8);
} }
mask_tmp += draw_area_w; mask_tmp += draw_area_w;
} }
@@ -247,7 +250,8 @@ static void fill_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, con
/*Fill the first line. Use `memcpy` because it's faster then simple value assignment*/ /*Fill the first line. Use `memcpy` because it's faster then simple value assignment*/
/*Set the first pixels manually*/ /*Set the first pixels manually*/
int32_t direct_fill_end = LV_MATH_MIN(draw_area->x2, draw_area->x1 + FILL_DIRECT_LEN + (draw_area_w & FILL_DIRECT_MASK) - 1); int32_t direct_fill_end = LV_MATH_MIN(draw_area->x2,
draw_area->x1 + FILL_DIRECT_LEN + (draw_area_w & FILL_DIRECT_MASK) - 1);
for(x = draw_area->x1; x <= direct_fill_end ; x++) { for(x = draw_area->x1; x <= direct_fill_end ; x++) {
disp_buf_tmp[x].full = color.full; disp_buf_tmp[x].full = color.full;
} }
@@ -286,8 +290,10 @@ static void fill_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, con
#if LV_COLOR_SCREEN_TRANSP #if LV_COLOR_SCREEN_TRANSP
if(disp->driver.screen_transp) { if(disp->driver.screen_transp) {
lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, color, opa, &last_res_color, &last_res_color.ch.alpha); lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, color, opa, &last_res_color,
} else &last_res_color.ch.alpha);
}
else
#endif #endif
{ {
last_res_color = lv_color_mix(color, disp_buf_tmp[x], opa); last_res_color = lv_color_mix(color, disp_buf_tmp[x], opa);
@@ -318,12 +324,13 @@ static void fill_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, con
for(y = draw_area->y1; y <= draw_area->y2; y++) { for(y = draw_area->y1; y <= draw_area->y2; y++) {
for(x = draw_area->x1; x <= draw_area->x2; x++) { for(x = draw_area->x1; x <= draw_area->x2; x++) {
if(mask_tmp[x] == 0) continue; if(mask_tmp[x] == 0) continue;
if(mask_tmp[x] != last_mask || last_dest_color.full != disp_buf_tmp[x].full) if(mask_tmp[x] != last_mask || last_dest_color.full != disp_buf_tmp[x].full) {
{
#if LV_COLOR_SCREEN_TRANSP #if LV_COLOR_SCREEN_TRANSP
if(disp->driver.screen_transp) { if(disp->driver.screen_transp) {
lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, color, mask_tmp[x], &last_res_color, &last_res_color.ch.alpha); lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, color, mask_tmp[x], &last_res_color,
} else &last_res_color.ch.alpha);
}
else
#endif #endif
{ {
if(mask_tmp[x] == LV_OPA_COVER) last_res_color = color; if(mask_tmp[x] == LV_OPA_COVER) last_res_color = color;
@@ -349,13 +356,15 @@ static void fill_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, con
lv_opa_t opa_tmp = mask_tmp[x] == LV_OPA_COVER ? opa : (uint32_t)((uint32_t)mask_tmp[x] * opa) >> 8; lv_opa_t opa_tmp = mask_tmp[x] == LV_OPA_COVER ? opa : (uint32_t)((uint32_t)mask_tmp[x] * opa) >> 8;
#if LV_COLOR_SCREEN_TRANSP #if LV_COLOR_SCREEN_TRANSP
if(disp->driver.screen_transp) { if(disp->driver.screen_transp) {
lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, color, opa_tmp, &last_res_color, &last_res_color.ch.alpha); lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, color, opa_tmp, &last_res_color,
} else &last_res_color.ch.alpha);
}
else
#endif #endif
{ {
if(opa_tmp == LV_OPA_COVER) last_res_color = lv_color_mix(color, disp_buf_tmp[x], mask_tmp[x]); if(opa_tmp == LV_OPA_COVER) last_res_color = lv_color_mix(color, disp_buf_tmp[x], mask_tmp[x]);
else if(opa_tmp == LV_OPA_TRANSP) last_res_color = disp_buf_tmp[x]; else if(opa_tmp == LV_OPA_TRANSP) last_res_color = disp_buf_tmp[x];
else last_res_color = lv_color_mix(color, disp_buf_tmp[x],opa_tmp); else last_res_color = lv_color_mix(color, disp_buf_tmp[x], opa_tmp);
} }
last_mask = mask_tmp[x]; last_mask = mask_tmp[x];
last_dest_color.full = disp_buf_tmp[x].full; last_dest_color.full = disp_buf_tmp[x].full;
@@ -382,7 +391,7 @@ static void fill_blended(const lv_area_t * disp_area, lv_color_t * disp_buf, co
lv_color_t (*blend_fp)(lv_color_t, lv_color_t, lv_opa_t); lv_color_t (*blend_fp)(lv_color_t, lv_color_t, lv_opa_t);
switch (mode) { switch(mode) {
case LV_BLEND_MODE_ADDITIVE: case LV_BLEND_MODE_ADDITIVE:
blend_fp = color_blend_true_color_additive; blend_fp = color_blend_true_color_additive;
break; break;
@@ -475,11 +484,12 @@ static void map_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, cons
if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) { if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) {
for(y = draw_area->y1; y <= draw_area->y2; y++) { for(y = draw_area->y1; y <= draw_area->y2; y++) {
for(x = draw_area->x1; x <= draw_area->x2; x++) { for(x = draw_area->x1; x <= draw_area->x2; x++) {
disp->driver.set_px_cb(&disp->driver, (void*)disp_buf, disp_w, x, y, map_buf_tmp[x], opa); disp->driver.set_px_cb(&disp->driver, (void *)disp_buf, disp_w, x, y, map_buf_tmp[x], opa);
} }
map_buf_tmp += map_w; map_buf_tmp += map_w;
} }
} else { }
else {
/* The mask is relative to the clipped area. /* The mask is relative to the clipped area.
* In the cycles below mask will be indexed from `draw_area.x1` * In the cycles below mask will be indexed from `draw_area.x1`
* but it corresponds to zero index. So prepare `mask_tmp` accordingly. */ * but it corresponds to zero index. So prepare `mask_tmp` accordingly. */
@@ -487,7 +497,8 @@ static void map_set_px(const lv_area_t * disp_area, lv_color_t * disp_buf, cons
for(y = draw_area->y1; y <= draw_area->y2; y++) { for(y = draw_area->y1; y <= draw_area->y2; y++) {
for(x = draw_area->x1; x <= draw_area->x2; x++) { for(x = draw_area->x1; x <= draw_area->x2; x++) {
disp->driver.set_px_cb(&disp->driver, (void*)disp_buf, disp_w, x, y, map_buf_tmp[x], (uint32_t)((uint32_t)opa * mask_tmp[x]) >> 8); disp->driver.set_px_cb(&disp->driver, (void *)disp_buf, disp_w, x, y, map_buf_tmp[x],
(uint32_t)((uint32_t)opa * mask_tmp[x]) >> 8);
} }
mask_tmp += draw_area_w; mask_tmp += draw_area_w;
map_buf_tmp += map_w; map_buf_tmp += map_w;
@@ -558,8 +569,10 @@ static void map_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, cons
for(x = draw_area->x1; x <= draw_area->x2; x++) { for(x = draw_area->x1; x <= draw_area->x2; x++) {
#if LV_COLOR_SCREEN_TRANSP #if LV_COLOR_SCREEN_TRANSP
if(disp->driver.screen_transp) { if(disp->driver.screen_transp) {
lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, map_buf_tmp[x], opa, &disp_buf_tmp[x], &disp_buf_tmp[x].ch.alpha); lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, map_buf_tmp[x], opa, &disp_buf_tmp[x],
} else &disp_buf_tmp[x].ch.alpha);
}
else
#endif #endif
{ {
disp_buf_tmp[x] = lv_color_mix(map_buf_tmp[x], disp_buf_tmp[x], opa); disp_buf_tmp[x] = lv_color_mix(map_buf_tmp[x], disp_buf_tmp[x], opa);
@@ -592,9 +605,11 @@ static void map_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, cons
if(mask_tmp[x] < LV_OPA_MIN) continue; if(mask_tmp[x] < LV_OPA_MIN) continue;
#if LV_COLOR_SCREEN_TRANSP #if LV_COLOR_SCREEN_TRANSP
if(disp->driver.screen_transp) { if(disp->driver.screen_transp) {
lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, map_buf_tmp[x], mask_tmp[x], &res_color, &opa_composed); lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, map_buf_tmp[x], mask_tmp[x], &res_color,
&opa_composed);
res_color.ch.alpha = opa_composed; res_color.ch.alpha = opa_composed;
} else }
else
#endif #endif
{ {
if(mask_tmp[x] > LV_OPA_MAX) res_color = map_buf_tmp[x]; if(mask_tmp[x] > LV_OPA_MAX) res_color = map_buf_tmp[x];
@@ -616,8 +631,10 @@ static void map_normal(const lv_area_t * disp_area, lv_color_t * disp_buf, cons
lv_opa_t opa_tmp = mask_tmp[x] >= LV_OPA_MAX ? opa : ((opa * mask_tmp[x]) >> 8); lv_opa_t opa_tmp = mask_tmp[x] >= LV_OPA_MAX ? opa : ((opa * mask_tmp[x]) >> 8);
#if LV_COLOR_SCREEN_TRANSP #if LV_COLOR_SCREEN_TRANSP
if(disp->driver.screen_transp) { if(disp->driver.screen_transp) {
lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, map_buf_tmp[x], opa_tmp, &disp_buf_tmp[x], &disp_buf_tmp[x].ch.alpha); lv_color_mix_with_alpha(disp_buf_tmp[x], disp_buf_tmp[x].ch.alpha, map_buf_tmp[x], opa_tmp, &disp_buf_tmp[x],
} else &disp_buf_tmp[x].ch.alpha);
}
else
#endif #endif
{ {
disp_buf_tmp[x] = lv_color_mix(map_buf_tmp[x], disp_buf_tmp[x], opa_tmp); disp_buf_tmp[x] = lv_color_mix(map_buf_tmp[x], disp_buf_tmp[x], opa_tmp);
@@ -652,7 +669,7 @@ static void map_blended(const lv_area_t * disp_area, lv_color_t * disp_buf, con
const lv_color_t * map_buf_tmp = map_buf + map_w * (draw_area->y1 - (map_area->y1 - disp_area->y1)); const lv_color_t * map_buf_tmp = map_buf + map_w * (draw_area->y1 - (map_area->y1 - disp_area->y1));
lv_color_t (*blend_fp)(lv_color_t, lv_color_t, lv_opa_t); lv_color_t (*blend_fp)(lv_color_t, lv_color_t, lv_opa_t);
switch (mode) { switch(mode) {
case LV_BLEND_MODE_ADDITIVE: case LV_BLEND_MODE_ADDITIVE:
blend_fp = color_blend_true_color_additive; blend_fp = color_blend_true_color_additive;
break; break;

View File

@@ -25,9 +25,11 @@
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, const void * src, lv_draw_img_dsc_t * draw_dsc); static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, const void * src,
lv_draw_img_dsc_t * draw_dsc);
static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, const uint8_t * map_p, lv_draw_img_dsc_t * draw_dsc, static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, const uint8_t * map_p,
lv_draw_img_dsc_t * draw_dsc,
bool chroma_key, bool alpha_byte); bool chroma_key, bool alpha_byte);
void show_error(const lv_area_t * coords, const lv_area_t * clip_area, const char * msg); void show_error(const lv_area_t * coords, const lv_area_t * clip_area, const char * msg);
@@ -95,19 +97,35 @@ uint8_t lv_img_cf_get_px_size(lv_img_cf_t cf)
switch(cf) { switch(cf) {
case LV_IMG_CF_UNKNOWN: case LV_IMG_CF_UNKNOWN:
case LV_IMG_CF_RAW: px_size = 0; break; case LV_IMG_CF_RAW:
px_size = 0;
break;
case LV_IMG_CF_TRUE_COLOR: case LV_IMG_CF_TRUE_COLOR:
case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED: px_size = LV_COLOR_SIZE; break; case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED:
case LV_IMG_CF_TRUE_COLOR_ALPHA: px_size = LV_IMG_PX_SIZE_ALPHA_BYTE << 3; break; px_size = LV_COLOR_SIZE;
break;
case LV_IMG_CF_TRUE_COLOR_ALPHA:
px_size = LV_IMG_PX_SIZE_ALPHA_BYTE << 3;
break;
case LV_IMG_CF_INDEXED_1BIT: case LV_IMG_CF_INDEXED_1BIT:
case LV_IMG_CF_ALPHA_1BIT: px_size = 1; break; case LV_IMG_CF_ALPHA_1BIT:
px_size = 1;
break;
case LV_IMG_CF_INDEXED_2BIT: case LV_IMG_CF_INDEXED_2BIT:
case LV_IMG_CF_ALPHA_2BIT: px_size = 2; break; case LV_IMG_CF_ALPHA_2BIT:
px_size = 2;
break;
case LV_IMG_CF_INDEXED_4BIT: case LV_IMG_CF_INDEXED_4BIT:
case LV_IMG_CF_ALPHA_4BIT: px_size = 4; break; case LV_IMG_CF_ALPHA_4BIT:
px_size = 4;
break;
case LV_IMG_CF_INDEXED_8BIT: case LV_IMG_CF_INDEXED_8BIT:
case LV_IMG_CF_ALPHA_8BIT: px_size = 8; break; case LV_IMG_CF_ALPHA_8BIT:
default: px_size = 0; break; px_size = 8;
break;
default:
px_size = 0;
break;
} }
return px_size; return px_size;
@@ -131,9 +149,12 @@ bool lv_img_cf_is_chroma_keyed(lv_img_cf_t cf)
case LV_IMG_CF_INDEXED_4BIT: case LV_IMG_CF_INDEXED_4BIT:
case LV_IMG_CF_INDEXED_8BIT: case LV_IMG_CF_INDEXED_8BIT:
#endif #endif
is_chroma_keyed = true; break; is_chroma_keyed = true;
break;
default: is_chroma_keyed = false; break; default:
is_chroma_keyed = false;
break;
} }
return is_chroma_keyed; return is_chroma_keyed;
@@ -158,8 +179,12 @@ bool lv_img_cf_has_alpha(lv_img_cf_t cf)
case LV_IMG_CF_ALPHA_1BIT: case LV_IMG_CF_ALPHA_1BIT:
case LV_IMG_CF_ALPHA_2BIT: case LV_IMG_CF_ALPHA_2BIT:
case LV_IMG_CF_ALPHA_4BIT: case LV_IMG_CF_ALPHA_4BIT:
case LV_IMG_CF_ALPHA_8BIT: has_alpha = true; break; case LV_IMG_CF_ALPHA_8BIT:
default: has_alpha = false; break; has_alpha = true;
break;
default:
has_alpha = false;
break;
} }
return has_alpha; return has_alpha;
@@ -183,9 +208,11 @@ lv_img_src_t lv_img_src_get_type(const void * src)
/*The first byte shows the type of the image source*/ /*The first byte shows the type of the image source*/
if(u8_p[0] >= 0x20 && u8_p[0] <= 0x7F) { if(u8_p[0] >= 0x20 && u8_p[0] <= 0x7F) {
img_src_type = LV_IMG_SRC_FILE; /*If it's an ASCII character then it's file name*/ img_src_type = LV_IMG_SRC_FILE; /*If it's an ASCII character then it's file name*/
} else if(u8_p[0] >= 0x80) { }
else if(u8_p[0] >= 0x80) {
img_src_type = LV_IMG_SRC_SYMBOL; /*Symbols begins after 0x7F*/ img_src_type = LV_IMG_SRC_SYMBOL; /*Symbols begins after 0x7F*/
} else { }
else {
img_src_type = LV_IMG_SRC_VARIABLE; /*`lv_img_dsc_t` is design to the first byte < 0x20*/ img_src_type = LV_IMG_SRC_VARIABLE; /*`lv_img_dsc_t` is design to the first byte < 0x20*/
} }
@@ -200,7 +227,8 @@ lv_img_src_t lv_img_src_get_type(const void * src)
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, const void * src, lv_draw_img_dsc_t * draw_dsc) static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mask, const void * src,
lv_draw_img_dsc_t * draw_dsc)
{ {
if(draw_dsc->opa <= LV_OPA_MIN) return LV_RES_OK; if(draw_dsc->opa <= LV_OPA_MIN) return LV_RES_OK;
@@ -255,7 +283,8 @@ static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mas
int32_t width = lv_area_get_width(&mask_com); int32_t width = lv_area_get_width(&mask_com);
uint8_t * buf = lv_mem_buf_get(lv_area_get_width(&mask_com) * LV_IMG_PX_SIZE_ALPHA_BYTE); /*+1 because of the possible alpha byte*/ uint8_t * buf = lv_mem_buf_get(lv_area_get_width(&mask_com) *
LV_IMG_PX_SIZE_ALPHA_BYTE); /*+1 because of the possible alpha byte*/
lv_area_t line; lv_area_t line;
lv_area_copy(&line, &mask_com); lv_area_copy(&line, &mask_com);
@@ -303,7 +332,8 @@ static lv_res_t lv_img_draw_core(const lv_area_t * coords, const lv_area_t * mas
* @param zoom zoom factor * @param zoom zoom factor
* @param antialias anti-alias transformations (rotate, zoom) or not * @param antialias anti-alias transformations (rotate, zoom) or not
*/ */
static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, const uint8_t * map_p, lv_draw_img_dsc_t * draw_dsc, bool chroma_key, bool alpha_byte) static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area, const uint8_t * map_p,
lv_draw_img_dsc_t * draw_dsc, bool chroma_key, bool alpha_byte)
{ {
/* Use the clip area as draw area*/ /* Use the clip area as draw area*/
lv_area_t draw_area; lv_area_t draw_area;
@@ -326,7 +356,8 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area,
if(other_mask_cnt == 0 && draw_dsc->angle == 0 && draw_dsc->zoom == LV_IMG_ZOOM_NONE && if(other_mask_cnt == 0 && draw_dsc->angle == 0 && draw_dsc->zoom == LV_IMG_ZOOM_NONE &&
chroma_key == false && alpha_byte == false && chroma_key == false && alpha_byte == false &&
draw_dsc->opa == LV_OPA_COVER && draw_dsc->recolor_opa == LV_OPA_TRANSP) { draw_dsc->opa == LV_OPA_COVER && draw_dsc->recolor_opa == LV_OPA_TRANSP) {
lv_blend_map(clip_area, map_area, (lv_color_t *)map_p, NULL, LV_DRAW_MASK_RES_FULL_COVER, LV_OPA_COVER, draw_dsc->blend_mode); lv_blend_map(clip_area, map_area, (lv_color_t *)map_p, NULL, LV_DRAW_MASK_RES_FULL_COVER, LV_OPA_COVER,
draw_dsc->blend_mode);
} }
/*In the other cases every pixel need to be checked one-by-one*/ /*In the other cases every pixel need to be checked one-by-one*/
else { else {
@@ -406,7 +437,8 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area,
#endif #endif
continue; continue;
} }
} else { }
else {
mask_buf[px_i] = LV_OPA_COVER; mask_buf[px_i] = LV_OPA_COVER;
} }
@@ -415,15 +447,16 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area,
#elif LV_COLOR_DEPTH == 16 #elif LV_COLOR_DEPTH == 16
c.full = map_px[0] + (map_px[1] << 8); c.full = map_px[0] + (map_px[1] << 8);
#elif LV_COLOR_DEPTH == 32 #elif LV_COLOR_DEPTH == 32
c.full = *((uint32_t*)map_px); c.full = *((uint32_t *)map_px);
#endif #endif
if (chroma_key) { if(chroma_key) {
if(c.full == chroma_keyed_color.full) { if(c.full == chroma_keyed_color.full) {
mask_buf[px_i] = LV_OPA_TRANSP; mask_buf[px_i] = LV_OPA_TRANSP;
continue; continue;
} }
} }
} else { }
else {
/*Rotate*/ /*Rotate*/
bool ret; bool ret;
int32_t rot_x = x + (disp_area->x1 + draw_area.x1) - map_area->x1; int32_t rot_x = x + (disp_area->x1 + draw_area.x1) - map_area->x1;
@@ -432,7 +465,8 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area,
if(ret == false) { if(ret == false) {
mask_buf[px_i] = LV_OPA_TRANSP; mask_buf[px_i] = LV_OPA_TRANSP;
continue; continue;
} else { }
else {
mask_buf[px_i] = trans_dsc.res.opa; mask_buf[px_i] = trans_dsc.res.opa;
c.full = trans_dsc.res.color.full; c.full = trans_dsc.res.color.full;
} }
@@ -448,11 +482,13 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area,
/*Apply the masks if any*/ /*Apply the masks if any*/
if(other_mask_cnt) { if(other_mask_cnt) {
lv_draw_mask_res_t mask_res_sub; lv_draw_mask_res_t mask_res_sub;
mask_res_sub = lv_draw_mask_apply(mask_buf + px_i_start, draw_area.x1 + vdb->area.x1, y + draw_area.y1 + vdb->area.y1, lv_area_get_width(&draw_area)); mask_res_sub = lv_draw_mask_apply(mask_buf + px_i_start, draw_area.x1 + vdb->area.x1, y + draw_area.y1 + vdb->area.y1,
lv_area_get_width(&draw_area));
if(mask_res_sub == LV_DRAW_MASK_RES_FULL_TRANSP) { if(mask_res_sub == LV_DRAW_MASK_RES_FULL_TRANSP) {
memset(mask_buf + px_i_start, 0x00, lv_area_get_width(&draw_area)); memset(mask_buf + px_i_start, 0x00, lv_area_get_width(&draw_area));
mask_res = LV_DRAW_MASK_RES_CHANGED; mask_res = LV_DRAW_MASK_RES_CHANGED;
} else if(mask_res_sub == LV_DRAW_MASK_RES_CHANGED) { }
else if(mask_res_sub == LV_DRAW_MASK_RES_CHANGED) {
mask_res = LV_DRAW_MASK_RES_CHANGED; mask_res = LV_DRAW_MASK_RES_CHANGED;
} }
} }
@@ -460,7 +496,8 @@ static void lv_draw_map(const lv_area_t * map_area, const lv_area_t * clip_area,
map_buf_tmp += map_w * px_size_byte; map_buf_tmp += map_w * px_size_byte;
if(px_i + lv_area_get_width(&draw_area) < mask_buf_size) { if(px_i + lv_area_get_width(&draw_area) < mask_buf_size) {
blend_area.y2 ++; blend_area.y2 ++;
} else { }
else {
lv_blend_map(clip_area, &blend_area, map2, mask_buf, mask_res, draw_dsc->opa, draw_dsc->blend_mode); lv_blend_map(clip_area, &blend_area, map2, mask_buf, mask_res, draw_dsc->opa, draw_dsc->blend_mode);
blend_area.y1 = blend_area.y2 + 1; blend_area.y1 = blend_area.y2 + 1;

View File

@@ -40,7 +40,7 @@ typedef struct {
lv_blend_mode_t blend_mode; lv_blend_mode_t blend_mode;
uint8_t antialias :1; uint8_t antialias : 1;
} lv_draw_img_dsc_t; } lv_draw_img_dsc_t;
/********************** /**********************

View File

@@ -32,10 +32,13 @@ typedef uint8_t cmd_state_t;
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area, const lv_font_t * font_p, uint32_t letter, static void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area, const lv_font_t * font_p,
uint32_t letter,
lv_color_t color, lv_opa_t opa); lv_color_t color, lv_opa_t opa);
static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area, const uint8_t * map_p, lv_color_t color, lv_opa_t opa); static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area,
static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area, const uint8_t * map_p, lv_color_t color, lv_opa_t opa); const uint8_t * map_p, lv_color_t color, lv_opa_t opa);
static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area,
const uint8_t * map_p, lv_color_t color, lv_opa_t opa);
static uint8_t hex_char_to_num(char hex); static uint8_t hex_char_to_num(char hex);
@@ -49,8 +52,9 @@ static const uint8_t bpp2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping w
static const uint8_t bpp4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/ static const uint8_t bpp4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
68, 85, 102, 119, 68, 85, 102, 119,
136, 153, 170, 187, 136, 153, 170, 187,
204, 221, 238, 255}; 204, 221, 238, 255
/*clang-format on*/ };
/*clang-format on*/
/********************** /**********************
* MACROS * MACROS
@@ -87,7 +91,7 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab
int32_t w; int32_t w;
/*No need to waste processor time if string is empty*/ /*No need to waste processor time if string is empty*/
if (txt[0] == '\0') return; if(txt[0] == '\0') return;
lv_area_t clipped_area; lv_area_t clipped_area;
bool clip_ok = lv_area_intersect(&clipped_area, coords, mask); bool clip_ok = lv_area_intersect(&clipped_area, coords, mask);
@@ -97,7 +101,8 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab
if((dsc->flag & LV_TXT_FLAG_EXPAND) == 0) { if((dsc->flag & LV_TXT_FLAG_EXPAND) == 0) {
/*Normally use the label's width as width*/ /*Normally use the label's width as width*/
w = lv_area_get_width(coords); w = lv_area_get_width(coords);
} else { }
else {
/*If EXAPND is enabled then not limit the text's width to the object's width*/ /*If EXAPND is enabled then not limit the text's width to the object's width*/
lv_point_t p; lv_point_t p;
lv_txt_get_size(&p, txt, dsc->font, dsc->letter_space, dsc->line_space, LV_COORD_MAX, lv_txt_get_size(&p, txt, dsc->font, dsc->letter_space, dsc->line_space, LV_COORD_MAX,
@@ -209,10 +214,10 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab
cmd_state = CMD_STATE_WAIT; cmd_state = CMD_STATE_WAIT;
i = 0; i = 0;
#if LV_USE_BIDI #if LV_USE_BIDI
char *bidi_txt = lv_mem_buf_get(line_end - line_start + 1); char * bidi_txt = lv_mem_buf_get(line_end - line_start + 1);
lv_bidi_process_paragraph(txt + line_start, bidi_txt, line_end - line_start, dsc->bidi_dir, NULL, 0); lv_bidi_process_paragraph(txt + line_start, bidi_txt, line_end - line_start, dsc->bidi_dir, NULL, 0);
#else #else
const char *bidi_txt = txt + line_start; const char * bidi_txt = txt + line_start;
#endif #endif
while(i < line_end - line_start) { while(i < line_end - line_start) {
@@ -237,9 +242,11 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab
par_start = i; par_start = i;
cmd_state = CMD_STATE_PAR; cmd_state = CMD_STATE_PAR;
continue; continue;
} else if(cmd_state == CMD_STATE_PAR) { /*Other start char in parameter escaped cmd. char */ }
else if(cmd_state == CMD_STATE_PAR) { /*Other start char in parameter escaped cmd. char */
cmd_state = CMD_STATE_WAIT; cmd_state = CMD_STATE_WAIT;
} else if(cmd_state == CMD_STATE_IN) { /*Command end */ }
else if(cmd_state == CMD_STATE_IN) { /*Command end */
cmd_state = CMD_STATE_WAIT; cmd_state = CMD_STATE_WAIT;
continue; continue;
} }
@@ -258,7 +265,8 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab
g = (hex_char_to_num(buf[2]) << 4) + hex_char_to_num(buf[3]); g = (hex_char_to_num(buf[2]) << 4) + hex_char_to_num(buf[3]);
b = (hex_char_to_num(buf[4]) << 4) + hex_char_to_num(buf[5]); b = (hex_char_to_num(buf[4]) << 4) + hex_char_to_num(buf[5]);
recolor = lv_color_make(r, g, b); recolor = lv_color_make(r, g, b);
} else { }
else {
recolor.full = dsc->color.full; recolor.full = dsc->color.full;
} }
cmd_state = CMD_STATE_IN; /*After the parameter the text is in the command*/ cmd_state = CMD_STATE_IN; /*After the parameter the text is in the command*/
@@ -358,7 +366,8 @@ void lv_draw_label(const lv_area_t * coords, const lv_area_t * mask, lv_draw_lab
* @param color color of letter * @param color color of letter
* @param opa opacity of letter (0..255) * @param opa opacity of letter (0..255)
*/ */
static void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area, const lv_font_t * font_p, uint32_t letter, static void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area, const lv_font_t * font_p,
uint32_t letter,
lv_color_t color, lv_opa_t opa) lv_color_t color, lv_opa_t opa)
{ {
if(opa < LV_OPA_MIN) return; if(opa < LV_OPA_MIN) return;
@@ -398,13 +407,15 @@ static void lv_draw_letter(const lv_point_t * pos_p, const lv_area_t * clip_area
if(font_p->subpx) { if(font_p->subpx) {
draw_letter_subpx(pos_x, pos_y, &g, clip_area, map_p, color, opa); draw_letter_subpx(pos_x, pos_y, &g, clip_area, map_p, color, opa);
} else { }
else {
draw_letter_normal(pos_x, pos_y, &g, clip_area, map_p, color, opa); draw_letter_normal(pos_x, pos_y, &g, clip_area, map_p, color, opa);
} }
} }
static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area, const uint8_t * map_p, lv_color_t color, lv_opa_t opa) static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area,
const uint8_t * map_p, lv_color_t color, lv_opa_t opa)
{ {
const uint8_t * bpp_opa_table; const uint8_t * bpp_opa_table;
@@ -482,14 +493,16 @@ static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph
if(letter_px != 0) { if(letter_px != 0) {
if(opa == LV_OPA_COVER) { if(opa == LV_OPA_COVER) {
px_opa = bpp == 8 ? letter_px : bpp_opa_table[letter_px]; px_opa = bpp == 8 ? letter_px : bpp_opa_table[letter_px];
} else { }
else {
px_opa = bpp == 8 ? (uint32_t)((uint32_t)letter_px * opa) >> 8 px_opa = bpp == 8 ? (uint32_t)((uint32_t)letter_px * opa) >> 8
: (uint32_t)((uint32_t)bpp_opa_table[letter_px] * opa) >> 8; : (uint32_t)((uint32_t)bpp_opa_table[letter_px] * opa) >> 8;
} }
mask_buf[mask_p] = px_opa; mask_buf[mask_p] = px_opa;
} else { }
else {
mask_buf[mask_p] = 0; mask_buf[mask_p] = 0;
} }
@@ -497,7 +510,8 @@ static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph
if(col_bit < 8 - bpp) { if(col_bit < 8 - bpp) {
col_bit += bpp; col_bit += bpp;
bitmask = bitmask >> bpp; bitmask = bitmask >> bpp;
} else { }
else {
col_bit = 0; col_bit = 0;
bitmask = bitmask_init; bitmask = bitmask_init;
map_p++; map_p++;
@@ -509,7 +523,8 @@ static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph
/*Apply masks if any*/ /*Apply masks if any*/
if(other_mask_cnt) { if(other_mask_cnt) {
lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf + mask_p_start, fill_area.x1, fill_area.y2, lv_area_get_width(&fill_area)); lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf + mask_p_start, fill_area.x1, fill_area.y2,
lv_area_get_width(&fill_area));
if(mask_res == LV_DRAW_MASK_RES_FULL_TRANSP) { if(mask_res == LV_DRAW_MASK_RES_FULL_TRANSP) {
memset(mask_buf + mask_p_start, 0x00, lv_area_get_width(&fill_area)); memset(mask_buf + mask_p_start, 0x00, lv_area_get_width(&fill_area));
} }
@@ -517,7 +532,8 @@ static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph
if((uint32_t) mask_p + (row_end - row_start) < mask_buf_size) { if((uint32_t) mask_p + (row_end - row_start) < mask_buf_size) {
fill_area.y2 ++; fill_area.y2 ++;
} else { }
else {
lv_blend_fill(clip_area, &fill_area, lv_blend_fill(clip_area, &fill_area,
color, mask_buf, LV_DRAW_MASK_RES_CHANGED, opa, color, mask_buf, LV_DRAW_MASK_RES_CHANGED, opa,
LV_BLEND_MODE_NORMAL); LV_BLEND_MODE_NORMAL);
@@ -545,7 +561,8 @@ static void draw_letter_normal(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph
lv_mem_buf_release(mask_buf); lv_mem_buf_release(mask_buf);
} }
static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area, const uint8_t * map_p, lv_color_t color, lv_opa_t opa) static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_dsc_t * g, const lv_area_t * clip_area,
const uint8_t * map_p, lv_color_t color, lv_opa_t opa)
{ {
const uint8_t * bpp_opa_table; const uint8_t * bpp_opa_table;
uint32_t bitmask_init; uint32_t bitmask_init;
@@ -644,11 +661,13 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_
if(letter_px != 0) { if(letter_px != 0) {
if(opa == LV_OPA_COVER) { if(opa == LV_OPA_COVER) {
px_opa = bpp == 8 ? letter_px : bpp_opa_table[letter_px]; px_opa = bpp == 8 ? letter_px : bpp_opa_table[letter_px];
} else { }
else {
px_opa = bpp == 8 ? (uint32_t)((uint32_t)letter_px * opa) >> 8 px_opa = bpp == 8 ? (uint32_t)((uint32_t)letter_px * opa) >> 8
: (uint32_t)((uint32_t)bpp_opa_table[letter_px] * opa) >> 8; : (uint32_t)((uint32_t)bpp_opa_table[letter_px] * opa) >> 8;
} }
} else { }
else {
px_opa = 0; px_opa = 0;
} }
@@ -664,7 +683,8 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_
#else #else
uint8_t bg_rgb[3] = {vdb_buf_tmp->ch.red, uint8_t bg_rgb[3] = {vdb_buf_tmp->ch.red,
(vdb_buf_tmp->ch.green_h << 3) + vdb_buf_tmp->ch.green_l, (vdb_buf_tmp->ch.green_h << 3) + vdb_buf_tmp->ch.green_l,
vdb_buf_tmp->ch.blue}; vdb_buf_tmp->ch.blue
};
#endif #endif
#if LV_FONT_SUBPX_BGR #if LV_FONT_SUBPX_BGR
@@ -696,7 +716,8 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_
if(col_bit < 8 - bpp) { if(col_bit < 8 - bpp) {
col_bit += bpp; col_bit += bpp;
bitmask = bitmask >> bpp; bitmask = bitmask >> bpp;
} else { }
else {
col_bit = 0; col_bit = 0;
bitmask = bitmask_init; bitmask = bitmask_init;
map_p++; map_p++;
@@ -705,7 +726,8 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_
/*Apply masks if any*/ /*Apply masks if any*/
if(other_mask_cnt) { if(other_mask_cnt) {
lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf + mask_p_start, map_area.x1, map_area.y2, lv_area_get_width(&map_area)); lv_draw_mask_res_t mask_res = lv_draw_mask_apply(mask_buf + mask_p_start, map_area.x1, map_area.y2,
lv_area_get_width(&map_area));
if(mask_res == LV_DRAW_MASK_RES_FULL_TRANSP) { if(mask_res == LV_DRAW_MASK_RES_FULL_TRANSP) {
memset(mask_buf + mask_p_start, 0x00, lv_area_get_width(&map_area)); memset(mask_buf + mask_p_start, 0x00, lv_area_get_width(&map_area));
} }
@@ -713,7 +735,8 @@ static void draw_letter_subpx(lv_coord_t pos_x, lv_coord_t pos_y, lv_font_glyph_
if((uint32_t) mask_p + (row_end - row_start) < mask_buf_size) { if((uint32_t) mask_p + (row_end - row_start) < mask_buf_size) {
map_area.y2 ++; map_area.y2 ++;
} else { }
else {
lv_blend_map(clip_area, &map_area, color_buf, mask_buf, LV_DRAW_MASK_RES_CHANGED, opa, LV_BLEND_MODE_NORMAL); lv_blend_map(clip_area, &map_area, color_buf, mask_buf, LV_DRAW_MASK_RES_CHANGED, opa, LV_BLEND_MODE_NORMAL);
map_area.y1 = map_area.y2 + 1; map_area.y1 = map_area.y2 + 1;
@@ -752,17 +775,32 @@ static uint8_t hex_char_to_num(char hex)
if(hex >= '0' && hex <= '9') { if(hex >= '0' && hex <= '9') {
result = hex - '0'; result = hex - '0';
} else { }
else {
if(hex >= 'a') hex -= 'a' - 'A'; /*Convert to upper case*/ if(hex >= 'a') hex -= 'a' - 'A'; /*Convert to upper case*/
switch(hex) { switch(hex) {
case 'A': result = 10; break; case 'A':
case 'B': result = 11; break; result = 10;
case 'C': result = 12; break; break;
case 'D': result = 13; break; case 'B':
case 'E': result = 14; break; result = 11;
case 'F': result = 15; break; break;
default: result = 0; break; case 'C':
result = 12;
break;
case 'D':
result = 13;
break;
case 'E':
result = 14;
break;
case 'F':
result = 15;
break;
default:
result = 0;
break;
} }
} }

View File

@@ -41,7 +41,7 @@ typedef struct {
lv_txt_flag_t flag; lv_txt_flag_t flag;
lv_text_decor_t decor; lv_text_decor_t decor;
lv_blend_mode_t blend_mode; lv_blend_mode_t blend_mode;
}lv_draw_label_dsc_t; } lv_draw_label_dsc_t;
/** Store some info to speed up drawing of very large texts /** Store some info to speed up drawing of very large texts
* It takes a lot of time to get the first visible character because * It takes a lot of time to get the first visible character because
@@ -58,7 +58,7 @@ typedef struct {
/** The 'y1' coordinate of the label when the hint was saved. /** The 'y1' coordinate of the label when the hint was saved.
* Used to invalidate the hint if the label has moved too much. */ * Used to invalidate the hint if the label has moved too much. */
int32_t coord_y; int32_t coord_y;
}lv_draw_label_hint_t; } lv_draw_label_hint_t;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES

View File

@@ -24,9 +24,12 @@
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc); static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip,
static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc); lv_draw_line_dsc_t * dsc);
static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc); static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip,
lv_draw_line_dsc_t * dsc);
static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip,
lv_draw_line_dsc_t * dsc);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@@ -56,7 +59,8 @@ void lv_draw_line_dsc_init(lv_draw_line_dsc_t * dsc)
* @param style pointer to a line's style * @param style pointer to a line's style
* @param opa_scale scale down all opacities by the factor * @param opa_scale scale down all opacities by the factor
*/ */
void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc) void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip,
lv_draw_line_dsc_t * dsc)
{ {
if(dsc->width == 0) return; if(dsc->width == 0) return;
if(dsc->opa <= LV_OPA_MIN) return; if(dsc->opa <= LV_OPA_MIN) return;
@@ -64,10 +68,10 @@ void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv
if(point1->x == point2->x && point1->y == point2->y) return; if(point1->x == point2->x && point1->y == point2->y) return;
lv_area_t clip_line; lv_area_t clip_line;
clip_line.x1 = LV_MATH_MIN(point1->x, point2->x) - dsc->width/2; clip_line.x1 = LV_MATH_MIN(point1->x, point2->x) - dsc->width / 2;
clip_line.x2 = LV_MATH_MAX(point1->x, point2->x) + dsc->width/2; clip_line.x2 = LV_MATH_MAX(point1->x, point2->x) + dsc->width / 2;
clip_line.y1 = LV_MATH_MIN(point1->y, point2->y) - dsc->width/2; clip_line.y1 = LV_MATH_MIN(point1->y, point2->y) - dsc->width / 2;
clip_line.y2 = LV_MATH_MAX(point1->y, point2->y) + dsc->width/2; clip_line.y2 = LV_MATH_MAX(point1->y, point2->y) + dsc->width / 2;
bool is_common; bool is_common;
is_common = lv_area_intersect(&clip_line, &clip_line, clip); is_common = lv_area_intersect(&clip_line, &clip_line, clip);
@@ -111,7 +115,8 @@ void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc) static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip,
lv_draw_line_dsc_t * dsc)
{ {
lv_opa_t opa = dsc->opa; lv_opa_t opa = dsc->opa;
@@ -139,7 +144,7 @@ static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2,
/*If there is no mask then simply draw a rectangle*/ /*If there is no mask then simply draw a rectangle*/
if(simple_mode) { if(simple_mode) {
lv_blend_fill(clip, &draw_area, lv_blend_fill(clip, &draw_area,
dsc->color, NULL, LV_DRAW_MASK_RES_FULL_COVER,opa, dsc->color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa,
LV_BLEND_MODE_NORMAL); LV_BLEND_MODE_NORMAL);
} }
/*If there other mask apply it*/ /*If there other mask apply it*/
@@ -182,9 +187,11 @@ static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2,
int16_t diff = dsc->dash_width - dash_cnt; int16_t diff = dsc->dash_width - dash_cnt;
i += diff; i += diff;
dash_cnt += diff; dash_cnt += diff;
} else if(dash_cnt >= dsc->dash_gap + dsc->dash_width) { }
else if(dash_cnt >= dsc->dash_gap + dsc->dash_width) {
dash_cnt = 0; dash_cnt = 0;
} else { }
else {
mask_buf[i] = 0x00; mask_buf[i] = 0x00;
} }
} }
@@ -205,7 +212,8 @@ static void draw_line_hor(const lv_point_t * point1, const lv_point_t * point2,
} }
static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc) static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip,
lv_draw_line_dsc_t * dsc)
{ {
lv_opa_t opa = dsc->opa; lv_opa_t opa = dsc->opa;
@@ -294,7 +302,8 @@ static void draw_line_ver(const lv_point_t * point1, const lv_point_t * point2,
} }
static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip, lv_draw_line_dsc_t * dsc) static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * clip,
lv_draw_line_dsc_t * dsc)
{ {
lv_opa_t opa = dsc->opa; lv_opa_t opa = dsc->opa;
@@ -306,7 +315,8 @@ static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2,
p2.y = point2->y; p2.y = point2->y;
p1.x = point1->x; p1.x = point1->x;
p2.x = point2->x; p2.x = point2->x;
} else { }
else {
p1.y = point2->y; p1.y = point2->y;
p2.y = point1->y; p2.y = point1->y;
p1.x = point2->x; p1.x = point2->x;
@@ -353,20 +363,28 @@ static void draw_line_skew(const lv_point_t * point1, const lv_point_t * point2,
if(flat) { if(flat) {
if(xdiff > 0) { if(xdiff > 0) {
lv_draw_mask_line_points_init(&mask_left_param, p1.x, p1.y - w_half0, p2.x, p2.y - w_half0, LV_DRAW_MASK_LINE_SIDE_LEFT); lv_draw_mask_line_points_init(&mask_left_param, p1.x, p1.y - w_half0, p2.x, p2.y - w_half0,
lv_draw_mask_line_points_init(&mask_right_param, p1.x, p1.y + w_half1, p2.x, p2.y + w_half1, LV_DRAW_MASK_LINE_SIDE_RIGHT); LV_DRAW_MASK_LINE_SIDE_LEFT);
} else { lv_draw_mask_line_points_init(&mask_right_param, p1.x, p1.y + w_half1, p2.x, p2.y + w_half1,
lv_draw_mask_line_points_init(&mask_left_param, p1.x, p1.y + w_half1, p2.x, p2.y + w_half1, LV_DRAW_MASK_LINE_SIDE_LEFT); LV_DRAW_MASK_LINE_SIDE_RIGHT);
lv_draw_mask_line_points_init(&mask_right_param, p1.x, p1.y - w_half0, p2.x, p2.y - w_half0, LV_DRAW_MASK_LINE_SIDE_RIGHT);
} }
} else { else {
lv_draw_mask_line_points_init(&mask_left_param, p1.x + w_half1, p1.y, p2.x + w_half1, p2.y, LV_DRAW_MASK_LINE_SIDE_LEFT); lv_draw_mask_line_points_init(&mask_left_param, p1.x, p1.y + w_half1, p2.x, p2.y + w_half1,
lv_draw_mask_line_points_init(&mask_right_param, p1.x - w_half0, p1.y, p2.x - w_half0, p2.y, LV_DRAW_MASK_LINE_SIDE_RIGHT); LV_DRAW_MASK_LINE_SIDE_LEFT);
lv_draw_mask_line_points_init(&mask_right_param, p1.x, p1.y - w_half0, p2.x, p2.y - w_half0,
LV_DRAW_MASK_LINE_SIDE_RIGHT);
}
}
else {
lv_draw_mask_line_points_init(&mask_left_param, p1.x + w_half1, p1.y, p2.x + w_half1, p2.y,
LV_DRAW_MASK_LINE_SIDE_LEFT);
lv_draw_mask_line_points_init(&mask_right_param, p1.x - w_half0, p1.y, p2.x - w_half0, p2.y,
LV_DRAW_MASK_LINE_SIDE_RIGHT);
} }
/*Use the normal vector for the endings*/ /*Use the normal vector for the endings*/
lv_draw_mask_line_points_init(&mask_top_param, p1.x, p1.y, p1.x - ydiff, p1.y + xdiff, LV_DRAW_MASK_LINE_SIDE_BOTTOM); lv_draw_mask_line_points_init(&mask_top_param, p1.x, p1.y, p1.x - ydiff, p1.y + xdiff, LV_DRAW_MASK_LINE_SIDE_BOTTOM);
lv_draw_mask_line_points_init(&mask_bottom_param, p2.x, p2.y,p2.x - ydiff, p2.y + xdiff, LV_DRAW_MASK_LINE_SIDE_TOP); lv_draw_mask_line_points_init(&mask_bottom_param, p2.x, p2.y, p2.x - ydiff, p2.y + xdiff, LV_DRAW_MASK_LINE_SIDE_TOP);
int16_t mask_left_id = lv_draw_mask_add(&mask_left_param, NULL); int16_t mask_left_id = lv_draw_mask_add(&mask_left_param, NULL);
int16_t mask_right_id = lv_draw_mask_add(&mask_right_param, NULL); int16_t mask_right_id = lv_draw_mask_add(&mask_right_param, NULL);

View File

@@ -28,10 +28,10 @@ typedef struct {
lv_style_int_t dash_width; lv_style_int_t dash_width;
lv_style_int_t dash_gap; lv_style_int_t dash_gap;
lv_opa_t opa; lv_opa_t opa;
lv_blend_mode_t blend_mode :2; lv_blend_mode_t blend_mode : 2;
uint8_t round_start :1; uint8_t round_start : 1;
uint8_t round_end :1; uint8_t round_end : 1;
}lv_draw_line_dsc_t; } lv_draw_line_dsc_t;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
@@ -45,7 +45,8 @@ typedef struct {
* @param style pointer to a line's style * @param style pointer to a line's style
* @param opa_scale scale down all opacities by the factor * @param opa_scale scale down all opacities by the factor
*/ */
void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask, lv_draw_line_dsc_t * dsc); void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask,
lv_draw_line_dsc_t * dsc);
void lv_draw_line_dsc_init(lv_draw_line_dsc_t * dsc); void lv_draw_line_dsc_init(lv_draw_line_dsc_t * dsc);

View File

@@ -19,23 +19,29 @@
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
typedef struct typedef struct {
{
void * param; void * param;
void * custom_id; void * custom_id;
}lv_mask_saved_t; } lv_mask_saved_t;
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_line_param_t * param); static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_radius_param_t * param); lv_draw_mask_line_param_t * param);
static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_angle_param_t * param); static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
static lv_draw_mask_res_t lv_draw_mask_fade(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_fade_param_t * param); lv_draw_mask_radius_param_t * param);
static lv_draw_mask_res_t lv_draw_mask_map(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_map_param_t * param); static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
lv_draw_mask_angle_param_t * param);
static lv_draw_mask_res_t lv_draw_mask_fade(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
lv_draw_mask_fade_param_t * param);
static lv_draw_mask_res_t lv_draw_mask_map(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
lv_draw_mask_map_param_t * param);
static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_line_param_t * p); static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_line_param_t * p); lv_draw_mask_line_param_t * p);
static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
lv_draw_mask_line_param_t * p);
static inline lv_opa_t mask_mix(lv_opa_t mask_act, lv_opa_t mask_new); static inline lv_opa_t mask_mix(lv_opa_t mask_act, lv_opa_t mask_new);
@@ -98,7 +104,7 @@ lv_draw_mask_res_t lv_draw_mask_apply(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_
for(i = 0; i < LV_MASK_MAX_NUM; i++) { for(i = 0; i < LV_MASK_MAX_NUM; i++) {
if(mask_list[i].param) { if(mask_list[i].param) {
dsc = mask_list[i].param; dsc = mask_list[i].param;
res = dsc->cb(mask_buf, abs_x, abs_y, len, (void*)mask_list[i].param); res = dsc->cb(mask_buf, abs_x, abs_y, len, (void *)mask_list[i].param);
if(res == LV_DRAW_MASK_RES_FULL_TRANSP) return LV_DRAW_MASK_RES_FULL_TRANSP; if(res == LV_DRAW_MASK_RES_FULL_TRANSP) return LV_DRAW_MASK_RES_FULL_TRANSP;
else if(res == LV_DRAW_MASK_RES_CHANGED) changed = true; else if(res == LV_DRAW_MASK_RES_CHANGED) changed = true;
} }
@@ -171,7 +177,8 @@ uint8_t lv_draw_mask_get_cnt(void)
* With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept
* With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept
*/ */
void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t p1y, lv_coord_t p2x, lv_coord_t p2y, lv_draw_mask_line_side_t side) void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t p1y, lv_coord_t p2x,
lv_coord_t p2y, lv_draw_mask_line_side_t side)
{ {
memset(param, 0x00, sizeof(lv_draw_mask_line_param_t)); memset(param, 0x00, sizeof(lv_draw_mask_line_param_t));
@@ -194,14 +201,14 @@ void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t
param->origo.x = p1x; param->origo.x = p1x;
param->origo.y = p1y; param->origo.y = p1y;
param->flat = (LV_MATH_ABS(p2x-p1x) > LV_MATH_ABS(p2y-p1y)) ? 1 : 0; param->flat = (LV_MATH_ABS(p2x - p1x) > LV_MATH_ABS(p2y - p1y)) ? 1 : 0;
param->yx_steep = 0; param->yx_steep = 0;
param->xy_steep = 0; param->xy_steep = 0;
param->dsc.cb = (lv_draw_mask_cb_t)lv_draw_mask_line; param->dsc.cb = (lv_draw_mask_cb_t)lv_draw_mask_line;
param->dsc.type = LV_DRAW_MASK_TYPE_LINE; param->dsc.type = LV_DRAW_MASK_TYPE_LINE;
int32_t dx = p2x-p1x; int32_t dx = p2x - p1x;
int32_t dy = p2y-p1y; int32_t dy = p2y - p1y;
if(param->flat) { if(param->flat) {
/*Normalize the steep. Delta x should be relative to delta x = 1024*/ /*Normalize the steep. Delta x should be relative to delta x = 1024*/
@@ -217,7 +224,8 @@ void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t
param->xy_steep = (m * dx) >> 10; param->xy_steep = (m * dx) >> 10;
} }
param->steep = param->yx_steep; param->steep = param->yx_steep;
} else { }
else {
/*Normalize the steep. Delta y should be relative to delta x = 1024*/ /*Normalize the steep. Delta y should be relative to delta x = 1024*/
int32_t m; int32_t m;
@@ -258,7 +266,8 @@ void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t
* With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept
* With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept
*/ */
void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t* param, lv_coord_t p1x, lv_coord_t py, int16_t angle, lv_draw_mask_line_side_t side) void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t py, int16_t angle,
lv_draw_mask_line_side_t side)
{ {
/* Find an optimal degree. /* Find an optimal degree.
* lv_mask_line_points_init will swap the points to keep the smaller y in p1 * lv_mask_line_points_init will swap the points to keep the smaller y in p1
@@ -285,7 +294,8 @@ void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t* param, lv_coord_t p
* @param start_angle start angle in degrees. 0 deg on the right, 90 deg, on the bottom * @param start_angle start angle in degrees. 0 deg on the right, 90 deg, on the bottom
* @param end_angle end angle * @param end_angle end angle
*/ */
void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vertex_x, lv_coord_t vertex_y, lv_coord_t start_angle, lv_coord_t end_angle) void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vertex_x, lv_coord_t vertex_y,
lv_coord_t start_angle, lv_coord_t end_angle)
{ {
lv_draw_mask_line_side_t start_side; lv_draw_mask_line_side_t start_side;
lv_draw_mask_line_side_t end_side; lv_draw_mask_line_side_t end_side;
@@ -303,7 +313,8 @@ void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vert
if(end_angle < start_angle) { if(end_angle < start_angle) {
param->delta_deg = 360 - start_angle + end_angle; param->delta_deg = 360 - start_angle + end_angle;
} else { }
else {
param->delta_deg = LV_MATH_ABS(end_angle - start_angle); param->delta_deg = LV_MATH_ABS(end_angle - start_angle);
} }
@@ -319,7 +330,8 @@ void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vert
} }
else if(start_angle >= 180 && start_angle < 360) { else if(start_angle >= 180 && start_angle < 360) {
start_side = LV_DRAW_MASK_LINE_SIDE_RIGHT; start_side = LV_DRAW_MASK_LINE_SIDE_RIGHT;
} else { }
else {
LV_DEBUG_ASSERT(false, "Unexpected start_angle", start_angle); LV_DEBUG_ASSERT(false, "Unexpected start_angle", start_angle);
return; return;
} }
@@ -329,7 +341,8 @@ void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vert
} }
else if(end_angle >= 180 && end_angle < 360) { else if(end_angle >= 180 && end_angle < 360) {
end_side = LV_DRAW_MASK_LINE_SIDE_LEFT; end_side = LV_DRAW_MASK_LINE_SIDE_LEFT;
} else { }
else {
LV_DEBUG_ASSERT(false, "Unexpected end_angle", end_angle); LV_DEBUG_ASSERT(false, "Unexpected end_angle", end_angle);
return; return;
} }
@@ -369,12 +382,13 @@ void lv_draw_mask_radius_init(lv_draw_mask_radius_param_t * param, const lv_area
* @param opa_bottom opacity at the bottom * @param opa_bottom opacity at the bottom
* @param y_bottom at which coordinate reach `opa_bottom`. * @param y_bottom at which coordinate reach `opa_bottom`.
*/ */
void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t * param, lv_area_t * coords, lv_opa_t opa_top, lv_coord_t y_top, lv_opa_t opa_bottom, lv_coord_t y_bottom) void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t * param, lv_area_t * coords, lv_opa_t opa_top, lv_coord_t y_top,
lv_opa_t opa_bottom, lv_coord_t y_bottom)
{ {
lv_area_copy(&param->cfg.coords, coords); lv_area_copy(&param->cfg.coords, coords);
param->cfg.opa_top= opa_top; param->cfg.opa_top = opa_top;
param->cfg.opa_bottom = opa_bottom; param->cfg.opa_bottom = opa_bottom;
param->cfg.y_top= y_top; param->cfg.y_top = y_top;
param->cfg.y_bottom = y_bottom; param->cfg.y_bottom = y_bottom;
param->dsc.cb = (lv_draw_mask_cb_t)lv_draw_mask_fade; param->dsc.cb = (lv_draw_mask_cb_t)lv_draw_mask_fade;
param->dsc.type = LV_DRAW_MASK_TYPE_FADE; param->dsc.type = LV_DRAW_MASK_TYPE_FADE;
@@ -400,7 +414,8 @@ void lv_draw_mask_map_init(lv_draw_mask_map_param_t * param, lv_area_t * coords,
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_line_param_t * p) static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
lv_draw_mask_line_param_t * p)
{ {
/*Make to points relative to the vertex*/ /*Make to points relative to the vertex*/
abs_y -= p->origo.y; abs_y -= p->origo.y;
@@ -411,8 +426,9 @@ static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_
/*Horizontal*/ /*Horizontal*/
if(p->flat) { if(p->flat) {
/*Non sense: Can't be on the right/left of a horizontal line*/ /*Non sense: Can't be on the right/left of a horizontal line*/
if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_LEFT || p->cfg.side == LV_DRAW_MASK_LINE_SIDE_RIGHT) return LV_DRAW_MASK_RES_FULL_COVER; if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_LEFT ||
else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_TOP && abs_y+1 < 0) return LV_DRAW_MASK_RES_FULL_COVER; p->cfg.side == LV_DRAW_MASK_LINE_SIDE_RIGHT) return LV_DRAW_MASK_RES_FULL_COVER;
else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_TOP && abs_y + 1 < 0) return LV_DRAW_MASK_RES_FULL_COVER;
else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_BOTTOM && abs_y > 0) return LV_DRAW_MASK_RES_FULL_COVER; else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_BOTTOM && abs_y > 0) return LV_DRAW_MASK_RES_FULL_COVER;
else { else {
return LV_DRAW_MASK_RES_FULL_TRANSP; return LV_DRAW_MASK_RES_FULL_TRANSP;
@@ -421,7 +437,8 @@ static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_
/*Vertical*/ /*Vertical*/
else { else {
/*Non sense: Can't be on the top/bottom of a vertical line*/ /*Non sense: Can't be on the top/bottom of a vertical line*/
if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_TOP || p->cfg.side == LV_DRAW_MASK_LINE_SIDE_BOTTOM) return LV_DRAW_MASK_RES_FULL_COVER; if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_TOP ||
p->cfg.side == LV_DRAW_MASK_LINE_SIDE_BOTTOM) return LV_DRAW_MASK_RES_FULL_COVER;
else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_RIGHT && abs_x > 0) return LV_DRAW_MASK_RES_FULL_COVER; else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_RIGHT && abs_x > 0) return LV_DRAW_MASK_RES_FULL_COVER;
else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_LEFT) { else if(p->cfg.side == LV_DRAW_MASK_LINE_SIDE_LEFT) {
if(abs_x + len < 0) return LV_DRAW_MASK_RES_FULL_COVER; if(abs_x + len < 0) return LV_DRAW_MASK_RES_FULL_COVER;
@@ -438,7 +455,7 @@ static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_
int32_t k = - abs_x; int32_t k = - abs_x;
if(k < 0) k = 0; if(k < 0) k = 0;
if(k >= len) return LV_DRAW_MASK_RES_FULL_TRANSP; if(k >= len) return LV_DRAW_MASK_RES_FULL_TRANSP;
else if(k >= 0 && k < len) memset(&mask_buf[0], 0x00,k); else if(k >= 0 && k < len) memset(&mask_buf[0], 0x00, k);
return LV_DRAW_MASK_RES_CHANGED; return LV_DRAW_MASK_RES_CHANGED;
} }
} }
@@ -448,14 +465,16 @@ static lv_draw_mask_res_t lv_draw_mask_line(lv_opa_t * mask_buf, lv_coord_t abs_
lv_draw_mask_res_t res; lv_draw_mask_res_t res;
if(p->flat) { if(p->flat) {
res = line_mask_flat(mask_buf, abs_x, abs_y, len, p); res = line_mask_flat(mask_buf, abs_x, abs_y, len, p);
} else { }
else {
res = line_mask_steep(mask_buf, abs_x, abs_y, len, p); res = line_mask_steep(mask_buf, abs_x, abs_y, len, p);
} }
return res; return res;
} }
static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_line_param_t * p) static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
lv_draw_mask_line_param_t * p)
{ {
int32_t y_at_x; int32_t y_at_x;
y_at_x = (int32_t)((int32_t)p->yx_steep * abs_x) >> 10; y_at_x = (int32_t)((int32_t)p->yx_steep * abs_x) >> 10;
@@ -464,15 +483,18 @@ static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x,
if(y_at_x > abs_y) { if(y_at_x > abs_y) {
if(p->inv) { if(p->inv) {
return LV_DRAW_MASK_RES_FULL_COVER; return LV_DRAW_MASK_RES_FULL_COVER;
} else { }
else {
return LV_DRAW_MASK_RES_FULL_TRANSP; return LV_DRAW_MASK_RES_FULL_TRANSP;
} }
} }
} else { }
else {
if(y_at_x < abs_y) { if(y_at_x < abs_y) {
if(p->inv) { if(p->inv) {
return LV_DRAW_MASK_RES_FULL_COVER; return LV_DRAW_MASK_RES_FULL_COVER;
} else { }
else {
return LV_DRAW_MASK_RES_FULL_TRANSP; return LV_DRAW_MASK_RES_FULL_TRANSP;
} }
} }
@@ -485,15 +507,18 @@ static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x,
if(y_at_x < abs_y) { if(y_at_x < abs_y) {
if(p->inv) { if(p->inv) {
return LV_DRAW_MASK_RES_FULL_TRANSP; return LV_DRAW_MASK_RES_FULL_TRANSP;
} else { }
else {
return LV_DRAW_MASK_RES_FULL_COVER; return LV_DRAW_MASK_RES_FULL_COVER;
} }
} }
} else { }
else {
if(y_at_x > abs_y) { if(y_at_x > abs_y) {
if(p->inv) { if(p->inv) {
return LV_DRAW_MASK_RES_FULL_TRANSP; return LV_DRAW_MASK_RES_FULL_TRANSP;
} else { }
else {
return LV_DRAW_MASK_RES_FULL_COVER; return LV_DRAW_MASK_RES_FULL_COVER;
} }
} }
@@ -514,7 +539,7 @@ static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x,
if(xef) { if(xef) {
if(k >= 0 && k < len) { if(k >= 0 && k < len) {
m = 255 - (((255-xef) * (255 - px_h)) >> 9); m = 255 - (((255 - xef) * (255 - px_h)) >> 9);
if(p->inv) m = 255 - m; if(p->inv) m = 255 - m;
mask_buf[k] = mask_mix(mask_buf[k], m); mask_buf[k] = mask_mix(mask_buf[k], m);
} }
@@ -547,11 +572,11 @@ static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x,
if(k > len) { if(k > len) {
return LV_DRAW_MASK_RES_FULL_TRANSP; return LV_DRAW_MASK_RES_FULL_TRANSP;
} }
if(k >= 0) if(k >= 0) {
{
memset(&mask_buf[0], 0x00, k); memset(&mask_buf[0], 0x00, k);
} }
} else { }
else {
k++; k++;
if(k < 0) { if(k < 0) {
return LV_DRAW_MASK_RES_FULL_TRANSP; return LV_DRAW_MASK_RES_FULL_TRANSP;
@@ -564,7 +589,8 @@ static lv_draw_mask_res_t line_mask_flat(lv_opa_t * mask_buf, lv_coord_t abs_x,
return LV_DRAW_MASK_RES_CHANGED; return LV_DRAW_MASK_RES_CHANGED;
} }
static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_line_param_t * p) static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
lv_draw_mask_line_param_t * p)
{ {
int32_t k; int32_t k;
int32_t x_at_y; int32_t x_at_y;
@@ -575,7 +601,8 @@ static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x,
if(x_at_y < abs_x) { if(x_at_y < abs_x) {
if(p->inv) { if(p->inv) {
return LV_DRAW_MASK_RES_FULL_COVER; return LV_DRAW_MASK_RES_FULL_COVER;
} else { }
else {
return LV_DRAW_MASK_RES_FULL_TRANSP; return LV_DRAW_MASK_RES_FULL_TRANSP;
} }
} }
@@ -586,7 +613,8 @@ static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x,
if(x_at_y > abs_x + len) { if(x_at_y > abs_x + len) {
if(p->inv) { if(p->inv) {
return LV_DRAW_MASK_RES_FULL_TRANSP; return LV_DRAW_MASK_RES_FULL_TRANSP;
} else { }
else {
return LV_DRAW_MASK_RES_FULL_COVER; return LV_DRAW_MASK_RES_FULL_COVER;
} }
} }
@@ -623,32 +651,34 @@ static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x,
} }
if(k >= 0) memset(&mask_buf[0], 0x00, k); if(k >= 0) memset(&mask_buf[0], 0x00, k);
} else { }
else {
if(k > len) k = len; if(k > len) k = len;
if(k == 0) return LV_DRAW_MASK_RES_FULL_TRANSP; if(k == 0) return LV_DRAW_MASK_RES_FULL_TRANSP;
else if(k > 0) memset(&mask_buf[k] ,0x00, len - k); else if(k > 0) memset(&mask_buf[k], 0x00, len - k);
} }
} else { }
else {
int32_t y_inters; int32_t y_inters;
if(p->xy_steep < 0) { if(p->xy_steep < 0) {
y_inters = (xef * (-p->yx_steep)) >> 10; y_inters = (xef * (-p->yx_steep)) >> 10;
if(k >= 0 && k < len ) { if(k >= 0 && k < len) {
m = (y_inters * xef) >> 9; m = (y_inters * xef) >> 9;
if(p->inv) m = 255 - m; if(p->inv) m = 255 - m;
mask_buf[k] = mask_mix(mask_buf[k], m); mask_buf[k] = mask_mix(mask_buf[k], m);
} }
k--; k--;
int32_t x_inters = ((255-y_inters) * (-p->xy_steep)) >> 10; int32_t x_inters = ((255 - y_inters) * (-p->xy_steep)) >> 10;
if(k >= 0 && k < len ) { if(k >= 0 && k < len) {
m = 255-(((255-y_inters) * x_inters) >> 9); m = 255 - (((255 - y_inters) * x_inters) >> 9);
if(p->inv) m = 255 - m; if(p->inv) m = 255 - m;
mask_buf[k] = mask_mix(mask_buf[k], m); mask_buf[k] = mask_mix(mask_buf[k], m);
} }
k+=2; k += 2;
if(p->inv) { if(p->inv) {
k = xei - abs_x - 1; k = xei - abs_x - 1;
@@ -656,24 +686,26 @@ static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x,
if(k > len) k = len; if(k > len) k = len;
else if(k > 0) memset(&mask_buf[0], 0x00, k); else if(k > 0) memset(&mask_buf[0], 0x00, k);
} else { }
else {
if(k > len) return LV_DRAW_MASK_RES_FULL_COVER; if(k > len) return LV_DRAW_MASK_RES_FULL_COVER;
if(k >= 0) memset(&mask_buf[k] ,0x00, len - k); if(k >= 0) memset(&mask_buf[k], 0x00, len - k);
} }
} else { }
y_inters = ((255-xef) * p->yx_steep) >> 10; else {
if(k >= 0 && k < len ) { y_inters = ((255 - xef) * p->yx_steep) >> 10;
m = 255 - ((y_inters * (255-xef)) >> 9); if(k >= 0 && k < len) {
m = 255 - ((y_inters * (255 - xef)) >> 9);
if(p->inv) m = 255 - m; if(p->inv) m = 255 - m;
mask_buf[k] = mask_mix(mask_buf[k], m); mask_buf[k] = mask_mix(mask_buf[k], m);
} }
k++; k++;
int32_t x_inters = ((255-y_inters) * p->xy_steep) >> 10; int32_t x_inters = ((255 - y_inters) * p->xy_steep) >> 10;
if(k >= 0 && k < len ) { if(k >= 0 && k < len) {
m = ((255-y_inters) * x_inters) >> 9; m = ((255 - y_inters) * x_inters) >> 9;
if(p->inv) m = 255 - m; if(p->inv) m = 255 - m;
mask_buf[k] = mask_mix(mask_buf[k], m); mask_buf[k] = mask_mix(mask_buf[k], m);
} }
@@ -684,10 +716,11 @@ static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x,
if(k > len) return LV_DRAW_MASK_RES_FULL_TRANSP; if(k > len) return LV_DRAW_MASK_RES_FULL_TRANSP;
if(k >= 0) memset(&mask_buf[0], 0x00, k); if(k >= 0) memset(&mask_buf[0], 0x00, k);
} else { }
else {
if(k > len) k = len; if(k > len) k = len;
if(k == 0) return LV_DRAW_MASK_RES_FULL_TRANSP; if(k == 0) return LV_DRAW_MASK_RES_FULL_TRANSP;
else if(k > 0) memset(&mask_buf[k] ,0x00, len - k); else if(k > 0) memset(&mask_buf[k], 0x00, len - k);
} }
} }
@@ -697,7 +730,8 @@ static lv_draw_mask_res_t line_mask_steep(lv_opa_t * mask_buf, lv_coord_t abs_x,
} }
static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_angle_param_t * p) static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
lv_draw_mask_angle_param_t * p)
{ {
int32_t rel_y = abs_y - p->cfg.vertex_p.y; int32_t rel_y = abs_y - p->cfg.vertex_p.y;
int32_t rel_x = abs_x - p->cfg.vertex_p.x; int32_t rel_x = abs_x - p->cfg.vertex_p.x;
@@ -713,7 +747,7 @@ static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs
/*Start angle mask can work only from the end of end angle mask */ /*Start angle mask can work only from the end of end angle mask */
int32_t end_angle_first = (rel_y * p->end_line.xy_steep) >> 10; int32_t end_angle_first = (rel_y * p->end_line.xy_steep) >> 10;
int32_t start_angle_last= ((rel_y+1) * p->start_line.xy_steep) >> 10; int32_t start_angle_last = ((rel_y + 1) * p->start_line.xy_steep) >> 10;
/*Do not let the line end cross the vertex else it will affect the opposite part*/ /*Do not let the line end cross the vertex else it will affect the opposite part*/
@@ -742,9 +776,9 @@ static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs
if(tmp > len) tmp = len; if(tmp > len) tmp = len;
if(tmp < 0) tmp = 0; if(tmp < 0) tmp = 0;
res2 = lv_draw_mask_line(&mask_buf[tmp], abs_x+tmp, abs_y, len-tmp, &p->end_line); res2 = lv_draw_mask_line(&mask_buf[tmp], abs_x + tmp, abs_y, len - tmp, &p->end_line);
if(res2 == LV_DRAW_MASK_RES_FULL_TRANSP) { if(res2 == LV_DRAW_MASK_RES_FULL_TRANSP) {
memset(&mask_buf[tmp], 0x00, len-tmp); memset(&mask_buf[tmp], 0x00, len - tmp);
} }
if(res1 == res2) return res1; if(res1 == res2) return res1;
else return LV_DRAW_MASK_RES_CHANGED; else return LV_DRAW_MASK_RES_CHANGED;
@@ -757,7 +791,7 @@ static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs
/*Start angle mask can work only from the end of end angle mask */ /*Start angle mask can work only from the end of end angle mask */
int32_t end_angle_first = (rel_y * p->end_line.xy_steep) >> 10; int32_t end_angle_first = (rel_y * p->end_line.xy_steep) >> 10;
int32_t start_angle_last= ((rel_y+1) * p->start_line.xy_steep) >> 10; int32_t start_angle_last = ((rel_y + 1) * p->start_line.xy_steep) >> 10;
/*Do not let the line end cross the vertex else it will affect the opposite part*/ /*Do not let the line end cross the vertex else it will affect the opposite part*/
if(p->cfg.start_angle > 270 && p->cfg.start_angle <= 359 && start_angle_last < 0) start_angle_last = 0; if(p->cfg.start_angle > 270 && p->cfg.start_angle <= 359 && start_angle_last < 0) start_angle_last = 0;
@@ -776,7 +810,7 @@ static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs
int32_t tmp = start_angle_last + dist - rel_x; int32_t tmp = start_angle_last + dist - rel_x;
if(tmp > len) tmp = len; if(tmp > len) tmp = len;
if(tmp > 0) { if(tmp > 0) {
res1 = lv_draw_mask_line(&mask_buf[0], abs_x, abs_y, tmp, (lv_draw_mask_line_param_t*)&p->end_line); res1 = lv_draw_mask_line(&mask_buf[0], abs_x, abs_y, tmp, (lv_draw_mask_line_param_t *)&p->end_line);
if(res1 == LV_DRAW_MASK_RES_FULL_TRANSP) { if(res1 == LV_DRAW_MASK_RES_FULL_TRANSP) {
memset(&mask_buf[0], 0x00, tmp); memset(&mask_buf[0], 0x00, tmp);
} }
@@ -784,9 +818,9 @@ static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs
if(tmp > len) tmp = len; if(tmp > len) tmp = len;
if(tmp < 0) tmp = 0; if(tmp < 0) tmp = 0;
res2 = lv_draw_mask_line(&mask_buf[tmp], abs_x+tmp, abs_y, len-tmp, (lv_draw_mask_line_param_t*)&p->start_line); res2 = lv_draw_mask_line(&mask_buf[tmp], abs_x + tmp, abs_y, len - tmp, (lv_draw_mask_line_param_t *)&p->start_line);
if(res2 == LV_DRAW_MASK_RES_FULL_TRANSP) { if(res2 == LV_DRAW_MASK_RES_FULL_TRANSP) {
memset(&mask_buf[tmp], 0x00, len-tmp); memset(&mask_buf[tmp], 0x00, len - tmp);
} }
if(res1 == res2) return res1; if(res1 == res2) return res1;
else return LV_DRAW_MASK_RES_CHANGED; else return LV_DRAW_MASK_RES_CHANGED;
@@ -835,13 +869,15 @@ static lv_draw_mask_res_t lv_draw_mask_angle(lv_opa_t * mask_buf, lv_coord_t abs
} }
} }
static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_radius_param_t * p) static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
lv_draw_mask_radius_param_t * p)
{ {
if(p->cfg.outer == 0) { if(p->cfg.outer == 0) {
if(abs_y < p->cfg.rect.y1 || abs_y > p->cfg.rect.y2) { if(abs_y < p->cfg.rect.y1 || abs_y > p->cfg.rect.y2) {
return LV_DRAW_MASK_RES_FULL_TRANSP; return LV_DRAW_MASK_RES_FULL_TRANSP;
} }
} else { }
else {
if(abs_y < p->cfg.rect.y1 || abs_y > p->cfg.rect.y2) { if(abs_y < p->cfg.rect.y1 || abs_y > p->cfg.rect.y2) {
return LV_DRAW_MASK_RES_FULL_COVER; return LV_DRAW_MASK_RES_FULL_COVER;
} }
@@ -860,7 +896,7 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab
int32_t first = p->cfg.rect.x2 - abs_x + 1; int32_t first = p->cfg.rect.x2 - abs_x + 1;
if(first <= 0) return LV_DRAW_MASK_RES_FULL_TRANSP; if(first <= 0) return LV_DRAW_MASK_RES_FULL_TRANSP;
else if(first < len) { else if(first < len) {
memset(&mask_buf[first], 0x00, len-first); memset(&mask_buf[first], 0x00, len - first);
} }
if(last == 0 && first == len) return LV_DRAW_MASK_RES_FULL_COVER; if(last == 0 && first == len) return LV_DRAW_MASK_RES_FULL_COVER;
else return LV_DRAW_MASK_RES_CHANGED; else return LV_DRAW_MASK_RES_CHANGED;
@@ -879,7 +915,7 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab
return LV_DRAW_MASK_RES_CHANGED; return LV_DRAW_MASK_RES_CHANGED;
} }
int32_t k = p->cfg.rect.x1 -abs_x; /*First relevant coordinate on the of the mask*/ int32_t k = p->cfg.rect.x1 - abs_x; /*First relevant coordinate on the of the mask*/
int32_t w = lv_area_get_width(&p->cfg.rect); int32_t w = lv_area_get_width(&p->cfg.rect);
int32_t h = lv_area_get_height(&p->cfg.rect); int32_t h = lv_area_get_height(&p->cfg.rect);
abs_x -= p->cfg.rect.x1; abs_x -= p->cfg.rect.x1;
@@ -900,7 +936,7 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab
lv_sqrt(r2 - (y * y), &x0); lv_sqrt(r2 - (y * y), &x0);
lv_sqrt_res_t x1; lv_sqrt_res_t x1;
lv_sqrt(r2 - ((y-1) * (y-1)), &x1); lv_sqrt(r2 - ((y - 1) * (y - 1)), &x1);
/* If x1 is on the next round coordinate (e.g. x0: 3.5, x1:4.0) /* If x1 is on the next round coordinate (e.g. x0: 3.5, x1:4.0)
* then treat x1 as x1: 3.99 to handle them as they were on the same pixel*/ * then treat x1 as x1: 3.99 to handle them as they were on the same pixel*/
@@ -923,7 +959,7 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab
} }
/*Right corner*/ /*Right corner*/
int32_t kr = k+(w-ofs-1); int32_t kr = k + (w - ofs - 1);
if(kr >= 0 && kr < len) { if(kr >= 0 && kr < len) {
mask_buf[kr] = mask_mix(mask_buf[kr], m); mask_buf[kr] = mask_mix(mask_buf[kr], m);
} }
@@ -941,14 +977,15 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab
return LV_DRAW_MASK_RES_FULL_TRANSP; return LV_DRAW_MASK_RES_FULL_TRANSP;
} }
if(kr <= len) { if(kr <= len) {
memset(&mask_buf[kr], 0x00, len-kr); memset(&mask_buf[kr], 0x00, len - kr);
} }
} else { }
else {
kl++; kl++;
int32_t first = kl; int32_t first = kl;
if(first < 0) first = 0; if(first < 0) first = 0;
int32_t len_tmp = kr-first; int32_t len_tmp = kr - first;
if(len_tmp + first > len) len_tmp = len - first; if(len_tmp + first > len) len_tmp = len - first;
if(first < len && len_tmp >= 0) { if(first < len && len_tmp >= 0) {
memset(&mask_buf[first], 0x00, len_tmp); memset(&mask_buf[first], 0x00, len_tmp);
@@ -959,13 +996,13 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab
else { else {
int32_t ofs = p->cfg.radius - (x0.i + 1); int32_t ofs = p->cfg.radius - (x0.i + 1);
int32_t kl = k + ofs; int32_t kl = k + ofs;
int32_t kr = k + (w - ofs -1); int32_t kr = k + (w - ofs - 1);
if(p->cfg.outer) { if(p->cfg.outer) {
int32_t first = kl + 1; int32_t first = kl + 1;
if(first < 0) first = 0; if(first < 0) first = 0;
int32_t len_tmp = kr-first; int32_t len_tmp = kr - first;
if(len_tmp + first > len) len_tmp = len - first; if(len_tmp + first > len) len_tmp = len - first;
if(first < len && len_tmp >= 0) { if(first < len && len_tmp >= 0) {
memset(&mask_buf[first], 0x00, len_tmp); memset(&mask_buf[first], 0x00, len_tmp);
@@ -987,7 +1024,7 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab
/*The first y intersection is special as it might be in the previous line*/ /*The first y intersection is special as it might be in the previous line*/
if(y_prev.i >= y) { if(y_prev.i >= y) {
lv_sqrt(r2 - (i * i), &y_next); lv_sqrt(r2 - (i * i), &y_next);
m = 255 - (((255-x0.f) * (255 - y_next.f)) >> 9); m = 255 - (((255 - x0.f) * (255 - y_next.f)) >> 9);
if(p->cfg.outer) m = 255 - m; if(p->cfg.outer) m = 255 - m;
if(kl >= 0 && kl < len) mask_buf[kl] = mask_mix(mask_buf[kl], m); if(kl >= 0 && kl < len) mask_buf[kl] = mask_mix(mask_buf[kl], m);
@@ -1041,7 +1078,8 @@ static lv_draw_mask_res_t lv_draw_mask_radius(lv_opa_t * mask_buf, lv_coord_t ab
} }
static lv_draw_mask_res_t lv_draw_mask_fade(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_fade_param_t * p) static lv_draw_mask_res_t lv_draw_mask_fade(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
lv_draw_mask_fade_param_t * p)
{ {
if(abs_y < p->cfg.coords.y1) return LV_DRAW_MASK_RES_FULL_COVER; if(abs_y < p->cfg.coords.y1) return LV_DRAW_MASK_RES_FULL_COVER;
if(abs_y > p->cfg.coords.y2) return LV_DRAW_MASK_RES_FULL_COVER; if(abs_y > p->cfg.coords.y2) return LV_DRAW_MASK_RES_FULL_COVER;
@@ -1064,12 +1102,14 @@ static lv_draw_mask_res_t lv_draw_mask_fade(lv_opa_t * mask_buf, lv_coord_t abs_
mask_buf[i] = mask_mix(mask_buf[i], p->cfg.opa_top); mask_buf[i] = mask_mix(mask_buf[i], p->cfg.opa_top);
} }
return LV_DRAW_MASK_RES_CHANGED; return LV_DRAW_MASK_RES_CHANGED;
} else if(abs_y >= p->cfg.y_bottom) { }
else if(abs_y >= p->cfg.y_bottom) {
for(i = 0; i < len; i++) { for(i = 0; i < len; i++) {
mask_buf[i] = mask_mix(mask_buf[i], p->cfg.opa_bottom); mask_buf[i] = mask_mix(mask_buf[i], p->cfg.opa_bottom);
} }
return LV_DRAW_MASK_RES_CHANGED; return LV_DRAW_MASK_RES_CHANGED;
} else { }
else {
/*Calculate the opa proportionally*/ /*Calculate the opa proportionally*/
int16_t opa_diff = p->cfg.opa_bottom - p->cfg.opa_top; int16_t opa_diff = p->cfg.opa_bottom - p->cfg.opa_top;
int32_t y_diff = p->cfg.y_bottom - p->cfg.y_top + 1; int32_t y_diff = p->cfg.y_bottom - p->cfg.y_top + 1;
@@ -1086,7 +1126,8 @@ static lv_draw_mask_res_t lv_draw_mask_fade(lv_opa_t * mask_buf, lv_coord_t abs_
return LV_DRAW_MASK_RES_FULL_COVER; return LV_DRAW_MASK_RES_FULL_COVER;
} }
static lv_draw_mask_res_t lv_draw_mask_map(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, lv_draw_mask_map_param_t * p) static lv_draw_mask_res_t lv_draw_mask_map(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
lv_draw_mask_map_param_t * p)
{ {
/*Handle out of the mask cases*/ /*Handle out of the mask cases*/
if(abs_y < p->cfg.coords.y1) return LV_DRAW_MASK_RES_FULL_COVER; if(abs_y < p->cfg.coords.y1) return LV_DRAW_MASK_RES_FULL_COVER;
@@ -1106,7 +1147,8 @@ static lv_draw_mask_res_t lv_draw_mask_map(lv_opa_t * mask_buf, lv_coord_t abs_x
x_ofs = p->cfg.coords.x1 - abs_x; x_ofs = p->cfg.coords.x1 - abs_x;
len -= x_ofs; len -= x_ofs;
mask_buf += x_ofs; mask_buf += x_ofs;
} else { }
else {
map_tmp += (abs_x - p->cfg.coords.x1); map_tmp += (abs_x - p->cfg.coords.x1);
} }
@@ -1124,6 +1166,6 @@ static inline lv_opa_t mask_mix(lv_opa_t mask_act, lv_opa_t mask_new)
if(mask_new >= LV_OPA_MAX) return mask_act; if(mask_new >= LV_OPA_MAX) return mask_act;
if(mask_new <= LV_OPA_MIN) return 0; if(mask_new <= LV_OPA_MIN) return 0;
return (int32_t)((int32_t) (mask_act * mask_new) >> 8); return (int32_t)((int32_t)(mask_act * mask_new) >> 8);
} }

View File

@@ -53,14 +53,15 @@ enum {
LV_DRAW_MASK_LINE_SIDE_BOTTOM, LV_DRAW_MASK_LINE_SIDE_BOTTOM,
}; };
typedef lv_draw_mask_res_t (*lv_draw_mask_cb_t)(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len, void * p); typedef lv_draw_mask_res_t (*lv_draw_mask_cb_t)(lv_opa_t * mask_buf, lv_coord_t abs_x, lv_coord_t abs_y, lv_coord_t len,
void * p);
typedef uint8_t lv_draw_mask_line_side_t; typedef uint8_t lv_draw_mask_line_side_t;
typedef struct { typedef struct {
lv_draw_mask_cb_t cb; lv_draw_mask_cb_t cb;
lv_draw_mask_type_t type; lv_draw_mask_type_t type;
}lv_draw_mask_common_dsc_t; } lv_draw_mask_common_dsc_t;
typedef struct { typedef struct {
/*The first element must be the common descriptor*/ /*The first element must be the common descriptor*/
@@ -74,8 +75,8 @@ typedef struct {
lv_point_t p2; lv_point_t p2;
/*Which side to keep?*/ /*Which side to keep?*/
lv_draw_mask_line_side_t side :2; lv_draw_mask_line_side_t side : 2;
}cfg; } cfg;
/*A point of the line*/ /*A point of the line*/
lv_point_t origo; lv_point_t origo;
@@ -93,13 +94,13 @@ typedef struct {
int32_t spx; int32_t spx;
/*1: It's a flat line? (Near to horizontal)*/ /*1: It's a flat line? (Near to horizontal)*/
uint8_t flat :1; uint8_t flat : 1;
/* Invert the mask. The default is: Keep the left part. /* Invert the mask. The default is: Keep the left part.
* It is used to select left/right/top/bottom*/ * It is used to select left/right/top/bottom*/
uint8_t inv:1; uint8_t inv: 1;
}lv_draw_mask_line_param_t; } lv_draw_mask_line_param_t;
typedef struct { typedef struct {
/*The first element must be the common descriptor*/ /*The first element must be the common descriptor*/
@@ -109,12 +110,12 @@ typedef struct {
lv_point_t vertex_p; lv_point_t vertex_p;
lv_coord_t start_angle; lv_coord_t start_angle;
lv_coord_t end_angle; lv_coord_t end_angle;
}cfg; } cfg;
lv_draw_mask_line_param_t start_line; lv_draw_mask_line_param_t start_line;
lv_draw_mask_line_param_t end_line; lv_draw_mask_line_param_t end_line;
uint16_t delta_deg; uint16_t delta_deg;
}lv_draw_mask_angle_param_t; } lv_draw_mask_angle_param_t;
typedef struct { typedef struct {
/*The first element must be the common descriptor*/ /*The first element must be the common descriptor*/
@@ -124,10 +125,10 @@ typedef struct {
lv_area_t rect; lv_area_t rect;
lv_coord_t radius; lv_coord_t radius;
/* Invert the mask. 0: Keep the pixels inside.*/ /* Invert the mask. 0: Keep the pixels inside.*/
uint8_t outer:1; uint8_t outer: 1;
}cfg; } cfg;
}lv_draw_mask_radius_param_t; } lv_draw_mask_radius_param_t;
typedef struct { typedef struct {
/*The first element must be the common descriptor*/ /*The first element must be the common descriptor*/
@@ -139,9 +140,9 @@ typedef struct {
lv_coord_t y_bottom; lv_coord_t y_bottom;
lv_opa_t opa_top; lv_opa_t opa_top;
lv_opa_t opa_bottom; lv_opa_t opa_bottom;
}cfg; } cfg;
}lv_draw_mask_fade_param_t; } lv_draw_mask_fade_param_t;
typedef struct _lv_draw_mask_map_param_t { typedef struct _lv_draw_mask_map_param_t {
/*The first element must be the common descriptor*/ /*The first element must be the common descriptor*/
@@ -150,8 +151,8 @@ typedef struct _lv_draw_mask_map_param_t {
struct { struct {
lv_area_t coords; lv_area_t coords;
const lv_opa_t * map; const lv_opa_t * map;
}cfg; } cfg;
}lv_draw_mask_map_param_t; } lv_draw_mask_map_param_t;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
@@ -211,7 +212,8 @@ uint8_t lv_draw_mask_get_cnt(void);
* With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept
* With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept
*/ */
void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t p1y, lv_coord_t p2x, lv_coord_t p2y, lv_draw_mask_line_side_t side); void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t p1y, lv_coord_t p2x,
lv_coord_t p2y, lv_draw_mask_line_side_t side);
/** /**
*Initialize a line mask from a point and an angle. *Initialize a line mask from a point and an angle.
@@ -223,7 +225,8 @@ void lv_draw_mask_line_points_init(lv_draw_mask_line_param_t * param, lv_coord_t
* With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept * With `LV_DRAW_MASK_LINE_SIDE_LEFT/RIGHT` and horizontal line all pixels are kept
* With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept * With `LV_DRAW_MASK_LINE_SIDE_TOP/BOTTOM` and vertical line all pixels are kept
*/ */
void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t py, int16_t angle, lv_draw_mask_line_side_t side); void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t * param, lv_coord_t p1x, lv_coord_t py, int16_t angle,
lv_draw_mask_line_side_t side);
/** /**
* Initialize an angle mask. * Initialize an angle mask.
@@ -233,7 +236,8 @@ void lv_draw_mask_line_angle_init(lv_draw_mask_line_param_t * param, lv_coord_t
* @param start_angle start angle in degrees. 0 deg on the right, 90 deg, on the bottom * @param start_angle start angle in degrees. 0 deg on the right, 90 deg, on the bottom
* @param end_angle end angle * @param end_angle end angle
*/ */
void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vertex_x, lv_coord_t vertex_y, lv_coord_t start_angle, lv_coord_t end_angle); void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vertex_x, lv_coord_t vertex_y,
lv_coord_t start_angle, lv_coord_t end_angle);
/** /**
* Initialize a fade mask. * Initialize a fade mask.
@@ -253,7 +257,8 @@ void lv_draw_mask_radius_init(lv_draw_mask_radius_param_t * param, const lv_area
* @param opa_bottom opacity at the bottom * @param opa_bottom opacity at the bottom
* @param y_bottom at which coordinate reach `opa_bottom`. * @param y_bottom at which coordinate reach `opa_bottom`.
*/ */
void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t * param, lv_area_t * coords, lv_opa_t opa_top, lv_coord_t y_top, lv_opa_t opa_bottom, lv_coord_t y_bottom); void lv_draw_mask_fade_init(lv_draw_mask_fade_param_t * param, lv_area_t * coords, lv_opa_t opa_top, lv_coord_t y_top,
lv_opa_t opa_bottom, lv_coord_t y_bottom);
/** /**
* Initialize a map mask. * Initialize a map mask.

View File

@@ -100,27 +100,27 @@ void lv_draw_rect(const lv_area_t * coords, const lv_area_t * clip, lv_draw_rect
*/ */
void lv_draw_px(const lv_point_t * point, const lv_area_t * clip_area, const lv_style_t * style) void lv_draw_px(const lv_point_t * point, const lv_area_t * clip_area, const lv_style_t * style)
{ {
// lv_opa_t opa = style->body.opa; // lv_opa_t opa = style->body.opa;
// if(opa_scale != LV_OPA_COVER) opa = (opa * opa_scale) >> 8; // if(opa_scale != LV_OPA_COVER) opa = (opa * opa_scale) >> 8;
// //
// if(opa > LV_OPA_MAX) opa = LV_OPA_COVER; // if(opa > LV_OPA_MAX) opa = LV_OPA_COVER;
// //
// lv_area_t fill_area; // lv_area_t fill_area;
// fill_area.x1 = point->x; // fill_area.x1 = point->x;
// fill_area.y1 = point->y; // fill_area.y1 = point->y;
// fill_area.x2 = point->x; // fill_area.x2 = point->x;
// fill_area.y2 = point->y; // fill_area.y2 = point->y;
// //
// uint8_t mask_cnt = lv_draw_mask_get_cnt(); // uint8_t mask_cnt = lv_draw_mask_get_cnt();
// //
// if(mask_cnt == 0) { // if(mask_cnt == 0) {
// lv_blend_fill(clip_area, &fill_area, style->body.main_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, style->body.blend_mode); // lv_blend_fill(clip_area, &fill_area, style->body.main_color, NULL, LV_DRAW_MASK_RES_FULL_COVER, opa, style->body.blend_mode);
// } else { // } else {
// uint8_t mask_buf; // uint8_t mask_buf;
// lv_draw_mask_res_t mask_res; // lv_draw_mask_res_t mask_res;
// mask_res = lv_draw_mask_apply(&mask_buf, point->x, point->y, 1); // mask_res = lv_draw_mask_apply(&mask_buf, point->x, point->y, 1);
// lv_blend_fill(clip_area, &fill_area, style->body.main_color, &mask_buf, mask_res, opa, style->body.blend_mode); // lv_blend_fill(clip_area, &fill_area, style->body.main_color, &mask_buf, mask_res, opa, style->body.blend_mode);
// } // }
} }
/********************** /**********************
@@ -268,15 +268,18 @@ static void draw_bg(const lv_area_t * coords, const lv_area_t * clip, lv_draw_re
if(mask_ofs < 0) mask_ofs = 0; if(mask_ofs < 0) mask_ofs = 0;
lv_blend_fill(clip, &fill_area2, lv_blend_fill(clip, &fill_area2,
grad_color, mask_buf + mask_ofs, mask_res, opa, dsc->bg_blend_mode); grad_color, mask_buf + mask_ofs, mask_res, opa, dsc->bg_blend_mode);
} else { }
else {
if(dsc->bg_grad_dir == LV_GRAD_DIR_HOR) { if(dsc->bg_grad_dir == LV_GRAD_DIR_HOR) {
lv_blend_map(clip, &fill_area, grad_map, mask_buf, mask_res, opa, dsc->bg_blend_mode); lv_blend_map(clip, &fill_area, grad_map, mask_buf, mask_res, opa, dsc->bg_blend_mode);
} else if(dsc->bg_grad_dir == LV_GRAD_DIR_VER) { }
else if(dsc->bg_grad_dir == LV_GRAD_DIR_VER) {
lv_blend_fill(clip, &fill_area, lv_blend_fill(clip, &fill_area,
grad_color,mask_buf, mask_res, opa, dsc->bg_blend_mode); grad_color, mask_buf, mask_res, opa, dsc->bg_blend_mode);
} else if(other_mask_cnt != 0) { }
else if(other_mask_cnt != 0) {
lv_blend_fill(clip, &fill_area, lv_blend_fill(clip, &fill_area,
grad_color,mask_buf, mask_res, opa, dsc->bg_blend_mode); grad_color, mask_buf, mask_res, opa, dsc->bg_blend_mode);
} }
} }
fill_area.y1++; fill_area.y1++;
@@ -460,7 +463,7 @@ static void draw_border(const lv_area_t * coords, const lv_area_t * clip, lv_dra
lv_blend_fill(clip, &fill_area2, color, mask_buf, mask_res, opa, blend_mode); lv_blend_fill(clip, &fill_area2, color, mask_buf, mask_res, opa, blend_mode);
/*Draw the bottom horizontal line*/ /*Draw the bottom horizontal line*/
if(fill_area2.y2 > coords->y2 - dsc->border_width ) { if(fill_area2.y2 > coords->y2 - dsc->border_width) {
fill_area2.x1 = coords->x1 + rout; fill_area2.x1 = coords->x1 + rout;
fill_area2.x2 = coords->x2 - rout; fill_area2.x2 = coords->x2 - rout;
@@ -513,7 +516,7 @@ static void draw_border(const lv_area_t * coords, const lv_area_t * clip, lv_dra
memset(mask_buf, LV_OPA_COVER, draw_area_w); memset(mask_buf, LV_OPA_COVER, draw_area_w);
mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w); mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w);
lv_blend_fill( clip, &fill_area, color, mask_buf, mask_res, opa, blend_mode); lv_blend_fill(clip, &fill_area, color, mask_buf, mask_res, opa, blend_mode);
fill_area.y1++; fill_area.y1++;
fill_area.y2++; fill_area.y2++;
@@ -718,7 +721,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra
if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED; if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED;
lv_blend_fill(clip, &a, lv_blend_fill(clip, &a,
dsc->shadow_color, mask_buf+first_px, mask_res, opa, dsc->shadow_blend_mode); dsc->shadow_color, mask_buf + first_px, mask_res, opa, dsc->shadow_blend_mode);
a.y1++; a.y1++;
a.y2++; a.y2++;
} }
@@ -741,8 +744,8 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra
a.y1 = sh_area.y1; a.y1 = sh_area.y1;
a.y2 = a.y1; a.y2 = a.y1;
if(a.x2 > sh_area.x1 + lv_area_get_width(&sh_area)/2 - 1) { if(a.x2 > sh_area.x1 + lv_area_get_width(&sh_area) / 2 - 1) {
a.x2 = sh_area.x1 + lv_area_get_width(&sh_area)/2 -1 ; a.x2 = sh_area.x1 + lv_area_get_width(&sh_area) / 2 - 1 ;
} }
first_px = 0; first_px = 0;
@@ -783,7 +786,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra
} }
/*Fill the left side*/ /*Fill the left side*/
a.y1 = sh_area.y1+corner_size; a.y1 = sh_area.y1 + corner_size;
a.y2 = a.y1; a.y2 = a.y1;
sh_buf_tmp = sh_buf + corner_size * (corner_size - 1); sh_buf_tmp = sh_buf + corner_size * (corner_size - 1);
@@ -851,7 +854,8 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra
lv_blend_fill(clip, &a, lv_blend_fill(clip, &a,
dsc->shadow_color, mask_buf, mask_res, opa, dsc->shadow_blend_mode); dsc->shadow_color, mask_buf, mask_res, opa, dsc->shadow_blend_mode);
} else { }
else {
lv_opa_t opa_tmp = sh_buf_tmp[0]; lv_opa_t opa_tmp = sh_buf_tmp[0];
if(opa_tmp != LV_OPA_COVER || opa != LV_OPA_COVER) opa_tmp = (opa * opa_tmp) >> 8; if(opa_tmp != LV_OPA_COVER || opa != LV_OPA_COVER) opa_tmp = (opa * opa_tmp) >> 8;
@@ -867,7 +871,7 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra
/*Fill the bottom side*/ /*Fill the bottom side*/
int32_t y_min = simple_mode ? (corner_size - (sh_area.y2 - coords->y2)) : ver_mid_dist; int32_t y_min = simple_mode ? (corner_size - (sh_area.y2 - coords->y2)) : ver_mid_dist;
if(y_min < 0) y_min = 0; if(y_min < 0) y_min = 0;
sh_buf_tmp = sh_buf + corner_size * (corner_size - y_min - 1 ) + corner_size - 1; sh_buf_tmp = sh_buf + corner_size * (corner_size - y_min - 1) + corner_size - 1;
a.y1 = sh_area.y2 - corner_size + 1 + y_min; a.y1 = sh_area.y2 - corner_size + 1 + y_min;
a.y2 = a.y1; a.y2 = a.y1;
@@ -879,7 +883,8 @@ static void draw_shadow(const lv_area_t * coords, const lv_area_t * clip, lv_dra
if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED; if(mask_res == LV_DRAW_MASK_RES_FULL_COVER) mask_res = LV_DRAW_MASK_RES_CHANGED;
lv_blend_fill(clip, &a, lv_blend_fill(clip, &a,
dsc->shadow_color, mask_buf, mask_res, opa, dsc->shadow_blend_mode); dsc->shadow_color, mask_buf, mask_res, opa, dsc->shadow_blend_mode);
} else { }
else {
lv_opa_t opa_tmp = sh_buf_tmp[0]; lv_opa_t opa_tmp = sh_buf_tmp[0];
if(opa_tmp != LV_OPA_COVER || opa != LV_OPA_COVER) opa_tmp = (opa * opa_tmp) >> 8; if(opa_tmp != LV_OPA_COVER || opa != LV_OPA_COVER) opa_tmp = (opa * opa_tmp) >> 8;
lv_blend_fill(clip, &a, lv_blend_fill(clip, &a,
@@ -921,7 +926,7 @@ static void shadow_draw_corner_buf(const lv_area_t * coords, uint16_t * sh_buf,
lv_area_t sh_area; lv_area_t sh_area;
lv_area_copy(&sh_area, coords); lv_area_copy(&sh_area, coords);
sh_area.x2 = sw / 2 + r -1 - ((sw & 1) ? 0 : 1); sh_area.x2 = sw / 2 + r - 1 - ((sw & 1) ? 0 : 1);
sh_area.y1 = sw / 2 + 1; sh_area.y1 = sw / 2 + 1;
sh_area.x1 = sh_area.x2 - lv_area_get_width(coords); sh_area.x1 = sh_area.x2 - lv_area_get_width(coords);
@@ -944,11 +949,12 @@ static void shadow_draw_corner_buf(const lv_area_t * coords, uint16_t * sh_buf,
lv_draw_mask_res_t mask_res = mask_param.dsc.cb(mask_line, 0, y, size, &mask_param); lv_draw_mask_res_t mask_res = mask_param.dsc.cb(mask_line, 0, y, size, &mask_param);
if(mask_res == LV_DRAW_MASK_RES_FULL_TRANSP) { if(mask_res == LV_DRAW_MASK_RES_FULL_TRANSP) {
memset(sh_ups_tmp_buf, 0x00, size * sizeof(sh_ups_tmp_buf[0])); memset(sh_ups_tmp_buf, 0x00, size * sizeof(sh_ups_tmp_buf[0]));
} else { }
else {
int32_t i; int32_t i;
sh_ups_tmp_buf[0] = (mask_line[0] << SHADOW_UPSACALE_SHIFT) / sw; sh_ups_tmp_buf[0] = (mask_line[0] << SHADOW_UPSACALE_SHIFT) / sw;
for(i = 1; i < size; i++) { for(i = 1; i < size; i++) {
if(mask_line[i] == mask_line[i-1]) sh_ups_tmp_buf[i] = sh_ups_tmp_buf[i-1]; if(mask_line[i] == mask_line[i - 1]) sh_ups_tmp_buf[i] = sh_ups_tmp_buf[i - 1];
else sh_ups_tmp_buf[i] = (mask_line[i] << SHADOW_UPSACALE_SHIFT) / sw; else sh_ups_tmp_buf[i] = (mask_line[i] << SHADOW_UPSACALE_SHIFT) / sw;
} }
} }
@@ -981,7 +987,7 @@ static void shadow_draw_corner_buf(const lv_area_t * coords, uint16_t * sh_buf,
uint32_t i; uint32_t i;
sh_buf[0] = (sh_buf[0] << SHADOW_UPSACALE_SHIFT) / sw; sh_buf[0] = (sh_buf[0] << SHADOW_UPSACALE_SHIFT) / sw;
for(i = 1; i < (uint32_t) size * size; i++) { for(i = 1; i < (uint32_t) size * size; i++) {
if(sh_buf[i] == sh_buf[i-1]) sh_buf[i] = sh_buf[i-1]; if(sh_buf[i] == sh_buf[i - 1]) sh_buf[i] = sh_buf[i - 1];
else sh_buf[i] = (sh_buf[i] << SHADOW_UPSACALE_SHIFT) / sw; else sh_buf[i] = (sh_buf[i] << SHADOW_UPSACALE_SHIFT) / sw;
} }
@@ -1011,8 +1017,8 @@ static void shadow_blur_corner(lv_coord_t size, lv_coord_t sw, uint16_t * sh_ups
uint16_t * sh_ups_tmp_buf = sh_ups_buf; uint16_t * sh_ups_tmp_buf = sh_ups_buf;
for(y = 0; y < size; y++) { for(y = 0; y < size; y++) {
int32_t v = sh_ups_tmp_buf[size-1] * sw; int32_t v = sh_ups_tmp_buf[size - 1] * sw;
for(x = size - 1; x >=0; x--) { for(x = size - 1; x >= 0; x--) {
sh_ups_blur_buf[x] = v; sh_ups_blur_buf[x] = v;
/*Forget the right pixel*/ /*Forget the right pixel*/
@@ -1034,7 +1040,7 @@ static void shadow_blur_corner(lv_coord_t size, lv_coord_t sw, uint16_t * sh_ups
uint32_t i; uint32_t i;
sh_ups_buf[0] = sh_ups_buf[0] / sw; sh_ups_buf[0] = sh_ups_buf[0] / sw;
for(i = 1; i < (uint32_t)size * size; i++) { for(i = 1; i < (uint32_t)size * size; i++) {
if(sh_ups_buf[i] == sh_ups_buf[i-1]) sh_ups_buf[i] = sh_ups_buf[i-1]; if(sh_ups_buf[i] == sh_ups_buf[i - 1]) sh_ups_buf[i] = sh_ups_buf[i - 1];
else sh_ups_buf[i] = sh_ups_buf[i] / sw; else sh_ups_buf[i] = sh_ups_buf[i] / sw;
} }
@@ -1213,7 +1219,7 @@ static void draw_outline(const lv_area_t * coords, const lv_area_t * clip, lv_dr
lv_blend_fill(clip, &fill_area2, color, mask_buf, mask_res, opa, blend_mode); lv_blend_fill(clip, &fill_area2, color, mask_buf, mask_res, opa, blend_mode);
/*Draw the bottom horizontal line*/ /*Draw the bottom horizontal line*/
if(fill_area2.y2 > area_outer.y2 - dsc->outline_width ) { if(fill_area2.y2 > area_outer.y2 - dsc->outline_width) {
fill_area2.x1 = area_outer.x1 + rout; fill_area2.x1 = area_outer.x1 + rout;
fill_area2.x2 = area_outer.x2 - rout; fill_area2.x2 = area_outer.x2 - rout;
@@ -1256,7 +1262,7 @@ static void draw_outline(const lv_area_t * coords, const lv_area_t * clip, lv_dr
memset(mask_buf, LV_OPA_COVER, draw_area_w); memset(mask_buf, LV_OPA_COVER, draw_area_w);
mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w); mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w);
lv_blend_fill( clip, &fill_area, color, mask_buf, mask_res, opa, blend_mode); lv_blend_fill(clip, &fill_area, color, mask_buf, mask_res, opa, blend_mode);
fill_area.y1++; fill_area.y1++;
fill_area.y2++; fill_area.y2++;
@@ -1282,7 +1288,7 @@ static void draw_pattern(const lv_area_t * coords, const lv_area_t * clip, lv_dr
if(src_type == LV_IMG_SRC_FILE || src_type == LV_IMG_SRC_VARIABLE) { if(src_type == LV_IMG_SRC_FILE || src_type == LV_IMG_SRC_VARIABLE) {
lv_img_header_t header; lv_img_header_t header;
lv_res_t res = lv_img_decoder_get_info(dsc->pattern_image, &header); lv_res_t res = lv_img_decoder_get_info(dsc->pattern_image, &header);
if(res!= LV_RES_OK) { if(res != LV_RES_OK) {
LV_LOG_WARN("draw_img: can't get image info"); LV_LOG_WARN("draw_img: can't get image info");
return; return;
} }
@@ -1294,17 +1300,20 @@ static void draw_pattern(const lv_area_t * coords, const lv_area_t * clip, lv_dr
img_dsc.opa = dsc->pattern_opa; img_dsc.opa = dsc->pattern_opa;
img_dsc.recolor_opa = dsc->pattern_recolor_opa; img_dsc.recolor_opa = dsc->pattern_recolor_opa;
img_dsc.recolor = dsc->pattern_recolor; img_dsc.recolor = dsc->pattern_recolor;
} else if(src_type == LV_IMG_SRC_SYMBOL) { }
else if(src_type == LV_IMG_SRC_SYMBOL) {
lv_draw_label_dsc_init(&label_dsc); lv_draw_label_dsc_init(&label_dsc);
label_dsc.color = dsc->pattern_recolor; label_dsc.color = dsc->pattern_recolor;
label_dsc.font = dsc->pattern_font; label_dsc.font = dsc->pattern_font;
label_dsc.opa = dsc->pattern_opa; label_dsc.opa = dsc->pattern_opa;
lv_point_t s; lv_point_t s;
lv_txt_get_size(&s, dsc->pattern_image, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, LV_TXT_FLAG_NONE); lv_txt_get_size(&s, dsc->pattern_image, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX,
LV_TXT_FLAG_NONE);
img_w = s.x; img_w = s.x;
img_h = s.y; img_h = s.y;
} else { }
else {
/*Trigger the error handler of image drawer*/ /*Trigger the error handler of image drawer*/
LV_LOG_WARN("lv_img_design: image source type is unknown"); LV_LOG_WARN("lv_img_design: image source type is unknown");
lv_draw_img(coords, clip, NULL, NULL); lv_draw_img(coords, clip, NULL, NULL);
@@ -1333,7 +1342,8 @@ static void draw_pattern(const lv_area_t * coords, const lv_area_t * clip, lv_dr
} }
} }
lv_draw_mask_remove_id(radius_mask_id); lv_draw_mask_remove_id(radius_mask_id);
} else { }
else {
int32_t obj_w = lv_area_get_width(coords); int32_t obj_w = lv_area_get_width(coords);
int32_t obj_h = lv_area_get_height(coords); int32_t obj_h = lv_area_get_height(coords);
coords_tmp.x1 = coords->x1 + (obj_w - img_w) / 2; coords_tmp.x1 = coords->x1 + (obj_w - img_w) / 2;
@@ -1371,7 +1381,8 @@ static void draw_value(const lv_area_t * coords, const lv_area_t * clip, lv_draw
if(dsc->value_opa <= LV_OPA_MIN) return; if(dsc->value_opa <= LV_OPA_MIN) return;
lv_point_t s; lv_point_t s;
lv_txt_get_size(&s, dsc->value_str, dsc->value_font, dsc->value_letter_space, dsc->value_line_space, LV_COORD_MAX, LV_TXT_FLAG_NONE); lv_txt_get_size(&s, dsc->value_str, dsc->value_font, dsc->value_letter_space, dsc->value_line_space, LV_COORD_MAX,
LV_TXT_FLAG_NONE);
lv_area_t value_area; lv_area_t value_area;
value_area.x1 = 0; value_area.x1 = 0;

View File

@@ -64,7 +64,7 @@ typedef struct {
lv_color_t pattern_recolor; lv_color_t pattern_recolor;
lv_opa_t pattern_opa; lv_opa_t pattern_opa;
lv_opa_t pattern_recolor_opa; lv_opa_t pattern_recolor_opa;
uint8_t pattern_repeat :1; uint8_t pattern_repeat : 1;
lv_blend_mode_t pattern_blend_mode; lv_blend_mode_t pattern_blend_mode;
/*Value*/ /*Value*/
@@ -78,7 +78,7 @@ typedef struct {
lv_style_int_t value_line_space; lv_style_int_t value_line_space;
lv_align_t value_align; lv_align_t value_align;
lv_blend_mode_t value_blend_mode; lv_blend_mode_t value_blend_mode;
}lv_draw_rect_dsc_t; } lv_draw_rect_dsc_t;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES

View File

@@ -52,7 +52,8 @@ void lv_draw_triangle(const lv_point_t * points, const lv_area_t * clip_area, lv
* @param clip_area polygon will be drawn only in this area * @param clip_area polygon will be drawn only in this area
* @param draw_dsc pointer to an initialized `lv_draw_rect_dsc_t` variable * @param draw_dsc pointer to an initialized `lv_draw_rect_dsc_t` variable
*/ */
void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_area_t * clip_area, lv_draw_rect_dsc_t * draw_dsc) void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_area_t * clip_area,
lv_draw_rect_dsc_t * draw_dsc)
{ {
if(point_cnt < 3) return; if(point_cnt < 3) return;
if(points == NULL) return; if(points == NULL) return;
@@ -111,7 +112,8 @@ void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_are
i_next_right = i_prev_right + 1; i_next_right = i_prev_right + 1;
if(i_next_right > point_cnt - 1) i_next_right = 0; if(i_next_right > point_cnt - 1) i_next_right = 0;
} else { }
else {
i_next_left = i_prev_left + 1; i_next_left = i_prev_left + 1;
if(i_next_left > point_cnt - 1) i_next_left = 0; if(i_next_left > point_cnt - 1) i_next_left = 0;
@@ -148,7 +150,7 @@ void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_are
i_prev_right = i_next_right; i_prev_right = i_next_right;
} }
}while( mask_cnt < point_cnt); } while(mask_cnt < point_cnt);
lv_draw_rect(&poly_coords, clip_area, draw_dsc); lv_draw_rect(&poly_coords, clip_area, draw_dsc);

View File

@@ -42,7 +42,8 @@ void lv_draw_triangle(const lv_point_t * points, const lv_area_t * clip, lv_draw
* @param clip_area polygon will be drawn only in this area * @param clip_area polygon will be drawn only in this area
* @param draw_dsc pointer to an initialized `lv_draw_rect_dsc_t` variable * @param draw_dsc pointer to an initialized `lv_draw_rect_dsc_t` variable
*/ */
void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_area_t * mask, lv_draw_rect_dsc_t * draw_dsc); void lv_draw_polygon(const lv_point_t * points, uint16_t point_cnt, const lv_area_t * mask,
lv_draw_rect_dsc_t * draw_dsc);
/********************** /**********************
* MACROS * MACROS

View File

@@ -63,7 +63,8 @@ lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t
#if LV_COLOR_SIZE == 32 #if LV_COLOR_SIZE == 32
p_color.ch.alpha = 0xFF; /*Only the color should be get so use a deafult alpha value*/ p_color.ch.alpha = 0xFF; /*Only the color should be get so use a deafult alpha value*/
#endif #endif
} else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) { }
else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) {
buf_u8 += 4 * 2; buf_u8 += 4 * 2;
uint8_t bit = x & 0x7; uint8_t bit = x & 0x7;
x = x >> 3; x = x >> 3;
@@ -73,7 +74,8 @@ lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t
* so the possible real width are 8, 16, 24 ...*/ * so the possible real width are 8, 16, 24 ...*/
uint32_t px = ((dsc->header.w + 7) >> 3) * y + x; uint32_t px = ((dsc->header.w + 7) >> 3) * y + x;
p_color.full = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit); p_color.full = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit);
} else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) { }
else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) {
buf_u8 += 4 * 4; buf_u8 += 4 * 4;
uint8_t bit = (x & 0x3) * 2; uint8_t bit = (x & 0x3) * 2;
x = x >> 2; x = x >> 2;
@@ -83,7 +85,8 @@ lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t
* so the possible real width are 4, 8, 12 ...*/ * so the possible real width are 4, 8, 12 ...*/
uint32_t px = ((dsc->header.w + 3) >> 2) * y + x; uint32_t px = ((dsc->header.w + 3) >> 2) * y + x;
p_color.full = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit); p_color.full = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit);
} else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) { }
else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) {
buf_u8 += 4 * 16; buf_u8 += 4 * 16;
uint8_t bit = (x & 0x1) * 4; uint8_t bit = (x & 0x1) * 4;
x = x >> 1; x = x >> 1;
@@ -93,11 +96,13 @@ lv_color_t lv_img_buf_get_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t
* so the possible real width are 2, 4, 6 ...*/ * so the possible real width are 2, 4, 6 ...*/
uint32_t px = ((dsc->header.w + 1) >> 1) * y + x; uint32_t px = ((dsc->header.w + 1) >> 1) * y + x;
p_color.full = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit); p_color.full = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit);
} else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) { }
else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) {
buf_u8 += 4 * 256; buf_u8 += 4 * 256;
uint32_t px = dsc->header.w * y + x; uint32_t px = dsc->header.w * y + x;
p_color.full = buf_u8[px]; p_color.full = buf_u8[px];
} else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || dsc->header.cf == LV_IMG_CF_ALPHA_2BIT || }
else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || dsc->header.cf == LV_IMG_CF_ALPHA_2BIT ||
dsc->header.cf == LV_IMG_CF_ALPHA_4BIT || dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { dsc->header.cf == LV_IMG_CF_ALPHA_4BIT || dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
p_color = color; p_color = color;
} }
@@ -119,7 +124,8 @@ lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y)
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) { if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) {
uint32_t px = dsc->header.w * y * LV_IMG_PX_SIZE_ALPHA_BYTE + x * LV_IMG_PX_SIZE_ALPHA_BYTE; uint32_t px = dsc->header.w * y * LV_IMG_PX_SIZE_ALPHA_BYTE + x * LV_IMG_PX_SIZE_ALPHA_BYTE;
return buf_u8[px + LV_IMG_PX_SIZE_ALPHA_BYTE - 1]; return buf_u8[px + LV_IMG_PX_SIZE_ALPHA_BYTE - 1];
} else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) { }
else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) {
uint8_t bit = x & 0x7; uint8_t bit = x & 0x7;
x = x >> 3; x = x >> 3;
@@ -129,7 +135,8 @@ lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y)
uint32_t px = ((dsc->header.w + 7) >> 3) * y + x; uint32_t px = ((dsc->header.w + 7) >> 3) * y + x;
uint8_t px_opa = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit); uint8_t px_opa = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit);
return px_opa ? LV_OPA_TRANSP : LV_OPA_COVER; return px_opa ? LV_OPA_TRANSP : LV_OPA_COVER;
} else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) { }
else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) {
const uint8_t opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/ const uint8_t opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
uint8_t bit = (x & 0x3) * 2; uint8_t bit = (x & 0x3) * 2;
@@ -141,9 +148,11 @@ lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y)
uint32_t px = ((dsc->header.w + 3) >> 2) * y + x; uint32_t px = ((dsc->header.w + 3) >> 2) * y + x;
uint8_t px_opa = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit); uint8_t px_opa = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit);
return opa_table[px_opa]; return opa_table[px_opa];
} else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) { }
else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) {
const uint8_t opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/ const uint8_t opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255}; 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255
};
uint8_t bit = (x & 0x1) * 4; uint8_t bit = (x & 0x1) * 4;
x = x >> 1; x = x >> 1;
@@ -154,7 +163,8 @@ lv_opa_t lv_img_buf_get_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y)
uint32_t px = ((dsc->header.w + 1) >> 1) * y + x; uint32_t px = ((dsc->header.w + 1) >> 1) * y + x;
uint8_t px_opa = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit); uint8_t px_opa = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit);
return opa_table[px_opa]; return opa_table[px_opa];
} else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { }
else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
uint32_t px = dsc->header.w * y + x; uint32_t px = dsc->header.w * y + x;
return buf_u8[px]; return buf_u8[px];
} }
@@ -178,7 +188,8 @@ void lv_img_buf_set_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_
uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3; uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3;
uint32_t px = dsc->header.w * y * px_size + x * px_size; uint32_t px = dsc->header.w * y * px_size + x * px_size;
buf_u8[px + px_size - 1] = opa; buf_u8[px + px_size - 1] = opa;
} else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) { }
else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT) {
opa = opa >> 7; /*opa -> [0,1]*/ opa = opa >> 7; /*opa -> [0,1]*/
uint8_t bit = x & 0x7; uint8_t bit = x & 0x7;
x = x >> 3; x = x >> 3;
@@ -189,7 +200,8 @@ void lv_img_buf_set_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_
uint32_t px = ((dsc->header.w + 7) >> 3) * y + x; uint32_t px = ((dsc->header.w + 7) >> 3) * y + x;
buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit)); buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit));
buf_u8[px] = buf_u8[px] | ((opa & 0x1) << (7 - bit)); buf_u8[px] = buf_u8[px] | ((opa & 0x1) << (7 - bit));
} else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) { }
else if(dsc->header.cf == LV_IMG_CF_ALPHA_2BIT) {
opa = opa >> 6; /*opa -> [0,3]*/ opa = opa >> 6; /*opa -> [0,3]*/
uint8_t bit = (x & 0x3) * 2; uint8_t bit = (x & 0x3) * 2;
x = x >> 2; x = x >> 2;
@@ -200,7 +212,8 @@ void lv_img_buf_set_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_
uint32_t px = ((dsc->header.w + 3) >> 2) * y + x; uint32_t px = ((dsc->header.w + 3) >> 2) * y + x;
buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit)); buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit));
buf_u8[px] = buf_u8[px] | ((opa & 0x3) << (6 - bit)); buf_u8[px] = buf_u8[px] | ((opa & 0x3) << (6 - bit));
} else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) { }
else if(dsc->header.cf == LV_IMG_CF_ALPHA_4BIT) {
opa = opa >> 4; /*opa -> [0,15]*/ opa = opa >> 4; /*opa -> [0,15]*/
uint8_t bit = (x & 0x1) * 4; uint8_t bit = (x & 0x1) * 4;
x = x >> 1; x = x >> 1;
@@ -211,7 +224,8 @@ void lv_img_buf_set_px_alpha(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_
uint32_t px = ((dsc->header.w + 1) >> 1) * y + x; uint32_t px = ((dsc->header.w + 1) >> 1) * y + x;
buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit)); buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit));
buf_u8[px] = buf_u8[px] | ((opa & 0xF) << (4 - bit)); buf_u8[px] = buf_u8[px] | ((opa & 0xF) << (4 - bit));
} else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { }
else if(dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
uint32_t px = dsc->header.w * y + x; uint32_t px = dsc->header.w * y + x;
buf_u8[px] = opa; buf_u8[px] = opa;
} }
@@ -233,11 +247,13 @@ void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_
uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3; uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3;
uint32_t px = dsc->header.w * y * px_size + x * px_size; uint32_t px = dsc->header.w * y * px_size + x * px_size;
memcpy(&buf_u8[px], &c, px_size); memcpy(&buf_u8[px], &c, px_size);
} else if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) { }
else if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_ALPHA) {
uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3; uint8_t px_size = lv_img_cf_get_px_size(dsc->header.cf) >> 3;
uint32_t px = dsc->header.w * y * px_size + x * px_size; uint32_t px = dsc->header.w * y * px_size + x * px_size;
memcpy(&buf_u8[px], &c, px_size - 1); /*-1 to not overwrite the alpha value*/ memcpy(&buf_u8[px], &c, px_size - 1); /*-1 to not overwrite the alpha value*/
} else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) { }
else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) {
buf_u8 += sizeof(lv_color32_t) * 2; /*Skip the palette*/ buf_u8 += sizeof(lv_color32_t) * 2; /*Skip the palette*/
uint8_t bit = x & 0x7; uint8_t bit = x & 0x7;
@@ -249,7 +265,8 @@ void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_
uint32_t px = ((dsc->header.w + 7) >> 3) * y + x; uint32_t px = ((dsc->header.w + 7) >> 3) * y + x;
buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit)); buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit));
buf_u8[px] = buf_u8[px] | ((c.full & 0x1) << (7 - bit)); buf_u8[px] = buf_u8[px] | ((c.full & 0x1) << (7 - bit));
} else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) { }
else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) {
buf_u8 += sizeof(lv_color32_t) * 4; /*Skip the palette*/ buf_u8 += sizeof(lv_color32_t) * 4; /*Skip the palette*/
uint8_t bit = (x & 0x3) * 2; uint8_t bit = (x & 0x3) * 2;
x = x >> 2; x = x >> 2;
@@ -261,7 +278,8 @@ void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_
buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit)); buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit));
buf_u8[px] = buf_u8[px] | ((c.full & 0x3) << (6 - bit)); buf_u8[px] = buf_u8[px] | ((c.full & 0x3) << (6 - bit));
} else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) { }
else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) {
buf_u8 += sizeof(lv_color32_t) * 16; /*Skip the palette*/ buf_u8 += sizeof(lv_color32_t) * 16; /*Skip the palette*/
uint8_t bit = (x & 0x1) * 4; uint8_t bit = (x & 0x1) * 4;
x = x >> 1; x = x >> 1;
@@ -272,7 +290,8 @@ void lv_img_buf_set_px_color(lv_img_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_
uint32_t px = ((dsc->header.w + 1) >> 1) * y + x; uint32_t px = ((dsc->header.w + 1) >> 1) * y + x;
buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit)); buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit));
buf_u8[px] = buf_u8[px] | ((c.full & 0xF) << (4 - bit)); buf_u8[px] = buf_u8[px] | ((c.full & 0xF) << (4 - bit));
} else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) { }
else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) {
buf_u8 += sizeof(lv_color32_t) * 256; /*Skip the palette*/ buf_u8 += sizeof(lv_color32_t) * 256; /*Skip the palette*/
uint32_t px = dsc->header.w * y + x; uint32_t px = dsc->header.w * y + x;
buf_u8[px] = c.full; buf_u8[px] = c.full;
@@ -310,10 +329,10 @@ void lv_img_buf_set_palette(lv_img_dsc_t * dsc, uint8_t id, lv_color_t c)
* @param cf a color format (`LV_IMG_CF_...`) * @param cf a color format (`LV_IMG_CF_...`)
* @return an allocated image, or NULL on failure * @return an allocated image, or NULL on failure
*/ */
lv_img_dsc_t *lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf) lv_img_dsc_t * lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf)
{ {
/* Allocate image descriptor */ /* Allocate image descriptor */
lv_img_dsc_t *dsc = lv_mem_alloc(sizeof(lv_img_dsc_t)); lv_img_dsc_t * dsc = lv_mem_alloc(sizeof(lv_img_dsc_t));
if(dsc == NULL) if(dsc == NULL)
return NULL; return NULL;
@@ -346,7 +365,7 @@ lv_img_dsc_t *lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf)
* Free an allocated image buffer * Free an allocated image buffer
* @param dsc image buffer to free * @param dsc image buffer to free
*/ */
void lv_img_buf_free(lv_img_dsc_t *dsc) void lv_img_buf_free(lv_img_dsc_t * dsc)
{ {
if(dsc != NULL) { if(dsc != NULL) {
if(dsc->data != NULL) if(dsc->data != NULL)
@@ -366,18 +385,30 @@ void lv_img_buf_free(lv_img_dsc_t *dsc)
uint32_t lv_img_buf_get_img_size(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf) uint32_t lv_img_buf_get_img_size(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf)
{ {
switch(cf) { switch(cf) {
case LV_IMG_CF_TRUE_COLOR: return LV_IMG_BUF_SIZE_TRUE_COLOR(w, h); case LV_IMG_CF_TRUE_COLOR:
case LV_IMG_CF_TRUE_COLOR_ALPHA: return LV_IMG_BUF_SIZE_TRUE_COLOR_ALPHA(w, h); return LV_IMG_BUF_SIZE_TRUE_COLOR(w, h);
case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED: return LV_IMG_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h); case LV_IMG_CF_TRUE_COLOR_ALPHA:
case LV_IMG_CF_ALPHA_1BIT: return LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h); return LV_IMG_BUF_SIZE_TRUE_COLOR_ALPHA(w, h);
case LV_IMG_CF_ALPHA_2BIT: return LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h); case LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED:
case LV_IMG_CF_ALPHA_4BIT: return LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h); return LV_IMG_BUF_SIZE_TRUE_COLOR_CHROMA_KEYED(w, h);
case LV_IMG_CF_ALPHA_8BIT: return LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h); case LV_IMG_CF_ALPHA_1BIT:
case LV_IMG_CF_INDEXED_1BIT: return LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h); return LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h);
case LV_IMG_CF_INDEXED_2BIT: return LV_IMG_BUF_SIZE_INDEXED_2BIT(w, h); case LV_IMG_CF_ALPHA_2BIT:
case LV_IMG_CF_INDEXED_4BIT: return LV_IMG_BUF_SIZE_INDEXED_4BIT(w, h); return LV_IMG_BUF_SIZE_ALPHA_2BIT(w, h);
case LV_IMG_CF_INDEXED_8BIT: return LV_IMG_BUF_SIZE_INDEXED_8BIT(w, h); case LV_IMG_CF_ALPHA_4BIT:
default: return 0; return LV_IMG_BUF_SIZE_ALPHA_4BIT(w, h);
case LV_IMG_CF_ALPHA_8BIT:
return LV_IMG_BUF_SIZE_ALPHA_8BIT(w, h);
case LV_IMG_CF_INDEXED_1BIT:
return LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h);
case LV_IMG_CF_INDEXED_2BIT:
return LV_IMG_BUF_SIZE_INDEXED_2BIT(w, h);
case LV_IMG_CF_INDEXED_4BIT:
return LV_IMG_BUF_SIZE_INDEXED_4BIT(w, h);
case LV_IMG_CF_INDEXED_8BIT:
return LV_IMG_BUF_SIZE_INDEXED_8BIT(w, h);
default:
return 0;
} }
} }
@@ -405,7 +436,8 @@ void lv_img_buf_transform_init(lv_img_transform_dsc_t * dsc)
dsc->tmp.chroma_keyed = lv_img_cf_is_chroma_keyed(dsc->cfg.cf) ? 1 : 0; dsc->tmp.chroma_keyed = lv_img_cf_is_chroma_keyed(dsc->cfg.cf) ? 1 : 0;
dsc->tmp.has_alpha = lv_img_cf_has_alpha(dsc->cfg.cf) ? 1 : 0; dsc->tmp.has_alpha = lv_img_cf_has_alpha(dsc->cfg.cf) ? 1 : 0;
if(dsc->cfg.cf == LV_IMG_CF_TRUE_COLOR || dsc->cfg.cf == LV_IMG_CF_TRUE_COLOR_ALPHA || dsc->cfg.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) { if(dsc->cfg.cf == LV_IMG_CF_TRUE_COLOR || dsc->cfg.cf == LV_IMG_CF_TRUE_COLOR_ALPHA ||
dsc->cfg.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED) {
dsc->tmp.native_color = 1; dsc->tmp.native_color = 1;
} }
@@ -443,7 +475,8 @@ bool lv_img_buf_transform(lv_img_transform_dsc_t * dsc, lv_coord_t x, lv_coord_t
/*Get the source pixel from the upscaled image*/ /*Get the source pixel from the upscaled image*/
xs = ((dsc->tmp.cosma * xt - dsc->tmp.sinma * yt) >> (LV_TRIGO_SHIFT - 8)) + dsc->tmp.pivot_x_256; xs = ((dsc->tmp.cosma * xt - dsc->tmp.sinma * yt) >> (LV_TRIGO_SHIFT - 8)) + dsc->tmp.pivot_x_256;
ys = ((dsc->tmp.sinma * xt + dsc->tmp.cosma * yt) >> (LV_TRIGO_SHIFT - 8)) + dsc->tmp.pivot_y_256; ys = ((dsc->tmp.sinma * xt + dsc->tmp.cosma * yt) >> (LV_TRIGO_SHIFT - 8)) + dsc->tmp.pivot_y_256;
} else { }
else {
xt *= dsc->tmp.zoom_inv; xt *= dsc->tmp.zoom_inv;
yt *= dsc->tmp.zoom_inv; yt *= dsc->tmp.zoom_inv;
xs = ((dsc->tmp.cosma * xt - dsc->tmp.sinma * yt) >> (LV_TRIGO_SHIFT)) + dsc->tmp.pivot_x_256; xs = ((dsc->tmp.cosma * xt - dsc->tmp.sinma * yt) >> (LV_TRIGO_SHIFT)) + dsc->tmp.pivot_x_256;
@@ -472,13 +505,15 @@ bool lv_img_buf_transform(lv_img_transform_dsc_t * dsc, lv_coord_t x, lv_coord_t
pxi = dsc->cfg.src_w * ys_int * px_size + xs_int * px_size; pxi = dsc->cfg.src_w * ys_int * px_size + xs_int * px_size;
memcpy(&dsc->res.color, &src_u8[pxi], px_size); memcpy(&dsc->res.color, &src_u8[pxi], px_size);
} else { }
else {
px_size = LV_IMG_PX_SIZE_ALPHA_BYTE; px_size = LV_IMG_PX_SIZE_ALPHA_BYTE;
pxi = dsc->cfg.src_w * ys_int * px_size + xs_int * px_size; pxi = dsc->cfg.src_w * ys_int * px_size + xs_int * px_size;
memcpy(&dsc->res.color, &src_u8[pxi], px_size - 1); memcpy(&dsc->res.color, &src_u8[pxi], px_size - 1);
dsc->res.opa = src_u8[pxi + px_size - 1]; dsc->res.opa = src_u8[pxi + px_size - 1];
} }
} else { }
else {
pxi = 0; /*unused*/ pxi = 0; /*unused*/
px_size = 0; /*unused*/ px_size = 0; /*unused*/
dsc->res.color = lv_img_buf_get_px_color(&dsc->tmp.img_dsc, xs_int, ys_int, dsc->cfg.color); dsc->res.color = lv_img_buf_get_px_color(&dsc->tmp.img_dsc, xs_int, ys_int, dsc->cfg.color);
@@ -516,7 +551,8 @@ bool lv_img_buf_transform(lv_img_transform_dsc_t * dsc, lv_coord_t x, lv_coord_t
* @param zoom zoom, (256 no zoom) * @param zoom zoom, (256 no zoom)
* @param pivot x,y pivot coordinates of rotation * @param pivot x,y pivot coordinates of rotation
*/ */
void lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom, lv_point_t * pivot) void lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom,
lv_point_t * pivot)
{ {
int32_t angle_low = angle / 10; int32_t angle_low = angle / 10;
@@ -543,8 +579,8 @@ void lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h
lv_area_t a; lv_area_t a;
a.x1 = ((-pivot->x) * zoom) >> 8; a.x1 = ((-pivot->x) * zoom) >> 8;
a.y1 = ((-pivot->y) * zoom) >> 8; a.y1 = ((-pivot->y) * zoom) >> 8;
a.x2 = ((w -pivot->x) * zoom) >> 8; a.x2 = ((w - pivot->x) * zoom) >> 8;
a.y2 = ((h -pivot->y) * zoom) >> 8; a.y2 = ((h - pivot->y) * zoom) >> 8;
xt = a.x1; xt = a.x1;
yt = a.y1; yt = a.y1;
@@ -590,11 +626,13 @@ static inline bool transform_anti_alias(lv_img_transform_dsc_t * dsc)
xn = - 1; xn = - 1;
if(dsc->tmp.xs_int + xn < 0) xn = 0; if(dsc->tmp.xs_int + xn < 0) xn = 0;
xr = xs_fract + 0x80; xr = xs_fract + 0x80;
} else if(xs_fract > 0x90) { }
else if(xs_fract > 0x90) {
xn = 1; xn = 1;
if(dsc->tmp.xs_int + xn >= dsc->cfg.src_w) xn = 0; if(dsc->tmp.xs_int + xn >= dsc->cfg.src_w) xn = 0;
xr = (0xFF - xs_fract) + 0x80; xr = (0xFF - xs_fract) + 0x80;
} else { }
else {
xn = 0; xn = 0;
xr = 0xFF; xr = 0xFF;
} }
@@ -607,12 +645,14 @@ static inline bool transform_anti_alias(lv_img_transform_dsc_t * dsc)
if(dsc->tmp.ys_int + yn < 0) yn = 0; if(dsc->tmp.ys_int + yn < 0) yn = 0;
yr = ys_fract + 0x80; yr = ys_fract + 0x80;
} else if(ys_fract > 0x90) { }
else if(ys_fract > 0x90) {
yn = 1; yn = 1;
if(dsc->tmp.ys_int + yn >= dsc->cfg.src_h) yn = 0; if(dsc->tmp.ys_int + yn >= dsc->cfg.src_h) yn = 0;
yr = (0xFF - ys_fract) + 0x80; yr = (0xFF - ys_fract) + 0x80;
} else { }
else {
yn = 0; yn = 0;
yr = 0xFF; yr = 0xFF;
} }
@@ -630,13 +670,15 @@ static inline bool transform_anti_alias(lv_img_transform_dsc_t * dsc)
if(dsc->tmp.native_color) { if(dsc->tmp.native_color) {
memcpy(&c01, &src_u8[dsc->tmp.pxi + dsc->tmp.px_size * xn], sizeof(lv_color_t)); memcpy(&c01, &src_u8[dsc->tmp.pxi + dsc->tmp.px_size * xn], sizeof(lv_color_t));
memcpy(&c10, &src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn], sizeof(lv_color_t)); memcpy(&c10, &src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn], sizeof(lv_color_t));
memcpy(&c11, &src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn + dsc->tmp.px_size * xn], sizeof(lv_color_t)); memcpy(&c11, &src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn + dsc->tmp.px_size * xn],
sizeof(lv_color_t));
if(dsc->tmp.has_alpha) { if(dsc->tmp.has_alpha) {
a10 = src_u8[dsc->tmp.pxi + dsc->tmp.px_size * xn + dsc->tmp.px_size - 1]; a10 = src_u8[dsc->tmp.pxi + dsc->tmp.px_size * xn + dsc->tmp.px_size - 1];
a01 = src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn + dsc->tmp.px_size - 1]; a01 = src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn + dsc->tmp.px_size - 1];
a11 = src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn + dsc->tmp.px_size * xn + dsc->tmp.px_size - 1]; a11 = src_u8[dsc->tmp.pxi + dsc->cfg.src_w * dsc->tmp.px_size * yn + dsc->tmp.px_size * xn + dsc->tmp.px_size - 1];
} }
} else { }
else {
c01 = lv_img_buf_get_px_color(&dsc->tmp.img_dsc, dsc->tmp.xs_int + xn, dsc->tmp.ys_int, dsc->cfg.color); c01 = lv_img_buf_get_px_color(&dsc->tmp.img_dsc, dsc->tmp.xs_int + xn, dsc->tmp.ys_int, dsc->cfg.color);
c10 = lv_img_buf_get_px_color(&dsc->tmp.img_dsc, dsc->tmp.xs_int, dsc->tmp.ys_int + yn, dsc->cfg.color); c10 = lv_img_buf_get_px_color(&dsc->tmp.img_dsc, dsc->tmp.xs_int, dsc->tmp.ys_int + yn, dsc->cfg.color);
c11 = lv_img_buf_get_px_color(&dsc->tmp.img_dsc, dsc->tmp.xs_int + xn, dsc->tmp.ys_int + yn, dsc->cfg.color); c11 = lv_img_buf_get_px_color(&dsc->tmp.img_dsc, dsc->tmp.xs_int + xn, dsc->tmp.ys_int + yn, dsc->cfg.color);
@@ -662,7 +704,8 @@ static inline bool transform_anti_alias(lv_img_transform_dsc_t * dsc)
if(a10 <= LV_OPA_MIN) xr0 = LV_OPA_COVER; if(a10 <= LV_OPA_MIN) xr0 = LV_OPA_COVER;
if(a01 <= LV_OPA_MIN) xr1 = LV_OPA_TRANSP; if(a01 <= LV_OPA_MIN) xr1 = LV_OPA_TRANSP;
if(a11 <= LV_OPA_MIN) xr1 = LV_OPA_COVER; if(a11 <= LV_OPA_MIN) xr1 = LV_OPA_COVER;
} else { }
else {
xr0 = xr; xr0 = xr;
xr1 = xr; xr1 = xr;
dsc->res.opa = LV_OPA_COVER; dsc->res.opa = LV_OPA_COVER;

View File

@@ -103,8 +103,7 @@ typedef uint8_t lv_img_cf_t;
/** /**
* LittlevGL image header * LittlevGL image header
*/ */
typedef struct typedef struct {
{
/* The first 8 bit is very important to distinguish the different source types. /* The first 8 bit is very important to distinguish the different source types.
* For more info see `lv_img_get_src_type()` in lv_img.c */ * For more info see `lv_img_get_src_type()` in lv_img.c */
@@ -121,8 +120,7 @@ typedef struct
/** Image header it is compatible with /** Image header it is compatible with
* the result from image converter utility*/ * the result from image converter utility*/
typedef struct typedef struct {
{
lv_img_header_t header; lv_img_header_t header;
uint32_t data_size; uint32_t data_size;
const uint8_t * data; const uint8_t * data;
@@ -140,12 +138,12 @@ typedef struct {
lv_color_t color; /*a color used for `LV_IMG_CF_INDEXED_1/2/4/8BIT` color formats*/ lv_color_t color; /*a color used for `LV_IMG_CF_INDEXED_1/2/4/8BIT` color formats*/
lv_img_cf_t cf; /*color format of the image to rotate*/ lv_img_cf_t cf; /*color format of the image to rotate*/
bool antialias; bool antialias;
}cfg; } cfg;
struct { struct {
lv_color_t color; lv_color_t color;
lv_opa_t opa; lv_opa_t opa;
}res; } res;
struct { struct {
@@ -155,9 +153,9 @@ typedef struct {
int32_t sinma; int32_t sinma;
int32_t cosma; int32_t cosma;
uint8_t chroma_keyed :1; uint8_t chroma_keyed : 1;
uint8_t has_alpha :1; uint8_t has_alpha : 1;
uint8_t native_color :1; uint8_t native_color : 1;
uint16_t zoom_inv; uint16_t zoom_inv;
@@ -168,8 +166,8 @@ typedef struct {
lv_coord_t ys_int; lv_coord_t ys_int;
uint32_t pxi; uint32_t pxi;
uint8_t px_size; uint8_t px_size;
}tmp; } tmp;
}lv_img_transform_dsc_t; } lv_img_transform_dsc_t;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
@@ -182,7 +180,7 @@ typedef struct {
* @param cf a color format (`LV_IMG_CF_...`) * @param cf a color format (`LV_IMG_CF_...`)
* @return an allocated image, or NULL on failure * @return an allocated image, or NULL on failure
*/ */
lv_img_dsc_t *lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf); lv_img_dsc_t * lv_img_buf_alloc(lv_coord_t w, lv_coord_t h, lv_img_cf_t cf);
/** /**
* Get the color of an image's pixel * Get the color of an image's pixel
@@ -242,7 +240,7 @@ void lv_img_buf_set_palette(lv_img_dsc_t * dsc, uint8_t id, lv_color_t c);
* Free an allocated image buffer * Free an allocated image buffer
* @param dsc image buffer to free * @param dsc image buffer to free
*/ */
void lv_img_buf_free(lv_img_dsc_t *dsc); void lv_img_buf_free(lv_img_dsc_t * dsc);
/** /**
* Get the memory consumption of a raw bitmap, given color format and dimensions. * Get the memory consumption of a raw bitmap, given color format and dimensions.
@@ -279,7 +277,8 @@ bool lv_img_buf_transform(lv_img_transform_dsc_t * dsc, lv_coord_t x, lv_coord_t
* @param zoom zoom, (256 no zoom) * @param zoom zoom, (256 no zoom)
* @param pivot x,y pivot coordinates of rotation * @param pivot x,y pivot coordinates of rotation
*/ */
void lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom, lv_point_t * pivot); void lv_img_buf_get_transformed_area(lv_area_t * res, lv_coord_t w, lv_coord_t h, int16_t angle, uint16_t zoom,
lv_point_t * pivot);
/********************** /**********************
* MACROS * MACROS

View File

@@ -14,7 +14,7 @@
#include "../lv_misc/lv_gc.h" #include "../lv_misc/lv_gc.h"
#if defined(LV_GC_INCLUDE) #if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE #include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
/********************* /*********************
* DEFINES * DEFINES
@@ -30,7 +30,7 @@
#define LV_IMG_CACHE_LIFE_LIMIT 1000 #define LV_IMG_CACHE_LIFE_LIMIT 1000
#if LV_IMG_CACHE_DEF_SIZE < 1 #if LV_IMG_CACHE_DEF_SIZE < 1
#error "LV_IMG_CACHE_DEF_SIZE must be >= 1. See lv_conf.h" #error "LV_IMG_CACHE_DEF_SIZE must be >= 1. See lv_conf.h"
#endif #endif
/********************** /**********************
@@ -86,7 +86,8 @@ lv_img_cache_entry_t * lv_img_cache_open(const void * src, lv_color_t color)
lv_img_src_t src_type = lv_img_src_get_type(cache[i].dec_dsc.src); lv_img_src_t src_type = lv_img_src_get_type(cache[i].dec_dsc.src);
if(src_type == LV_IMG_SRC_VARIABLE) { if(src_type == LV_IMG_SRC_VARIABLE) {
if(cache[i].dec_dsc.src == src && cache[i].dec_dsc.color.full == color.full) match = true; if(cache[i].dec_dsc.src == src && cache[i].dec_dsc.color.full == color.full) match = true;
} else if(src_type == LV_IMG_SRC_FILE) { }
else if(src_type == LV_IMG_SRC_FILE) {
if(strcmp(cache[i].dec_dsc.src, src) == 0) match = true; if(strcmp(cache[i].dec_dsc.src, src) == 0) match = true;
} }
@@ -116,7 +117,8 @@ lv_img_cache_entry_t * lv_img_cache_open(const void * src, lv_color_t color)
if(cached_src->dec_dsc.src) { if(cached_src->dec_dsc.src) {
lv_img_decoder_close(&cached_src->dec_dsc); lv_img_decoder_close(&cached_src->dec_dsc);
LV_LOG_INFO("image draw: cache miss, close and reuse an entry"); LV_LOG_INFO("image draw: cache miss, close and reuse an entry");
} else { }
else {
LV_LOG_INFO("image draw: cache miss, cached to an empty entry"); LV_LOG_INFO("image draw: cache miss, cached to an empty entry");
} }

View File

@@ -28,8 +28,7 @@ extern "C" {
* *
* To avoid repeating this heavy load images can be cached. * To avoid repeating this heavy load images can be cached.
*/ */
typedef struct typedef struct {
{
lv_img_decoder_dsc_t dec_dsc; /**< Image information */ lv_img_decoder_dsc_t dec_dsc; /**< Image information */
/** Count the cache entries's life. Add `time_tio_open` to `life` when the entry is used. /** Count the cache entries's life. Add `time_tio_open` to `life` when the entry is used.

View File

@@ -14,7 +14,7 @@
#include "../lv_misc/lv_gc.h" #include "../lv_misc/lv_gc.h"
#if defined(LV_GC_INCLUDE) #if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE #include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
/********************* /*********************
@@ -26,8 +26,7 @@
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
typedef struct typedef struct {
{
#if LV_USE_FILESYSTEM #if LV_USE_FILESYSTEM
lv_fs_file_t * f; lv_fs_file_t * f;
#endif #endif
@@ -93,8 +92,7 @@ lv_res_t lv_img_decoder_get_info(const char * src, lv_img_header_t * header)
lv_res_t res = LV_RES_INV; lv_res_t res = LV_RES_INV;
lv_img_decoder_t * d; lv_img_decoder_t * d;
LV_LL_READ(LV_GC_ROOT(_lv_img_defoder_ll), d) LV_LL_READ(LV_GC_ROOT(_lv_img_defoder_ll), d) {
{
res = LV_RES_INV; res = LV_RES_INV;
if(d->info_cb) { if(d->info_cb) {
res = d->info_cb(d, src, header); res = d->info_cb(d, src, header);
@@ -127,15 +125,15 @@ lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t * dsc, const void * src, lv_co
size_t fnlen = strlen(src); size_t fnlen = strlen(src);
dsc->src = lv_mem_alloc(fnlen + 1); dsc->src = lv_mem_alloc(fnlen + 1);
strcpy((char *)dsc->src, src); strcpy((char *)dsc->src, src);
} else { }
else {
dsc->src = src; dsc->src = src;
} }
lv_res_t res = LV_RES_INV; lv_res_t res = LV_RES_INV;
lv_img_decoder_t * d; lv_img_decoder_t * d;
LV_LL_READ(LV_GC_ROOT(_lv_img_defoder_ll), d) LV_LL_READ(LV_GC_ROOT(_lv_img_defoder_ll), d) {
{
/*Info an Open callbacks are required*/ /*Info an Open callbacks are required*/
if(d->info_cb == NULL || d->open_cb == NULL) continue; if(d->info_cb == NULL || d->open_cb == NULL) continue;
@@ -305,7 +303,8 @@ lv_res_t lv_img_decoder_built_in_info(lv_img_decoder_t * decoder, const void * s
/* Symbols always have transparent parts. Important because of cover check in the design /* Symbols always have transparent parts. Important because of cover check in the design
* function. The actual value doesn't matter because lv_draw_label will draw it*/ * function. The actual value doesn't matter because lv_draw_label will draw it*/
header->cf = LV_IMG_CF_ALPHA_1BIT; header->cf = LV_IMG_CF_ALPHA_1BIT;
} else { }
else {
LV_LOG_WARN("Image get info found unknown src type"); LV_LOG_WARN("Image get info found unknown src type");
return LV_RES_INV; return LV_RES_INV;
} }
@@ -357,7 +356,8 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder
LV_LOG_WARN("Image built-in decoder cannot read file because LV_USE_FILESYSTEM = 0"); LV_LOG_WARN("Image built-in decoder cannot read file because LV_USE_FILESYSTEM = 0");
return LV_RES_INV; return LV_RES_INV;
#endif #endif
} else if(dsc->src_type == LV_IMG_SRC_VARIABLE) { }
else if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
/*The variables should have valid data*/ /*The variables should have valid data*/
if(((lv_img_dsc_t *)dsc->src)->data == NULL) { if(((lv_img_dsc_t *)dsc->src)->data == NULL) {
return LV_RES_INV; return LV_RES_INV;
@@ -372,7 +372,8 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder
* So simply give its pointer*/ * So simply give its pointer*/
dsc->img_data = ((lv_img_dsc_t *)dsc->src)->data; dsc->img_data = ((lv_img_dsc_t *)dsc->src)->data;
return LV_RES_OK; return LV_RES_OK;
} else { }
else {
/*If it's a file it need to be read line by line later*/ /*If it's a file it need to be read line by line later*/
dsc->img_data = NULL; dsc->img_data = NULL;
return LV_RES_OK; return LV_RES_OK;
@@ -421,7 +422,8 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder
LV_LOG_WARN("Image built-in decoder can read the palette because LV_USE_FILESYSTEM = 0"); LV_LOG_WARN("Image built-in decoder can read the palette because LV_USE_FILESYSTEM = 0");
return LV_RES_INV; return LV_RES_INV;
#endif #endif
} else { }
else {
/*The palette begins in the beginning of the image data. Just point to it.*/ /*The palette begins in the beginning of the image data. Just point to it.*/
lv_color32_t * palette_p = (lv_color32_t *)((lv_img_dsc_t *)dsc->src)->data; lv_color32_t * palette_p = (lv_color32_t *)((lv_img_dsc_t *)dsc->src)->data;
@@ -486,14 +488,17 @@ lv_res_t lv_img_decoder_built_in_read_line(lv_img_decoder_t * decoder, lv_img_de
if(dsc->src_type == LV_IMG_SRC_FILE) { if(dsc->src_type == LV_IMG_SRC_FILE) {
res = lv_img_decoder_built_in_line_true_color(dsc, x, y, len, buf); res = lv_img_decoder_built_in_line_true_color(dsc, x, y, len, buf);
} }
} else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || dsc->header.cf == LV_IMG_CF_ALPHA_2BIT || }
else if(dsc->header.cf == LV_IMG_CF_ALPHA_1BIT || dsc->header.cf == LV_IMG_CF_ALPHA_2BIT ||
dsc->header.cf == LV_IMG_CF_ALPHA_4BIT || dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) { dsc->header.cf == LV_IMG_CF_ALPHA_4BIT || dsc->header.cf == LV_IMG_CF_ALPHA_8BIT) {
res = lv_img_decoder_built_in_line_alpha(dsc, x, y, len, buf); res = lv_img_decoder_built_in_line_alpha(dsc, x, y, len, buf);
} else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT || dsc->header.cf == LV_IMG_CF_INDEXED_2BIT || }
else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT || dsc->header.cf == LV_IMG_CF_INDEXED_2BIT ||
dsc->header.cf == LV_IMG_CF_INDEXED_4BIT || dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) { dsc->header.cf == LV_IMG_CF_INDEXED_4BIT || dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) {
res = lv_img_decoder_built_in_line_indexed(dsc, x, y, len, buf); res = lv_img_decoder_built_in_line_indexed(dsc, x, y, len, buf);
} else { }
else {
LV_LOG_WARN("Built-in image decoder read not supports the color format"); LV_LOG_WARN("Built-in image decoder read not supports the color format");
return LV_RES_INV; return LV_RES_INV;
} }
@@ -570,7 +575,8 @@ static lv_res_t lv_img_decoder_built_in_line_alpha(lv_img_decoder_dsc_t * dsc, l
const lv_opa_t alpha1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/ const lv_opa_t alpha1_opa_table[2] = {0, 255}; /*Opacity mapping with bpp = 1 (Just for compatibility)*/
const lv_opa_t alpha2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/ const lv_opa_t alpha2_opa_table[4] = {0, 85, 170, 255}; /*Opacity mapping with bpp = 2*/
const lv_opa_t alpha4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/ const lv_opa_t alpha4_opa_table[16] = {0, 17, 34, 51, /*Opacity mapping with bpp = 4*/
68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255}; 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255
};
/*Simply fill the buffer with the color. Later only the alpha value will be modified.*/ /*Simply fill the buffer with the color. Later only the alpha value will be modified.*/
lv_color_t bg_color = dsc->color; lv_color_t bg_color = dsc->color;
@@ -635,7 +641,8 @@ static lv_res_t lv_img_decoder_built_in_line_alpha(lv_img_decoder_dsc_t * dsc, l
const lv_img_dsc_t * img_dsc = dsc->src; const lv_img_dsc_t * img_dsc = dsc->src;
data_tmp = img_dsc->data + ofs; data_tmp = img_dsc->data + ofs;
} else { }
else {
#if LV_USE_FILESYSTEM #if LV_USE_FILESYSTEM
lv_fs_seek(user_data->f, ofs + 4); /*+4 to skip the header*/ lv_fs_seek(user_data->f, ofs + 4); /*+4 to skip the header*/
lv_fs_read(user_data->f, fs_buf, w, NULL); lv_fs_read(user_data->f, fs_buf, w, NULL);
@@ -720,7 +727,8 @@ static lv_res_t lv_img_decoder_built_in_line_indexed(lv_img_decoder_dsc_t * dsc,
if(dsc->src_type == LV_IMG_SRC_VARIABLE) { if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
const lv_img_dsc_t * img_dsc = dsc->src; const lv_img_dsc_t * img_dsc = dsc->src;
data_tmp = img_dsc->data + ofs; data_tmp = img_dsc->data + ofs;
} else { }
else {
#if LV_USE_FILESYSTEM #if LV_USE_FILESYSTEM
lv_fs_seek(user_data->f, ofs + 4); /*+4 to skip the header*/ lv_fs_seek(user_data->f, ofs + 4); /*+4 to skip the header*/
lv_fs_read(user_data->f, fs_buf, w, NULL); lv_fs_read(user_data->f, fs_buf, w, NULL);

View File

@@ -84,8 +84,7 @@ typedef lv_res_t (*lv_img_decoder_read_line_f_t)(struct _lv_img_decoder * decode
*/ */
typedef void (*lv_img_decoder_close_f_t)(struct _lv_img_decoder * decoder, struct _lv_img_decoder_dsc * dsc); typedef void (*lv_img_decoder_close_f_t)(struct _lv_img_decoder * decoder, struct _lv_img_decoder_dsc * dsc);
typedef struct _lv_img_decoder typedef struct _lv_img_decoder {
{
lv_img_decoder_info_f_t info_cb; lv_img_decoder_info_f_t info_cb;
lv_img_decoder_open_f_t open_cb; lv_img_decoder_open_f_t open_cb;
lv_img_decoder_read_line_f_t read_line_cb; lv_img_decoder_read_line_f_t read_line_cb;
@@ -97,8 +96,7 @@ typedef struct _lv_img_decoder
} lv_img_decoder_t; } lv_img_decoder_t;
/**Describe an image decoding session. Stores data about the decoding*/ /**Describe an image decoding session. Stores data about the decoding*/
typedef struct _lv_img_decoder_dsc typedef struct _lv_img_decoder_dsc {
{
/**The decoder which was able to open the image source*/ /**The decoder which was able to open the image source*/
lv_img_decoder_t * decoder; lv_img_decoder_t * decoder;

View File

@@ -58,7 +58,8 @@ const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t lett
* @return true: descriptor is successfully loaded into `dsc_out`. * @return true: descriptor is successfully loaded into `dsc_out`.
* false: the letter was not found, no data is loaded to `dsc_out` * false: the letter was not found, no data is loaded to `dsc_out`
*/ */
bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter, uint32_t letter_next) bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter,
uint32_t letter_next)
{ {
return font_p->get_glyph_dsc(font_p, dsc_out, letter, letter_next); return font_p->get_glyph_dsc(font_p, dsc_out, letter, letter_next);
} }

View File

@@ -39,15 +39,14 @@ extern "C" {
*-----------------*/ *-----------------*/
/** Describes the properties of a glyph. */ /** Describes the properties of a glyph. */
typedef struct typedef struct {
{
uint16_t adv_w; /**< The glyph needs this space. Draw the next glyph after this width. 8 bit integer, 4 bit fractional */ uint16_t adv_w; /**< The glyph needs this space. Draw the next glyph after this width. 8 bit integer, 4 bit fractional */
uint16_t box_w; /**< Width of the glyph's bounding box*/ uint16_t box_w; /**< Width of the glyph's bounding box*/
uint16_t box_h; /**< Height of the glyph's bounding box*/ uint16_t box_h; /**< Height of the glyph's bounding box*/
int16_t ofs_x; /**< x offset of the bounding box*/ int16_t ofs_x; /**< x offset of the bounding box*/
int16_t ofs_y; /**< y offset of the bounding box*/ int16_t ofs_y; /**< y offset of the bounding box*/
uint8_t bpp; /**< Bit-per-pixel: 1, 2, 4, 8*/ uint8_t bpp; /**< Bit-per-pixel: 1, 2, 4, 8*/
}lv_font_glyph_dsc_t; } lv_font_glyph_dsc_t;
/** The bitmaps might be upscaled by 3 to achieve subpixel rendering. */ /** The bitmaps might be upscaled by 3 to achieve subpixel rendering. */
@@ -61,8 +60,7 @@ enum {
typedef uint8_t lv_font_subpx_t; typedef uint8_t lv_font_subpx_t;
/** Describe the properties of a font*/ /** Describe the properties of a font*/
typedef struct _lv_font_struct typedef struct _lv_font_struct {
{
/** Get a glyph's descriptor from a font*/ /** Get a glyph's descriptor from a font*/
bool (*get_glyph_dsc)(const struct _lv_font_struct *, lv_font_glyph_dsc_t *, uint32_t letter, uint32_t letter_next); bool (*get_glyph_dsc)(const struct _lv_font_struct *, lv_font_glyph_dsc_t *, uint32_t letter, uint32_t letter_next);
@@ -72,7 +70,7 @@ typedef struct _lv_font_struct
/*Pointer to the font in a font pack (must have the same line height)*/ /*Pointer to the font in a font pack (must have the same line height)*/
lv_coord_t line_height; /**< The real line height where any text fits*/ lv_coord_t line_height; /**< The real line height where any text fits*/
lv_coord_t base_line; /**< Base line measured from the top of the line_height*/ lv_coord_t base_line; /**< Base line measured from the top of the line_height*/
uint8_t subpx :2; /**< An element of `lv_font_subpx_t`*/ uint8_t subpx : 2; /**< An element of `lv_font_subpx_t`*/
void * dsc; /**< Store implementation specific or run_time data or caching here*/ void * dsc; /**< Store implementation specific or run_time data or caching here*/
#if LV_USE_USER_DATA #if LV_USE_USER_DATA
lv_font_user_data_t user_data; /**< Custom user data for font. */ lv_font_user_data_t user_data; /**< Custom user data for font. */
@@ -101,7 +99,8 @@ const uint8_t * lv_font_get_glyph_bitmap(const lv_font_t * font_p, uint32_t lett
* @return true: descriptor is successfully loaded into `dsc_out`. * @return true: descriptor is successfully loaded into `dsc_out`.
* false: the letter was not found, no data is loaded to `dsc_out` * false: the letter was not found, no data is loaded to `dsc_out`
*/ */
bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter, uint32_t letter_next); bool lv_font_get_glyph_dsc(const lv_font_t * font_p, lv_font_glyph_dsc_t * dsc_out, uint32_t letter,
uint32_t letter_next);
/** /**
* Get the width of a glyph with kerning * Get the width of a glyph with kerning

View File

@@ -26,7 +26,7 @@ typedef enum {
RLE_STATE_SINGLE = 0, RLE_STATE_SINGLE = 0,
RLE_STATE_REPEATE, RLE_STATE_REPEATE,
RLE_STATE_COUNTER, RLE_STATE_COUNTER,
}rle_state_t; } rle_state_t;
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
@@ -88,8 +88,7 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic
if(gdsc) return &fdsc->glyph_bitmap[gdsc->bitmap_index]; if(gdsc) return &fdsc->glyph_bitmap[gdsc->bitmap_index];
} }
/*Handle compressed bitmap*/ /*Handle compressed bitmap*/
else else {
{
static uint8_t * buf = NULL; static uint8_t * buf = NULL;
uint32_t gsize = gdsc->box_w * gdsc->box_h; uint32_t gsize = gdsc->box_w * gdsc->box_h;
@@ -97,10 +96,18 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic
uint32_t buf_size = gsize; uint32_t buf_size = gsize;
switch(fdsc->bpp) { switch(fdsc->bpp) {
case 1: buf_size = gsize >> 3; break; case 1:
case 2: buf_size = gsize >> 2; break; buf_size = gsize >> 3;
case 3: buf_size = gsize >> 1; break; break;
case 4: buf_size = gsize >> 1; break; case 2:
buf_size = gsize >> 2;
break;
case 3:
buf_size = gsize >> 1;
break;
case 4:
buf_size = gsize >> 1;
break;
} }
if(lv_mem_get_size(buf) < buf_size) { if(lv_mem_get_size(buf) < buf_size) {
@@ -109,7 +116,7 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic
if(buf == NULL) return NULL; if(buf == NULL) return NULL;
} }
decompress(&fdsc->glyph_bitmap[gdsc->bitmap_index], buf, gdsc->box_w , gdsc->box_h, (uint8_t)fdsc->bpp); decompress(&fdsc->glyph_bitmap[gdsc->bitmap_index], buf, gdsc->box_w, gdsc->box_h, (uint8_t)fdsc->bpp);
return buf; return buf;
} }
@@ -125,7 +132,8 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic
* @return true: descriptor is successfully loaded into `dsc_out`. * @return true: descriptor is successfully loaded into `dsc_out`.
* false: the letter was not found, no data is loaded to `dsc_out` * false: the letter was not found, no data is loaded to `dsc_out`
*/ */
bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter,
uint32_t unicode_letter_next)
{ {
bool is_tab = false; bool is_tab = false;
if(unicode_letter == '\t') { if(unicode_letter == '\t') {
@@ -195,7 +203,8 @@ static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter)
glyph_id = fdsc->cmaps[i].glyph_id_start + gid_ofs_8[rcp]; glyph_id = fdsc->cmaps[i].glyph_id_start + gid_ofs_8[rcp];
} }
else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_TINY) { else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_TINY) {
uint8_t * p = lv_utils_bsearch(&rcp, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length, sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare); uint8_t * p = lv_utils_bsearch(&rcp, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length,
sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare);
if(p) { if(p) {
lv_uintptr_t ofs = (lv_uintptr_t)(p - (uint8_t *) fdsc->cmaps[i].unicode_list); lv_uintptr_t ofs = (lv_uintptr_t)(p - (uint8_t *) fdsc->cmaps[i].unicode_list);
@@ -204,10 +213,11 @@ static uint32_t get_glyph_dsc_id(const lv_font_t * font, uint32_t letter)
} }
} }
else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_FULL) { else if(fdsc->cmaps[i].type == LV_FONT_FMT_TXT_CMAP_SPARSE_FULL) {
uint8_t * p = lv_utils_bsearch(&rcp, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length, sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare); uint8_t * p = lv_utils_bsearch(&rcp, fdsc->cmaps[i].unicode_list, fdsc->cmaps[i].list_length,
sizeof(fdsc->cmaps[i].unicode_list[0]), unicode_list_compare);
if(p) { if(p) {
lv_uintptr_t ofs = (lv_uintptr_t)(p - (uint8_t*) fdsc->cmaps[i].unicode_list); lv_uintptr_t ofs = (lv_uintptr_t)(p - (uint8_t *) fdsc->cmaps[i].unicode_list);
ofs = ofs >> 1; /*The list stores `uint16_t` so the get the index divide by 2*/ ofs = ofs >> 1; /*The list stores `uint16_t` so the get the index divide by 2*/
const uint8_t * gid_ofs_16 = fdsc->cmaps[i].glyph_id_ofs_list; const uint8_t * gid_ofs_16 = fdsc->cmaps[i].glyph_id_ofs_list;
glyph_id = fdsc->cmaps[i].glyph_id_start + gid_ofs_16[ofs]; glyph_id = fdsc->cmaps[i].glyph_id_start + gid_ofs_16[ofs];
@@ -248,7 +258,8 @@ static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t
ofs = ofs >> 1; /*ofs is for pair, divide by 2 to refer as a single value*/ ofs = ofs >> 1; /*ofs is for pair, divide by 2 to refer as a single value*/
value = kdsc->values[ofs]; value = kdsc->values[ofs];
} }
} else if(kdsc->glyph_ids_size == 1) { }
else if(kdsc->glyph_ids_size == 1) {
/* Use binary search to find the kern value. /* Use binary search to find the kern value.
* The pairs are ordered left_id first, then right_id secondly. */ * The pairs are ordered left_id first, then right_id secondly. */
const uint16_t * g_ids = kdsc->glyph_ids; const uint16_t * g_ids = kdsc->glyph_ids;
@@ -257,15 +268,17 @@ static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t
/*If the `g_id_both` were found get its index from the pointer*/ /*If the `g_id_both` were found get its index from the pointer*/
if(kid_p) { if(kid_p) {
lv_uintptr_t ofs = (lv_uintptr_t) (kid_p - (const uint8_t *)g_ids); lv_uintptr_t ofs = (lv_uintptr_t)(kid_p - (const uint8_t *)g_ids);
ofs = ofs >> 4; /*ofs is 4 byte pairs, divide by 4 to refer as a single value*/ ofs = ofs >> 4; /*ofs is 4 byte pairs, divide by 4 to refer as a single value*/
value = kdsc->values[ofs]; value = kdsc->values[ofs];
} }
} else { }
else {
/*Invalid value*/ /*Invalid value*/
} }
} else { }
else {
/*Kern classes*/ /*Kern classes*/
const lv_font_fmt_txt_kern_classes_t * kdsc = fdsc->kern_dsc; const lv_font_fmt_txt_kern_classes_t * kdsc = fdsc->kern_dsc;
uint8_t left_class = kdsc->left_class_mapping[gid_left]; uint8_t left_class = kdsc->left_class_mapping[gid_left];
@@ -274,7 +287,7 @@ static int8_t get_kern_value(const lv_font_t * font, uint32_t gid_left, uint32_t
/* If class = 0, kerning not exist for that glyph /* If class = 0, kerning not exist for that glyph
* else got the value form `class_pair_values` 2D array*/ * else got the value form `class_pair_values` 2D array*/
if(left_class > 0 && right_class > 0) { if(left_class > 0 && right_class > 0) {
value = kdsc->class_pair_values[(left_class-1)* kdsc->right_class_cnt + (right_class-1)]; value = kdsc->class_pair_values[(left_class - 1) * kdsc->right_class_cnt + (right_class - 1)];
} }
} }
@@ -325,7 +338,7 @@ static void decompress(const uint8_t * in, uint8_t * out, lv_coord_t w, lv_coord
lv_coord_t y; lv_coord_t y;
lv_coord_t x; lv_coord_t x;
for(x = 0; x < w; x++) { for(x = 0; x < w; x++) {
bits_write(out,wrp, line_buf1[x], bpp); bits_write(out, wrp, line_buf1[x], bpp);
wrp += wr_size; wrp += wr_size;
} }
@@ -334,7 +347,7 @@ static void decompress(const uint8_t * in, uint8_t * out, lv_coord_t w, lv_coord
for(x = 0; x < w; x++) { for(x = 0; x < w; x++) {
line_buf1[x] = line_buf2[x] ^ line_buf1[x]; line_buf1[x] = line_buf2[x] ^ line_buf1[x];
bits_write(out,wrp, line_buf1[x], bpp); bits_write(out, wrp, line_buf1[x], bpp);
wrp += wr_size; wrp += wr_size;
} }
} }
@@ -388,14 +401,30 @@ static void bits_write(uint8_t * out, uint32_t bit_pos, uint8_t val, uint8_t len
if(len == 3) { if(len == 3) {
len = 4; len = 4;
switch(val) { switch(val) {
case 0: val = 0; break; case 0:
case 1: val = 2; break; val = 0;
case 2: val = 4; break; break;
case 3: val = 6; break; case 1:
case 4: val = 9; break; val = 2;
case 5: val = 11; break; break;
case 6: val = 13; break; case 2:
case 7: val = 15; break; val = 4;
break;
case 3:
val = 6;
break;
case 4:
val = 9;
break;
case 5:
val = 11;
break;
case 6:
val = 13;
break;
case 7:
val = 15;
break;
} }
} }
@@ -444,14 +473,16 @@ static uint8_t rle_next(void)
rle_rdp += 6; rle_rdp += 6;
if(rle_cnt != 0) { if(rle_cnt != 0) {
rle_state = RLE_STATE_COUNTER; rle_state = RLE_STATE_COUNTER;
} else { }
else {
ret = get_bits(rle_in, rle_rdp, rle_bpp); ret = get_bits(rle_in, rle_rdp, rle_bpp);
rle_prev_v = ret; rle_prev_v = ret;
rle_rdp += rle_bpp; rle_rdp += rle_bpp;
rle_state = RLE_STATE_SINGLE; rle_state = RLE_STATE_SINGLE;
} }
} }
} else { }
else {
ret = get_bits(rle_in, rle_rdp, rle_bpp); ret = get_bits(rle_in, rle_rdp, rle_bpp);
rle_prev_v = ret; rle_prev_v = ret;
rle_rdp += rle_bpp; rle_rdp += rle_bpp;

View File

@@ -27,11 +27,10 @@ extern "C" {
**********************/ **********************/
/** This describes a glyph. */ /** This describes a glyph. */
typedef struct typedef struct {
{
#if LV_FONT_FMT_TXT_LARGE == 0 #if LV_FONT_FMT_TXT_LARGE == 0
uint32_t bitmap_index : 20; /**< Start index of the bitmap. A font can be max 1 MB. */ uint32_t bitmap_index : 20; /**< Start index of the bitmap. A font can be max 1 MB. */
uint32_t adv_w :12; /**< Draw the next glyph after this width. 8.4 format (real_value * 16 is stored). */ uint32_t adv_w : 12; /**< Draw the next glyph after this width. 8.4 format (real_value * 16 is stored). */
uint8_t box_w; /**< Width of the glyph's bounding box*/ uint8_t box_w; /**< Width of the glyph's bounding box*/
uint8_t box_h; /**< Height of the glyph's bounding box*/ uint8_t box_h; /**< Height of the glyph's bounding box*/
int8_t ofs_x; /**< x offset of the bounding box*/ int8_t ofs_x; /**< x offset of the bounding box*/
@@ -44,7 +43,7 @@ typedef struct
int16_t ofs_x; /**< x offset of the bounding box*/ int16_t ofs_x; /**< x offset of the bounding box*/
int16_t ofs_y; /**< y offset of the bounding box. Measured from the top of the line*/ int16_t ofs_y; /**< y offset of the bounding box. Measured from the top of the line*/
#endif #endif
}lv_font_fmt_txt_glyph_dsc_t; } lv_font_fmt_txt_glyph_dsc_t;
/** Format of font character map. */ /** Format of font character map. */
@@ -112,7 +111,7 @@ typedef struct {
/** Type of this character map*/ /** Type of this character map*/
lv_font_fmt_txt_cmap_type_t type; lv_font_fmt_txt_cmap_type_t type;
}lv_font_fmt_txt_cmap_t; } lv_font_fmt_txt_cmap_t;
/** A simple mapping of kern values from pairs*/ /** A simple mapping of kern values from pairs*/
typedef struct { typedef struct {
@@ -125,9 +124,9 @@ typedef struct {
*/ */
const void * glyph_ids; const void * glyph_ids;
const int8_t * values; const int8_t * values;
uint32_t pair_cnt :24; uint32_t pair_cnt : 24;
uint32_t glyph_ids_size :2; /*0: `glyph_ids` is stored as `uint8_t`; 1: as `uint16_t`*/ uint32_t glyph_ids_size : 2; /*0: `glyph_ids` is stored as `uint8_t`; 1: as `uint16_t`*/
}lv_font_fmt_txt_kern_pair_t; } lv_font_fmt_txt_kern_pair_t;
/** More complex but more optimal class based kern value storage*/ /** More complex but more optimal class based kern value storage*/
typedef struct { typedef struct {
@@ -144,14 +143,14 @@ typedef struct {
const uint8_t * right_class_mapping; /*Map the glyph_ids to classes: index -> glyph_id -> class_id*/ const uint8_t * right_class_mapping; /*Map the glyph_ids to classes: index -> glyph_id -> class_id*/
uint8_t left_class_cnt; uint8_t left_class_cnt;
uint8_t right_class_cnt; uint8_t right_class_cnt;
}lv_font_fmt_txt_kern_classes_t; } lv_font_fmt_txt_kern_classes_t;
/** Bitmap formats*/ /** Bitmap formats*/
typedef enum { typedef enum {
LV_FONT_FMT_TXT_PLAIN = 0, LV_FONT_FMT_TXT_PLAIN = 0,
LV_FONT_FMT_TXT_COMPRESSED = 1, LV_FONT_FMT_TXT_COMPRESSED = 1,
}lv_font_fmt_txt_bitmap_format_t; } lv_font_fmt_txt_bitmap_format_t;
/*Describe store additional data for fonts */ /*Describe store additional data for fonts */
@@ -176,25 +175,25 @@ typedef struct {
uint16_t kern_scale; uint16_t kern_scale;
/*Number of cmap tables*/ /*Number of cmap tables*/
uint16_t cmap_num :10; uint16_t cmap_num : 10;
/*Bit per pixel: 1, 2, 3, 4*/ /*Bit per pixel: 1, 2, 3, 4*/
uint16_t bpp :3; uint16_t bpp : 3;
/*Type of `kern_dsc`*/ /*Type of `kern_dsc`*/
uint16_t kern_classes :1; uint16_t kern_classes : 1;
/* /*
* storage format of the bitmap * storage format of the bitmap
* from `lv_font_fmt_txt_bitmap_format_t` * from `lv_font_fmt_txt_bitmap_format_t`
*/ */
uint16_t bitmap_format :2; uint16_t bitmap_format : 2;
/*Cache the last letter and is glyph id*/ /*Cache the last letter and is glyph id*/
uint32_t last_letter; uint32_t last_letter;
uint32_t last_glyph_id; uint32_t last_glyph_id;
}lv_font_fmt_txt_dsc_t; } lv_font_fmt_txt_dsc_t;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES
@@ -216,7 +215,8 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t lett
* @return true: descriptor is successfully loaded into `dsc_out`. * @return true: descriptor is successfully loaded into `dsc_out`.
* false: the letter was not found, no data is loaded to `dsc_out` * false: the letter was not found, no data is loaded to `dsc_out`
*/ */
bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next); bool lv_font_get_glyph_dsc_fmt_txt(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter,
uint32_t unicode_letter_next);
/********************** /**********************
* MACROS * MACROS

View File

@@ -7,7 +7,7 @@
******************************************************************************/ ******************************************************************************/
#ifndef LV_FONT_ROBOTO_12 #ifndef LV_FONT_ROBOTO_12
#define LV_FONT_ROBOTO_12 1 #define LV_FONT_ROBOTO_12 1
#endif #endif
#if LV_FONT_ROBOTO_12 #if LV_FONT_ROBOTO_12
@@ -1334,8 +1334,7 @@ static const uint16_t unicode_list_1[] = {
}; };
/*Collect the unicode lists and glyph_id offsets*/ /*Collect the unicode lists and glyph_id offsets*/
static const lv_font_fmt_txt_cmap_t cmaps[] = static const lv_font_fmt_txt_cmap_t cmaps[] = {
{
{ {
.range_start = 32, .range_length = 95, .glyph_id_start = 1, .range_start = 32, .range_length = 95, .glyph_id_start = 1,
.unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY
@@ -1352,8 +1351,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] =
/*Map glyph_ids to kern left classes*/ /*Map glyph_ids to kern left classes*/
static const uint8_t kern_left_class_mapping[] = static const uint8_t kern_left_class_mapping[] = {
{
0, 1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0,
2, 3, 0, 0, 0, 4, 0, 4, 2, 3, 0, 0, 0, 4, 0, 4,
5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
@@ -1377,8 +1375,7 @@ static const uint8_t kern_left_class_mapping[] =
}; };
/*Map glyph_ids to kern right classes*/ /*Map glyph_ids to kern right classes*/
static const uint8_t kern_right_class_mapping[] = static const uint8_t kern_right_class_mapping[] = {
{
0, 1, 0, 2, 0, 0, 0, 3, 0, 1, 0, 2, 0, 0, 0, 3,
2, 0, 4, 5, 0, 6, 7, 6, 2, 0, 4, 5, 0, 6, 7, 6,
8, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0,
@@ -1402,8 +1399,7 @@ static const uint8_t kern_right_class_mapping[] =
}; };
/*Kern values between classes*/ /*Kern values between classes*/
static const int8_t kern_class_values[] = static const int8_t kern_class_values[] = {
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, -4, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -1583,8 +1579,7 @@ static const int8_t kern_class_values[] =
/*Collect the kern class' data in one place*/ /*Collect the kern class' data in one place*/
static const lv_font_fmt_txt_kern_classes_t kern_classes = static const lv_font_fmt_txt_kern_classes_t kern_classes = {
{
.class_pair_values = kern_class_values, .class_pair_values = kern_class_values,
.left_class_mapping = kern_left_class_mapping, .left_class_mapping = kern_left_class_mapping,
.right_class_mapping = kern_right_class_mapping, .right_class_mapping = kern_right_class_mapping,

View File

@@ -7,7 +7,7 @@
******************************************************************************/ ******************************************************************************/
#ifndef LV_FONT_ROBOTO_12_SUBPX #ifndef LV_FONT_ROBOTO_12_SUBPX
#define LV_FONT_ROBOTO_12_SUBPX 1 #define LV_FONT_ROBOTO_12_SUBPX 1
#endif #endif
#if LV_FONT_ROBOTO_12_SUBPX #if LV_FONT_ROBOTO_12_SUBPX
@@ -3125,8 +3125,7 @@ static const uint16_t unicode_list_1[] = {
}; };
/*Collect the unicode lists and glyph_id offsets*/ /*Collect the unicode lists and glyph_id offsets*/
static const lv_font_fmt_txt_cmap_t cmaps[] = static const lv_font_fmt_txt_cmap_t cmaps[] = {
{
{ {
.range_start = 32, .range_length = 95, .glyph_id_start = 1, .range_start = 32, .range_length = 95, .glyph_id_start = 1,
.unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY
@@ -3143,8 +3142,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] =
/*Map glyph_ids to kern left classes*/ /*Map glyph_ids to kern left classes*/
static const uint8_t kern_left_class_mapping[] = static const uint8_t kern_left_class_mapping[] = {
{
0, 1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0,
2, 3, 0, 0, 0, 4, 0, 4, 2, 3, 0, 0, 0, 4, 0, 4,
5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
@@ -3168,8 +3166,7 @@ static const uint8_t kern_left_class_mapping[] =
}; };
/*Map glyph_ids to kern right classes*/ /*Map glyph_ids to kern right classes*/
static const uint8_t kern_right_class_mapping[] = static const uint8_t kern_right_class_mapping[] = {
{
0, 1, 0, 2, 0, 0, 0, 3, 0, 1, 0, 2, 0, 0, 0, 3,
2, 0, 4, 5, 0, 6, 7, 6, 2, 0, 4, 5, 0, 6, 7, 6,
8, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0,
@@ -3193,8 +3190,7 @@ static const uint8_t kern_right_class_mapping[] =
}; };
/*Kern values between classes*/ /*Kern values between classes*/
static const int8_t kern_class_values[] = static const int8_t kern_class_values[] = {
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, 0, 0, -4, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -3374,8 +3370,7 @@ static const int8_t kern_class_values[] =
/*Collect the kern class' data in one place*/ /*Collect the kern class' data in one place*/
static const lv_font_fmt_txt_kern_classes_t kern_classes = static const lv_font_fmt_txt_kern_classes_t kern_classes = {
{
.class_pair_values = kern_class_values, .class_pair_values = kern_class_values,
.left_class_mapping = kern_left_class_mapping, .left_class_mapping = kern_left_class_mapping,
.right_class_mapping = kern_right_class_mapping, .right_class_mapping = kern_right_class_mapping,

View File

@@ -7,7 +7,7 @@
******************************************************************************/ ******************************************************************************/
#ifndef LV_FONT_ROBOTO_16 #ifndef LV_FONT_ROBOTO_16
#define LV_FONT_ROBOTO_16 1 #define LV_FONT_ROBOTO_16 1
#endif #endif
#if LV_FONT_ROBOTO_16 #if LV_FONT_ROBOTO_16
@@ -1826,8 +1826,7 @@ static const uint16_t unicode_list_1[] = {
}; };
/*Collect the unicode lists and glyph_id offsets*/ /*Collect the unicode lists and glyph_id offsets*/
static const lv_font_fmt_txt_cmap_t cmaps[] = static const lv_font_fmt_txt_cmap_t cmaps[] = {
{
{ {
.range_start = 32, .range_length = 95, .glyph_id_start = 1, .range_start = 32, .range_length = 95, .glyph_id_start = 1,
.unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY
@@ -1844,8 +1843,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] =
/*Pair left and right glyphs for kerning*/ /*Pair left and right glyphs for kerning*/
static const uint8_t kern_pair_glyph_ids[] = static const uint8_t kern_pair_glyph_ids[] = {
{
1, 53, 1, 53,
3, 3, 3, 3,
3, 8, 3, 8,
@@ -2285,8 +2283,7 @@ static const uint8_t kern_pair_glyph_ids[] =
/* Kerning between the respective left and right glyphs /* Kerning between the respective left and right glyphs
* 4.4 format which needs to scaled with `kern_scale`*/ * 4.4 format which needs to scaled with `kern_scale`*/
static const int8_t kern_pair_values[] = static const int8_t kern_pair_values[] = {
{
-5, -13, -13, -15, -6, -7, -7, -7, -5, -13, -13, -15, -6, -7, -7, -7,
-7, -2, -2, -8, -2, -7, -10, 1, -7, -2, -2, -8, -2, -7, -10, 1,
-13, -13, -15, -6, -7, -7, -7, -7, -13, -13, -15, -6, -7, -7, -7, -7,
@@ -2342,11 +2339,10 @@ static const int8_t kern_pair_values[] =
2, -13, -13, -2, -2, -2, -2, 2, 2, -13, -13, -2, -2, -2, -2, 2,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2 -2, -2, -2
}; };
/*Collect the kern pair's data in one place*/ /*Collect the kern pair's data in one place*/
static const lv_font_fmt_txt_kern_pair_t kern_pairs = static const lv_font_fmt_txt_kern_pair_t kern_pairs = {
{
.glyph_ids = kern_pair_glyph_ids, .glyph_ids = kern_pair_glyph_ids,
.values = kern_pair_values, .values = kern_pair_values,
.pair_cnt = 435, .pair_cnt = 435,

View File

@@ -7,7 +7,7 @@
******************************************************************************/ ******************************************************************************/
#ifndef LV_FONT_ROBOTO_22 #ifndef LV_FONT_ROBOTO_22
#define LV_FONT_ROBOTO_22 1 #define LV_FONT_ROBOTO_22 1
#endif #endif
#if LV_FONT_ROBOTO_22 #if LV_FONT_ROBOTO_22
@@ -2930,8 +2930,7 @@ static const uint16_t unicode_list_1[] = {
}; };
/*Collect the unicode lists and glyph_id offsets*/ /*Collect the unicode lists and glyph_id offsets*/
static const lv_font_fmt_txt_cmap_t cmaps[] = static const lv_font_fmt_txt_cmap_t cmaps[] = {
{
{ {
.range_start = 32, .range_length = 95, .glyph_id_start = 1, .range_start = 32, .range_length = 95, .glyph_id_start = 1,
.unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY
@@ -2948,8 +2947,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] =
/*Map glyph_ids to kern left classes*/ /*Map glyph_ids to kern left classes*/
static const uint8_t kern_left_class_mapping[] = static const uint8_t kern_left_class_mapping[] = {
{
0, 1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0,
2, 3, 0, 0, 0, 4, 0, 4, 2, 3, 0, 0, 0, 4, 0, 4,
5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
@@ -2973,8 +2971,7 @@ static const uint8_t kern_left_class_mapping[] =
}; };
/*Map glyph_ids to kern right classes*/ /*Map glyph_ids to kern right classes*/
static const uint8_t kern_right_class_mapping[] = static const uint8_t kern_right_class_mapping[] = {
{
0, 1, 0, 2, 0, 0, 0, 3, 0, 1, 0, 2, 0, 0, 0, 3,
2, 0, 4, 5, 0, 6, 7, 6, 2, 0, 4, 5, 0, 6, 7, 6,
8, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0,
@@ -2998,8 +2995,7 @@ static const uint8_t kern_right_class_mapping[] =
}; };
/*Kern values between classes*/ /*Kern values between classes*/
static const int8_t kern_class_values[] = static const int8_t kern_class_values[] = {
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, -7, 0, 0, 0, 0, 0, 0, 0, -7, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -3179,8 +3175,7 @@ static const int8_t kern_class_values[] =
/*Collect the kern class' data in one place*/ /*Collect the kern class' data in one place*/
static const lv_font_fmt_txt_kern_classes_t kern_classes = static const lv_font_fmt_txt_kern_classes_t kern_classes = {
{
.class_pair_values = kern_class_values, .class_pair_values = kern_class_values,
.left_class_mapping = kern_left_class_mapping, .left_class_mapping = kern_left_class_mapping,
.right_class_mapping = kern_right_class_mapping, .right_class_mapping = kern_right_class_mapping,

View File

@@ -7,7 +7,7 @@
******************************************************************************/ ******************************************************************************/
#ifndef LV_FONT_ROBOTO_28 #ifndef LV_FONT_ROBOTO_28
#define LV_FONT_ROBOTO_28 1 #define LV_FONT_ROBOTO_28 1
#endif #endif
#if LV_FONT_ROBOTO_28 #if LV_FONT_ROBOTO_28
@@ -4315,8 +4315,7 @@ static const uint16_t unicode_list_1[] = {
}; };
/*Collect the unicode lists and glyph_id offsets*/ /*Collect the unicode lists and glyph_id offsets*/
static const lv_font_fmt_txt_cmap_t cmaps[] = static const lv_font_fmt_txt_cmap_t cmaps[] = {
{
{ {
.range_start = 32, .range_length = 95, .glyph_id_start = 1, .range_start = 32, .range_length = 95, .glyph_id_start = 1,
.unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY
@@ -4333,8 +4332,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] =
/*Map glyph_ids to kern left classes*/ /*Map glyph_ids to kern left classes*/
static const uint8_t kern_left_class_mapping[] = static const uint8_t kern_left_class_mapping[] = {
{
0, 1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0,
2, 3, 0, 0, 0, 4, 0, 4, 2, 3, 0, 0, 0, 4, 0, 4,
5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
@@ -4358,8 +4356,7 @@ static const uint8_t kern_left_class_mapping[] =
}; };
/*Map glyph_ids to kern right classes*/ /*Map glyph_ids to kern right classes*/
static const uint8_t kern_right_class_mapping[] = static const uint8_t kern_right_class_mapping[] = {
{
0, 1, 0, 2, 0, 0, 0, 3, 0, 1, 0, 2, 0, 0, 0, 3,
2, 0, 4, 5, 0, 6, 7, 6, 2, 0, 4, 5, 0, 6, 7, 6,
8, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0,
@@ -4383,8 +4380,7 @@ static const uint8_t kern_right_class_mapping[] =
}; };
/*Kern values between classes*/ /*Kern values between classes*/
static const int8_t kern_class_values[] = static const int8_t kern_class_values[] = {
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, -9, 0, 0, 0, 0, 0, 0, 0, -9, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -4564,8 +4560,7 @@ static const int8_t kern_class_values[] =
/*Collect the kern class' data in one place*/ /*Collect the kern class' data in one place*/
static const lv_font_fmt_txt_kern_classes_t kern_classes = static const lv_font_fmt_txt_kern_classes_t kern_classes = {
{
.class_pair_values = kern_class_values, .class_pair_values = kern_class_values,
.left_class_mapping = kern_left_class_mapping, .left_class_mapping = kern_left_class_mapping,
.right_class_mapping = kern_right_class_mapping, .right_class_mapping = kern_right_class_mapping,

View File

@@ -7,7 +7,7 @@
******************************************************************************/ ******************************************************************************/
#ifndef LV_FONT_ROBOTO_28_COMPRESSED #ifndef LV_FONT_ROBOTO_28_COMPRESSED
#define LV_FONT_ROBOTO_28_COMPRESSED 1 #define LV_FONT_ROBOTO_28_COMPRESSED 1
#endif #endif
#if LV_FONT_ROBOTO_28_COMPRESSED #if LV_FONT_ROBOTO_28_COMPRESSED
@@ -2157,8 +2157,7 @@ static const uint16_t unicode_list_1[] = {
}; };
/*Collect the unicode lists and glyph_id offsets*/ /*Collect the unicode lists and glyph_id offsets*/
static const lv_font_fmt_txt_cmap_t cmaps[] = static const lv_font_fmt_txt_cmap_t cmaps[] = {
{
{ {
.range_start = 32, .range_length = 95, .glyph_id_start = 1, .range_start = 32, .range_length = 95, .glyph_id_start = 1,
.unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY
@@ -2175,8 +2174,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] =
/*Map glyph_ids to kern left classes*/ /*Map glyph_ids to kern left classes*/
static const uint8_t kern_left_class_mapping[] = static const uint8_t kern_left_class_mapping[] = {
{
0, 1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0,
2, 3, 0, 0, 0, 4, 0, 4, 2, 3, 0, 0, 0, 4, 0, 4,
5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
@@ -2200,8 +2198,7 @@ static const uint8_t kern_left_class_mapping[] =
}; };
/*Map glyph_ids to kern right classes*/ /*Map glyph_ids to kern right classes*/
static const uint8_t kern_right_class_mapping[] = static const uint8_t kern_right_class_mapping[] = {
{
0, 1, 0, 2, 0, 0, 0, 3, 0, 1, 0, 2, 0, 0, 0, 3,
2, 0, 4, 5, 0, 6, 7, 6, 2, 0, 4, 5, 0, 6, 7, 6,
8, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0,
@@ -2225,8 +2222,7 @@ static const uint8_t kern_right_class_mapping[] =
}; };
/*Kern values between classes*/ /*Kern values between classes*/
static const int8_t kern_class_values[] = static const int8_t kern_class_values[] = {
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, -9, 0, 0, 0, 0, 0, 0, 0, -9, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -2406,8 +2402,7 @@ static const int8_t kern_class_values[] =
/*Collect the kern class' data in one place*/ /*Collect the kern class' data in one place*/
static const lv_font_fmt_txt_kern_classes_t kern_classes = static const lv_font_fmt_txt_kern_classes_t kern_classes = {
{
.class_pair_values = kern_class_values, .class_pair_values = kern_class_values,
.left_class_mapping = kern_left_class_mapping, .left_class_mapping = kern_left_class_mapping,
.right_class_mapping = kern_right_class_mapping, .right_class_mapping = kern_right_class_mapping,

View File

@@ -7,7 +7,7 @@
******************************************************************************/ ******************************************************************************/
#ifndef LV_FONT_UNSCII_8 #ifndef LV_FONT_UNSCII_8
#define LV_FONT_UNSCII_8 1 #define LV_FONT_UNSCII_8 1
#endif #endif
#if LV_FONT_UNSCII_8 #if LV_FONT_UNSCII_8
@@ -418,8 +418,7 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
/*Collect the unicode lists and glyph_id offsets*/ /*Collect the unicode lists and glyph_id offsets*/
static const lv_font_fmt_txt_cmap_t cmaps[] = static const lv_font_fmt_txt_cmap_t cmaps[] = {
{
{ {
.range_start = 32, .range_length = 96, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY, .range_start = 32, .range_length = 96, .type = LV_FONT_FMT_TXT_CMAP_FORMAT0_TINY,
.glyph_id_start = 1, .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0 .glyph_id_start = 1, .unicode_list = NULL, .glyph_id_ofs_list = NULL, .list_length = 0

View File

@@ -20,7 +20,7 @@
#include "../lv_themes/lv_theme.h" #include "../lv_themes/lv_theme.h"
#if defined(LV_GC_INCLUDE) #if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE #include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
/********************* /*********************
@@ -170,8 +170,7 @@ void lv_disp_drv_update(lv_disp_t * disp, lv_disp_drv_t * new_drv)
memcpy(&disp->driver, new_drv, sizeof(lv_disp_drv_t)); memcpy(&disp->driver, new_drv, sizeof(lv_disp_drv_t));
lv_obj_t * scr; lv_obj_t * scr;
LV_LL_READ(disp->scr_ll, scr) LV_LL_READ(disp->scr_ll, scr) {
{
lv_obj_set_size(scr, lv_disp_get_hor_res(disp), lv_disp_get_ver_res(disp)); lv_obj_set_size(scr, lv_disp_get_hor_res(disp), lv_disp_get_ver_res(disp));
} }
} }
@@ -352,7 +351,8 @@ bool lv_disp_is_true_double_buf(lv_disp_t * disp)
if(lv_disp_is_double_buf(disp) && disp->driver.buffer->size == scr_size) { if(lv_disp_is_double_buf(disp) && disp->driver.buffer->size == scr_size) {
return true; return true;
} else { }
else {
return false; return false;
} }
} }

View File

@@ -44,8 +44,7 @@ struct _disp_drv_t;
/** /**
* Structure for holding display buffer information. * Structure for holding display buffer information.
*/ */
typedef struct typedef struct {
{
void * buf1; /**< First display buffer. */ void * buf1; /**< First display buffer. */
void * buf2; /**< Second display buffer. */ void * buf2; /**< Second display buffer. */
@@ -59,8 +58,7 @@ typedef struct
/** /**
* Display Driver structure to be registered by HAL * Display Driver structure to be registered by HAL
*/ */
typedef struct _disp_drv_t typedef struct _disp_drv_t {
{
lv_coord_t hor_res; /**< Horizontal resolution. */ lv_coord_t hor_res; /**< Horizontal resolution. */
lv_coord_t ver_res; /**< Vertical resolution. */ lv_coord_t ver_res; /**< Vertical resolution. */
@@ -124,8 +122,7 @@ struct _lv_obj_t;
* Display structure. * Display structure.
* ::lv_disp_drv_t is the first member of the structure. * ::lv_disp_drv_t is the first member of the structure.
*/ */
typedef struct _disp_t typedef struct _disp_t {
{
/**< Driver to the display*/ /**< Driver to the display*/
lv_disp_drv_t driver; lv_disp_drv_t driver;

View File

@@ -16,7 +16,7 @@
#include "lv_hal_disp.h" #include "lv_hal_disp.h"
#if defined(LV_GC_INCLUDE) #if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE #include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
/********************* /*********************
@@ -148,7 +148,8 @@ bool lv_indev_read(lv_indev_t * indev, lv_indev_data_t * data)
LV_LOG_TRACE("idnev read started"); LV_LOG_TRACE("idnev read started");
cont = indev->driver.read_cb(&indev->driver, data); cont = indev->driver.read_cb(&indev->driver, data);
LV_LOG_TRACE("idnev read finished"); LV_LOG_TRACE("idnev read finished");
} else { }
else {
LV_LOG_WARN("indev function registered"); LV_LOG_WARN("indev function registered");
} }

View File

@@ -69,8 +69,7 @@ enum {
typedef uint8_t lv_gesture_dir_t; typedef uint8_t lv_gesture_dir_t;
/** Data structure passed to an input driver to fill */ /** Data structure passed to an input driver to fill */
typedef struct typedef struct {
{
lv_point_t point; /**< For LV_INDEV_TYPE_POINTER the currently pressed point*/ lv_point_t point; /**< For LV_INDEV_TYPE_POINTER the currently pressed point*/
uint32_t key; /**< For LV_INDEV_TYPE_KEYPAD the currently pressed key*/ uint32_t key; /**< For LV_INDEV_TYPE_KEYPAD the currently pressed key*/
uint32_t btn_id; /**< For LV_INDEV_TYPE_BUTTON the currently pressed button*/ uint32_t btn_id; /**< For LV_INDEV_TYPE_BUTTON the currently pressed button*/
@@ -81,8 +80,7 @@ typedef struct
/** Initialized by the user and registered by 'lv_indev_add()'*/ /** Initialized by the user and registered by 'lv_indev_add()'*/
typedef struct _lv_indev_drv_t typedef struct _lv_indev_drv_t {
{
/**< Input device type*/ /**< Input device type*/
lv_indev_type_t type; lv_indev_type_t type;
@@ -128,13 +126,11 @@ typedef struct _lv_indev_drv_t
/** Run time data of input devices /** Run time data of input devices
* Internally used by the library, you should not need to touch it. * Internally used by the library, you should not need to touch it.
*/ */
typedef struct _lv_indev_proc_t typedef struct _lv_indev_proc_t {
{
lv_indev_state_t state; /**< Current state of the input device. */ lv_indev_state_t state; /**< Current state of the input device. */
union union {
{ struct {
struct /*Pointer and button data*/
{ /*Pointer and button data*/
lv_point_t act_point; /**< Current point of input device. */ lv_point_t act_point; /**< Current point of input device. */
lv_point_t last_point; /**< Last point of input device. */ lv_point_t last_point; /**< Last point of input device. */
lv_point_t vect; /**< Difference between `act_point` and `last_point`. */ lv_point_t vect; /**< Difference between `act_point` and `last_point`. */
@@ -153,8 +149,8 @@ typedef struct _lv_indev_proc_t
lv_drag_dir_t drag_dir : 3; lv_drag_dir_t drag_dir : 3;
uint8_t gesture_sent : 1; uint8_t gesture_sent : 1;
} pointer; } pointer;
struct struct {
{ /*Keypad data*/ /*Keypad data*/
lv_indev_state_t last_state; lv_indev_state_t last_state;
uint32_t last_key; uint32_t last_key;
} keypad; } keypad;
@@ -175,8 +171,7 @@ struct _lv_group_t;
/** The main input device descriptor with driver, runtime data ('proc') and some additional /** The main input device descriptor with driver, runtime data ('proc') and some additional
* information*/ * information*/
typedef struct _lv_indev_t typedef struct _lv_indev_t {
{
lv_indev_drv_t driver; lv_indev_drv_t driver;
lv_indev_proc_t proc; lv_indev_proc_t proc;
struct _lv_obj_t * cursor; /**< Cursor for LV_INPUT_TYPE_POINTER*/ struct _lv_obj_t * cursor; /**< Cursor for LV_INPUT_TYPE_POINTER*/

View File

@@ -10,7 +10,7 @@
#include <stddef.h> #include <stddef.h>
#if LV_TICK_CUSTOM == 1 #if LV_TICK_CUSTOM == 1
#include LV_TICK_CUSTOM_INCLUDE #include LV_TICK_CUSTOM_INCLUDE
#endif #endif
/********************* /*********************
@@ -81,7 +81,8 @@ uint32_t lv_tick_elaps(uint32_t prev_tick)
/*If there is no overflow in sys_time simple subtract*/ /*If there is no overflow in sys_time simple subtract*/
if(act_time >= prev_tick) { if(act_time >= prev_tick) {
prev_tick = act_time - prev_tick; prev_tick = act_time - prev_tick;
} else { }
else {
prev_tick = UINT32_MAX - prev_tick + 1; prev_tick = UINT32_MAX - prev_tick + 1;
prev_tick += act_time; prev_tick += act_time;
} }

View File

@@ -18,7 +18,7 @@
#include "lv_gc.h" #include "lv_gc.h"
#if defined(LV_GC_INCLUDE) #if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE #include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
/********************* /*********************
@@ -209,7 +209,8 @@ lv_anim_value_t lv_anim_path_linear(const lv_anim_t * a)
uint32_t step; uint32_t step;
if(a->time == a->act_time) { if(a->time == a->act_time) {
step = LV_ANIM_RESOLUTION; /*Use the last value if the time fully elapsed*/ step = LV_ANIM_RESOLUTION; /*Use the last value if the time fully elapsed*/
} else { }
else {
step = ((int32_t)a->act_time * LV_ANIM_RESOLUTION) / a->time; step = ((int32_t)a->act_time * LV_ANIM_RESOLUTION) / a->time;
} }
@@ -344,24 +345,28 @@ lv_anim_value_t lv_anim_path_bounce(const lv_anim_t * a)
if(t < 408) { if(t < 408) {
/*Go down*/ /*Go down*/
t = (t * 2500) >> 10; /*[0..1024] range*/ t = (t * 2500) >> 10; /*[0..1024] range*/
} else if(t >= 408 && t < 614) { }
else if(t >= 408 && t < 614) {
/*First bounce back*/ /*First bounce back*/
t -= 408; t -= 408;
t = t * 5; /*to [0..1024] range*/ t = t * 5; /*to [0..1024] range*/
t = 1024 - t; t = 1024 - t;
diff = diff / 6; diff = diff / 6;
} else if(t >= 614 && t < 819) { }
else if(t >= 614 && t < 819) {
/*Fall back*/ /*Fall back*/
t -= 614; t -= 614;
t = t * 5; /*to [0..1024] range*/ t = t * 5; /*to [0..1024] range*/
diff = diff / 6; diff = diff / 6;
} else if(t >= 819 && t < 921) { }
else if(t >= 819 && t < 921) {
/*Second bounce back*/ /*Second bounce back*/
t -= 819; t -= 819;
t = t * 10; /*to [0..1024] range*/ t = t * 10; /*to [0..1024] range*/
t = 1024 - t; t = 1024 - t;
diff = diff / 16; diff = diff / 16;
} else if(t >= 921 && t <= 1024) { }
else if(t >= 921 && t <= 1024) {
/*Fall back*/ /*Fall back*/
t -= 921; t -= 921;
t = t * 10; /*to [0..1024] range*/ t = t * 10; /*to [0..1024] range*/
@@ -407,8 +412,7 @@ static void anim_task(lv_task_t * param)
(void)param; (void)param;
lv_anim_t * a; lv_anim_t * a;
LV_LL_READ(LV_GC_ROOT(_lv_anim_ll), a) LV_LL_READ(LV_GC_ROOT(_lv_anim_ll), a) {
{
a->has_run = 0; a->has_run = 0;
} }

View File

@@ -66,8 +66,7 @@ typedef void (*lv_anim_ready_cb_t)(struct _lv_anim_t *);
typedef void (*lv_anim_start_cb_t)(struct _lv_anim_t *); typedef void (*lv_anim_start_cb_t)(struct _lv_anim_t *);
/** Describes an animation*/ /** Describes an animation*/
typedef struct _lv_anim_t typedef struct _lv_anim_t {
{
void * var; /**<Variable to animate*/ void * var; /**<Variable to animate*/
lv_anim_exec_xcb_t exec_cb; /**< Function to execute to animate*/ lv_anim_exec_xcb_t exec_cb; /**< Function to execute to animate*/
lv_anim_path_cb_t path_cb; /**< Function to get the steps of animations*/ lv_anim_path_cb_t path_cb; /**< Function to get the steps of animations*/
@@ -81,7 +80,7 @@ typedef struct _lv_anim_t
uint32_t playback_time; /**< Duration of playback animation*/ uint32_t playback_time; /**< Duration of playback animation*/
uint32_t repeat_delay; /**< Wait before repeat*/ uint32_t repeat_delay; /**< Wait before repeat*/
uint16_t repeat_cnt; /**< Repeat count for the animation*/ uint16_t repeat_cnt; /**< Repeat count for the animation*/
uint8_t early_apply :1; /**< 1: Apply start value immediately even is there is `delay` */ uint8_t early_apply : 1; /**< 1: Apply start value immediately even is there is `delay` */
#if LV_USE_USER_DATA #if LV_USE_USER_DATA
lv_anim_user_data_t user_data; /**< Custom user data*/ lv_anim_user_data_t user_data; /**< Custom user data*/
#endif #endif

View File

@@ -215,7 +215,8 @@ 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)) { 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; return true;
} else { }
else {
return false; return false;
} }
} }
@@ -408,8 +409,8 @@ static bool lv_point_within_circle(const lv_area_t * area, const lv_point_t * p)
lv_coord_t px = p->x - cx; lv_coord_t px = p->x - cx;
lv_coord_t py = p->y - cy; lv_coord_t py = p->y - cy;
int32_t r_sqrd = r*r; int32_t r_sqrd = r * r;
int32_t dist = (px*px) + (py*py); int32_t dist = (px * px) + (py * py);
if(dist <= r_sqrd) if(dist <= r_sqrd)
return true; return true;

View File

@@ -35,15 +35,13 @@ LV_EXPORT_CONST_INT(LV_COORD_MIN);
/** /**
* Represents a point on the screen. * Represents a point on the screen.
*/ */
typedef struct typedef struct {
{
lv_coord_t x; lv_coord_t x;
lv_coord_t y; lv_coord_t y;
} lv_point_t; } lv_point_t;
/** Represents an area of the screen. */ /** Represents an area of the screen. */
typedef struct typedef struct {
{
lv_coord_t x1; lv_coord_t x1;
lv_coord_t y1; lv_coord_t y1;
lv_coord_t x2; lv_coord_t x2;

View File

@@ -21,7 +21,7 @@
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static void lv_async_task_cb(lv_task_t *task); static void lv_async_task_cb(lv_task_t * task);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@@ -38,14 +38,14 @@ static void lv_async_task_cb(lv_task_t *task);
lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data) lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data)
{ {
/*Allocate an info structure */ /*Allocate an info structure */
lv_async_info_t *info = lv_mem_alloc(sizeof(lv_async_info_t)); lv_async_info_t * info = lv_mem_alloc(sizeof(lv_async_info_t));
if(info == NULL) if(info == NULL)
return LV_RES_INV; return LV_RES_INV;
/* Create a new task */ /* Create a new task */
/* Use highest priority so that it will run before a refresh */ /* Use highest priority so that it will run before a refresh */
lv_task_t *task = lv_task_create(lv_async_task_cb, 0, LV_TASK_PRIO_HIGHEST, info); lv_task_t * task = lv_task_create(lv_async_task_cb, 0, LV_TASK_PRIO_HIGHEST, info);
if(task == NULL) { if(task == NULL) {
lv_mem_free(info); lv_mem_free(info);
@@ -65,9 +65,9 @@ lv_res_t lv_async_call(lv_async_cb_t async_xcb, void * user_data)
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
static void lv_async_task_cb(lv_task_t *task) static void lv_async_task_cb(lv_task_t * task)
{ {
lv_async_info_t *info = (lv_async_info_t *)task->user_data; lv_async_info_t * info = (lv_async_info_t *)task->user_data;
info->cb(info->user_data); info->cb(info->user_data);

View File

@@ -32,7 +32,7 @@ typedef void (*lv_async_cb_t)(void *);
typedef struct _lv_async_info_t { typedef struct _lv_async_info_t {
lv_async_cb_t cb; lv_async_cb_t cb;
void *user_data; void * user_data;
} lv_async_info_t; } lv_async_info_t;
struct _lv_obj_t; struct _lv_obj_t;

View File

@@ -26,19 +26,21 @@
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
typedef struct typedef struct {
{
uint32_t bracklet_pos; uint32_t bracklet_pos;
lv_bidi_dir_t dir; lv_bidi_dir_t dir;
}bracket_stack_t; } bracket_stack_t;
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static lv_bidi_dir_t get_next_run(const char * txt, lv_bidi_dir_t base_dir, uint32_t max_len, uint32_t * len, uint16_t * pos_conv_len); static lv_bidi_dir_t get_next_run(const char * txt, lv_bidi_dir_t base_dir, uint32_t max_len, uint32_t * len,
static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *pos_conv_out, uint16_t pos_conv_rd_base, uint16_t pos_conv_len); uint16_t * pos_conv_len);
static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t * pos_conv_out, uint16_t pos_conv_rd_base,
uint16_t pos_conv_len);
static uint32_t char_change_to_pair(uint32_t letter); static uint32_t char_change_to_pair(uint32_t letter);
static lv_bidi_dir_t bracket_process(const char * txt, uint32_t next_pos, uint32_t len, uint32_t letter, lv_bidi_dir_t base_dir); static lv_bidi_dir_t bracket_process(const char * txt, uint32_t next_pos, uint32_t len, uint32_t letter,
lv_bidi_dir_t base_dir);
static void fill_pos_conv(uint16_t * out, uint16_t len, uint16_t index); static void fill_pos_conv(uint16_t * out, uint16_t len, uint16_t index);
static uint32_t get_txt_len(const char * txt, uint32_t max_len); static uint32_t get_txt_len(const char * txt, uint32_t max_len);
@@ -185,23 +187,24 @@ bool lv_bidi_letter_is_neutral(uint32_t letter)
* @param is_rtl tell the the char at `viasual_pos` is RTL or LTR context * @param is_rtl tell the the char at `viasual_pos` is RTL or LTR context
* @return the logical character position * @return the logical character position
*/ */
uint16_t lv_bidi_get_logical_pos(const char * str_in, char **bidi_txt, uint32_t len, lv_bidi_dir_t base_dir, uint32_t visual_pos, bool *is_rtl) uint16_t lv_bidi_get_logical_pos(const char * str_in, char ** bidi_txt, uint32_t len, lv_bidi_dir_t base_dir,
uint32_t visual_pos, bool * is_rtl)
{ {
uint32_t pos_conv_len = get_txt_len(str_in, len); uint32_t pos_conv_len = get_txt_len(str_in, len);
char * buf = lv_mem_buf_get(len + 1); char * buf = lv_mem_buf_get(len + 1);
if(buf == NULL) return (uint16_t) -1; if(buf == NULL) return (uint16_t) -1;
uint16_t *pos_conv_buf = lv_mem_buf_get(pos_conv_len * sizeof(uint16_t)); uint16_t * pos_conv_buf = lv_mem_buf_get(pos_conv_len * sizeof(uint16_t));
if(pos_conv_buf == NULL) { if(pos_conv_buf == NULL) {
lv_mem_buf_release(buf); lv_mem_buf_release(buf);
return (uint16_t) -1; return (uint16_t) -1;
} }
if (bidi_txt) *bidi_txt = buf; if(bidi_txt) *bidi_txt = buf;
lv_bidi_process_paragraph(str_in, bidi_txt? *bidi_txt: NULL, len, base_dir, pos_conv_buf, pos_conv_len); lv_bidi_process_paragraph(str_in, bidi_txt ? *bidi_txt : NULL, len, base_dir, pos_conv_buf, pos_conv_len);
if (is_rtl) *is_rtl = IS_RTL_POS(pos_conv_buf[visual_pos]); if(is_rtl) *is_rtl = IS_RTL_POS(pos_conv_buf[visual_pos]);
if(bidi_txt == NULL) lv_mem_buf_release(buf); if(bidi_txt == NULL) lv_mem_buf_release(buf);
uint16_t res = GET_POS(pos_conv_buf[visual_pos]); uint16_t res = GET_POS(pos_conv_buf[visual_pos]);
@@ -221,26 +224,27 @@ uint16_t lv_bidi_get_logical_pos(const char * str_in, char **bidi_txt, uint32_t
* @param is_rtl tell the the char at `logical_pos` is RTL or LTR context * @param is_rtl tell the the char at `logical_pos` is RTL or LTR context
* @return the visual character position * @return the visual character position
*/ */
uint16_t lv_bidi_get_visual_pos(const char * str_in, char **bidi_txt, uint16_t len, lv_bidi_dir_t base_dir, uint32_t logical_pos, bool *is_rtl) uint16_t lv_bidi_get_visual_pos(const char * str_in, char ** bidi_txt, uint16_t len, lv_bidi_dir_t base_dir,
uint32_t logical_pos, bool * is_rtl)
{ {
uint32_t pos_conv_len = get_txt_len(str_in, len); uint32_t pos_conv_len = get_txt_len(str_in, len);
char * buf = lv_mem_buf_get(len + 1); char * buf = lv_mem_buf_get(len + 1);
if(buf == NULL) return (uint16_t) -1; if(buf == NULL) return (uint16_t) -1;
uint16_t *pos_conv_buf = lv_mem_buf_get(pos_conv_len * sizeof(uint16_t)); uint16_t * pos_conv_buf = lv_mem_buf_get(pos_conv_len * sizeof(uint16_t));
if(pos_conv_buf == NULL) { if(pos_conv_buf == NULL) {
lv_mem_buf_release(buf); lv_mem_buf_release(buf);
return (uint16_t) -1; return (uint16_t) -1;
} }
if (bidi_txt) *bidi_txt = buf; if(bidi_txt) *bidi_txt = buf;
lv_bidi_process_paragraph(str_in, bidi_txt ? *bidi_txt: NULL, len, base_dir, pos_conv_buf, pos_conv_len); lv_bidi_process_paragraph(str_in, bidi_txt ? *bidi_txt : NULL, len, base_dir, pos_conv_buf, pos_conv_len);
for (uint16_t i = 0; i < pos_conv_len; i++){ for(uint16_t i = 0; i < pos_conv_len; i++) {
if (GET_POS(pos_conv_buf[i]) == logical_pos){ if(GET_POS(pos_conv_buf[i]) == logical_pos) {
if (is_rtl) *is_rtl = IS_RTL_POS(pos_conv_buf[i]); if(is_rtl) *is_rtl = IS_RTL_POS(pos_conv_buf[i]);
lv_mem_buf_release(pos_conv_buf); lv_mem_buf_release(pos_conv_buf);
if(bidi_txt == NULL) lv_mem_buf_release(buf); if(bidi_txt == NULL) lv_mem_buf_release(buf);
@@ -262,7 +266,8 @@ uint16_t lv_bidi_get_visual_pos(const char * str_in, char **bidi_txt, uint16_t l
* Can be `NULL` is unused * Can be `NULL` is unused
* @param pos_conv_len length of `pos_conv_out` in element count * @param pos_conv_len length of `pos_conv_out` in element count
*/ */
void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_bidi_dir_t base_dir, uint16_t *pos_conv_out, uint16_t pos_conv_len) void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_bidi_dir_t base_dir,
uint16_t * pos_conv_out, uint16_t pos_conv_len)
{ {
uint32_t run_len = 0; uint32_t run_len = 0;
lv_bidi_dir_t run_dir; lv_bidi_dir_t run_dir;
@@ -282,7 +287,7 @@ void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len
pos_conv_wr = 0; pos_conv_wr = 0;
} }
if (str_out) str_out[len] = '\0'; if(str_out) str_out[len] = '\0';
lv_bidi_dir_t dir = base_dir; lv_bidi_dir_t dir = base_dir;
@@ -305,18 +310,20 @@ void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len
if(rd) { if(rd) {
if(base_dir == LV_BIDI_DIR_LTR) { if(base_dir == LV_BIDI_DIR_LTR) {
if (str_out) { if(str_out) {
memcpy(&str_out[wr], str_in, rd); memcpy(&str_out[wr], str_in, rd);
wr += rd; wr += rd;
} }
if (pos_conv_out) { if(pos_conv_out) {
fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_rd, 0); fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_rd, 0);
pos_conv_wr += pos_conv_rd; pos_conv_wr += pos_conv_rd;
} }
} else { }
else {
wr -= rd; wr -= rd;
pos_conv_wr -= pos_conv_rd; pos_conv_wr -= pos_conv_rd;
rtl_reverse(str_out? &str_out[wr]: NULL, str_in, rd, pos_conv_out? &pos_conv_out[pos_conv_wr]: NULL, 0, pos_conv_rd); rtl_reverse(str_out ? &str_out[wr] : NULL, str_in, rd, pos_conv_out ? &pos_conv_out[pos_conv_wr] : NULL, 0,
pos_conv_rd);
} }
} }
@@ -327,20 +334,23 @@ void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len
if(base_dir == LV_BIDI_DIR_LTR) { if(base_dir == LV_BIDI_DIR_LTR) {
if(run_dir == LV_BIDI_DIR_LTR) { if(run_dir == LV_BIDI_DIR_LTR) {
if (str_out) memcpy(&str_out[wr], &str_in[rd], run_len); if(str_out) memcpy(&str_out[wr], &str_in[rd], run_len);
if (pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_run_len, pos_conv_rd); if(pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_run_len, pos_conv_rd);
} }
else rtl_reverse(str_out? &str_out[wr]: NULL, &str_in[rd], run_len, pos_conv_out? &pos_conv_out[pos_conv_wr] : NULL, pos_conv_rd, pos_conv_run_len); else rtl_reverse(str_out ? &str_out[wr] : NULL, &str_in[rd], run_len, pos_conv_out ? &pos_conv_out[pos_conv_wr] : NULL,
pos_conv_rd, pos_conv_run_len);
wr += run_len; wr += run_len;
pos_conv_wr += pos_conv_run_len; pos_conv_wr += pos_conv_run_len;
} else { }
else {
wr -= run_len; wr -= run_len;
pos_conv_wr -= pos_conv_run_len; pos_conv_wr -= pos_conv_run_len;
if(run_dir == LV_BIDI_DIR_LTR) { if(run_dir == LV_BIDI_DIR_LTR) {
if (str_out) memcpy(&str_out[wr], &str_in[rd], run_len); if(str_out) memcpy(&str_out[wr], &str_in[rd], run_len);
if (pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_run_len, pos_conv_rd); if(pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_run_len, pos_conv_rd);
} }
else rtl_reverse(str_out? &str_out[wr]: NULL, &str_in[rd], run_len, pos_conv_out? &pos_conv_out[pos_conv_wr] : NULL, pos_conv_rd, pos_conv_run_len); else rtl_reverse(str_out ? &str_out[wr] : NULL, &str_in[rd], run_len, pos_conv_out ? &pos_conv_out[pos_conv_wr] : NULL,
pos_conv_rd, pos_conv_run_len);
} }
rd += run_len; rd += run_len;
@@ -386,13 +396,14 @@ static uint32_t get_txt_len(const char * txt, uint32_t max_len)
static void fill_pos_conv(uint16_t * out, uint16_t len, uint16_t index) static void fill_pos_conv(uint16_t * out, uint16_t len, uint16_t index)
{ {
uint16_t i; uint16_t i;
for (i = 0; i < len; i++) { for(i = 0; i < len; i++) {
out[i] = SET_RTL_POS(index, false); out[i] = SET_RTL_POS(index, false);
index++; index++;
} }
} }
static lv_bidi_dir_t get_next_run(const char * txt, lv_bidi_dir_t base_dir, uint32_t max_len, uint32_t * len, uint16_t * pos_conv_len) static lv_bidi_dir_t get_next_run(const char * txt, lv_bidi_dir_t base_dir, uint32_t max_len, uint32_t * len,
uint16_t * pos_conv_len)
{ {
uint32_t i = 0; uint32_t i = 0;
uint32_t letter; uint32_t letter;
@@ -473,7 +484,8 @@ static lv_bidi_dir_t get_next_run(const char * txt, lv_bidi_dir_t base_dir, uint
return run_dir; return run_dir;
} }
static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *pos_conv_out, uint16_t pos_conv_rd_base, uint16_t pos_conv_len) static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t * pos_conv_out, uint16_t pos_conv_rd_base,
uint16_t pos_conv_len)
{ {
uint32_t i = len; uint32_t i = len;
uint32_t wr = 0; uint32_t wr = 0;
@@ -498,7 +510,7 @@ static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *p
/*Finish on non-weak char */ /*Finish on non-weak char */
/*but treat number and currency related chars as weak*/ /*but treat number and currency related chars as weak*/
if (lv_bidi_letter_is_weak(letter) == false && letter != '.' && letter != ',' && letter != '$' && letter != '%') { if(lv_bidi_letter_is_weak(letter) == false && letter != '.' && letter != ',' && letter != '$' && letter != '%') {
lv_txt_encoded_next(src, &i); /*Rewind one letter*/ lv_txt_encoded_next(src, &i); /*Rewind one letter*/
pos_conv_i++; pos_conv_i++;
first_weak = i; first_weak = i;
@@ -511,8 +523,9 @@ static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *p
pos_conv_first_weak = 0; pos_conv_first_weak = 0;
} }
if (dest) memcpy(&dest[wr], &src[first_weak], last_weak - first_weak + 1); if(dest) memcpy(&dest[wr], &src[first_weak], last_weak - first_weak + 1);
if (pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_last_weak - pos_conv_first_weak + 1, pos_conv_rd_base + pos_conv_first_weak); if(pos_conv_out) fill_pos_conv(&pos_conv_out[pos_conv_wr], pos_conv_last_weak - pos_conv_first_weak + 1,
pos_conv_rd_base + pos_conv_first_weak);
wr += last_weak - first_weak + 1; wr += last_weak - first_weak + 1;
pos_conv_wr += pos_conv_last_weak - pos_conv_first_weak + 1; pos_conv_wr += pos_conv_last_weak - pos_conv_first_weak + 1;
} }
@@ -523,15 +536,15 @@ static void rtl_reverse(char * dest, const char * src, uint32_t len, uint16_t *p
/*Swap arithmetical symbols*/ /*Swap arithmetical symbols*/
if(letter_size == 1) { if(letter_size == 1) {
uint32_t new_letter = letter = char_change_to_pair(letter); uint32_t new_letter = letter = char_change_to_pair(letter);
if (dest) dest[wr] = (uint8_t)new_letter; if(dest) dest[wr] = (uint8_t)new_letter;
if (pos_conv_out) pos_conv_out[pos_conv_wr] = SET_RTL_POS(pos_conv_rd_base + pos_conv_letter, true); if(pos_conv_out) pos_conv_out[pos_conv_wr] = SET_RTL_POS(pos_conv_rd_base + pos_conv_letter, true);
wr++; wr++;
pos_conv_wr++; pos_conv_wr++;
} }
/*Just store the letter*/ /*Just store the letter*/
else { else {
if (dest) memcpy(&dest[wr], &src[i], letter_size); if(dest) memcpy(&dest[wr], &src[i], letter_size);
if (pos_conv_out) pos_conv_out[pos_conv_wr] = SET_RTL_POS(pos_conv_rd_base + pos_conv_i, true); if(pos_conv_out) pos_conv_out[pos_conv_wr] = SET_RTL_POS(pos_conv_rd_base + pos_conv_i, true);
wr += letter_size; wr += letter_size;
pos_conv_wr++; pos_conv_wr++;
} }
@@ -554,7 +567,8 @@ static uint32_t char_change_to_pair(uint32_t letter)
return letter; return letter;
} }
static lv_bidi_dir_t bracket_process(const char * txt, uint32_t next_pos, uint32_t len, uint32_t letter, lv_bidi_dir_t base_dir) static lv_bidi_dir_t bracket_process(const char * txt, uint32_t next_pos, uint32_t len, uint32_t letter,
lv_bidi_dir_t base_dir)
{ {
lv_bidi_dir_t bracket_dir = LV_BIDI_DIR_NEUTRAL; lv_bidi_dir_t bracket_dir = LV_BIDI_DIR_NEUTRAL;
@@ -570,7 +584,8 @@ static lv_bidi_dir_t bracket_process(const char * txt, uint32_t next_pos, uint32
if(letter_next == bracket_right[i]) { if(letter_next == bracket_right[i]) {
/*Closing bracket found*/ /*Closing bracket found*/
break; break;
} else { }
else {
/*Save the dir*/ /*Save the dir*/
lv_bidi_dir_t letter_dir = lv_bidi_get_letter_dir(letter_next); lv_bidi_dir_t letter_dir = lv_bidi_get_letter_dir(letter_next);
if(letter_dir == base_dir) { if(letter_dir == base_dir) {
@@ -619,7 +634,8 @@ static lv_bidi_dir_t bracket_process(const char * txt, uint32_t next_pos, uint32
br_stack_p++; br_stack_p++;
return bracket_dir; return bracket_dir;
} else if(br_stack_p > 0) { }
else if(br_stack_p > 0) {
/*Is the letter a closing bracket of the last opening?*/ /*Is the letter a closing bracket of the last opening?*/
if(letter == bracket_right[br_stack[br_stack_p - 1].bracklet_pos]) { if(letter == bracket_right[br_stack[br_stack_p - 1].bracklet_pos]) {
bracket_dir = br_stack[br_stack_p - 1].dir; bracket_dir = br_stack[br_stack_p - 1].dir;

View File

@@ -29,8 +29,7 @@ extern "C" {
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
enum enum {
{
/*The first 4 values are stored in `lv_obj_t` on 2 bits*/ /*The first 4 values are stored in `lv_obj_t` on 2 bits*/
LV_BIDI_DIR_LTR = 0x00, LV_BIDI_DIR_LTR = 0x00,
LV_BIDI_DIR_RTL = 0x01, LV_BIDI_DIR_RTL = 0x01,
@@ -104,7 +103,8 @@ bool lv_bidi_letter_is_neutral(uint32_t letter);
* @param is_rtl tell the the char at `viasual_pos` is RTL or LTR context * @param is_rtl tell the the char at `viasual_pos` is RTL or LTR context
* @return the logical character position * @return the logical character position
*/ */
uint16_t lv_bidi_get_logical_pos(const char * str_in, char **bidi_txt, uint32_t len, lv_bidi_dir_t base_dir, uint32_t visual_pos, bool *is_rtl); uint16_t lv_bidi_get_logical_pos(const char * str_in, char ** bidi_txt, uint32_t len, lv_bidi_dir_t base_dir,
uint32_t visual_pos, bool * is_rtl);
/** /**
* Get the visual position of a character in a line * Get the visual position of a character in a line
@@ -118,7 +118,8 @@ uint16_t lv_bidi_get_logical_pos(const char * str_in, char **bidi_txt, uint32_t
* @param is_rtl tell the the char at `logical_pos` is RTL or LTR context * @param is_rtl tell the the char at `logical_pos` is RTL or LTR context
* @return the visual character position * @return the visual character position
*/ */
uint16_t lv_bidi_get_visual_pos(const char * str_in, char **bidi_txt, uint16_t len, lv_bidi_dir_t base_dir, uint32_t logical_pos, bool *is_rtl); uint16_t lv_bidi_get_visual_pos(const char * str_in, char ** bidi_txt, uint16_t len, lv_bidi_dir_t base_dir,
uint32_t logical_pos, bool * is_rtl);
/** /**
* Bidi process a paragraph of text * Bidi process a paragraph of text
@@ -130,7 +131,8 @@ uint16_t lv_bidi_get_visual_pos(const char * str_in, char **bidi_txt, uint16_t l
* Can be `NULL` is unused * Can be `NULL` is unused
* @param pos_conv_len length of `pos_conv_out` in element count * @param pos_conv_len length of `pos_conv_out` in element count
*/ */
void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_bidi_dir_t base_dir, uint16_t *pos_conv_out, uint16_t pos_conv_len); void lv_bidi_process_paragraph(const char * str_in, char * str_out, uint32_t len, lv_bidi_dir_t base_dir,
uint16_t * pos_conv_out, uint16_t pos_conv_len);
/** /**
* Get the next paragraph from a text * Get the next paragraph from a text

View File

@@ -68,7 +68,8 @@ void lv_circ_next(lv_point_t * c, lv_coord_t * tmp)
if(*tmp <= 0) { if(*tmp <= 0) {
(*tmp) += 2 * c->y + 1; /*Change in decision criterion for y -> y+1*/ (*tmp) += 2 * c->y + 1; /*Change in decision criterion for y -> y+1*/
} else { }
else {
c->x--; c->x--;
(*tmp) += 2 * (c->y - c->x) + 1; /*Change for y -> y+1, x -> x-1*/ (*tmp) += 2 * (c->y - c->x) + 1; /*Change for y -> y+1, x -> x-1*/
} }

View File

@@ -138,7 +138,7 @@ lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r8, uint8_t g8, uint8_t b8)
hsv.v = (100 * rgbMax) >> 10; hsv.v = (100 * rgbMax) >> 10;
int32_t delta = rgbMax - rgbMin; int32_t delta = rgbMax - rgbMin;
if (LV_MATH_ABS(delta) < 3) { if(LV_MATH_ABS(delta) < 3) {
hsv.h = 0; hsv.h = 0;
hsv.s = 0; hsv.s = 0;
return hsv; return hsv;
@@ -163,7 +163,7 @@ lv_color_hsv_t lv_color_rgb_to_hsv(uint8_t r8, uint8_t g8, uint8_t b8)
h = 0; h = 0;
h *= 60; h *= 60;
h >>= 10; h >>= 10;
if (h < 0) h += 360; if(h < 0) h += 360;
hsv.h = h; hsv.h = h;
return hsv; return hsv;

View File

@@ -194,10 +194,8 @@ enum {
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
typedef union typedef union {
{ struct {
struct
{
uint8_t blue : 1; uint8_t blue : 1;
uint8_t green : 1; uint8_t green : 1;
uint8_t red : 1; uint8_t red : 1;
@@ -205,10 +203,8 @@ typedef union
uint8_t full; uint8_t full;
} lv_color1_t; } lv_color1_t;
typedef union typedef union {
{ struct {
struct
{
uint8_t blue : 2; uint8_t blue : 2;
uint8_t green : 3; uint8_t green : 3;
uint8_t red : 3; uint8_t red : 3;
@@ -216,10 +212,8 @@ typedef union
uint8_t full; uint8_t full;
} lv_color8_t; } lv_color8_t;
typedef union typedef union {
{ struct {
struct
{
#if LV_COLOR_16_SWAP == 0 #if LV_COLOR_16_SWAP == 0
uint16_t blue : 5; uint16_t blue : 5;
uint16_t green : 6; uint16_t green : 6;
@@ -234,10 +228,8 @@ typedef union
uint16_t full; uint16_t full;
} lv_color16_t; } lv_color16_t;
typedef union typedef union {
{ struct {
struct
{
uint8_t blue; uint8_t blue;
uint8_t green; uint8_t green;
uint8_t red; uint8_t red;
@@ -264,8 +256,7 @@ typedef lv_color32_t lv_color_t;
typedef uint8_t lv_opa_t; typedef uint8_t lv_opa_t;
typedef struct typedef struct {
{
uint16_t h; uint16_t h;
uint8_t s; uint8_t s;
uint8_t v; uint8_t v;
@@ -296,19 +287,22 @@ static inline uint8_t lv_color_to1(lv_color_t color)
#elif LV_COLOR_DEPTH == 8 #elif LV_COLOR_DEPTH == 8
if((LV_COLOR_GET_R(color) & 0x4) || (LV_COLOR_GET_G(color) & 0x4) || (LV_COLOR_GET_B(color) & 0x2)) { if((LV_COLOR_GET_R(color) & 0x4) || (LV_COLOR_GET_G(color) & 0x4) || (LV_COLOR_GET_B(color) & 0x2)) {
return 1; return 1;
} else { }
else {
return 0; return 0;
} }
#elif LV_COLOR_DEPTH == 16 #elif LV_COLOR_DEPTH == 16
if((LV_COLOR_GET_R(color) & 0x10) || (LV_COLOR_GET_G(color) & 0x20) || (LV_COLOR_GET_B(color) & 0x10)) { if((LV_COLOR_GET_R(color) & 0x10) || (LV_COLOR_GET_G(color) & 0x20) || (LV_COLOR_GET_B(color) & 0x10)) {
return 1; return 1;
} else { }
else {
return 0; return 0;
} }
#elif LV_COLOR_DEPTH == 32 #elif LV_COLOR_DEPTH == 32
if((LV_COLOR_GET_R(color) & 0x80) || (LV_COLOR_GET_G(color) & 0x80) || (LV_COLOR_GET_B(color) & 0x80)) { if((LV_COLOR_GET_R(color) & 0x80) || (LV_COLOR_GET_G(color) & 0x80) || (LV_COLOR_GET_B(color) & 0x80)) {
return 1; return 1;
} else { }
else {
return 0; return 0;
} }
#endif #endif
@@ -415,9 +409,9 @@ static inline uint32_t lv_color_to32(lv_color_t color)
* 6 259 3 0 255 * 6 259 3 0 255
*/ */
lv_color32_t ret; lv_color32_t ret;
LV_COLOR_SET_R32(ret, (LV_COLOR_GET_R(color) * 263 + 7 ) >> 5); LV_COLOR_SET_R32(ret, (LV_COLOR_GET_R(color) * 263 + 7) >> 5);
LV_COLOR_SET_G32(ret, (LV_COLOR_GET_G(color) * 259 + 3 ) >> 6); LV_COLOR_SET_G32(ret, (LV_COLOR_GET_G(color) * 259 + 3) >> 6);
LV_COLOR_SET_B32(ret, (LV_COLOR_GET_B(color) * 263 + 7 ) >> 5); LV_COLOR_SET_B32(ret, (LV_COLOR_GET_B(color) * 263 + 7) >> 5);
LV_COLOR_SET_A32(ret, 0xFF); LV_COLOR_SET_A32(ret, 0xFF);
return ret.full; return ret.full;
#elif LV_COLOR_DEPTH == 32 #elif LV_COLOR_DEPTH == 32
@@ -459,7 +453,8 @@ static inline lv_color_t lv_color_mix(lv_color_t c1, lv_color_t c2, uint8_t mix)
* @param res_color the result color * @param res_color the result color
* @param res_opa the result opacity * @param res_opa the result opacity
*/ */
static inline void lv_color_mix_with_alpha(lv_color_t bg_color, lv_opa_t bg_opa, lv_color_t fg_color, lv_opa_t fg_opa, lv_color_t * res_color, lv_opa_t * res_opa) static inline void lv_color_mix_with_alpha(lv_color_t bg_color, lv_opa_t bg_opa, lv_color_t fg_color, lv_opa_t fg_opa,
lv_color_t * res_color, lv_opa_t * res_opa)
{ {
/* Pick the foreground if it's fully opaque or the Background is fully transparent*/ /* Pick the foreground if it's fully opaque or the Background is fully transparent*/
if(fg_opa > LV_OPA_MAX || bg_opa <= LV_OPA_MIN) { if(fg_opa > LV_OPA_MAX || bg_opa <= LV_OPA_MIN) {

View File

@@ -15,7 +15,7 @@
#include "lv_gc.h" #include "lv_gc.h"
#if defined(LV_GC_INCLUDE) #if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE #include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
/********************* /*********************
@@ -27,7 +27,7 @@
* free function, otherwise compilation would fail. * free function, otherwise compilation would fail.
*/ */
#ifdef free #ifdef free
#undef free #undef free
#endif #endif
/********************** /**********************
@@ -422,7 +422,8 @@ lv_fs_res_t lv_fs_dir_close(lv_fs_dir_t * rddir_p)
if(rddir_p->drv->dir_close_cb == NULL) { if(rddir_p->drv->dir_close_cb == NULL) {
res = LV_FS_RES_NOT_IMP; res = LV_FS_RES_NOT_IMP;
} else { }
else {
res = rddir_p->drv->dir_close_cb(rddir_p->drv, rddir_p->dir_d); res = rddir_p->drv->dir_close_cb(rddir_p->drv, rddir_p->dir_d);
} }
@@ -453,7 +454,8 @@ lv_fs_res_t lv_fs_free_space(char letter, uint32_t * total_p, uint32_t * free_p)
if(drv->free_space_cb == NULL) { if(drv->free_space_cb == NULL) {
res = LV_FS_RES_NOT_IMP; res = LV_FS_RES_NOT_IMP;
} else { }
else {
uint32_t total_tmp = 0; uint32_t total_tmp = 0;
uint32_t free_tmp = 0; uint32_t free_tmp = 0;
res = drv->free_space_cb(drv, &total_tmp, &free_tmp); res = drv->free_space_cb(drv, &total_tmp, &free_tmp);
@@ -501,8 +503,7 @@ lv_fs_drv_t * lv_fs_get_drv(char letter)
{ {
lv_fs_drv_t * drv; lv_fs_drv_t * drv;
LV_LL_READ(LV_GC_ROOT(_lv_drv_ll), drv) LV_LL_READ(LV_GC_ROOT(_lv_drv_ll), drv) {
{
if(drv->letter == letter) { if(drv->letter == letter) {
return drv; return drv;
} }
@@ -520,8 +521,7 @@ char * lv_fs_get_letters(char * buf)
lv_fs_drv_t * drv; lv_fs_drv_t * drv;
uint8_t i = 0; uint8_t i = 0;
LV_LL_READ(LV_GC_ROOT(_lv_drv_ll), drv) LV_LL_READ(LV_GC_ROOT(_lv_drv_ll), drv) {
{
buf[i] = drv->letter; buf[i] = drv->letter;
i++; i++;
} }
@@ -542,7 +542,8 @@ const char * lv_fs_get_ext(const char * fn)
for(i = strlen(fn); i > 0; i--) { for(i = strlen(fn); i > 0; i--) {
if(fn[i] == '.') { if(fn[i] == '.') {
return &fn[i + 1]; return &fn[i + 1];
} else if(fn[i] == '/' || fn[i] == '\\') { }
else if(fn[i] == '/' || fn[i] == '\\') {
return ""; /*No extension if a '\' or '/' found*/ return ""; /*No extension if a '\' or '/' found*/
} }
} }
@@ -630,7 +631,8 @@ static const char * lv_fs_get_real_path(const char * path)
while(*path != '\0') { while(*path != '\0') {
if(*path == ':' || *path == '\\' || *path == '/') { if(*path == ':' || *path == '\\' || *path == '/') {
path++; path++;
} else { }
else {
break; break;
} }
} }

View File

@@ -60,8 +60,7 @@ enum {
}; };
typedef uint8_t lv_fs_mode_t; typedef uint8_t lv_fs_mode_t;
typedef struct _lv_fs_drv_t typedef struct _lv_fs_drv_t {
{
char letter; char letter;
uint16_t file_size; uint16_t file_size;
uint16_t rddir_size; uint16_t rddir_size;
@@ -88,14 +87,12 @@ typedef struct _lv_fs_drv_t
#endif #endif
} lv_fs_drv_t; } lv_fs_drv_t;
typedef struct typedef struct {
{
void * file_d; void * file_d;
lv_fs_drv_t * drv; lv_fs_drv_t * drv;
} lv_fs_file_t; } lv_fs_file_t;
typedef struct typedef struct {
{
void * dir_d; void * dir_d;
lv_fs_drv_t * drv; lv_fs_drv_t * drv;
} lv_fs_dir_t; } lv_fs_dir_t;

View File

@@ -11,7 +11,7 @@
#include "string.h" #include "string.h"
#if defined(LV_GC_INCLUDE) #if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE #include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
/********************* /*********************
@@ -31,7 +31,7 @@
**********************/ **********************/
#if(!defined(LV_ENABLE_GC)) || LV_ENABLE_GC == 0 #if(!defined(LV_ENABLE_GC)) || LV_ENABLE_GC == 0
LV_ROOTS LV_ROOTS
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
/********************** /**********************

View File

@@ -111,7 +111,8 @@ void * lv_ll_ins_prev(lv_ll_t * ll_p, void * n_act)
if(lv_ll_get_head(ll_p) == n_act) { if(lv_ll_get_head(ll_p) == n_act) {
n_new = lv_ll_ins_head(ll_p); n_new = lv_ll_ins_head(ll_p);
if(n_new == NULL) return NULL; if(n_new == NULL) return NULL;
} else { }
else {
n_new = lv_mem_alloc(ll_p->n_size + LL_NODE_META_SIZE); n_new = lv_mem_alloc(ll_p->n_size + LL_NODE_META_SIZE);
if(n_new == NULL) return NULL; if(n_new == NULL) return NULL;
@@ -166,18 +167,22 @@ void lv_ll_remove(lv_ll_t * ll_p, void * node_p)
ll_p->head = lv_ll_get_next(ll_p, node_p); ll_p->head = lv_ll_get_next(ll_p, node_p);
if(ll_p->head == NULL) { if(ll_p->head == NULL) {
ll_p->tail = NULL; ll_p->tail = NULL;
} else { }
else {
node_set_prev(ll_p, ll_p->head, NULL); node_set_prev(ll_p, ll_p->head, NULL);
} }
} else if(lv_ll_get_tail(ll_p) == node_p) { }
else if(lv_ll_get_tail(ll_p) == node_p) {
/*The new tail will be the node before 'n_act'*/ /*The new tail will be the node before 'n_act'*/
ll_p->tail = lv_ll_get_prev(ll_p, node_p); ll_p->tail = lv_ll_get_prev(ll_p, node_p);
if(ll_p->tail == NULL) { if(ll_p->tail == NULL) {
ll_p->head = NULL; ll_p->head = NULL;
} else { }
else {
node_set_next(ll_p, ll_p->tail, NULL); node_set_next(ll_p, ll_p->tail, NULL);
} }
} else { }
else {
lv_ll_node_t * n_prev = lv_ll_get_prev(ll_p, node_p); lv_ll_node_t * n_prev = lv_ll_get_prev(ll_p, node_p);
lv_ll_node_t * n_next = lv_ll_get_next(ll_p, node_p); lv_ll_node_t * n_next = lv_ll_get_next(ll_p, node_p);
@@ -233,7 +238,8 @@ void lv_ll_chg_list(lv_ll_t * ll_ori_p, lv_ll_t * ll_new_p, void * node, bool he
if(ll_new_p->tail == NULL) { /*If there is no tail (first node) set the tail too*/ if(ll_new_p->tail == NULL) { /*If there is no tail (first node) set the tail too*/
ll_new_p->tail = node; ll_new_p->tail = node;
} }
} else { }
else {
/*Set node as tail*/ /*Set node as tail*/
node_set_prev(ll_new_p, node, ll_new_p->tail); node_set_prev(ll_new_p, node, ll_new_p->tail);
node_set_next(ll_new_p, node, NULL); node_set_next(ll_new_p, node, NULL);

View File

@@ -30,8 +30,7 @@ extern "C" {
typedef uint8_t lv_ll_node_t; typedef uint8_t lv_ll_node_t;
/** Description of a linked list*/ /** Description of a linked list*/
typedef struct typedef struct {
{
uint32_t n_size; uint32_t n_size;
lv_ll_node_t * head; lv_ll_node_t * head;
lv_ll_node_t * tail; lv_ll_node_t * tail;

View File

@@ -13,7 +13,7 @@
#include "lv_printf.h" #include "lv_printf.h"
#if LV_LOG_PRINTF #if LV_LOG_PRINTF
#include <stdio.h> #include <stdio.h>
#endif #endif
/********************* /*********************

View File

@@ -32,7 +32,8 @@ static const int16_t sin0_90_table[] = {
17364, 17846, 18323, 18794, 19260, 19720, 20173, 20621, 21062, 21497, 21925, 22347, 22762, 23170, 23571, 23964, 17364, 17846, 18323, 18794, 19260, 19720, 20173, 20621, 21062, 21497, 21925, 22347, 22762, 23170, 23571, 23964,
24351, 24730, 25101, 25465, 25821, 26169, 26509, 26841, 27165, 27481, 27788, 28087, 28377, 28659, 28932, 29196, 24351, 24730, 25101, 25465, 25821, 26169, 26509, 26841, 27165, 27481, 27788, 28087, 28377, 28659, 28932, 29196,
29451, 29697, 29934, 30162, 30381, 30591, 30791, 30982, 31163, 31335, 31498, 31650, 31794, 31927, 32051, 32165, 29451, 29697, 29934, 30162, 30381, 30591, 30791, 30982, 31163, 31335, 31498, 31650, 31794, 31927, 32051, 32165,
32269, 32364, 32448, 32523, 32587, 32642, 32687, 32722, 32747, 32762, 32767}; 32269, 32364, 32448, 32523, 32587, 32642, 32687, 32722, 32747, 32762, 32767
};
/********************** /**********************
* MACROS * MACROS
@@ -56,13 +57,16 @@ int16_t lv_trigo_sin(int16_t angle)
if(angle < 90) { if(angle < 90) {
ret = sin0_90_table[angle]; ret = sin0_90_table[angle];
} else if(angle >= 90 && angle < 180) { }
else if(angle >= 90 && angle < 180) {
angle = 180 - angle; angle = 180 - angle;
ret = sin0_90_table[angle]; ret = sin0_90_table[angle];
} else if(angle >= 180 && angle < 270) { }
else if(angle >= 180 && angle < 270) {
angle = angle - 180; angle = angle - 180;
ret = -sin0_90_table[angle]; ret = -sin0_90_table[angle];
} else { /*angle >=270*/ }
else { /*angle >=270*/
angle = 360 - angle; angle = 360 - angle;
ret = -sin0_90_table[angle]; ret = -sin0_90_table[angle];
} }
@@ -274,7 +278,8 @@ uint16_t lv_atan2(int x, int y)
if(ux > uy) { if(ux > uy) {
degree = (uy * 45) / ux; // degree result will be 0-45 range degree = (uy * 45) / ux; // degree result will be 0-45 range
negflag += 0x10; // octant flag bit negflag += 0x10; // octant flag bit
} else { }
else {
degree = (ux * 45) / uy; // degree result will be 0-45 range degree = (ux * 45) / uy; // degree result will be 0-45 range
} }
@@ -286,7 +291,8 @@ uint16_t lv_atan2(int x, int y)
if(tempdegree <= 41) comp++; if(tempdegree <= 41) comp++;
if(tempdegree <= 37) comp++; if(tempdegree <= 37) comp++;
if(tempdegree <= 32) comp++; // max is 4 degrees compensated if(tempdegree <= 32) comp++; // max is 4 degrees compensated
} else { // else is lower half of range }
else { // else is lower half of range
if(tempdegree >= 2) comp++; if(tempdegree >= 2) comp++;
if(tempdegree >= 6) comp++; if(tempdegree >= 6) comp++;
if(tempdegree >= 10) comp++; if(tempdegree >= 10) comp++;
@@ -304,7 +310,8 @@ uint16_t lv_atan2(int x, int y)
degree = (180 + degree); degree = (180 + degree);
else // else is -Y +X else // else is -Y +X
degree = (180 - degree); degree = (180 - degree);
} else { // else is +Y }
else { // else is +Y
if(negflag & 0x01) // if +Y -X if(negflag & 0x01) // if +Y -X
degree = (360 - degree); degree = (360 - degree);
} }

View File

@@ -46,7 +46,7 @@ extern "C" {
typedef struct { typedef struct {
uint16_t i; uint16_t i;
uint16_t f; uint16_t f;
}lv_sqrt_res_t; } lv_sqrt_res_t;
/********************** /**********************

View File

@@ -13,11 +13,11 @@
#include <string.h> #include <string.h>
#if LV_MEM_CUSTOM != 0 #if LV_MEM_CUSTOM != 0
#include LV_MEM_CUSTOM_INCLUDE #include LV_MEM_CUSTOM_INCLUDE
#endif #endif
#if defined(LV_GC_INCLUDE) #if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE #include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
/********************* /*********************
@@ -25,13 +25,13 @@
*********************/ *********************/
/*Add memory junk on alloc (0xaa) and free(0xbb) (just for testing purposes)*/ /*Add memory junk on alloc (0xaa) and free(0xbb) (just for testing purposes)*/
#ifndef LV_MEM_ADD_JUNK #ifndef LV_MEM_ADD_JUNK
#define LV_MEM_ADD_JUNK 1 #define LV_MEM_ADD_JUNK 1
#endif #endif
#ifdef LV_ARCH_64 #ifdef LV_ARCH_64
#define MEM_UNIT uint64_t #define MEM_UNIT uint64_t
#else #else
#define MEM_UNIT uint32_t #define MEM_UNIT uint32_t
#endif #endif
/********************** /**********************
@@ -41,18 +41,15 @@
#if LV_ENABLE_GC == 0 /*gc custom allocations must not include header*/ #if LV_ENABLE_GC == 0 /*gc custom allocations must not include header*/
/*The size of this union must be 4 bytes (uint32_t)*/ /*The size of this union must be 4 bytes (uint32_t)*/
typedef union typedef union {
{ struct {
struct
{
MEM_UNIT used : 1; /* 1: if the entry is used*/ MEM_UNIT used : 1; /* 1: if the entry is used*/
MEM_UNIT d_size : 31; /* Size off the data (1 means 4 bytes)*/ MEM_UNIT d_size : 31; /* Size off the data (1 means 4 bytes)*/
} s; } s;
MEM_UNIT header; /* The header (used + d_size)*/ MEM_UNIT header; /* The header (used + d_size)*/
} lv_mem_header_t; } lv_mem_header_t;
typedef struct typedef struct {
{
lv_mem_header_t header; lv_mem_header_t header;
uint8_t first_data; /*First data byte in the allocated data (Just for easily create a pointer)*/ uint8_t first_data; /*First data byte in the allocated data (Just for easily create a pointer)*/
} lv_mem_ent_t; } lv_mem_ent_t;
@@ -63,16 +60,16 @@ typedef struct
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
#if LV_MEM_CUSTOM == 0 #if LV_MEM_CUSTOM == 0
static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e); static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e);
static void * ent_alloc(lv_mem_ent_t * e, size_t size); static void * ent_alloc(lv_mem_ent_t * e, size_t size);
static void ent_trunc(lv_mem_ent_t * e, size_t size); static void ent_trunc(lv_mem_ent_t * e, size_t size);
#endif #endif
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
**********************/ **********************/
#if LV_MEM_CUSTOM == 0 #if LV_MEM_CUSTOM == 0
static uint8_t * work_mem; static uint8_t * work_mem;
#endif #endif
static uint32_t zero_mem; /*Give the address of this variable if 0 byte should be allocated*/ static uint32_t zero_mem; /*Give the address of this variable if 0 byte should be allocated*/
@@ -165,7 +162,7 @@ void * lv_mem_alloc(size_t size)
} while(e != NULL && alloc == NULL); } while(e != NULL && alloc == NULL);
#else #else
/*Use custom, user defined malloc function*/ /*Use custom, user defined malloc function*/
#if LV_ENABLE_GC == 1 /*gc must not include header*/ #if LV_ENABLE_GC == 1 /*gc must not include header*/
alloc = LV_MEM_CUSTOM_ALLOC(size); alloc = LV_MEM_CUSTOM_ALLOC(size);
#else /* LV_ENABLE_GC */ #else /* LV_ENABLE_GC */
@@ -217,7 +214,8 @@ void lv_mem_free(const void * data)
while(e_next != NULL) { while(e_next != NULL) {
if(e_next->header.s.used == 0) { if(e_next->header.s.used == 0) {
e->header.s.d_size += e_next->header.s.d_size + sizeof(e->header); e->header.s.d_size += e_next->header.s.d_size + sizeof(e->header);
} else { }
else {
break; break;
} }
e_next = ent_get_next(e_next); e_next = ent_get_next(e_next);
@@ -324,7 +322,8 @@ void lv_mem_defrag(void)
while(e_free != NULL) { while(e_free != NULL) {
if(e_free->header.s.used != 0) { if(e_free->header.s.used != 0) {
e_free = ent_get_next(e_free); e_free = ent_get_next(e_free);
} else { }
else {
break; break;
} }
} }
@@ -336,7 +335,8 @@ void lv_mem_defrag(void)
while(e_next != NULL) { while(e_next != NULL) {
if(e_next->header.s.used == 0) { if(e_next->header.s.used == 0) {
e_free->header.s.d_size += e_next->header.s.d_size + sizeof(e_next->header); e_free->header.s.d_size += e_next->header.s.d_size + sizeof(e_next->header);
} else { }
else {
break; break;
} }
@@ -389,7 +389,8 @@ void lv_mem_monitor(lv_mem_monitor_t * mon_p)
if(e->header.s.d_size > mon_p->free_biggest_size) { if(e->header.s.d_size > mon_p->free_biggest_size) {
mon_p->free_biggest_size = e->header.s.d_size; mon_p->free_biggest_size = e->header.s.d_size;
} }
} else { }
else {
mon_p->used_cnt++; mon_p->used_cnt++;
} }
@@ -514,7 +515,8 @@ static lv_mem_ent_t * ent_get_next(lv_mem_ent_t * act_e)
if(act_e == NULL) { /*NULL means: get the first entry*/ if(act_e == NULL) { /*NULL means: get the first entry*/
next_e = (lv_mem_ent_t *)work_mem; next_e = (lv_mem_ent_t *)work_mem;
} else { /*Get the next entry */ }
else { /*Get the next entry */
uint8_t * data = &act_e->first_data; uint8_t * data = &act_e->first_data;
next_e = (lv_mem_ent_t *)&data[act_e->header.s.d_size]; next_e = (lv_mem_ent_t *)&data[act_e->header.s.d_size];

View File

@@ -35,8 +35,7 @@ extern "C" {
/** /**
* Heap information structure. * Heap information structure.
*/ */
typedef struct typedef struct {
{
uint32_t total_size; /**< Total heap size */ uint32_t total_size; /**< Total heap size */
uint32_t free_cnt; uint32_t free_cnt;
uint32_t free_size; /**< Size of available memory */ uint32_t free_size; /**< Size of available memory */
@@ -49,8 +48,8 @@ typedef struct
typedef struct { typedef struct {
void * p; void * p;
uint16_t size; uint16_t size;
uint8_t used :1; uint8_t used : 1;
}lv_mem_buf_t; } lv_mem_buf_t;
typedef lv_mem_buf_t lv_mem_buf_arr_t[LV_MEM_BUF_MAX_NUM]; typedef lv_mem_buf_t lv_mem_buf_arr_t[LV_MEM_BUF_MAX_NUM];
extern lv_mem_buf_arr_t _lv_mem_buf; extern lv_mem_buf_arr_t _lv_mem_buf;

View File

@@ -44,51 +44,51 @@
// numeric number including padded zeros (dynamically created on stack) // numeric number including padded zeros (dynamically created on stack)
// default: 32 byte // default: 32 byte
#ifndef PRINTF_NTOA_BUFFER_SIZE #ifndef PRINTF_NTOA_BUFFER_SIZE
#define PRINTF_NTOA_BUFFER_SIZE 32U #define PRINTF_NTOA_BUFFER_SIZE 32U
#endif #endif
// 'ftoa' conversion buffer size, this must be big enough to hold one converted // 'ftoa' conversion buffer size, this must be big enough to hold one converted
// float number including padded zeros (dynamically created on stack) // float number including padded zeros (dynamically created on stack)
// default: 32 byte // default: 32 byte
#ifndef PRINTF_FTOA_BUFFER_SIZE #ifndef PRINTF_FTOA_BUFFER_SIZE
#define PRINTF_FTOA_BUFFER_SIZE 32U #define PRINTF_FTOA_BUFFER_SIZE 32U
#endif #endif
// support for the floating point type (%f) // support for the floating point type (%f)
// default: activated // default: activated
#ifndef PRINTF_DISABLE_SUPPORT_FLOAT #ifndef PRINTF_DISABLE_SUPPORT_FLOAT
#define PRINTF_SUPPORT_FLOAT #define PRINTF_SUPPORT_FLOAT
#endif #endif
// support for exponential floating point notation (%e/%g) // support for exponential floating point notation (%e/%g)
// default: activated // default: activated
#ifndef PRINTF_DISABLE_SUPPORT_EXPONENTIAL #ifndef PRINTF_DISABLE_SUPPORT_EXPONENTIAL
#define PRINTF_SUPPORT_EXPONENTIAL #define PRINTF_SUPPORT_EXPONENTIAL
#endif #endif
// define the default floating point precision // define the default floating point precision
// default: 6 digits // default: 6 digits
#ifndef PRINTF_DEFAULT_FLOAT_PRECISION #ifndef PRINTF_DEFAULT_FLOAT_PRECISION
#define PRINTF_DEFAULT_FLOAT_PRECISION 6U #define PRINTF_DEFAULT_FLOAT_PRECISION 6U
#endif #endif
// define the largest float suitable to print with %f // define the largest float suitable to print with %f
// default: 1e9 // default: 1e9
#ifndef PRINTF_MAX_FLOAT #ifndef PRINTF_MAX_FLOAT
#define PRINTF_MAX_FLOAT 1e9 #define PRINTF_MAX_FLOAT 1e9
#endif #endif
// support for the long long types (%llu or %p) // support for the long long types (%llu or %p)
// default: activated // default: activated
#ifndef PRINTF_DISABLE_SUPPORT_LONG_LONG #ifndef PRINTF_DISABLE_SUPPORT_LONG_LONG
#define PRINTF_SUPPORT_LONG_LONG #define PRINTF_SUPPORT_LONG_LONG
#endif #endif
// support for the ptrdiff_t type (%t) // support for the ptrdiff_t type (%t)
// ptrdiff_t is normally defined in <stddef.h> as long or long long type // ptrdiff_t is normally defined in <stddef.h> as long or long long type
// default: activated // default: activated
#ifndef PRINTF_DISABLE_SUPPORT_PTRDIFF_T #ifndef PRINTF_DISABLE_SUPPORT_PTRDIFF_T
#define PRINTF_SUPPORT_PTRDIFF_T #define PRINTF_SUPPORT_PTRDIFF_T
#endif #endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@@ -110,44 +110,47 @@
// import float.h for DBL_MAX // import float.h for DBL_MAX
#if defined(PRINTF_SUPPORT_FLOAT) #if defined(PRINTF_SUPPORT_FLOAT)
#include <float.h> #include <float.h>
#endif #endif
// output function type // output function type
typedef void (*out_fct_type)(char character, void* buffer, size_t idx, size_t maxlen); typedef void (*out_fct_type)(char character, void * buffer, size_t idx, size_t maxlen);
// wrapper (used as buffer) for output function type // wrapper (used as buffer) for output function type
typedef struct { typedef struct {
void (*fct)(char character, void* arg); void (*fct)(char character, void * arg);
void* arg; void * arg;
} out_fct_wrap_type; } out_fct_wrap_type;
// internal buffer output // internal buffer output
static inline void _out_buffer(char character, void* buffer, size_t idx, size_t maxlen) static inline void _out_buffer(char character, void * buffer, size_t idx, size_t maxlen)
{ {
if (idx < maxlen) { if(idx < maxlen) {
((char*)buffer)[idx] = character; ((char *)buffer)[idx] = character;
} }
} }
// internal null output // internal null output
static inline void _out_null(char character, void* buffer, size_t idx, size_t maxlen) static inline void _out_null(char character, void * buffer, size_t idx, size_t maxlen)
{ {
(void)character; (void)buffer; (void)idx; (void)maxlen; (void)character;
(void)buffer;
(void)idx;
(void)maxlen;
} }
// internal secure strlen // internal secure strlen
// \return The length of the string (excluding the terminating 0) limited by 'maxsize' // \return The length of the string (excluding the terminating 0) limited by 'maxsize'
static inline unsigned int _strnlen_s(const char* str, size_t maxsize) static inline unsigned int _strnlen_s(const char * str, size_t maxsize)
{ {
const char* s; const char * s;
for (s = str; *s && maxsize--; ++s); for(s = str; *s && maxsize--; ++s);
return (unsigned int)(s - str); return (unsigned int)(s - str);
} }
@@ -161,10 +164,10 @@ static inline bool _is_digit(char ch)
// internal ASCII string to unsigned int conversion // internal ASCII string to unsigned int conversion
static unsigned int _atoi(const char** str) static unsigned int _atoi(const char ** str)
{ {
unsigned int i = 0U; unsigned int i = 0U;
while (_is_digit(**str)) { while(_is_digit(**str)) {
i = i * 10U + (unsigned int)(*((*str)++) - '0'); i = i * 10U + (unsigned int)(*((*str)++) - '0');
} }
return i; return i;
@@ -172,26 +175,27 @@ static unsigned int _atoi(const char** str)
// output the specified string in reverse, taking care of any zero-padding // output the specified string in reverse, taking care of any zero-padding
static size_t _out_rev(out_fct_type out, char* buffer, size_t idx, size_t maxlen, const char* buf, size_t len, unsigned int width, unsigned int flags) static size_t _out_rev(out_fct_type out, char * buffer, size_t idx, size_t maxlen, const char * buf, size_t len,
unsigned int width, unsigned int flags)
{ {
const size_t start_idx = idx; const size_t start_idx = idx;
// pad spaces up to given width // pad spaces up to given width
if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) { if(!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) {
size_t i; size_t i;
for (i = len; i < width; i++) { for(i = len; i < width; i++) {
out(' ', buffer, idx++, maxlen); out(' ', buffer, idx++, maxlen);
} }
} }
// reverse string // reverse string
while (len) { while(len) {
out(buf[--len], buffer, idx++, maxlen); out(buf[--len], buffer, idx++, maxlen);
} }
// append pad spaces up to given width // append pad spaces up to given width
if (flags & FLAGS_LEFT) { if(flags & FLAGS_LEFT) {
while (idx - start_idx < width) { while(idx - start_idx < width) {
out(' ', buffer, idx++, maxlen); out(' ', buffer, idx++, maxlen);
} }
} }
@@ -201,51 +205,52 @@ static size_t _out_rev(out_fct_type out, char* buffer, size_t idx, size_t maxlen
// internal itoa format // internal itoa format
static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t maxlen, char* buf, size_t len, bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags) static size_t _ntoa_format(out_fct_type out, char * buffer, size_t idx, size_t maxlen, char * buf, size_t len,
bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags)
{ {
// pad leading zeros // pad leading zeros
if (!(flags & FLAGS_LEFT)) { if(!(flags & FLAGS_LEFT)) {
if (width && (flags & FLAGS_ZEROPAD) && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) { if(width && (flags & FLAGS_ZEROPAD) && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) {
width--; width--;
} }
while ((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) { while((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = '0'; buf[len++] = '0';
} }
while ((flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) { while((flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = '0'; buf[len++] = '0';
} }
} }
// handle hash // handle hash
if (flags & FLAGS_HASH) { if(flags & FLAGS_HASH) {
if (!(flags & FLAGS_PRECISION) && len && ((len == prec) || (len == width))) { if(!(flags & FLAGS_PRECISION) && len && ((len == prec) || (len == width))) {
len--; len--;
if (len && (base == 16U)) { if(len && (base == 16U)) {
len--; len--;
} }
} }
if ((base == 16U) && !(flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) { if((base == 16U) && !(flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = 'x'; buf[len++] = 'x';
} }
else if ((base == 16U) && (flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) { else if((base == 16U) && (flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = 'X'; buf[len++] = 'X';
} }
else if ((base == 2U) && (len < PRINTF_NTOA_BUFFER_SIZE)) { else if((base == 2U) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
buf[len++] = 'b'; buf[len++] = 'b';
} }
if (len < PRINTF_NTOA_BUFFER_SIZE) { if(len < PRINTF_NTOA_BUFFER_SIZE) {
buf[len++] = '0'; buf[len++] = '0';
} }
} }
if (len < PRINTF_NTOA_BUFFER_SIZE) { if(len < PRINTF_NTOA_BUFFER_SIZE) {
if (negative) { if(negative) {
buf[len++] = '-'; buf[len++] = '-';
} }
else if (flags & FLAGS_PLUS) { else if(flags & FLAGS_PLUS) {
buf[len++] = '+'; // ignore the space if the '+' exists buf[len++] = '+'; // ignore the space if the '+' exists
} }
else if (flags & FLAGS_SPACE) { else if(flags & FLAGS_SPACE) {
buf[len++] = ' '; buf[len++] = ' ';
} }
} }
@@ -255,23 +260,24 @@ static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t ma
// internal itoa for 'long' type // internal itoa for 'long' type
static size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base, unsigned int prec, unsigned int width, unsigned int flags) static size_t _ntoa_long(out_fct_type out, char * buffer, size_t idx, size_t maxlen, unsigned long value, bool negative,
unsigned long base, unsigned int prec, unsigned int width, unsigned int flags)
{ {
char buf[PRINTF_NTOA_BUFFER_SIZE]; char buf[PRINTF_NTOA_BUFFER_SIZE];
size_t len = 0U; size_t len = 0U;
// no hash for 0 values // no hash for 0 values
if (!value) { if(!value) {
flags &= ~FLAGS_HASH; flags &= ~FLAGS_HASH;
} }
// write if precision != 0 and value is != 0 // write if precision != 0 and value is != 0
if (!(flags & FLAGS_PRECISION) || value) { if(!(flags & FLAGS_PRECISION) || value) {
do { do {
const char digit = (char)(value % base); const char digit = (char)(value % base);
buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
value /= base; value /= base;
} while (value && (len < PRINTF_NTOA_BUFFER_SIZE)); } while(value && (len < PRINTF_NTOA_BUFFER_SIZE));
} }
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags);
@@ -280,23 +286,24 @@ static size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxl
// internal itoa for 'long long' type // internal itoa for 'long long' type
#if defined(PRINTF_SUPPORT_LONG_LONG) #if defined(PRINTF_SUPPORT_LONG_LONG)
static size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags) static size_t _ntoa_long_long(out_fct_type out, char * buffer, size_t idx, size_t maxlen, unsigned long long value,
bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags)
{ {
char buf[PRINTF_NTOA_BUFFER_SIZE]; char buf[PRINTF_NTOA_BUFFER_SIZE];
size_t len = 0U; size_t len = 0U;
// no hash for 0 values // no hash for 0 values
if (!value) { if(!value) {
flags &= ~FLAGS_HASH; flags &= ~FLAGS_HASH;
} }
// write if precision != 0 and value is != 0 // write if precision != 0 and value is != 0
if (!(flags & FLAGS_PRECISION) || value) { if(!(flags & FLAGS_PRECISION) || value) {
do { do {
const char digit = (char)(value % base); const char digit = (char)(value % base);
buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10; buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
value /= base; value /= base;
} while (value && (len < PRINTF_NTOA_BUFFER_SIZE)); } while(value && (len < PRINTF_NTOA_BUFFER_SIZE));
} }
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags); return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags);
@@ -307,13 +314,15 @@ static size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t
#if defined(PRINTF_SUPPORT_FLOAT) #if defined(PRINTF_SUPPORT_FLOAT)
#if defined(PRINTF_SUPPORT_EXPONENTIAL) #if defined(PRINTF_SUPPORT_EXPONENTIAL)
// forward declaration so that _ftoa can switch to exp notation for values > PRINTF_MAX_FLOAT // forward declaration so that _ftoa can switch to exp notation for values > PRINTF_MAX_FLOAT
static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags); static size_t _etoa(out_fct_type out, char * buffer, size_t idx, size_t maxlen, double value, unsigned int prec,
unsigned int width, unsigned int flags);
#endif #endif
// internal ftoa for fixed decimal floating point // internal ftoa for fixed decimal floating point
static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) static size_t _ftoa(out_fct_type out, char * buffer, size_t idx, size_t maxlen, double value, unsigned int prec,
unsigned int width, unsigned int flags)
{ {
char buf[PRINTF_FTOA_BUFFER_SIZE]; char buf[PRINTF_FTOA_BUFFER_SIZE];
size_t len = 0U; size_t len = 0U;
@@ -323,16 +332,17 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
static const double pow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 }; static const double pow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
// test for special values // test for special values
if (value != value) if(value != value)
return _out_rev(out, buffer, idx, maxlen, "nan", 3, width, flags); return _out_rev(out, buffer, idx, maxlen, "nan", 3, width, flags);
if (value < -DBL_MAX) if(value < -DBL_MAX)
return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags); return _out_rev(out, buffer, idx, maxlen, "fni-", 4, width, flags);
if (value > DBL_MAX) if(value > DBL_MAX)
return _out_rev(out, buffer, idx, maxlen, (flags & FLAGS_PLUS) ? "fni+" : "fni", (flags & FLAGS_PLUS) ? 4U : 3U, width, flags); return _out_rev(out, buffer, idx, maxlen, (flags & FLAGS_PLUS) ? "fni+" : "fni", (flags & FLAGS_PLUS) ? 4U : 3U, width,
flags);
// test for very large values // test for very large values
// standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad // standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad
if ((value > PRINTF_MAX_FLOAT) || (value < -PRINTF_MAX_FLOAT)) { if((value > PRINTF_MAX_FLOAT) || (value < -PRINTF_MAX_FLOAT)) {
#if defined(PRINTF_SUPPORT_EXPONENTIAL) #if defined(PRINTF_SUPPORT_EXPONENTIAL)
return _etoa(out, buffer, idx, maxlen, value, prec, width, flags); return _etoa(out, buffer, idx, maxlen, value, prec, width, flags);
#else #else
@@ -342,17 +352,17 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
// test for negative // test for negative
bool negative = false; bool negative = false;
if (value < 0) { if(value < 0) {
negative = true; negative = true;
value = 0 - value; value = 0 - value;
} }
// set default precision, if not set explicitly // set default precision, if not set explicitly
if (!(flags & FLAGS_PRECISION)) { if(!(flags & FLAGS_PRECISION)) {
prec = PRINTF_DEFAULT_FLOAT_PRECISION; prec = PRINTF_DEFAULT_FLOAT_PRECISION;
} }
// limit precision to 9, cause a prec >= 10 can lead to overflow errors // limit precision to 9, cause a prec >= 10 can lead to overflow errors
while ((len < PRINTF_FTOA_BUFFER_SIZE) && (prec > 9U)) { while((len < PRINTF_FTOA_BUFFER_SIZE) && (prec > 9U)) {
buf[len++] = '0'; buf[len++] = '0';
prec--; prec--;
} }
@@ -362,24 +372,24 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
unsigned long frac = (unsigned long)tmp; unsigned long frac = (unsigned long)tmp;
diff = tmp - frac; diff = tmp - frac;
if (diff > 0.5) { if(diff > 0.5) {
++frac; ++frac;
// handle rollover, e.g. case 0.99 with prec 1 is 1.0 // handle rollover, e.g. case 0.99 with prec 1 is 1.0
if (frac >= pow10[prec]) { if(frac >= pow10[prec]) {
frac = 0; frac = 0;
++whole; ++whole;
} }
} }
else if (diff < 0.5) { else if(diff < 0.5) {
} }
else if ((frac == 0U) || (frac & 1U)) { else if((frac == 0U) || (frac & 1U)) {
// if halfway, round up if odd OR if last digit is 0 // if halfway, round up if odd OR if last digit is 0
++frac; ++frac;
} }
if (prec == 0U) { if(prec == 0U) {
diff = value - (double)whole; diff = value - (double)whole;
if ((!(diff < 0.5) || (diff > 0.5)) && (whole & 1)) { if((!(diff < 0.5) || (diff > 0.5)) && (whole & 1)) {
// exactly 0.5 and ODD, then round up // exactly 0.5 and ODD, then round up
// 1.5 -> 2, but 2.5 -> 2 // 1.5 -> 2, but 2.5 -> 2
++whole; ++whole;
@@ -388,49 +398,49 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
else { else {
unsigned int count = prec; unsigned int count = prec;
// now do fractional part, as an unsigned number // now do fractional part, as an unsigned number
while (len < PRINTF_FTOA_BUFFER_SIZE) { while(len < PRINTF_FTOA_BUFFER_SIZE) {
--count; --count;
buf[len++] = (char)(48U + (frac % 10U)); buf[len++] = (char)(48U + (frac % 10U));
if (!(frac /= 10U)) { if(!(frac /= 10U)) {
break; break;
} }
} }
// add extra 0s // add extra 0s
while ((len < PRINTF_FTOA_BUFFER_SIZE) && (count-- > 0U)) { while((len < PRINTF_FTOA_BUFFER_SIZE) && (count-- > 0U)) {
buf[len++] = '0'; buf[len++] = '0';
} }
if (len < PRINTF_FTOA_BUFFER_SIZE) { if(len < PRINTF_FTOA_BUFFER_SIZE) {
// add decimal // add decimal
buf[len++] = '.'; buf[len++] = '.';
} }
} }
// do whole part, number is reversed // do whole part, number is reversed
while (len < PRINTF_FTOA_BUFFER_SIZE) { while(len < PRINTF_FTOA_BUFFER_SIZE) {
buf[len++] = (char)(48 + (whole % 10)); buf[len++] = (char)(48 + (whole % 10));
if (!(whole /= 10)) { if(!(whole /= 10)) {
break; break;
} }
} }
// pad leading zeros // pad leading zeros
if (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD)) { if(!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD)) {
if (width && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) { if(width && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) {
width--; width--;
} }
while ((len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) { while((len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) {
buf[len++] = '0'; buf[len++] = '0';
} }
} }
if (len < PRINTF_FTOA_BUFFER_SIZE) { if(len < PRINTF_FTOA_BUFFER_SIZE) {
if (negative) { if(negative) {
buf[len++] = '-'; buf[len++] = '-';
} }
else if (flags & FLAGS_PLUS) { else if(flags & FLAGS_PLUS) {
buf[len++] = '+'; // ignore the space if the '+' exists buf[len++] = '+'; // ignore the space if the '+' exists
} }
else if (flags & FLAGS_SPACE) { else if(flags & FLAGS_SPACE) {
buf[len++] = ' '; buf[len++] = ' ';
} }
} }
@@ -441,21 +451,22 @@ static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
#if defined(PRINTF_SUPPORT_EXPONENTIAL) #if defined(PRINTF_SUPPORT_EXPONENTIAL)
// internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse <m.jasperse@gmail.com> // internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse <m.jasperse@gmail.com>
static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags) static size_t _etoa(out_fct_type out, char * buffer, size_t idx, size_t maxlen, double value, unsigned int prec,
unsigned int width, unsigned int flags)
{ {
// check for NaN and special values // check for NaN and special values
if ((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) { if((value != value) || (value > DBL_MAX) || (value < -DBL_MAX)) {
return _ftoa(out, buffer, idx, maxlen, value, prec, width, flags); return _ftoa(out, buffer, idx, maxlen, value, prec, width, flags);
} }
// determine the sign // determine the sign
const bool negative = value < 0; const bool negative = value < 0;
if (negative) { if(negative) {
value = -value; value = -value;
} }
// default precision // default precision
if (!(flags & FLAGS_PRECISION)) { if(!(flags & FLAGS_PRECISION)) {
prec = PRINTF_DEFAULT_FLOAT_PRECISION; prec = PRINTF_DEFAULT_FLOAT_PRECISION;
} }
@@ -479,7 +490,7 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
// compute exp(z) using continued fractions, see https://en.wikipedia.org/wiki/Exponential_function#Continued_fractions_for_ex // compute exp(z) using continued fractions, see https://en.wikipedia.org/wiki/Exponential_function#Continued_fractions_for_ex
conv.F *= 1 + 2 * z / (2 - z + (z2 / (6 + (z2 / (10 + z2 / 14))))); conv.F *= 1 + 2 * z / (2 - z + (z2 / (6 + (z2 / (10 + z2 / 14)))));
// correct for rounding errors // correct for rounding errors
if (value < conv.F) { if(value < conv.F) {
expval--; expval--;
conv.F /= 10; conv.F /= 10;
} }
@@ -488,10 +499,10 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
unsigned int minwidth = ((expval < 100) && (expval > -100)) ? 4U : 5U; unsigned int minwidth = ((expval < 100) && (expval > -100)) ? 4U : 5U;
// in "%g" mode, "prec" is the number of *significant figures* not decimals // in "%g" mode, "prec" is the number of *significant figures* not decimals
if (flags & FLAGS_ADAPT_EXP) { if(flags & FLAGS_ADAPT_EXP) {
// do we want to fall-back to "%f" mode? // do we want to fall-back to "%f" mode?
if ((value >= 1e-4) && (value < 1e6)) { if((value >= 1e-4) && (value < 1e6)) {
if ((int)prec > expval) { if((int)prec > expval) {
prec = (unsigned)((int)prec - expval - 1); prec = (unsigned)((int)prec - expval - 1);
} }
else { else {
@@ -504,7 +515,7 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
} }
else { else {
// we use one sigfig for the whole part // we use one sigfig for the whole part
if ((prec > 0) && (flags & FLAGS_PRECISION)) { if((prec > 0) && (flags & FLAGS_PRECISION)) {
--prec; --prec;
} }
} }
@@ -512,20 +523,21 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
// will everything fit? // will everything fit?
unsigned int fwidth = width; unsigned int fwidth = width;
if (width > minwidth) { if(width > minwidth) {
// we didn't fall-back so subtract the characters required for the exponent // we didn't fall-back so subtract the characters required for the exponent
fwidth -= minwidth; fwidth -= minwidth;
} else { }
else {
// not enough characters, so go back to default sizing // not enough characters, so go back to default sizing
fwidth = 0U; fwidth = 0U;
} }
if ((flags & FLAGS_LEFT) && minwidth) { if((flags & FLAGS_LEFT) && minwidth) {
// if we're padding on the right, DON'T pad the floating part // if we're padding on the right, DON'T pad the floating part
fwidth = 0U; fwidth = 0U;
} }
// rescale the float value // rescale the float value
if (expval) { if(expval) {
value /= conv.F; value /= conv.F;
} }
@@ -534,14 +546,15 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
idx = _ftoa(out, buffer, idx, maxlen, negative ? -value : value, prec, fwidth, flags & ~FLAGS_ADAPT_EXP); idx = _ftoa(out, buffer, idx, maxlen, negative ? -value : value, prec, fwidth, flags & ~FLAGS_ADAPT_EXP);
// output the exponent part // output the exponent part
if (minwidth) { if(minwidth) {
// output the exponential symbol // output the exponential symbol
out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen); out((flags & FLAGS_UPPERCASE) ? 'E' : 'e', buffer, idx++, maxlen);
// output the exponent value // output the exponent value
idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth-1, FLAGS_ZEROPAD | FLAGS_PLUS); idx = _ntoa_long(out, buffer, idx, maxlen, (expval < 0) ? -expval : expval, expval < 0, 10, 0, minwidth - 1,
FLAGS_ZEROPAD | FLAGS_PLUS);
// might need to right-pad spaces // might need to right-pad spaces
if (flags & FLAGS_LEFT) { if(flags & FLAGS_LEFT) {
while (idx - start_idx < width) out(' ', buffer, idx++, maxlen); while(idx - start_idx < width) out(' ', buffer, idx++, maxlen);
} }
} }
return idx; return idx;
@@ -551,20 +564,19 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
// internal vsnprintf // internal vsnprintf
static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char* format, va_list va) static int _vsnprintf(out_fct_type out, char * buffer, const size_t maxlen, const char * format, va_list va)
{ {
unsigned int flags, width, precision, n; unsigned int flags, width, precision, n;
size_t idx = 0U; size_t idx = 0U;
if (!buffer) { if(!buffer) {
// use null output function // use null output function
out = _out_null; out = _out_null;
} }
while (*format) while(*format) {
{
// format specifier? %[flags][width][.precision][length] // format specifier? %[flags][width][.precision][length]
if (*format != '%') { if(*format != '%') {
// no // no
out(*format, buffer, idx++, maxlen); out(*format, buffer, idx++, maxlen);
format++; format++;
@@ -578,26 +590,48 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
// evaluate flags // evaluate flags
flags = 0U; flags = 0U;
do { do {
switch (*format) { switch(*format) {
case '0': flags |= FLAGS_ZEROPAD; format++; n = 1U; break; case '0':
case '-': flags |= FLAGS_LEFT; format++; n = 1U; break; flags |= FLAGS_ZEROPAD;
case '+': flags |= FLAGS_PLUS; format++; n = 1U; break; format++;
case ' ': flags |= FLAGS_SPACE; format++; n = 1U; break; n = 1U;
case '#': flags |= FLAGS_HASH; format++; n = 1U; break; break;
default : n = 0U; break; case '-':
flags |= FLAGS_LEFT;
format++;
n = 1U;
break;
case '+':
flags |= FLAGS_PLUS;
format++;
n = 1U;
break;
case ' ':
flags |= FLAGS_SPACE;
format++;
n = 1U;
break;
case '#':
flags |= FLAGS_HASH;
format++;
n = 1U;
break;
default :
n = 0U;
break;
} }
} while (n); } while(n);
// evaluate width field // evaluate width field
width = 0U; width = 0U;
if (_is_digit(*format)) { if(_is_digit(*format)) {
width = _atoi(&format); width = _atoi(&format);
} }
else if (*format == '*') { else if(*format == '*') {
const int w = va_arg(va, int); const int w = va_arg(va, int);
if (w < 0) { if(w < 0) {
flags |= FLAGS_LEFT; // reverse padding flags |= FLAGS_LEFT; // reverse padding
width = (unsigned int)-w; width = (unsigned int) - w;
} }
else { else {
width = (unsigned int)w; width = (unsigned int)w;
@@ -607,13 +641,13 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
// evaluate precision field // evaluate precision field
precision = 0U; precision = 0U;
if (*format == '.') { if(*format == '.') {
flags |= FLAGS_PRECISION; flags |= FLAGS_PRECISION;
format++; format++;
if (_is_digit(*format)) { if(_is_digit(*format)) {
precision = _atoi(&format); precision = _atoi(&format);
} }
else if (*format == '*') { else if(*format == '*') {
const int prec = (int)va_arg(va, int); const int prec = (int)va_arg(va, int);
precision = prec > 0 ? (unsigned int)prec : 0U; precision = prec > 0 ? (unsigned int)prec : 0U;
format++; format++;
@@ -621,11 +655,11 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
} }
// evaluate length field // evaluate length field
switch (*format) { switch(*format) {
case 'l' : case 'l' :
flags |= FLAGS_LONG; flags |= FLAGS_LONG;
format++; format++;
if (*format == 'l') { if(*format == 'l') {
flags |= FLAGS_LONG_LONG; flags |= FLAGS_LONG_LONG;
format++; format++;
} }
@@ -633,7 +667,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
case 'h' : case 'h' :
flags |= FLAGS_SHORT; flags |= FLAGS_SHORT;
format++; format++;
if (*format == 'h') { if(*format == 'h') {
flags |= FLAGS_CHAR; flags |= FLAGS_CHAR;
format++; format++;
} }
@@ -657,7 +691,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
} }
// evaluate specifier // evaluate specifier
switch (*format) { switch(*format) {
case 'd' : case 'd' :
case 'i' : case 'i' :
case 'u' : case 'u' :
@@ -667,13 +701,13 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
case 'b' : { case 'b' : {
// set the base // set the base
unsigned int base; unsigned int base;
if (*format == 'x' || *format == 'X') { if(*format == 'x' || *format == 'X') {
base = 16U; base = 16U;
} }
else if (*format == 'o') { else if(*format == 'o') {
base = 8U; base = 8U;
} }
else if (*format == 'b') { else if(*format == 'b') {
base = 2U; base = 2U;
} }
else { else {
@@ -681,50 +715,55 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
flags &= ~FLAGS_HASH; // no hash for dec format flags &= ~FLAGS_HASH; // no hash for dec format
} }
// uppercase // uppercase
if (*format == 'X') { if(*format == 'X') {
flags |= FLAGS_UPPERCASE; flags |= FLAGS_UPPERCASE;
} }
// no plus or space flag for u, x, X, o, b // no plus or space flag for u, x, X, o, b
if ((*format != 'i') && (*format != 'd')) { if((*format != 'i') && (*format != 'd')) {
flags &= ~(FLAGS_PLUS | FLAGS_SPACE); flags &= ~(FLAGS_PLUS | FLAGS_SPACE);
} }
// ignore '0' flag when precision is given // ignore '0' flag when precision is given
if (flags & FLAGS_PRECISION) { if(flags & FLAGS_PRECISION) {
flags &= ~FLAGS_ZEROPAD; flags &= ~FLAGS_ZEROPAD;
} }
// convert the integer // convert the integer
if ((*format == 'i') || (*format == 'd')) { if((*format == 'i') || (*format == 'd')) {
// signed // signed
if (flags & FLAGS_LONG_LONG) { if(flags & FLAGS_LONG_LONG) {
#if defined(PRINTF_SUPPORT_LONG_LONG) #if defined(PRINTF_SUPPORT_LONG_LONG)
const long long value = va_arg(va, long long); const long long value = va_arg(va, long long);
idx = _ntoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); idx = _ntoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base,
precision, width, flags);
#endif #endif
} }
else if (flags & FLAGS_LONG) { else if(flags & FLAGS_LONG) {
const long value = va_arg(va, long); const long value = va_arg(va, long);
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision,
width, flags);
} }
else { else {
const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & FLAGS_SHORT) ? (short int)va_arg(va, int) : va_arg(va, int); const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & FLAGS_SHORT) ? (short int)va_arg(va,
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags); int) : va_arg(va, int);
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision,
width, flags);
} }
} }
else { else {
// unsigned // unsigned
if (flags & FLAGS_LONG_LONG) { if(flags & FLAGS_LONG_LONG) {
#if defined(PRINTF_SUPPORT_LONG_LONG) #if defined(PRINTF_SUPPORT_LONG_LONG)
idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags); idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags);
#endif #endif
} }
else if (flags & FLAGS_LONG) { else if(flags & FLAGS_LONG) {
idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags); idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags);
} }
else { else {
const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) : (flags & FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) : va_arg(va, unsigned int); const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char)va_arg(va,
unsigned int) : (flags & FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) : va_arg(va, unsigned int);
idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags); idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags);
} }
} }
@@ -734,7 +773,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
#if defined(PRINTF_SUPPORT_FLOAT) #if defined(PRINTF_SUPPORT_FLOAT)
case 'f' : case 'f' :
case 'F' : case 'F' :
if (*format == 'F') flags |= FLAGS_UPPERCASE; if(*format == 'F') flags |= FLAGS_UPPERCASE;
idx = _ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); idx = _ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
format++; format++;
break; break;
@@ -743,8 +782,8 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
case 'E': case 'E':
case 'g': case 'g':
case 'G': case 'G':
if ((*format == 'g')||(*format == 'G')) flags |= FLAGS_ADAPT_EXP; if((*format == 'g') || (*format == 'G')) flags |= FLAGS_ADAPT_EXP;
if ((*format == 'E')||(*format == 'G')) flags |= FLAGS_UPPERCASE; if((*format == 'E') || (*format == 'G')) flags |= FLAGS_UPPERCASE;
idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags); idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
format++; format++;
break; break;
@@ -753,16 +792,16 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
case 'c' : { case 'c' : {
unsigned int l = 1U; unsigned int l = 1U;
// pre padding // pre padding
if (!(flags & FLAGS_LEFT)) { if(!(flags & FLAGS_LEFT)) {
while (l++ < width) { while(l++ < width) {
out(' ', buffer, idx++, maxlen); out(' ', buffer, idx++, maxlen);
} }
} }
// char output // char output
out((char)va_arg(va, int), buffer, idx++, maxlen); out((char)va_arg(va, int), buffer, idx++, maxlen);
// post padding // post padding
if (flags & FLAGS_LEFT) { if(flags & FLAGS_LEFT) {
while (l++ < width) { while(l++ < width) {
out(' ', buffer, idx++, maxlen); out(' ', buffer, idx++, maxlen);
} }
} }
@@ -771,24 +810,24 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
} }
case 's' : { case 's' : {
const char* p = va_arg(va, char*); const char * p = va_arg(va, char *);
unsigned int l = _strnlen_s(p, precision ? precision : (size_t)-1); unsigned int l = _strnlen_s(p, precision ? precision : (size_t) -1);
// pre padding // pre padding
if (flags & FLAGS_PRECISION) { if(flags & FLAGS_PRECISION) {
l = (l < precision ? l : precision); l = (l < precision ? l : precision);
} }
if (!(flags & FLAGS_LEFT)) { if(!(flags & FLAGS_LEFT)) {
while (l++ < width) { while(l++ < width) {
out(' ', buffer, idx++, maxlen); out(' ', buffer, idx++, maxlen);
} }
} }
// string output // string output
while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) { while((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
out(*(p++), buffer, idx++, maxlen); out(*(p++), buffer, idx++, maxlen);
} }
// post padding // post padding
if (flags & FLAGS_LEFT) { if(flags & FLAGS_LEFT) {
while (l++ < width) { while(l++ < width) {
out(' ', buffer, idx++, maxlen); out(' ', buffer, idx++, maxlen);
} }
} }
@@ -797,16 +836,17 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
} }
case 'p' : { case 'p' : {
width = sizeof(void*) * 2U; width = sizeof(void *) * 2U;
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE; flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
#if defined(PRINTF_SUPPORT_LONG_LONG) #if defined(PRINTF_SUPPORT_LONG_LONG)
const bool is_ll = sizeof(uintptr_t) == sizeof(long long); const bool is_ll = sizeof(uintptr_t) == sizeof(long long);
if (is_ll) { if(is_ll) {
idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*), false, 16U, precision, width, flags); idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void *), false, 16U, precision, width, flags);
} }
else { else {
#endif #endif
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)), false, 16U, precision, width, flags); idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void *)), false, 16U, precision, width,
flags);
#if defined(PRINTF_SUPPORT_LONG_LONG) #if defined(PRINTF_SUPPORT_LONG_LONG)
} }
#endif #endif
@@ -836,7 +876,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
int lv_snprintf(char* buffer, size_t count, const char* format, ...) int lv_snprintf(char * buffer, size_t count, const char * format, ...)
{ {
va_list va; va_list va;
va_start(va, format); va_start(va, format);
@@ -845,7 +885,7 @@ int lv_snprintf(char* buffer, size_t count, const char* format, ...)
return ret; return ret;
} }
int lv_vsnprintf(char* buffer, size_t count, const char* format, va_list va) int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va)
{ {
return _vsnprintf(_out_buffer, buffer, count, format, va); return _vsnprintf(_out_buffer, buffer, count, format, va);
} }

View File

@@ -54,8 +54,8 @@ extern "C" {
* null character. A value equal or larger than count indicates truncation. Only when the returned value * null character. A value equal or larger than count indicates truncation. Only when the returned value
* is non-negative and less than count, the string has been completely written. * is non-negative and less than count, the string has been completely written.
*/ */
int lv_snprintf(char* buffer, size_t count, const char* format, ...); int lv_snprintf(char * buffer, size_t count, const char * format, ...);
int lv_vsnprintf(char* buffer, size_t count, const char* format, va_list va); int lv_vsnprintf(char * buffer, size_t count, const char * format, va_list va);
#else #else
#include LV_SPRINTF_INCLUDE #include LV_SPRINTF_INCLUDE

View File

@@ -14,7 +14,7 @@
#include "lv_gc.h" #include "lv_gc.h"
#if defined(LV_GC_INCLUDE) #if defined(LV_GC_INCLUDE)
#include LV_GC_INCLUDE #include LV_GC_INCLUDE
#endif /* LV_ENABLE_GC */ #endif /* LV_ENABLE_GC */
/********************* /*********************
@@ -305,8 +305,7 @@ void lv_task_set_prio(lv_task_t * task, lv_task_prio_t prio)
/*Find the tasks with new priority*/ /*Find the tasks with new priority*/
lv_task_t * i; lv_task_t * i;
LV_LL_READ(LV_GC_ROOT(_lv_task_ll), i) LV_LL_READ(LV_GC_ROOT(_lv_task_ll), i) {
{
if(i->prio <= prio) { if(i->prio <= prio) {
if(i != task) lv_ll_move_before(&LV_GC_ROOT(_lv_task_ll), task, i); if(i != task) lv_ll_move_before(&LV_GC_ROOT(_lv_task_ll), task, i);
break; break;

View File

@@ -57,8 +57,7 @@ typedef uint8_t lv_task_prio_t;
/** /**
* Descriptor of a lv_task * Descriptor of a lv_task
*/ */
typedef struct _lv_task_t typedef struct _lv_task_t {
{
uint32_t period; /**< How often the task should run */ uint32_t period; /**< How often the task should run */
uint32_t last_run; /**< Last time the task ran */ uint32_t last_run; /**< Last time the task ran */
lv_task_cb_t task_cb; /**< Task function */ lv_task_cb_t task_cb; /**< Task function */

View File

@@ -25,23 +25,23 @@
static inline bool is_break_char(uint32_t letter); static inline bool is_break_char(uint32_t letter);
#if LV_TXT_ENC == LV_TXT_ENC_UTF8 #if LV_TXT_ENC == LV_TXT_ENC_UTF8
static uint8_t lv_txt_utf8_size(const char * str); static uint8_t lv_txt_utf8_size(const char * str);
static uint32_t lv_txt_unicode_to_utf8(uint32_t letter_uni); static uint32_t lv_txt_unicode_to_utf8(uint32_t letter_uni);
static uint32_t lv_txt_utf8_conv_wc(uint32_t c); static uint32_t lv_txt_utf8_conv_wc(uint32_t c);
static uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i); static uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i);
static uint32_t lv_txt_utf8_prev(const char * txt, uint32_t * i_start); static uint32_t lv_txt_utf8_prev(const char * txt, uint32_t * i_start);
static uint32_t lv_txt_utf8_get_byte_id(const char * txt, uint32_t utf8_id); static uint32_t lv_txt_utf8_get_byte_id(const char * txt, uint32_t utf8_id);
static uint32_t lv_txt_utf8_get_char_id(const char * txt, uint32_t byte_id); static uint32_t lv_txt_utf8_get_char_id(const char * txt, uint32_t byte_id);
static uint32_t lv_txt_utf8_get_length(const char * txt); static uint32_t lv_txt_utf8_get_length(const char * txt);
#elif LV_TXT_ENC == LV_TXT_ENC_ASCII #elif LV_TXT_ENC == LV_TXT_ENC_ASCII
static uint8_t lv_txt_iso8859_1_size(const char * str); static uint8_t lv_txt_iso8859_1_size(const char * str);
static uint32_t lv_txt_unicode_to_iso8859_1(uint32_t letter_uni); static uint32_t lv_txt_unicode_to_iso8859_1(uint32_t letter_uni);
static uint32_t lv_txt_iso8859_1_conv_wc(uint32_t c); static uint32_t lv_txt_iso8859_1_conv_wc(uint32_t c);
static uint32_t lv_txt_iso8859_1_next(const char * txt, uint32_t * i); static uint32_t lv_txt_iso8859_1_next(const char * txt, uint32_t * i);
static uint32_t lv_txt_iso8859_1_prev(const char * txt, uint32_t * i_start); static uint32_t lv_txt_iso8859_1_prev(const char * txt, uint32_t * i_start);
static uint32_t lv_txt_iso8859_1_get_byte_id(const char * txt, uint32_t utf8_id); static uint32_t lv_txt_iso8859_1_get_byte_id(const char * txt, uint32_t utf8_id);
static uint32_t lv_txt_iso8859_1_get_char_id(const char * txt, uint32_t byte_id); static uint32_t lv_txt_iso8859_1_get_char_id(const char * txt, uint32_t byte_id);
static uint32_t lv_txt_iso8859_1_get_length(const char * txt); static uint32_t lv_txt_iso8859_1_get_length(const char * txt);
#endif #endif
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@@ -51,23 +51,23 @@ static uint32_t lv_txt_iso8859_1_get_length(const char * txt);
* GLOBAL VARIABLES * GLOBAL VARIABLES
**********************/ **********************/
#if LV_TXT_ENC == LV_TXT_ENC_UTF8 #if LV_TXT_ENC == LV_TXT_ENC_UTF8
uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_utf8_size; uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_utf8_size;
uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_utf8; uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_utf8;
uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_utf8_conv_wc; uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_utf8_conv_wc;
uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_utf8_next; uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_utf8_next;
uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_utf8_prev; uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_utf8_prev;
uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_utf8_get_byte_id; uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_utf8_get_byte_id;
uint32_t (*lv_txt_encoded_get_char_id)(const char *, uint32_t) = lv_txt_utf8_get_char_id; uint32_t (*lv_txt_encoded_get_char_id)(const char *, uint32_t) = lv_txt_utf8_get_char_id;
uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_utf8_get_length; uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_utf8_get_length;
#elif LV_TXT_ENC == LV_TXT_ENC_ASCII #elif LV_TXT_ENC == LV_TXT_ENC_ASCII
uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_iso8859_1_size; uint8_t (*lv_txt_encoded_size)(const char *) = lv_txt_iso8859_1_size;
uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_iso8859_1; uint32_t (*lv_txt_unicode_to_encoded)(uint32_t) = lv_txt_unicode_to_iso8859_1;
uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_iso8859_1_conv_wc; uint32_t (*lv_txt_encoded_conv_wc)(uint32_t) = lv_txt_iso8859_1_conv_wc;
uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_iso8859_1_next; uint32_t (*lv_txt_encoded_next)(const char *, uint32_t *) = lv_txt_iso8859_1_next;
uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_iso8859_1_prev; uint32_t (*lv_txt_encoded_prev)(const char *, uint32_t *) = lv_txt_iso8859_1_prev;
uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_iso8859_1_get_byte_id; uint32_t (*lv_txt_encoded_get_byte_id)(const char *, uint32_t) = lv_txt_iso8859_1_get_byte_id;
uint32_t (*lv_txt_encoded_get_char_id)(const char *, uint32_t) = lv_txt_iso8859_1_get_char_id; uint32_t (*lv_txt_encoded_get_char_id)(const char *, uint32_t) = lv_txt_iso8859_1_get_char_id;
uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_iso8859_1_get_length; uint32_t (*lv_txt_get_encoded_length)(const char *) = lv_txt_iso8859_1_get_length;
#endif #endif
@@ -109,10 +109,11 @@ void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t *
while(text[line_start] != '\0') { while(text[line_start] != '\0') {
new_line_start += lv_txt_get_next_line(&text[line_start], font, letter_space, max_width, flag); new_line_start += lv_txt_get_next_line(&text[line_start], font, letter_space, max_width, flag);
if ((unsigned long)size_res->y + (unsigned long)letter_height + (unsigned long)line_space > LV_MAX_OF(lv_coord_t)) { if((unsigned long)size_res->y + (unsigned long)letter_height + (unsigned long)line_space > LV_MAX_OF(lv_coord_t)) {
LV_LOG_WARN("lv_txt_get_size: integer overflow while calculating text height"); LV_LOG_WARN("lv_txt_get_size: integer overflow while calculating text height");
return; return;
} else { }
else {
size_res->y += letter_height; size_res->y += letter_height;
size_res->y += line_space; size_res->y += line_space;
} }
@@ -169,7 +170,7 @@ void lv_txt_get_size(lv_point_t * size_res, const char * text, const lv_font_t *
*/ */
static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font, static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
lv_coord_t letter_space, lv_coord_t max_width, lv_coord_t letter_space, lv_coord_t max_width,
lv_txt_flag_t flag, uint32_t *word_w_ptr, lv_txt_cmd_state_t * cmd_state, bool force) lv_txt_flag_t flag, uint32_t * word_w_ptr, lv_txt_cmd_state_t * cmd_state, bool force)
{ {
if(txt == NULL || txt[0] == '\0') return 0; if(txt == NULL || txt[0] == '\0') return 0;
if(font == NULL) return 0; if(font == NULL) return 0;
@@ -227,7 +228,7 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
} }
/* Update the output width */ /* Update the output width */
if( word_w_ptr != NULL && break_index == NO_BREAK_FOUND ) *word_w_ptr = cur_w; if(word_w_ptr != NULL && break_index == NO_BREAK_FOUND) *word_w_ptr = cur_w;
i = i_next; i = i_next;
@@ -236,22 +237,22 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
} }
/* Entire Word fits in the provided space */ /* Entire Word fits in the provided space */
if( break_index == NO_BREAK_FOUND ) { if(break_index == NO_BREAK_FOUND) {
if( word_len == 0 || (letter == '\r' && letter_next == '\n') ) i = i_next; if(word_len == 0 || (letter == '\r' && letter_next == '\n')) i = i_next;
return i; return i;
} }
#if LV_TXT_LINE_BREAK_LONG_LEN > 0 #if LV_TXT_LINE_BREAK_LONG_LEN > 0
/* Word doesn't fit in provided space, but isn't "long" */ /* Word doesn't fit in provided space, but isn't "long" */
if(word_len < LV_TXT_LINE_BREAK_LONG_LEN) { if(word_len < LV_TXT_LINE_BREAK_LONG_LEN) {
if( force ) return break_index; if(force) return break_index;
if(word_w_ptr != NULL) *word_w_ptr = 0; /* Return no word */ if(word_w_ptr != NULL) *word_w_ptr = 0; /* Return no word */
return 0; return 0;
} }
/* Word is "long," but insufficient amounts can fit in provided space */ /* Word is "long," but insufficient amounts can fit in provided space */
if(break_letter_count < LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN) { if(break_letter_count < LV_TXT_LINE_BREAK_LONG_PRE_MIN_LEN) {
if( force ) return break_index; if(force) return break_index;
if(word_w_ptr != NULL) *word_w_ptr = 0; if(word_w_ptr != NULL) *word_w_ptr = 0;
return 0; return 0;
} }
@@ -261,7 +262,7 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
i = break_index; i = break_index;
int32_t n_move = LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN - (word_len - break_letter_count); int32_t n_move = LV_TXT_LINE_BREAK_LONG_POST_MIN_LEN - (word_len - break_letter_count);
/* Move pointer "i" backwards */ /* Move pointer "i" backwards */
for(;n_move>0; n_move--){ for(; n_move > 0; n_move--) {
lv_txt_encoded_prev(txt, &i); lv_txt_encoded_prev(txt, &i);
// TODO: it would be appropriate to update the returned word width here // TODO: it would be appropriate to update the returned word width here
// However, in current usage, this doesn't impact anything. // However, in current usage, this doesn't impact anything.
@@ -269,7 +270,7 @@ static uint16_t lv_txt_get_next_word(const char * txt, const lv_font_t * font,
} }
return i; return i;
#else #else
if( force ) return break_index; if(force) return break_index;
if(word_w_ptr != NULL) *word_w_ptr = 0; /* Return no word */ if(word_w_ptr != NULL) *word_w_ptr = 0; /* Return no word */
(void) break_letter_count; (void) break_letter_count;
return 0; return 0;
@@ -300,10 +301,10 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
while(txt[i] != '\0' && max_width > 0) { while(txt[i] != '\0' && max_width > 0) {
uint32_t word_w = 0; uint32_t word_w = 0;
uint32_t advance = lv_txt_get_next_word(&txt[i], font, letter_space, max_width, flag, &word_w, &cmd_state, i==0); uint32_t advance = lv_txt_get_next_word(&txt[i], font, letter_space, max_width, flag, &word_w, &cmd_state, i == 0);
max_width -= word_w; max_width -= word_w;
if( advance == 0 ){ if(advance == 0) {
if(i == 0) lv_txt_encoded_next(txt, &i); // prevent inf loops if(i == 0) lv_txt_encoded_next(txt, &i); // prevent inf loops
break; break;
} }
@@ -312,7 +313,7 @@ uint16_t lv_txt_get_next_line(const char * txt, const lv_font_t * font,
if(txt[0] == '\n' || txt[0] == '\r') break; if(txt[0] == '\n' || txt[0] == '\r') break;
if(txt[i] == '\n' || txt[i] == '\r'){ if(txt[i] == '\n' || txt[i] == '\r') {
i++; /* Include the following newline in the current line */ i++; /* Include the following newline in the current line */
break; break;
} }
@@ -496,12 +497,14 @@ static uint32_t lv_txt_unicode_to_utf8(uint32_t letter_uni)
bytes[1] = ((letter_uni >> 0) & 0x3F) | 0x80; bytes[1] = ((letter_uni >> 0) & 0x3F) | 0x80;
bytes[2] = 0; bytes[2] = 0;
bytes[3] = 0; bytes[3] = 0;
} else if(letter_uni < 0x010000) { }
else if(letter_uni < 0x010000) {
bytes[0] = ((letter_uni >> 12) & 0x0F) | 0xE0; bytes[0] = ((letter_uni >> 12) & 0x0F) | 0xE0;
bytes[1] = ((letter_uni >> 6) & 0x3F) | 0x80; bytes[1] = ((letter_uni >> 6) & 0x3F) | 0x80;
bytes[2] = ((letter_uni >> 0) & 0x3F) | 0x80; bytes[2] = ((letter_uni >> 0) & 0x3F) | 0x80;
bytes[3] = 0; bytes[3] = 0;
} else if(letter_uni < 0x110000) { }
else if(letter_uni < 0x110000) {
bytes[0] = ((letter_uni >> 18) & 0x07) | 0xF0; bytes[0] = ((letter_uni >> 18) & 0x07) | 0xF0;
bytes[1] = ((letter_uni >> 12) & 0x3F) | 0x80; bytes[1] = ((letter_uni >> 12) & 0x3F) | 0x80;
bytes[2] = ((letter_uni >> 6) & 0x3F) | 0x80; bytes[2] = ((letter_uni >> 6) & 0x3F) | 0x80;
@@ -603,7 +606,8 @@ static uint32_t lv_txt_utf8_next(const char * txt, uint32_t * i)
if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/ if((txt[*i] & 0xC0) != 0x80) return 0; /*Invalid UTF-8 code*/
result += txt[*i] & 0x3F; result += txt[*i] & 0x3F;
(*i)++; (*i)++;
} else { }
else {
(*i)++; /*Not UTF-8 char. Go the next.*/ (*i)++; /*Not UTF-8 char. Go the next.*/
} }
} }

View File

@@ -100,10 +100,12 @@ void * lv_utils_bsearch(const void * key, const void * base, uint32_t n, uint32_
if((c = (*cmp)(key, middle)) > 0) { if((c = (*cmp)(key, middle)) > 0) {
n = (n / 2) - ((n & 1) == 0); n = (n / 2) - ((n & 1) == 0);
base = (middle += size); base = (middle += size);
} else if(c < 0) { }
else if(c < 0) {
n /= 2; n /= 2;
middle = base; middle = base;
} else { }
else {
return (char *)middle; return (char *)middle;
} }
} }

View File

@@ -76,11 +76,11 @@ typedef enum {
LV_THEME_TILEVIEW, LV_THEME_TILEVIEW,
LV_THEME_WIN, LV_THEME_WIN,
LV_THEME_WIN_BTN, /*The buttons are initialized separately*/ LV_THEME_WIN_BTN, /*The buttons are initialized separately*/
}lv_theme_style_t; } lv_theme_style_t;
typedef struct { typedef struct {
void (*apply_cb)(lv_obj_t *,lv_theme_style_t); void (*apply_cb)(lv_obj_t *, lv_theme_style_t);
}lv_theme_t; } lv_theme_t;
/********************** /**********************
* GLOBAL PROTOTYPES * GLOBAL PROTOTYPES

View File

@@ -60,94 +60,94 @@ static lv_style_t pad;
#if LV_USE_ARC #if LV_USE_ARC
static lv_style_t arc; static lv_style_t arc;
static lv_style_t arc_bg; static lv_style_t arc_bg;
#endif #endif
#if LV_USE_BAR #if LV_USE_BAR
static lv_style_t bar_bg; static lv_style_t bar_bg;
static lv_style_t bar_indic; static lv_style_t bar_indic;
#endif #endif
#if LV_USE_BTNMATRIX #if LV_USE_BTNMATRIX
static lv_style_t btnm_bg, btnm_btn; static lv_style_t btnm_bg, btnm_btn;
#endif #endif
#if LV_USE_CALENDAR #if LV_USE_CALENDAR
static lv_style_t calendar_date_nums, calendar_header, calendar_daynames; static lv_style_t calendar_date_nums, calendar_header, calendar_daynames;
#endif #endif
#if LV_USE_CPICKER #if LV_USE_CPICKER
static lv_style_t cpicker_bg, cpicker_indic; static lv_style_t cpicker_bg, cpicker_indic;
#endif #endif
#if LV_USE_CHART #if LV_USE_CHART
static lv_style_t chart_series_bg, chart_series; static lv_style_t chart_series_bg, chart_series;
#endif #endif
#if LV_USE_CHECKBOX #if LV_USE_CHECKBOX
static lv_style_t cb_bg, cb_bullet; static lv_style_t cb_bg, cb_bullet;
#endif #endif
#if LV_USE_DROPDOWN #if LV_USE_DROPDOWN
static lv_style_t ddlist_btn, ddlist_page, ddlist_sel; static lv_style_t ddlist_btn, ddlist_page, ddlist_sel;
#endif #endif
#if LV_USE_GAUGE #if LV_USE_GAUGE
static lv_style_t gauge_main, gauge_strong, gauge_needle; static lv_style_t gauge_main, gauge_strong, gauge_needle;
#endif #endif
#if LV_USE_KEYBOARD #if LV_USE_KEYBOARD
static lv_style_t kb_bg, kb_btn; static lv_style_t kb_bg, kb_btn;
#endif #endif
#if LV_USE_LED #if LV_USE_LED
static lv_style_t led; static lv_style_t led;
#endif #endif
#if LV_USE_LINEMETER #if LV_USE_LINEMETER
static lv_style_t lmeter; static lv_style_t lmeter;
#endif #endif
#if LV_USE_LIST #if LV_USE_LIST
static lv_style_t list_bg, list_btn; static lv_style_t list_bg, list_btn;
#endif #endif
#if LV_USE_MSGBOX #if LV_USE_MSGBOX
static lv_style_t mbox_btn_bg; static lv_style_t mbox_btn_bg;
#endif #endif
#if LV_USE_PAGE #if LV_USE_PAGE
static lv_style_t sb; static lv_style_t sb;
#endif #endif
#if LV_USE_ROLLER #if LV_USE_ROLLER
static lv_style_t roller_bg, roller_sel; static lv_style_t roller_bg, roller_sel;
#endif #endif
#if LV_USE_SLIDER #if LV_USE_SLIDER
static lv_style_t slider_knob; static lv_style_t slider_knob;
#endif #endif
#if LV_USE_SPINBOX #if LV_USE_SPINBOX
static lv_style_t spinbox_btn, spinbox_cursor; static lv_style_t spinbox_btn, spinbox_cursor;
#endif #endif
#if LV_USE_SWITCH #if LV_USE_SWITCH
static lv_style_t sw_knob; static lv_style_t sw_knob;
#endif #endif
#if LV_USE_TABLE #if LV_USE_TABLE
static lv_style_t table_cell; static lv_style_t table_cell;
#endif #endif
#if LV_USE_TABVIEW #if LV_USE_TABVIEW
static lv_style_t tabview_btns, tabview_btns_bg, tabview_indic, tabview_page_scrl; static lv_style_t tabview_btns, tabview_btns_bg, tabview_indic, tabview_page_scrl;
#endif #endif
#if LV_USE_TEXTAREA #if LV_USE_TEXTAREA
static lv_style_t ta_bg, ta_cursor, ta_oneline, ta_placeholder; static lv_style_t ta_bg, ta_cursor, ta_oneline, ta_placeholder;
#endif #endif
/********************** /**********************
@@ -177,7 +177,7 @@ static void basic_init(void)
lv_style_set_border_color(&panel, LV_STATE_DEFAULT, color_panel_border(LV_STATE_DEFAULT)); lv_style_set_border_color(&panel, LV_STATE_DEFAULT, color_panel_border(LV_STATE_DEFAULT));
lv_style_set_border_color(&panel, LV_STATE_FOCUSED, color_panel_border(LV_STATE_FOCUSED)); lv_style_set_border_color(&panel, LV_STATE_FOCUSED, color_panel_border(LV_STATE_FOCUSED));
lv_style_set_border_width(&panel, LV_STATE_DEFAULT, BORDER_WIDTH); lv_style_set_border_width(&panel, LV_STATE_DEFAULT, BORDER_WIDTH);
lv_style_set_border_side(&panel, LV_STATE_DEFAULT , LV_BORDER_SIDE_TOP); lv_style_set_border_side(&panel, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP);
lv_style_set_text_font(&panel, LV_STATE_DEFAULT, _font_normal); lv_style_set_text_font(&panel, LV_STATE_DEFAULT, _font_normal);
lv_style_set_text_color(&panel, LV_STATE_DEFAULT, color_panel_txt(LV_STATE_DEFAULT)); lv_style_set_text_color(&panel, LV_STATE_DEFAULT, color_panel_txt(LV_STATE_DEFAULT));
lv_style_set_value_color(&panel, LV_STATE_DEFAULT, color_panel_txt(LV_STATE_DEFAULT)); lv_style_set_value_color(&panel, LV_STATE_DEFAULT, color_panel_txt(LV_STATE_DEFAULT));
@@ -228,12 +228,13 @@ static void basic_init(void)
lv_style_set_text_color(&btn, LV_STATE_PRESSED, color_btn_txt(LV_STATE_PRESSED)); lv_style_set_text_color(&btn, LV_STATE_PRESSED, color_btn_txt(LV_STATE_PRESSED));
lv_style_set_text_color(&btn, LV_STATE_PRESSED, color_btn_txt(LV_STATE_CHECKED)); lv_style_set_text_color(&btn, LV_STATE_PRESSED, color_btn_txt(LV_STATE_CHECKED));
lv_style_set_text_color(&btn, LV_STATE_CHECKED | LV_STATE_PRESSED, color_btn_txt(LV_STATE_CHECKED | LV_STATE_PRESSED)); lv_style_set_text_color(&btn, LV_STATE_CHECKED | LV_STATE_PRESSED, color_btn_txt(LV_STATE_CHECKED | LV_STATE_PRESSED));
lv_style_set_text_color(&btn, LV_STATE_DISABLED,color_btn_txt(LV_STATE_DISABLED)); lv_style_set_text_color(&btn, LV_STATE_DISABLED, color_btn_txt(LV_STATE_DISABLED));
lv_style_set_image_recolor(&btn, LV_STATE_DEFAULT, color_btn_txt(LV_STATE_DEFAULT)); lv_style_set_image_recolor(&btn, LV_STATE_DEFAULT, color_btn_txt(LV_STATE_DEFAULT));
lv_style_set_image_recolor(&btn, LV_STATE_PRESSED, color_btn_txt(LV_STATE_PRESSED)); lv_style_set_image_recolor(&btn, LV_STATE_PRESSED, color_btn_txt(LV_STATE_PRESSED));
lv_style_set_image_recolor(&btn, LV_STATE_PRESSED, color_btn_txt(LV_STATE_CHECKED)); lv_style_set_image_recolor(&btn, LV_STATE_PRESSED, color_btn_txt(LV_STATE_CHECKED));
lv_style_set_image_recolor(&btn, LV_STATE_CHECKED | LV_STATE_PRESSED, color_btn_txt(LV_STATE_CHECKED | LV_STATE_PRESSED)); lv_style_set_image_recolor(&btn, LV_STATE_CHECKED | LV_STATE_PRESSED,
lv_style_set_image_recolor(&btn, LV_STATE_DISABLED,color_btn_txt(LV_STATE_DISABLED)); color_btn_txt(LV_STATE_CHECKED | LV_STATE_PRESSED));
lv_style_set_image_recolor(&btn, LV_STATE_DISABLED, color_btn_txt(LV_STATE_DISABLED));
lv_style_set_value_color(&btn, LV_STATE_DEFAULT, color_btn_txt(LV_STATE_DEFAULT)); lv_style_set_value_color(&btn, LV_STATE_DEFAULT, color_btn_txt(LV_STATE_DEFAULT));
lv_style_set_pad_left(&btn, LV_STATE_DEFAULT, LV_DPI / 5); lv_style_set_pad_left(&btn, LV_STATE_DEFAULT, LV_DPI / 5);
@@ -338,10 +339,10 @@ static void slider_init(void)
lv_style_set_bg_color(&slider_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_style_set_bg_color(&slider_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_style_set_value_color(&slider_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_style_set_value_color(&slider_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_style_set_radius(&slider_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_radius(&slider_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_style_set_pad_left(&slider_knob, LV_STATE_DEFAULT, LV_DPI/20); lv_style_set_pad_left(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20);
lv_style_set_pad_right(&slider_knob, LV_STATE_DEFAULT, LV_DPI/20); lv_style_set_pad_right(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20);
lv_style_set_pad_top(&slider_knob, LV_STATE_DEFAULT, LV_DPI/20); lv_style_set_pad_top(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20);
lv_style_set_pad_bottom(&slider_knob, LV_STATE_DEFAULT, LV_DPI/20); lv_style_set_pad_bottom(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20);
#endif #endif
} }
@@ -353,10 +354,10 @@ static void switch_init(void)
lv_style_set_bg_opa(&sw_knob, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_opa(&sw_knob, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&sw_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_style_set_bg_color(&sw_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE);
lv_style_set_radius(&sw_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_radius(&sw_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_style_set_pad_top(&sw_knob, LV_STATE_DEFAULT, - LV_DPI/20); lv_style_set_pad_top(&sw_knob, LV_STATE_DEFAULT, - LV_DPI / 20);
lv_style_set_pad_bottom(&sw_knob, LV_STATE_DEFAULT, - LV_DPI/20); lv_style_set_pad_bottom(&sw_knob, LV_STATE_DEFAULT, - LV_DPI / 20);
lv_style_set_pad_left(&sw_knob, LV_STATE_DEFAULT, - LV_DPI/20); lv_style_set_pad_left(&sw_knob, LV_STATE_DEFAULT, - LV_DPI / 20);
lv_style_set_pad_right(&sw_knob, LV_STATE_DEFAULT, - LV_DPI/20); lv_style_set_pad_right(&sw_knob, LV_STATE_DEFAULT, - LV_DPI / 20);
#endif #endif
} }
@@ -372,7 +373,7 @@ static void linemeter_init(void)
lv_style_set_pad_right(&lmeter, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_right(&lmeter, LV_STATE_DEFAULT, LV_DPI / 10);
lv_style_set_pad_top(&lmeter, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_top(&lmeter, LV_STATE_DEFAULT, LV_DPI / 10);
lv_style_set_pad_inner(&lmeter, LV_STATE_DEFAULT, LV_DPI / 6); lv_style_set_pad_inner(&lmeter, LV_STATE_DEFAULT, LV_DPI / 6);
lv_style_set_scale_width(&lmeter, LV_STATE_DEFAULT, LV_DPI/12); lv_style_set_scale_width(&lmeter, LV_STATE_DEFAULT, LV_DPI / 12);
lv_style_set_line_color(&lmeter, LV_STATE_DEFAULT, _color_primary); lv_style_set_line_color(&lmeter, LV_STATE_DEFAULT, _color_primary);
lv_style_set_scale_grad_color(&lmeter, LV_STATE_DEFAULT, _color_primary); lv_style_set_scale_grad_color(&lmeter, LV_STATE_DEFAULT, _color_primary);
@@ -401,7 +402,7 @@ static void gauge_init(void)
lv_style_set_pad_right(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_right(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 10);
lv_style_set_pad_top(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_top(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 10);
lv_style_set_pad_inner(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 6); lv_style_set_pad_inner(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 6);
lv_style_set_scale_width(&gauge_main, LV_STATE_DEFAULT, LV_DPI/12); lv_style_set_scale_width(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 12);
lv_style_init(&gauge_strong); lv_style_init(&gauge_strong);
lv_style_set_line_color(&gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_line_color(&gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888));
@@ -409,7 +410,7 @@ static void gauge_init(void)
lv_style_set_scale_end_color(&gauge_strong, LV_STATE_DEFAULT, _color_primary); lv_style_set_scale_end_color(&gauge_strong, LV_STATE_DEFAULT, _color_primary);
lv_style_set_line_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 25); lv_style_set_line_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 25);
lv_style_set_scale_end_line_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 25); lv_style_set_scale_end_line_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 25);
lv_style_set_scale_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI/7); lv_style_set_scale_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_init(&gauge_needle); lv_style_init(&gauge_needle);
lv_style_set_line_color(&gauge_needle, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_style_set_line_color(&gauge_needle, LV_STATE_DEFAULT, LV_COLOR_WHITE);
@@ -448,7 +449,7 @@ static void chart_init(void)
{ {
#if LV_USE_CHART #if LV_USE_CHART
lv_style_init(&chart_series_bg); lv_style_init(&chart_series_bg);
lv_style_set_line_width(&chart_series_bg, LV_STATE_DEFAULT , 1); lv_style_set_line_width(&chart_series_bg, LV_STATE_DEFAULT, 1);
lv_style_set_line_dash_width(&chart_series_bg, LV_STATE_DEFAULT, 4); lv_style_set_line_dash_width(&chart_series_bg, LV_STATE_DEFAULT, 4);
lv_style_set_line_dash_gap(&chart_series_bg, LV_STATE_DEFAULT, 4); lv_style_set_line_dash_gap(&chart_series_bg, LV_STATE_DEFAULT, 4);
lv_style_set_pad_bottom(&chart_series_bg, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_bottom(&chart_series_bg, LV_STATE_DEFAULT, LV_DPI / 10);
@@ -475,33 +476,33 @@ static void calendar_init(void)
lv_style_init(&calendar_header); lv_style_init(&calendar_header);
lv_style_set_pad_top(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 7); lv_style_set_pad_top(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_set_pad_left(&calendar_header, LV_STATE_DEFAULT , LV_DPI / 7); lv_style_set_pad_left(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_set_pad_right(&calendar_header, LV_STATE_DEFAULT , LV_DPI / 7); lv_style_set_pad_right(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_set_pad_bottom(&calendar_header, LV_STATE_DEFAULT , LV_DPI / 7); lv_style_set_pad_bottom(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_set_text_color(&calendar_header, LV_STATE_PRESSED, LV_COLOR_WHITE); lv_style_set_text_color(&calendar_header, LV_STATE_PRESSED, LV_COLOR_WHITE);
lv_style_init(&calendar_daynames); lv_style_init(&calendar_daynames);
lv_style_set_text_color(&calendar_daynames, LV_STATE_DEFAULT, lv_color_hex3(0xeee)); lv_style_set_text_color(&calendar_daynames, LV_STATE_DEFAULT, lv_color_hex3(0xeee));
lv_style_set_pad_left(&calendar_daynames, LV_STATE_DEFAULT , LV_DPI / 7); lv_style_set_pad_left(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_set_pad_right(&calendar_daynames, LV_STATE_DEFAULT , LV_DPI / 7); lv_style_set_pad_right(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_set_pad_bottom(&calendar_daynames, LV_STATE_DEFAULT , LV_DPI / 7); lv_style_set_pad_bottom(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_init(&calendar_date_nums); lv_style_init(&calendar_date_nums);
lv_style_set_radius(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 50); lv_style_set_radius(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 50);
lv_style_set_text_color(&calendar_date_nums, LV_STATE_CHECKED, LV_COLOR_WHITE); lv_style_set_text_color(&calendar_date_nums, LV_STATE_CHECKED, LV_COLOR_WHITE);
lv_style_set_text_color(&calendar_date_nums, LV_STATE_FOCUSED, _color_primary); lv_style_set_text_color(&calendar_date_nums, LV_STATE_FOCUSED, _color_primary);
lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_CHECKED , LV_OPA_20); lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_CHECKED, LV_OPA_20);
lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_PRESSED , LV_OPA_20); lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_PRESSED, LV_OPA_20);
lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_PRESSED | LV_STATE_CHECKED , LV_OPA_40); lv_style_set_bg_opa(&calendar_date_nums, LV_STATE_PRESSED | LV_STATE_CHECKED, LV_OPA_40);
lv_style_set_bg_color(&calendar_date_nums, LV_STATE_CHECKED, LV_COLOR_WHITE); lv_style_set_bg_color(&calendar_date_nums, LV_STATE_CHECKED, LV_COLOR_WHITE);
lv_style_set_border_width(&calendar_date_nums, LV_STATE_CHECKED , 2); lv_style_set_border_width(&calendar_date_nums, LV_STATE_CHECKED, 2);
lv_style_set_border_side(&calendar_date_nums, LV_STATE_CHECKED , LV_BORDER_SIDE_LEFT); lv_style_set_border_side(&calendar_date_nums, LV_STATE_CHECKED, LV_BORDER_SIDE_LEFT);
lv_style_set_border_color(&calendar_date_nums,LV_STATE_CHECKED, _color_primary); lv_style_set_border_color(&calendar_date_nums, LV_STATE_CHECKED, _color_primary);
lv_style_set_pad_inner(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 30); lv_style_set_pad_inner(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 30);
lv_style_set_pad_left(&calendar_date_nums, LV_STATE_DEFAULT , LV_DPI / 7); lv_style_set_pad_left(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_set_pad_right(&calendar_date_nums, LV_STATE_DEFAULT , LV_DPI / 7); lv_style_set_pad_right(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_set_pad_bottom(&calendar_date_nums, LV_STATE_DEFAULT , LV_DPI / 7); lv_style_set_pad_bottom(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 7);
#endif #endif
} }
@@ -534,12 +535,12 @@ static void checkbox_init(void)
#if LV_USE_CHECKBOX != 0 #if LV_USE_CHECKBOX != 0
lv_style_init(&cb_bg); lv_style_init(&cb_bg);
lv_style_set_radius(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 50); lv_style_set_radius(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 50);
lv_style_set_pad_inner(&cb_bg, LV_STATE_DEFAULT , LV_DPI / 20); lv_style_set_pad_inner(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 20);
lv_style_set_outline_color(&cb_bg, LV_STATE_DEFAULT, _color_primary); lv_style_set_outline_color(&cb_bg, LV_STATE_DEFAULT, _color_primary);
lv_style_set_outline_opa(&cb_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_style_set_outline_opa(&cb_bg, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_style_set_outline_opa(&cb_bg, LV_STATE_FOCUSED, LV_OPA_50); lv_style_set_outline_opa(&cb_bg, LV_STATE_FOCUSED, LV_OPA_50);
lv_style_set_outline_width(&cb_bg, LV_STATE_DEFAULT, 3); lv_style_set_outline_width(&cb_bg, LV_STATE_DEFAULT, 3);
lv_style_set_outline_pad(&cb_bg, LV_STATE_DEFAULT, LV_DPI/20); lv_style_set_outline_pad(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 20);
lv_style_set_transition_time(&cb_bg, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_time(&cb_bg, LV_STATE_DEFAULT, TRANSITION_TIME);
lv_style_set_transition_prop_6(&cb_bg, LV_STATE_DEFAULT, LV_STYLE_OUTLINE_OPA); lv_style_set_transition_prop_6(&cb_bg, LV_STATE_DEFAULT, LV_STYLE_OUTLINE_OPA);
@@ -554,7 +555,7 @@ static void checkbox_init(void)
lv_style_set_pattern_image(&cb_bullet, LV_STATE_CHECKED, LV_SYMBOL_OK); lv_style_set_pattern_image(&cb_bullet, LV_STATE_CHECKED, LV_SYMBOL_OK);
lv_style_set_pattern_recolor(&cb_bullet, LV_STATE_CHECKED, LV_COLOR_WHITE); lv_style_set_pattern_recolor(&cb_bullet, LV_STATE_CHECKED, LV_COLOR_WHITE);
lv_style_set_text_font(&cb_bullet, LV_STATE_CHECKED, _font_small); lv_style_set_text_font(&cb_bullet, LV_STATE_CHECKED, _font_small);
lv_style_set_transition_time(&cb_bullet, LV_STATE_DEFAULT , TRANSITION_TIME); lv_style_set_transition_time(&cb_bullet, LV_STATE_DEFAULT, TRANSITION_TIME);
lv_style_set_transition_prop_5(&cb_bullet, LV_STATE_DEFAULT, LV_STYLE_BG_OPA); lv_style_set_transition_prop_5(&cb_bullet, LV_STATE_DEFAULT, LV_STYLE_BG_OPA);
lv_style_set_transition_prop_6(&cb_bullet, LV_STATE_DEFAULT, LV_STYLE_BORDER_COLOR); lv_style_set_transition_prop_6(&cb_bullet, LV_STATE_DEFAULT, LV_STYLE_BORDER_COLOR);
#endif #endif
@@ -587,11 +588,11 @@ static void keyboard_init(void)
lv_style_init(&kb_bg); lv_style_init(&kb_bg);
lv_style_copy(&kb_bg, &panel); lv_style_copy(&kb_bg, &panel);
lv_style_set_pad_inner(&kb_bg, LV_STATE_DEFAULT, LV_DPI/20); lv_style_set_pad_inner(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20);
lv_style_set_pad_left(&kb_bg, LV_STATE_DEFAULT, LV_DPI/20); lv_style_set_pad_left(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20);
lv_style_set_pad_right(&kb_bg, LV_STATE_DEFAULT, LV_DPI/20); lv_style_set_pad_right(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20);
lv_style_set_pad_top(&kb_bg, LV_STATE_DEFAULT, LV_DPI/20); lv_style_set_pad_top(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20);
lv_style_set_pad_bottom(&kb_bg, LV_STATE_DEFAULT, LV_DPI/20); lv_style_set_pad_bottom(&kb_bg, LV_STATE_DEFAULT, LV_DPI / 20);
#endif #endif
} }
@@ -611,9 +612,9 @@ static void page_init(void)
lv_style_set_bg_opa(&sb, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_opa(&sb, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&sb, LV_STATE_DEFAULT, lv_color_hex(0x3a3d42)); lv_style_set_bg_color(&sb, LV_STATE_DEFAULT, lv_color_hex(0x3a3d42));
lv_style_set_radius(&sb, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_radius(&sb, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_style_set_size(&sb,LV_STATE_DEFAULT, LV_DPI / 30); lv_style_set_size(&sb, LV_STATE_DEFAULT, LV_DPI / 30);
lv_style_set_pad_right(&sb,LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_pad_right(&sb, LV_STATE_DEFAULT, LV_DPI / 20);
lv_style_set_pad_bottom(&sb,LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_pad_bottom(&sb, LV_STATE_DEFAULT, LV_DPI / 20);
#endif #endif
} }
@@ -686,7 +687,7 @@ static void list_init(void)
lv_style_set_radius(&list_btn, LV_STATE_PRESSED, 0); lv_style_set_radius(&list_btn, LV_STATE_PRESSED, 0);
lv_style_set_radius(&list_btn, LV_STATE_CHECKED, 0); lv_style_set_radius(&list_btn, LV_STATE_CHECKED, 0);
lv_style_set_bg_opa(&list_btn, LV_STATE_PRESSED, LV_OPA_COVER); lv_style_set_bg_opa(&list_btn, LV_STATE_PRESSED, LV_OPA_COVER);
lv_style_set_bg_opa(&list_btn, LV_STATE_CHECKED , LV_OPA_COVER); lv_style_set_bg_opa(&list_btn, LV_STATE_CHECKED, LV_OPA_COVER);
lv_style_set_bg_color(&list_btn, LV_STATE_DEFAULT, color_btn(LV_STATE_DEFAULT)); lv_style_set_bg_color(&list_btn, LV_STATE_DEFAULT, color_btn(LV_STATE_DEFAULT));
lv_style_set_bg_color(&list_btn, LV_STATE_PRESSED, color_btn(LV_STATE_PRESSED)); lv_style_set_bg_color(&list_btn, LV_STATE_PRESSED, color_btn(LV_STATE_PRESSED));
lv_style_set_bg_color(&list_btn, LV_STATE_DISABLED, color_btn(LV_STATE_DISABLED)); lv_style_set_bg_color(&list_btn, LV_STATE_DISABLED, color_btn(LV_STATE_DISABLED));
@@ -768,7 +769,7 @@ static void tabview_init(void)
lv_style_set_bg_color(&tabview_btns_bg, LV_STATE_DEFAULT, color_panel(LV_STATE_DEFAULT)); lv_style_set_bg_color(&tabview_btns_bg, LV_STATE_DEFAULT, color_panel(LV_STATE_DEFAULT));
lv_style_set_border_color(&tabview_btns_bg, LV_STATE_DEFAULT, color_panel_border(LV_STATE_DEFAULT)); lv_style_set_border_color(&tabview_btns_bg, LV_STATE_DEFAULT, color_panel_border(LV_STATE_DEFAULT));
lv_style_set_border_width(&tabview_btns_bg, LV_STATE_DEFAULT, LV_DPI / 30 > 0 ? LV_DPI / 30 : 1); lv_style_set_border_width(&tabview_btns_bg, LV_STATE_DEFAULT, LV_DPI / 30 > 0 ? LV_DPI / 30 : 1);
lv_style_set_border_side(&tabview_btns_bg, LV_STATE_DEFAULT , LV_BORDER_SIDE_BOTTOM); lv_style_set_border_side(&tabview_btns_bg, LV_STATE_DEFAULT, LV_BORDER_SIDE_BOTTOM);
lv_style_set_text_color(&tabview_btns_bg, LV_STATE_DEFAULT, lv_color_hex(0x979a9f)); lv_style_set_text_color(&tabview_btns_bg, LV_STATE_DEFAULT, lv_color_hex(0x979a9f));
lv_style_set_text_font(&tabview_btns_bg, LV_STATE_DEFAULT, _font_normal); lv_style_set_text_font(&tabview_btns_bg, LV_STATE_DEFAULT, _font_normal);
lv_style_set_image_recolor(&tabview_btns_bg, LV_STATE_DEFAULT, lv_color_hex(0x979a9f)); lv_style_set_image_recolor(&tabview_btns_bg, LV_STATE_DEFAULT, lv_color_hex(0x979a9f));
@@ -810,10 +811,10 @@ static void table_init(void)
lv_style_set_border_color(&table_cell, LV_STATE_DEFAULT, lv_color_hex(0x303338)); lv_style_set_border_color(&table_cell, LV_STATE_DEFAULT, lv_color_hex(0x303338));
lv_style_set_border_width(&table_cell, LV_STATE_DEFAULT, 1); lv_style_set_border_width(&table_cell, LV_STATE_DEFAULT, 1);
lv_style_set_border_side(&table_cell, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM); lv_style_set_border_side(&table_cell, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM);
lv_style_set_pad_left(&table_cell, LV_STATE_DEFAULT, LV_DPI/7); lv_style_set_pad_left(&table_cell, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_set_pad_right(&table_cell, LV_STATE_DEFAULT, LV_DPI/7); lv_style_set_pad_right(&table_cell, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_set_pad_top(&table_cell, LV_STATE_DEFAULT, LV_DPI/7); lv_style_set_pad_top(&table_cell, LV_STATE_DEFAULT, LV_DPI / 7);
lv_style_set_pad_bottom(&table_cell, LV_STATE_DEFAULT, LV_DPI/7); lv_style_set_pad_bottom(&table_cell, LV_STATE_DEFAULT, LV_DPI / 7);
#endif #endif
} }
@@ -901,18 +902,18 @@ void lv_theme_material_apply(lv_obj_t * obj, lv_theme_style_t name)
case LV_THEME_SCR: case LV_THEME_SCR:
lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN); lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN);
list = lv_obj_get_style_list(obj, LV_OBJ_PART_MAIN); list = lv_obj_get_style_list(obj, LV_OBJ_PART_MAIN);
lv_style_list_add_style(list, &scr); lv_style_list_add_style(list, &scr);
break; break;
case LV_THEME_OBJ: case LV_THEME_OBJ:
lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN); lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN);
list = lv_obj_get_style_list(obj, LV_OBJ_PART_MAIN); list = lv_obj_get_style_list(obj, LV_OBJ_PART_MAIN);
lv_style_list_add_style(list, &panel); lv_style_list_add_style(list, &panel);
break; break;
#if LV_USE_CONT #if LV_USE_CONT
case LV_THEME_CONT: case LV_THEME_CONT:
lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN); lv_obj_clean_style_list(obj, LV_OBJ_PART_MAIN);
list = lv_obj_get_style_list(obj, LV_CONT_PART_MAIN); list = lv_obj_get_style_list(obj, LV_CONT_PART_MAIN);
lv_style_list_add_style(list, &panel); lv_style_list_add_style(list, &panel);
break; break;
#endif #endif
@@ -920,7 +921,7 @@ lv_style_list_add_style(list, &panel);
case LV_THEME_BTN: case LV_THEME_BTN:
lv_obj_clean_style_list(obj, LV_BTN_PART_MAIN); lv_obj_clean_style_list(obj, LV_BTN_PART_MAIN);
list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN); list = lv_obj_get_style_list(obj, LV_BTN_PART_MAIN);
lv_style_list_add_style(list, &btn); lv_style_list_add_style(list, &btn);
break; break;
#endif #endif
@@ -931,8 +932,8 @@ lv_style_list_add_style(list, &btn);
lv_obj_clean_style_list(obj, LV_BTNMATRIX_PART_BTN); lv_obj_clean_style_list(obj, LV_BTNMATRIX_PART_BTN);
list = lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BTN); list = lv_obj_get_style_list(obj, LV_BTNMATRIX_PART_BTN);
lv_style_list_add_style(list, &btn); lv_style_list_add_style(list, &btn);
lv_style_list_add_style(list, &btnm_btn); lv_style_list_add_style(list, &btnm_btn);
break; break;
#endif #endif
@@ -940,12 +941,12 @@ lv_style_list_add_style(list, &btnm_btn);
case LV_THEME_KEYBOARD: case LV_THEME_KEYBOARD:
lv_obj_clean_style_list(obj, LV_KEYBOARD_PART_BG); lv_obj_clean_style_list(obj, LV_KEYBOARD_PART_BG);
list = lv_obj_get_style_list(obj, LV_KEYBOARD_PART_BG); list = lv_obj_get_style_list(obj, LV_KEYBOARD_PART_BG);
lv_style_list_add_style(list, &kb_bg); lv_style_list_add_style(list, &kb_bg);
lv_obj_clean_style_list(obj, LV_KEYBOARD_PART_BTN); lv_obj_clean_style_list(obj, LV_KEYBOARD_PART_BTN);
list = lv_obj_get_style_list(obj, LV_KEYBOARD_PART_BTN); list = lv_obj_get_style_list(obj, LV_KEYBOARD_PART_BTN);
lv_style_list_add_style(list, &btn); lv_style_list_add_style(list, &btn);
lv_style_list_add_style(list, &kb_btn); lv_style_list_add_style(list, &kb_btn);
break; break;
#endif #endif
@@ -954,7 +955,7 @@ lv_style_list_add_style(list, &kb_btn);
lv_obj_clean_style_list(obj, LV_BAR_PART_BG); lv_obj_clean_style_list(obj, LV_BAR_PART_BG);
list = lv_obj_get_style_list(obj, LV_BAR_PART_BG); list = lv_obj_get_style_list(obj, LV_BAR_PART_BG);
lv_style_list_add_style(list, &bar_bg); lv_style_list_add_style(list, &bar_bg);
lv_obj_clean_style_list(obj, LV_BAR_PART_INDIC); lv_obj_clean_style_list(obj, LV_BAR_PART_INDIC);
list = lv_obj_get_style_list(obj, LV_BAR_PART_INDIC); list = lv_obj_get_style_list(obj, LV_BAR_PART_INDIC);

View File

@@ -169,11 +169,11 @@ void lv_arc_set_end_angle(lv_obj_t * arc, int16_t end)
lv_obj_invalidate(arc); lv_obj_invalidate(arc);
} }
/*Only a smaller incremental move*/ /*Only a smaller incremental move*/
else if(ext->arc_angle_end > ext->arc_angle_start && end > ext->arc_angle_start ) { else if(ext->arc_angle_end > ext->arc_angle_start && end > ext->arc_angle_start) {
inv_arc_area(arc, LV_MATH_MIN(ext->arc_angle_end, end), LV_MATH_MAX(ext->arc_angle_end, end)); inv_arc_area(arc, LV_MATH_MIN(ext->arc_angle_end, end), LV_MATH_MAX(ext->arc_angle_end, end));
} }
/*Only a smaller incremental move*/ /*Only a smaller incremental move*/
else if(ext->arc_angle_end < ext->arc_angle_start && end < ext->arc_angle_start ) { else if(ext->arc_angle_end < ext->arc_angle_start && end < ext->arc_angle_start) {
inv_arc_area(arc, LV_MATH_MIN(ext->arc_angle_end, end), LV_MATH_MAX(ext->arc_angle_end, end)); inv_arc_area(arc, LV_MATH_MIN(ext->arc_angle_end, end), LV_MATH_MAX(ext->arc_angle_end, end));
} }
/*Crossing the end angle makes the whole arc change*/ /*Crossing the end angle makes the whole arc change*/
@@ -181,7 +181,7 @@ void lv_arc_set_end_angle(lv_obj_t * arc, int16_t end)
lv_obj_invalidate(arc); lv_obj_invalidate(arc);
} }
ext->arc_angle_end= end; ext->arc_angle_end = end;
} }
@@ -259,11 +259,11 @@ void lv_arc_set_bg_end_angle(lv_obj_t * arc, int16_t end)
lv_obj_invalidate(arc); lv_obj_invalidate(arc);
} }
/*Only a smaller incremental move*/ /*Only a smaller incremental move*/
else if(ext->bg_angle_end > ext->bg_angle_start && end > ext->bg_angle_start ) { else if(ext->bg_angle_end > ext->bg_angle_start && end > ext->bg_angle_start) {
inv_arc_area(arc, LV_MATH_MIN(ext->bg_angle_end, end), LV_MATH_MAX(ext->bg_angle_end, end)); inv_arc_area(arc, LV_MATH_MIN(ext->bg_angle_end, end), LV_MATH_MAX(ext->bg_angle_end, end));
} }
/*Only a smaller incremental move*/ /*Only a smaller incremental move*/
else if(ext->bg_angle_end < ext->bg_angle_start && end < ext->bg_angle_start ) { else if(ext->bg_angle_end < ext->bg_angle_start && end < ext->bg_angle_start) {
inv_arc_area(arc, LV_MATH_MIN(ext->bg_angle_end, end), LV_MATH_MAX(ext->bg_angle_end, end)); inv_arc_area(arc, LV_MATH_MIN(ext->bg_angle_end, end), LV_MATH_MAX(ext->bg_angle_end, end));
} }
/*Crossing the end angle makes the whole arc change*/ /*Crossing the end angle makes the whole arc change*/
@@ -271,7 +271,7 @@ void lv_arc_set_bg_end_angle(lv_obj_t * arc, int16_t end)
lv_obj_invalidate(arc); lv_obj_invalidate(arc);
} }
ext->bg_angle_end= end; ext->bg_angle_end = end;
} }
/** /**
@@ -513,32 +513,41 @@ static void inv_arc_area(lv_obj_t * arc, uint16_t start_angle, uint16_t end_angl
lv_obj_invalidate_area(arc, &inv_area); lv_obj_invalidate_area(arc, &inv_area);
} }
} else if(start_quarter == 0 && end_quarter == 1) { }
else if(start_quarter == 0 && end_quarter == 1) {
inv_area.x1 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area; inv_area.x1 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.y1 = y + ((LV_MATH_MIN(lv_trigo_sin(end_angle), lv_trigo_sin(start_angle)) * rin) >> LV_TRIGO_SHIFT) - extra_area; inv_area.y1 = y + ((LV_MATH_MIN(lv_trigo_sin(end_angle),
lv_trigo_sin(start_angle)) * rin) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.x2 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area; inv_area.x2 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
inv_area.y2 = y + rout + extra_area; inv_area.y2 = y + rout + extra_area;
lv_obj_invalidate_area(arc, &inv_area); lv_obj_invalidate_area(arc, &inv_area);
} else if(start_quarter == 1 && end_quarter == 2) { }
else if(start_quarter == 1 && end_quarter == 2) {
inv_area.x1 = x - rout - extra_area; inv_area.x1 = x - rout - extra_area;
inv_area.y1 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area; inv_area.y1 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.x2 = x + ((LV_MATH_MAX(lv_trigo_sin(start_angle + 90) , lv_trigo_sin(end_angle + 90)) * rin) >> LV_TRIGO_SHIFT) + extra_area; inv_area.x2 = x + ((LV_MATH_MAX(lv_trigo_sin(start_angle + 90),
lv_trigo_sin(end_angle + 90)) * rin) >> LV_TRIGO_SHIFT) + extra_area;
inv_area.y2 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area; inv_area.y2 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
lv_obj_invalidate_area(arc, &inv_area); lv_obj_invalidate_area(arc, &inv_area);
} else if(start_quarter == 2 && end_quarter == 3) { }
else if(start_quarter == 2 && end_quarter == 3) {
inv_area.x1 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area; inv_area.x1 = x + ((lv_trigo_sin(start_angle + 90) * rout) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.y1 = y - rout - extra_area; inv_area.y1 = y - rout - extra_area;
inv_area.x2 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area; inv_area.x2 = x + ((lv_trigo_sin(end_angle + 90) * rout) >> LV_TRIGO_SHIFT) + extra_area;
inv_area.y2 = y + (LV_MATH_MAX(lv_trigo_sin(end_angle) * rin, lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area; inv_area.y2 = y + (LV_MATH_MAX(lv_trigo_sin(end_angle) * rin,
lv_trigo_sin(start_angle) * rin) >> LV_TRIGO_SHIFT) + extra_area;
lv_obj_invalidate_area(arc, &inv_area); lv_obj_invalidate_area(arc, &inv_area);
} else if(start_quarter == 3 && end_quarter == 0) { }
inv_area.x1 = x + ((LV_MATH_MIN(lv_trigo_sin(end_angle + 90), lv_trigo_sin(start_angle + 90)) * rin) >> LV_TRIGO_SHIFT) - extra_area; else if(start_quarter == 3 && end_quarter == 0) {
inv_area.x1 = x + ((LV_MATH_MIN(lv_trigo_sin(end_angle + 90),
lv_trigo_sin(start_angle + 90)) * rin) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.y1 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area; inv_area.y1 = y + ((lv_trigo_sin(start_angle) * rout) >> LV_TRIGO_SHIFT) - extra_area;
inv_area.x2 = x + rout + extra_area; inv_area.x2 = x + rout + extra_area;
inv_area.y2 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area; inv_area.y2 = y + ((lv_trigo_sin(end_angle) * rout) >> LV_TRIGO_SHIFT) + extra_area;
lv_obj_invalidate_area(arc, &inv_area); lv_obj_invalidate_area(arc, &inv_area);
} else { }
else {
lv_obj_invalidate(arc); lv_obj_invalidate(arc);
} }
} }

View File

@@ -27,8 +27,7 @@ extern "C" {
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
/*Data of arc*/ /*Data of arc*/
typedef struct typedef struct {
{
/*New data for this type */ /*New data for this type */
lv_coord_t arc_angle_start; lv_coord_t arc_angle_start;
lv_coord_t arc_angle_end; lv_coord_t arc_angle_end;

View File

@@ -26,10 +26,10 @@
#define LV_BAR_SIZE_MIN 4 /*hor. pad and ver. pad cannot make the indicator smaller then this [px]*/ #define LV_BAR_SIZE_MIN 4 /*hor. pad and ver. pad cannot make the indicator smaller then this [px]*/
#if LV_USE_ANIMATION #if LV_USE_ANIMATION
#define LV_BAR_IS_ANIMATING(anim_struct) (((anim_struct).anim_state) != LV_BAR_ANIM_STATE_INV) #define LV_BAR_IS_ANIMATING(anim_struct) (((anim_struct).anim_state) != LV_BAR_ANIM_STATE_INV)
#define LV_BAR_GET_ANIM_VALUE(orig_value, anim_struct) (LV_BAR_IS_ANIMATING(anim_struct) ? ((anim_struct).anim_end) : (orig_value)) #define LV_BAR_GET_ANIM_VALUE(orig_value, anim_struct) (LV_BAR_IS_ANIMATING(anim_struct) ? ((anim_struct).anim_end) : (orig_value))
#else #else
#define LV_BAR_GET_ANIM_VALUE(orig_value, anim_struct) (orig_value) #define LV_BAR_GET_ANIM_VALUE(orig_value, anim_struct) (orig_value)
#endif #endif
/********************** /**********************
* TYPEDEFS * TYPEDEFS
@@ -46,10 +46,11 @@ static void draw_bg(lv_obj_t * bar, const lv_area_t * clip_area);
static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area); static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area);
#if LV_USE_ANIMATION #if LV_USE_ANIMATION
static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_t *value_ptr, lv_bar_anim_t *anim_info, lv_anim_enable_t en); static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_t * value_ptr,
static void lv_bar_init_anim(lv_obj_t * bar, lv_bar_anim_t * bar_anim); lv_bar_anim_t * anim_info, lv_anim_enable_t en);
static void lv_bar_anim(lv_bar_anim_t * bar, lv_anim_value_t value); static void lv_bar_init_anim(lv_obj_t * bar, lv_bar_anim_t * bar_anim);
static void lv_bar_anim_ready(lv_anim_t * a); static void lv_bar_anim(lv_bar_anim_t * bar, lv_anim_value_t value);
static void lv_bar_anim_ready(lv_anim_t * a);
#endif #endif
/********************** /**********************
@@ -117,7 +118,8 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, const lv_obj_t * copy)
lv_bar_set_value(bar, ext->cur_value, false); lv_bar_set_value(bar, ext->cur_value, false);
lv_theme_apply(bar, LV_THEME_BAR); lv_theme_apply(bar, LV_THEME_BAR);
} else { }
else {
lv_bar_ext_t * ext_copy = lv_obj_get_ext_attr(copy); lv_bar_ext_t * ext_copy = lv_obj_get_ext_attr(copy);
ext->min_value = ext_copy->min_value; ext->min_value = ext_copy->min_value;
ext->start_value = ext_copy->start_value; ext->start_value = ext_copy->start_value;
@@ -322,7 +324,8 @@ int16_t lv_bar_get_max_value(const lv_obj_t * bar)
* @param bar pointer to bar object * @param bar pointer to bar object
* @return bar type * @return bar type
*/ */
lv_bar_type_t lv_bar_get_type(lv_obj_t * bar) { lv_bar_type_t lv_bar_get_type(lv_obj_t * bar)
{
LV_ASSERT_OBJ(bar, LV_OBJX_NAME); LV_ASSERT_OBJ(bar, LV_OBJX_NAME);
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar); lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
@@ -367,7 +370,8 @@ static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area
if(mode == LV_DESIGN_COVER_CHK) { if(mode == LV_DESIGN_COVER_CHK) {
/*Return false if the object is not covers the mask area*/ /*Return false if the object is not covers the mask area*/
return ancestor_design_f(bar, clip_area, mode); return ancestor_design_f(bar, clip_area, mode);
} else if(mode == LV_DESIGN_DRAW_MAIN) { }
else if(mode == LV_DESIGN_DRAW_MAIN) {
draw_bg(bar, clip_area); draw_bg(bar, clip_area);
draw_indic(bar, clip_area); draw_indic(bar, clip_area);
@@ -382,7 +386,8 @@ static lv_design_res_t lv_bar_design(lv_obj_t * bar, const lv_area_t * clip_area
lv_obj_init_draw_rect_dsc(bar, LV_BAR_PART_BG, &draw_dsc); lv_obj_init_draw_rect_dsc(bar, LV_BAR_PART_BG, &draw_dsc);
lv_draw_rect(&bar->coords, clip_area, &draw_dsc); lv_draw_rect(&bar->coords, clip_area, &draw_dsc);
} else if(mode == LV_DESIGN_DRAW_POST) { }
else if(mode == LV_DESIGN_DRAW_POST) {
} }
return LV_DESIGN_RES_OK; return LV_DESIGN_RES_OK;
@@ -407,7 +412,8 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area)
int32_t range = ext->max_value - ext->min_value; int32_t range = ext->max_value - ext->min_value;
bool hor = objw >= objh ? true : false; bool hor = objw >= objh ? true : false;
bool sym = false; bool sym = false;
if(ext->type == LV_BAR_TYPE_SYM && ext->min_value < 0 && ext->max_value > 0 && ext->start_value == ext->min_value) sym = true; if(ext->type == LV_BAR_TYPE_SYM && ext->min_value < 0 && ext->max_value > 0 &&
ext->start_value == ext->min_value) sym = true;
/*Calculate the indicator area*/ /*Calculate the indicator area*/
lv_style_int_t bg_left = lv_obj_get_style_pad_left(bar, LV_BAR_PART_BG); lv_style_int_t bg_left = lv_obj_get_style_pad_left(bar, LV_BAR_PART_BG);
@@ -425,7 +431,8 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area)
if(hor && lv_area_get_height(&ext->indic_area) < LV_BAR_SIZE_MIN) { if(hor && lv_area_get_height(&ext->indic_area) < LV_BAR_SIZE_MIN) {
ext->indic_area.y1 = bar->coords.y1 + (objh / 2) - (LV_BAR_SIZE_MIN / 2); ext->indic_area.y1 = bar->coords.y1 + (objh / 2) - (LV_BAR_SIZE_MIN / 2);
ext->indic_area.y2 = ext->indic_area.y1 + LV_BAR_SIZE_MIN; ext->indic_area.y2 = ext->indic_area.y1 + LV_BAR_SIZE_MIN;
} else if(!hor && lv_area_get_width(&ext->indic_area) < LV_BAR_SIZE_MIN) { }
else if(!hor && lv_area_get_width(&ext->indic_area) < LV_BAR_SIZE_MIN) {
ext->indic_area.x1 = bar->coords.x1 + (objw / 2) - (LV_BAR_SIZE_MIN / 2); ext->indic_area.x1 = bar->coords.x1 + (objw / 2) - (LV_BAR_SIZE_MIN / 2);
ext->indic_area.x2 = ext->indic_area.x1 + LV_BAR_SIZE_MIN; ext->indic_area.x2 = ext->indic_area.x1 + LV_BAR_SIZE_MIN;
} }
@@ -439,13 +446,14 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area)
lv_coord_t anim_cur_value_x, anim_start_value_x; lv_coord_t anim_cur_value_x, anim_start_value_x;
lv_coord_t * axis1, * axis2; lv_coord_t * axis1, * axis2;
lv_coord_t (*indic_length_calc)(const lv_area_t *area); lv_coord_t (*indic_length_calc)(const lv_area_t * area);
if(hor) { if(hor) {
axis1 = &ext->indic_area.x1; axis1 = &ext->indic_area.x1;
axis2 = &ext->indic_area.x2; axis2 = &ext->indic_area.x2;
indic_length_calc = lv_area_get_width; indic_length_calc = lv_area_get_width;
} else { }
else {
axis1 = &ext->indic_area.y1; axis1 = &ext->indic_area.y1;
axis2 = &ext->indic_area.y2; axis2 = &ext->indic_area.y2;
indic_length_calc = lv_area_get_height; indic_length_calc = lv_area_get_height;
@@ -458,11 +466,13 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area)
lv_coord_t anim_start_value_end_x = lv_coord_t anim_start_value_end_x =
(int32_t)((int32_t)anim_length * (ext->start_value_anim.anim_end - ext->min_value)) / range; (int32_t)((int32_t)anim_length * (ext->start_value_anim.anim_end - ext->min_value)) / range;
anim_start_value_x = (((anim_start_value_end_x - anim_start_value_start_x) * ext->start_value_anim.anim_state) / LV_BAR_ANIM_STATE_END); anim_start_value_x = (((anim_start_value_end_x - anim_start_value_start_x) * ext->start_value_anim.anim_state) /
LV_BAR_ANIM_STATE_END);
if(anim_start_value_end_x < anim_start_value_start_x) if(anim_start_value_end_x < anim_start_value_start_x)
anim_start_value_x += anim_start_value_start_x; anim_start_value_x += anim_start_value_start_x;
} else }
else
#endif #endif
{ {
anim_start_value_x = (int32_t)((int32_t)anim_length * (ext->start_value - ext->min_value)) / range; anim_start_value_x = (int32_t)((int32_t)anim_length * (ext->start_value - ext->min_value)) / range;
@@ -475,11 +485,13 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area)
lv_coord_t anim_cur_value_end_x = lv_coord_t anim_cur_value_end_x =
(int32_t)((int32_t)anim_length * (ext->cur_value_anim.anim_end - ext->min_value)) / range; (int32_t)((int32_t)anim_length * (ext->cur_value_anim.anim_end - ext->min_value)) / range;
anim_cur_value_x = (((anim_cur_value_end_x - anim_cur_value_start_x) * ext->cur_value_anim.anim_state) / LV_BAR_ANIM_STATE_END); anim_cur_value_x = (((anim_cur_value_end_x - anim_cur_value_start_x) * ext->cur_value_anim.anim_state) /
LV_BAR_ANIM_STATE_END);
if(anim_cur_value_end_x < anim_cur_value_start_x) if(anim_cur_value_end_x < anim_cur_value_start_x)
anim_cur_value_x += anim_cur_value_start_x; anim_cur_value_x += anim_cur_value_start_x;
} else }
else
#endif #endif
{ {
anim_cur_value_x = (int32_t)((int32_t)anim_length * (ext->cur_value - ext->min_value)) / range; anim_cur_value_x = (int32_t)((int32_t)anim_length * (ext->cur_value - ext->min_value)) / range;
@@ -489,7 +501,8 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area)
if(hor) { if(hor) {
*axis2 = *axis1 + anim_cur_value_x; *axis2 = *axis1 + anim_cur_value_x;
*axis1 += anim_start_value_x; *axis1 += anim_start_value_x;
} else { }
else {
*axis2 -= anim_start_value_x; *axis2 -= anim_start_value_x;
*axis1 = *axis2 - anim_cur_value_x; *axis1 = *axis2 - anim_cur_value_x;
} }
@@ -560,7 +573,8 @@ static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area)
if(hor && lv_area_get_height(&mask_indic_max_area) < LV_BAR_SIZE_MIN) { if(hor && lv_area_get_height(&mask_indic_max_area) < LV_BAR_SIZE_MIN) {
mask_indic_max_area.y1 = bar->coords.y1 + (objh / 2) - (LV_BAR_SIZE_MIN / 2); mask_indic_max_area.y1 = bar->coords.y1 + (objh / 2) - (LV_BAR_SIZE_MIN / 2);
mask_indic_max_area.y2 = mask_indic_max_area.y1 + LV_BAR_SIZE_MIN; mask_indic_max_area.y2 = mask_indic_max_area.y1 + LV_BAR_SIZE_MIN;
} else if(!hor && lv_area_get_width(&mask_indic_max_area) < LV_BAR_SIZE_MIN) { }
else if(!hor && lv_area_get_width(&mask_indic_max_area) < LV_BAR_SIZE_MIN) {
mask_indic_max_area.x1 = bar->coords.x1 + (objw / 2) - (LV_BAR_SIZE_MIN / 2); mask_indic_max_area.x1 = bar->coords.x1 + (objw / 2) - (LV_BAR_SIZE_MIN / 2);
mask_indic_max_area.x2 = mask_indic_max_area.x1 + LV_BAR_SIZE_MIN; mask_indic_max_area.x2 = mask_indic_max_area.x1 + LV_BAR_SIZE_MIN;
} }
@@ -675,12 +689,15 @@ static void lv_bar_anim_ready(lv_anim_t * a)
lv_obj_invalidate(var->bar); lv_obj_invalidate(var->bar);
} }
static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_t *value_ptr, lv_bar_anim_t *anim_info, lv_anim_enable_t en) { static void lv_bar_set_value_with_anim(lv_obj_t * bar, int16_t new_value, int16_t * value_ptr,
lv_bar_anim_t * anim_info, lv_anim_enable_t en)
{
if(en == LV_ANIM_OFF) { if(en == LV_ANIM_OFF) {
*value_ptr = new_value; *value_ptr = new_value;
lv_obj_invalidate(bar); lv_obj_invalidate(bar);
} else { }
lv_bar_ext_t *ext = lv_obj_get_ext_attr(bar); else {
lv_bar_ext_t * ext = lv_obj_get_ext_attr(bar);
/*No animation in progress -> simply set the values*/ /*No animation in progress -> simply set the values*/
if(anim_info->anim_state == LV_BAR_ANIM_STATE_INV) { if(anim_info->anim_state == LV_BAR_ANIM_STATE_INV) {
anim_info->anim_start = *value_ptr; anim_info->anim_start = *value_ptr;

View File

@@ -60,8 +60,7 @@ typedef struct {
#endif #endif
/** Data of bar*/ /** Data of bar*/
typedef struct typedef struct {
{
/*No inherited ext, derived from the base object */ /*No inherited ext, derived from the base object */
/*New data for this type */ /*New data for this type */

View File

@@ -152,8 +152,8 @@ void lv_btn_set_state(lv_obj_t * btn, lv_btn_state_t state)
break; break;
} }
// /*Make the state change happen immediately, without transition*/ // /*Make the state change happen immediately, without transition*/
// btn->prev_state = btn->state; // btn->prev_state = btn->state;
} }
/** /**
@@ -168,7 +168,8 @@ void lv_btn_toggle(lv_obj_t * btn)
if(lv_obj_get_state(btn, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) { if(lv_obj_get_state(btn, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) {
lv_obj_clear_state(btn, LV_STATE_CHECKED); lv_obj_clear_state(btn, LV_STATE_CHECKED);
} else { }
else {
lv_obj_add_state(btn, LV_STATE_CHECKED); lv_obj_add_state(btn, LV_STATE_CHECKED);
} }
} }
@@ -190,10 +191,12 @@ lv_btn_state_t lv_btn_get_state(const lv_obj_t * btn)
if(state & LV_STATE_DISABLED) { if(state & LV_STATE_DISABLED) {
return LV_BTN_STATE_DISABLED; return LV_BTN_STATE_DISABLED;
} else if(state & LV_STATE_CHECKED) { }
else if(state & LV_STATE_CHECKED) {
if(state & LV_STATE_PRESSED) return LV_BTN_STATE_CHECKED_PRESSED; if(state & LV_STATE_PRESSED) return LV_BTN_STATE_CHECKED_PRESSED;
else return LV_BTN_STATE_CHECKED_RELEASED; else return LV_BTN_STATE_CHECKED_RELEASED;
} else { }
else {
if(state & LV_STATE_PRESSED) return LV_BTN_STATE_PRESSED; if(state & LV_STATE_PRESSED) return LV_BTN_STATE_PRESSED;
else return LV_BTN_STATE_RELEASED; else return LV_BTN_STATE_RELEASED;
} }
@@ -232,9 +235,11 @@ static lv_design_res_t lv_btn_design(lv_obj_t * btn, const lv_area_t * clip_area
{ {
if(mode == LV_DESIGN_COVER_CHK) { if(mode == LV_DESIGN_COVER_CHK) {
return ancestor_design(btn, clip_area, mode); return ancestor_design(btn, clip_area, mode);
} else if(mode == LV_DESIGN_DRAW_MAIN) { }
else if(mode == LV_DESIGN_DRAW_MAIN) {
ancestor_design(btn, clip_area, mode); ancestor_design(btn, clip_area, mode);
} else if(mode == LV_DESIGN_DRAW_POST) { }
else if(mode == LV_DESIGN_DRAW_POST) {
ancestor_design(btn, clip_area, mode); ancestor_design(btn, clip_area, mode);
} }
@@ -267,7 +272,8 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
if(lv_obj_get_state(btn, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) { if(lv_obj_get_state(btn, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) {
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);
toggled = 0; toggled = 0;
} else { }
else {
lv_btn_set_state(btn, LV_BTN_STATE_CHECKED_RELEASED); lv_btn_set_state(btn, LV_BTN_STATE_CHECKED_RELEASED);
toggled = 1; toggled = 1;
} }
@@ -275,7 +281,8 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
res = lv_event_send(btn, LV_EVENT_VALUE_CHANGED, &toggled); res = lv_event_send(btn, LV_EVENT_VALUE_CHANGED, &toggled);
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
} }
} else if(sign == LV_SIGNAL_CONTROL) { }
else if(sign == LV_SIGNAL_CONTROL) {
char c = *((char *)param); char c = *((char *)param);
if(c == LV_KEY_RIGHT || c == LV_KEY_UP) { if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
if(lv_btn_get_checkable(btn)) { if(lv_btn_get_checkable(btn)) {
@@ -286,7 +293,8 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
} }
} else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) { }
else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
if(lv_btn_get_checkable(btn)) { if(lv_btn_get_checkable(btn)) {
lv_btn_set_state(btn, LV_BTN_STATE_RELEASED); lv_btn_set_state(btn, LV_BTN_STATE_RELEASED);

View File

@@ -46,8 +46,7 @@ enum {
typedef uint8_t lv_btn_state_t; typedef uint8_t lv_btn_state_t;
/** Extended data of button*/ /** Extended data of button*/
typedef struct typedef struct {
{
/** Ext. of ancestor*/ /** Ext. of ancestor*/
lv_cont_ext_t cont; lv_cont_ext_t cont;
@@ -57,7 +56,7 @@ typedef struct
/**Styles*/ /**Styles*/
enum { enum {
LV_BTN_PART_MAIN = LV_OBJ_PART_MAIN , LV_BTN_PART_MAIN = LV_OBJ_PART_MAIN,
_LV_BTN_PART_VIRTUAL_LAST, _LV_BTN_PART_VIRTUAL_LAST,
_LV_BTN_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST, _LV_BTN_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST,
}; };

View File

@@ -112,9 +112,9 @@ lv_obj_t * lv_btnmatrix_create(lv_obj_t * par, const lv_obj_t * copy)
} }
/*Copy an existing object*/ /*Copy an existing object*/
else { else {
// lv_btnmatrix_ext_t * copy_ext = lv_obj_get_ext_attr(copy); // lv_btnmatrix_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
// memcpy((void*)ext->styles_btn, copy_ext->styles_btn, sizeof(ext->styles_btn)); // memcpy((void*)ext->styles_btn, copy_ext->styles_btn, sizeof(ext->styles_btn));
// lv_btnmatrix_set_map(new_btnm, lv_btnmatrix_get_map_array(copy)); // lv_btnmatrix_set_map(new_btnm, lv_btnmatrix_get_map_array(copy));
} }
LV_LOG_INFO("button matrix created"); LV_LOG_INFO("button matrix created");
@@ -199,7 +199,7 @@ void lv_btnmatrix_set_map(lv_obj_t * btnm, const char * map[])
/*Make sure the last row is at the bottom of 'btnm'*/ /*Make sure the last row is at the bottom of 'btnm'*/
if(map_p_tmp[btn_cnt][0] == '\0') { /*Last row?*/ if(map_p_tmp[btn_cnt][0] == '\0') { /*Last row?*/
btn_h = lv_obj_get_height(btnm)- act_y - bottom - 1; btn_h = lv_obj_get_height(btnm) - act_y - bottom - 1;
} }
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(btnm); lv_bidi_dir_t base_dir = lv_obj_get_base_dir(btnm);
@@ -225,7 +225,8 @@ void lv_btnmatrix_set_map(lv_obj_t * btnm, const char * map[])
if(base_dir == LV_BIDI_DIR_RTL) { if(base_dir == LV_BIDI_DIR_RTL) {
act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * inner; act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * inner;
act_x = lv_obj_get_width(btnm) - right - act_x - act_unit_w - 1; act_x = lv_obj_get_width(btnm) - right - act_x - act_unit_w - 1;
} else { }
else {
act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * inner + act_x = (unit_act_cnt * all_unit_w) / unit_cnt + i * inner +
left; left;
} }
@@ -235,7 +236,8 @@ void lv_btnmatrix_set_map(lv_obj_t * btnm, const char * map[])
if(inner == 0 && act_x != left) { if(inner == 0 && act_x != left) {
lv_area_set(&ext->button_areas[btn_i], ext->button_areas[btn_i - 1].x2, act_y, act_x + act_unit_w, lv_area_set(&ext->button_areas[btn_i], ext->button_areas[btn_i - 1].x2, act_y, act_x + act_unit_w,
act_y + btn_h); act_y + btn_h);
} else { }
else {
lv_area_set(&ext->button_areas[btn_i], act_x, act_y, act_x + act_unit_w, act_y + btn_h); lv_area_set(&ext->button_areas[btn_i], act_x, act_y, act_x + act_unit_w, act_y + btn_h);
} }
@@ -480,7 +482,8 @@ const char * lv_btnmatrix_get_active_btn_text(const lv_obj_t * btnm)
lv_btnmatrix_ext_t * ext = lv_obj_get_ext_attr(btnm); lv_btnmatrix_ext_t * ext = lv_obj_get_ext_attr(btnm);
if(ext->btn_id_act != LV_BTNMATRIX_BTN_NONE) { if(ext->btn_id_act != LV_BTNMATRIX_BTN_NONE) {
return lv_btnmatrix_get_btn_text(btnm, ext->btn_id_act); return lv_btnmatrix_get_btn_text(btnm, ext->btn_id_act);
} else { }
else {
return NULL; return NULL;
} }
} }
@@ -716,7 +719,8 @@ static lv_design_res_t lv_btnmatrix_design(lv_obj_t * btnm, const lv_area_t * cl
/*Left/right columns*/ /*Left/right columns*/
if(txt_i == 0) { /*First button*/ if(txt_i == 0) { /*First button*/
draw_rect_dsc_act->border_side &= ~LV_BORDER_SIDE_LEFT; draw_rect_dsc_act->border_side &= ~LV_BORDER_SIDE_LEFT;
} else if(strcmp(ext->map_p[txt_i - 1], "\n") == 0) { }
else if(strcmp(ext->map_p[txt_i - 1], "\n") == 0) {
draw_rect_dsc_act->border_side &= ~LV_BORDER_SIDE_LEFT; draw_rect_dsc_act->border_side &= ~LV_BORDER_SIDE_LEFT;
} }
@@ -745,7 +749,8 @@ static lv_design_res_t lv_btnmatrix_design(lv_obj_t * btnm, const lv_area_t * cl
lv_draw_label(&area_tmp, clip_area, draw_label_dsc_act, txt, NULL); lv_draw_label(&area_tmp, clip_area, draw_label_dsc_act, txt, NULL);
} }
} else if(mode == LV_DESIGN_DRAW_POST) { }
else if(mode == LV_DESIGN_DRAW_POST) {
ancestor_design_f(btnm, clip_area, mode); ancestor_design_f(btnm, clip_area, mode);
} }
return LV_DESIGN_RES_OK; return LV_DESIGN_RES_OK;
@@ -779,13 +784,16 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
lv_obj_clean_style_list(btnm, LV_BTNMATRIX_PART_BTN); lv_obj_clean_style_list(btnm, LV_BTNMATRIX_PART_BTN);
lv_mem_free(ext->button_areas); lv_mem_free(ext->button_areas);
lv_mem_free(ext->ctrl_bits); lv_mem_free(ext->ctrl_bits);
} else if(sign == LV_SIGNAL_STYLE_CHG) { }
else if(sign == LV_SIGNAL_STYLE_CHG) {
lv_btnmatrix_set_map(btnm, ext->map_p); lv_btnmatrix_set_map(btnm, ext->map_p);
} else if(sign == LV_SIGNAL_COORD_CHG) { }
else if(sign == LV_SIGNAL_COORD_CHG) {
if(lv_obj_get_width(btnm) != lv_area_get_width(param) || lv_obj_get_height(btnm) != lv_area_get_height(param)) { if(lv_obj_get_width(btnm) != lv_area_get_width(param) || lv_obj_get_height(btnm) != lv_area_get_height(param)) {
lv_btnmatrix_set_map(btnm, ext->map_p); lv_btnmatrix_set_map(btnm, ext->map_p);
} }
} else if(sign == LV_SIGNAL_PRESSED) { }
else if(sign == LV_SIGNAL_PRESSED) {
invalidate_button_area(btnm, ext->btn_id_pr); invalidate_button_area(btnm, ext->btn_id_pr);
lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
@@ -806,7 +814,8 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
} }
} }
#if LV_USE_GROUP #if LV_USE_GROUP
else if(indev_type == LV_INDEV_TYPE_KEYPAD || (indev_type == LV_INDEV_TYPE_ENCODER && lv_group_get_editing(lv_obj_get_group(btnm)))) { else if(indev_type == LV_INDEV_TYPE_KEYPAD || (indev_type == LV_INDEV_TYPE_ENCODER &&
lv_group_get_editing(lv_obj_get_group(btnm)))) {
ext->btn_id_pr = ext->btn_id_focused; ext->btn_id_pr = ext->btn_id_focused;
invalidate_button_area(btnm, ext->btn_id_focused); invalidate_button_area(btnm, ext->btn_id_focused);
} }
@@ -820,7 +829,8 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
res = lv_event_send(btnm, LV_EVENT_VALUE_CHANGED, &b); res = lv_event_send(btnm, LV_EVENT_VALUE_CHANGED, &b);
} }
} }
} else if(sign == LV_SIGNAL_PRESSING) { }
else if(sign == LV_SIGNAL_PRESSING) {
uint16_t btn_pr; uint16_t btn_pr;
/*Search the pressed area*/ /*Search the pressed area*/
lv_indev_get_point(param, &p); lv_indev_get_point(param, &p);
@@ -845,14 +855,16 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
ext->btn_id_pr = btn_pr; ext->btn_id_pr = btn_pr;
ext->btn_id_act = btn_pr; ext->btn_id_act = btn_pr;
} else if(sign == LV_SIGNAL_RELEASED) { }
else if(sign == LV_SIGNAL_RELEASED) {
if(ext->btn_id_pr != LV_BTNMATRIX_BTN_NONE) { if(ext->btn_id_pr != LV_BTNMATRIX_BTN_NONE) {
/*Toggle the button if enabled*/ /*Toggle the button if enabled*/
if(button_is_tgl_enabled(ext->ctrl_bits[ext->btn_id_pr]) && if(button_is_tgl_enabled(ext->ctrl_bits[ext->btn_id_pr]) &&
!button_is_inactive(ext->ctrl_bits[ext->btn_id_pr])) { !button_is_inactive(ext->ctrl_bits[ext->btn_id_pr])) {
if(button_get_tgl_state(ext->ctrl_bits[ext->btn_id_pr])) { if(button_get_tgl_state(ext->ctrl_bits[ext->btn_id_pr])) {
ext->ctrl_bits[ext->btn_id_pr] &= (~LV_BTNMATRIX_CTRL_CHECK_STATE); ext->ctrl_bits[ext->btn_id_pr] &= (~LV_BTNMATRIX_CTRL_CHECK_STATE);
} else { }
else {
ext->ctrl_bits[ext->btn_id_pr] |= LV_BTNMATRIX_CTRL_CHECK_STATE; ext->ctrl_bits[ext->btn_id_pr] |= LV_BTNMATRIX_CTRL_CHECK_STATE;
} }
if(ext->one_toggle) make_one_button_toggled(btnm, ext->btn_id_pr); if(ext->one_toggle) make_one_button_toggled(btnm, ext->btn_id_pr);
@@ -877,7 +889,8 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
res = lv_event_send(btnm, LV_EVENT_VALUE_CHANGED, &b); res = lv_event_send(btnm, LV_EVENT_VALUE_CHANGED, &b);
} }
} }
} else if(sign == LV_SIGNAL_LONG_PRESS_REP) { }
else if(sign == LV_SIGNAL_LONG_PRESS_REP) {
if(ext->btn_id_act != LV_BTNMATRIX_BTN_NONE) { if(ext->btn_id_act != LV_BTNMATRIX_BTN_NONE) {
if(button_is_repeat_disabled(ext->ctrl_bits[ext->btn_id_act]) == false && if(button_is_repeat_disabled(ext->ctrl_bits[ext->btn_id_act]) == false &&
button_is_inactive(ext->ctrl_bits[ext->btn_id_act]) == false && button_is_inactive(ext->ctrl_bits[ext->btn_id_act]) == false &&
@@ -886,11 +899,13 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
res = lv_event_send(btnm, LV_EVENT_VALUE_CHANGED, &b); res = lv_event_send(btnm, LV_EVENT_VALUE_CHANGED, &b);
} }
} }
} else if(sign == LV_SIGNAL_PRESS_LOST) { }
else if(sign == LV_SIGNAL_PRESS_LOST) {
ext->btn_id_pr = LV_BTNMATRIX_BTN_NONE; ext->btn_id_pr = LV_BTNMATRIX_BTN_NONE;
ext->btn_id_act = LV_BTNMATRIX_BTN_NONE; ext->btn_id_act = LV_BTNMATRIX_BTN_NONE;
lv_obj_invalidate(btnm); lv_obj_invalidate(btnm);
} else if(sign == LV_SIGNAL_FOCUS) { }
else if(sign == LV_SIGNAL_FOCUS) {
#if LV_USE_GROUP #if LV_USE_GROUP
lv_indev_t * indev = lv_indev_get_act(); lv_indev_t * indev = lv_indev_get_act();
lv_indev_type_t indev_type = lv_indev_get_type(indev); lv_indev_type_t indev_type = lv_indev_get_type(indev);
@@ -905,10 +920,12 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
/*In navigation mode don't select any button but in edit mode select the fist*/ /*In navigation mode don't select any button but in edit mode select the fist*/
if(lv_group_get_editing(lv_obj_get_group(btnm))) { if(lv_group_get_editing(lv_obj_get_group(btnm))) {
ext->btn_id_focused = 0; ext->btn_id_focused = 0;
} else { }
else {
ext->btn_id_focused = LV_BTNMATRIX_BTN_NONE; ext->btn_id_focused = LV_BTNMATRIX_BTN_NONE;
} }
} else if (indev_type == LV_INDEV_TYPE_KEYPAD) { }
else if(indev_type == LV_INDEV_TYPE_KEYPAD) {
ext->btn_id_focused = 0; ext->btn_id_focused = 0;
} }
@@ -921,7 +938,8 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
ext->btn_id_focused = LV_BTNMATRIX_BTN_NONE; ext->btn_id_focused = LV_BTNMATRIX_BTN_NONE;
ext->btn_id_pr = LV_BTNMATRIX_BTN_NONE; ext->btn_id_pr = LV_BTNMATRIX_BTN_NONE;
ext->btn_id_act = LV_BTNMATRIX_BTN_NONE; ext->btn_id_act = LV_BTNMATRIX_BTN_NONE;
} else if(sign == LV_SIGNAL_CONTROL) { }
else if(sign == LV_SIGNAL_CONTROL) {
char c = *((char *)param); char c = *((char *)param);
if(c == LV_KEY_RIGHT) { if(c == LV_KEY_RIGHT) {
if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE)
@@ -931,17 +949,20 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
if(ext->btn_id_focused >= ext->btn_cnt - 1) ext->btn_id_focused = ext->btn_cnt - 1; if(ext->btn_id_focused >= ext->btn_cnt - 1) ext->btn_id_focused = ext->btn_cnt - 1;
ext->btn_id_act = ext->btn_id_focused; ext->btn_id_act = ext->btn_id_focused;
lv_obj_invalidate(btnm); lv_obj_invalidate(btnm);
} else if(c == LV_KEY_LEFT) { }
else if(c == LV_KEY_LEFT) {
if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) ext->btn_id_focused = 0; if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) ext->btn_id_focused = 0;
if(ext->btn_id_focused > 0) ext->btn_id_focused--; if(ext->btn_id_focused > 0) ext->btn_id_focused--;
ext->btn_id_act = ext->btn_id_focused; ext->btn_id_act = ext->btn_id_focused;
lv_obj_invalidate(btnm); lv_obj_invalidate(btnm);
} else if(c == LV_KEY_DOWN) { }
else if(c == LV_KEY_DOWN) {
lv_style_int_t pad_inner = lv_obj_get_style_pad_inner(btnm, LV_BTNMATRIX_PART_BG); lv_style_int_t pad_inner = lv_obj_get_style_pad_inner(btnm, LV_BTNMATRIX_PART_BG);
/*Find the area below the the current*/ /*Find the area below the the current*/
if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) { if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) {
ext->btn_id_focused = 0; ext->btn_id_focused = 0;
} else { }
else {
uint16_t area_below; uint16_t area_below;
lv_coord_t pr_center = lv_coord_t pr_center =
ext->button_areas[ext->btn_id_focused].x1 + (lv_area_get_width(&ext->button_areas[ext->btn_id_focused]) >> 1); ext->button_areas[ext->btn_id_focused].x1 + (lv_area_get_width(&ext->button_areas[ext->btn_id_focused]) >> 1);
@@ -960,12 +981,14 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
} }
ext->btn_id_act = ext->btn_id_focused; ext->btn_id_act = ext->btn_id_focused;
lv_obj_invalidate(btnm); lv_obj_invalidate(btnm);
} else if(c == LV_KEY_UP) { }
else if(c == LV_KEY_UP) {
lv_style_int_t pad_inner = lv_obj_get_style_pad_inner(btnm, LV_BTNMATRIX_PART_BG); lv_style_int_t pad_inner = lv_obj_get_style_pad_inner(btnm, LV_BTNMATRIX_PART_BG);
/*Find the area below the the current*/ /*Find the area below the the current*/
if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) { if(ext->btn_id_focused == LV_BTNMATRIX_BTN_NONE) {
ext->btn_id_focused = 0; ext->btn_id_focused = 0;
} else { }
else {
int16_t area_above; int16_t area_above;
lv_coord_t pr_center = lv_coord_t pr_center =
ext->button_areas[ext->btn_id_focused].x1 + (lv_area_get_width(&ext->button_areas[ext->btn_id_focused]) >> 1); ext->button_areas[ext->btn_id_focused].x1 + (lv_area_get_width(&ext->button_areas[ext->btn_id_focused]) >> 1);
@@ -984,7 +1007,8 @@ static lv_res_t lv_btnmatrix_signal(lv_obj_t * btnm, lv_signal_t sign, void * pa
ext->btn_id_act = ext->btn_id_focused; ext->btn_id_act = ext->btn_id_focused;
lv_obj_invalidate(btnm); lv_obj_invalidate(btnm);
} }
} else if(sign == LV_SIGNAL_GET_EDITABLE) { }
else if(sign == LV_SIGNAL_GET_EDITABLE) {
bool * editable = (bool *)param; bool * editable = (bool *)param;
*editable = true; *editable = true;
} }

View File

@@ -46,8 +46,7 @@ enum {
typedef uint16_t lv_btnmatrix_ctrl_t; typedef uint16_t lv_btnmatrix_ctrl_t;
/*Data of button matrix*/ /*Data of button matrix*/
typedef struct typedef struct {
{
/*No inherited ext.*/ /*Ext. of ancestor*/ /*No inherited ext.*/ /*Ext. of ancestor*/
/*New data for this type */ /*New data for this type */
const char ** map_p; /*Pointer to the current map*/ const char ** map_p; /*Pointer to the current map*/

View File

@@ -59,7 +59,8 @@ static lv_signal_cb_t ancestor_signal;
static lv_design_cb_t ancestor_design; static lv_design_cb_t ancestor_design;
static const char * day_name[7] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"}; static const char * day_name[7] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"};
static const char * month_name[12] = {"January", "February", "March", "April", "May", "June", static const char * month_name[12] = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"}; "July", "August", "September", "October", "November", "December"
};
/********************** /**********************
* MACROS * MACROS
@@ -131,7 +132,7 @@ lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy)
if(copy == NULL) { if(copy == NULL) {
lv_theme_apply(calendar, LV_THEME_CALENDAR); lv_theme_apply(calendar, LV_THEME_CALENDAR);
lv_obj_set_size(calendar, 5*LV_DPI/2, 5*LV_DPI/2); lv_obj_set_size(calendar, 5 * LV_DPI / 2, 5 * LV_DPI / 2);
} }
/*Copy an existing calendar*/ /*Copy an existing calendar*/
@@ -153,7 +154,7 @@ lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy)
ext->style_header = copy_ext->style_header; ext->style_header = copy_ext->style_header;
ext->style_day_names = copy_ext->style_day_names; ext->style_day_names = copy_ext->style_day_names;
/*Refresh the style with new signal function*/ /*Refresh the style with new signal function*/
// lv_obj_refresh_style(new_calendar); // lv_obj_refresh_style(new_calendar);
} }
LV_LOG_INFO("calendar created"); LV_LOG_INFO("calendar created");
@@ -432,7 +433,8 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void *
lv_obj_clean_style_list(calendar, LV_CALENDAR_PART_HEADER); lv_obj_clean_style_list(calendar, LV_CALENDAR_PART_HEADER);
lv_obj_clean_style_list(calendar, LV_CALENDAR_PART_DAY_NAMES); lv_obj_clean_style_list(calendar, LV_CALENDAR_PART_DAY_NAMES);
lv_obj_clean_style_list(calendar, LV_CALENDAR_PART_DATE); lv_obj_clean_style_list(calendar, LV_CALENDAR_PART_DATE);
} else if(sign == LV_SIGNAL_PRESSING) { }
else if(sign == LV_SIGNAL_PRESSING) {
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
lv_area_t header_area; lv_area_t header_area;
lv_area_copy(&header_area, &calendar->coords); lv_area_copy(&header_area, &calendar->coords);
@@ -447,7 +449,8 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void *
if(p.x < header_area.x1 + lv_area_get_width(&header_area) / 2) { if(p.x < header_area.x1 + lv_area_get_width(&header_area) / 2) {
if(ext->btn_pressing != -1) lv_obj_invalidate(calendar); if(ext->btn_pressing != -1) lv_obj_invalidate(calendar);
ext->btn_pressing = -1; ext->btn_pressing = -1;
} else { }
else {
if(ext->btn_pressing != 1) lv_obj_invalidate(calendar); if(ext->btn_pressing != 1) lv_obj_invalidate(calendar);
ext->btn_pressing = 1; ext->btn_pressing = 1;
} }
@@ -469,7 +472,8 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void *
ext->pressed_date.month = 0; ext->pressed_date.month = 0;
ext->pressed_date.day = 0; ext->pressed_date.day = 0;
} }
} else if(sign == LV_SIGNAL_PRESS_LOST) { }
else if(sign == LV_SIGNAL_PRESS_LOST) {
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
ext->btn_pressing = 0; ext->btn_pressing = 0;
ext->pressed_date.year = 0; ext->pressed_date.year = 0;
@@ -477,23 +481,28 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void *
ext->pressed_date.day = 0; ext->pressed_date.day = 0;
lv_obj_invalidate(calendar); lv_obj_invalidate(calendar);
} else if(sign == LV_SIGNAL_RELEASED) { }
else if(sign == LV_SIGNAL_RELEASED) {
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
if(ext->btn_pressing < 0) { if(ext->btn_pressing < 0) {
if(ext->showed_date.month <= 1) { if(ext->showed_date.month <= 1) {
ext->showed_date.month = 12; ext->showed_date.month = 12;
ext->showed_date.year--; ext->showed_date.year--;
} else { }
else {
ext->showed_date.month--; ext->showed_date.month--;
} }
} else if(ext->btn_pressing > 0) { }
else if(ext->btn_pressing > 0) {
if(ext->showed_date.month >= 12) { if(ext->showed_date.month >= 12) {
ext->showed_date.month = 1; ext->showed_date.month = 1;
ext->showed_date.year++; ext->showed_date.year++;
} else { }
else {
ext->showed_date.month++; ext->showed_date.month++;
} }
} else if(ext->pressed_date.year != 0) { }
else if(ext->pressed_date.year != 0) {
res = lv_event_send(calendar, LV_EVENT_VALUE_CHANGED, NULL); res = lv_event_send(calendar, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
@@ -504,22 +513,26 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void *
ext->pressed_date.month = 0; ext->pressed_date.month = 0;
ext->pressed_date.day = 0; ext->pressed_date.day = 0;
lv_obj_invalidate(calendar); lv_obj_invalidate(calendar);
} else if(sign == LV_SIGNAL_CONTROL) { }
else if(sign == LV_SIGNAL_CONTROL) {
uint8_t c = *((uint8_t *)param); uint8_t c = *((uint8_t *)param);
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar); lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
if(c == LV_KEY_RIGHT || c == LV_KEY_UP) { if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
if(ext->showed_date.month >= 12) { if(ext->showed_date.month >= 12) {
ext->showed_date.month = 1; ext->showed_date.month = 1;
ext->showed_date.year++; ext->showed_date.year++;
} else { }
else {
ext->showed_date.month++; ext->showed_date.month++;
} }
lv_obj_invalidate(calendar); lv_obj_invalidate(calendar);
} else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) { }
else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) {
if(ext->showed_date.month <= 1) { if(ext->showed_date.month <= 1) {
ext->showed_date.month = 12; ext->showed_date.month = 12;
ext->showed_date.year--; ext->showed_date.year--;
} else { }
else {
ext->showed_date.month--; ext->showed_date.month--;
} }
lv_obj_invalidate(calendar); lv_obj_invalidate(calendar);
@@ -603,19 +616,22 @@ static bool calculate_touched_day(lv_obj_t * calendar, const lv_point_t * touche
ext->pressed_date.month = ext->showed_date.month == 1 ? 12 : (ext->showed_date.month - 1); ext->pressed_date.month = ext->showed_date.month == 1 ? 12 : (ext->showed_date.month - 1);
ext->pressed_date.day = get_month_length(ext->pressed_date.year, ext->pressed_date.month) - ext->pressed_date.day = get_month_length(ext->pressed_date.year, ext->pressed_date.month) -
get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) + 1 + i_pos; get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) + 1 + i_pos;
} else if(i_pos < (get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) + }
else if(i_pos < (get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) +
get_month_length(ext->showed_date.year, ext->showed_date.month))) { get_month_length(ext->showed_date.year, ext->showed_date.month))) {
ext->pressed_date.year = ext->showed_date.year; ext->pressed_date.year = ext->showed_date.year;
ext->pressed_date.month = ext->showed_date.month; ext->pressed_date.month = ext->showed_date.month;
ext->pressed_date.day = i_pos + 1 - get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1); ext->pressed_date.day = i_pos + 1 - get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1);
} else if(i_pos < 42) { }
else if(i_pos < 42) {
ext->pressed_date.year = ext->showed_date.year + (ext->showed_date.month == 12 ? 1 : 0); ext->pressed_date.year = ext->showed_date.year + (ext->showed_date.month == 12 ? 1 : 0);
ext->pressed_date.month = ext->showed_date.month == 12 ? 1 : (ext->showed_date.month + 1); ext->pressed_date.month = ext->showed_date.month == 12 ? 1 : (ext->showed_date.month + 1);
ext->pressed_date.day = i_pos + 1 - get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) - ext->pressed_date.day = i_pos + 1 - get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) -
get_month_length(ext->showed_date.year, ext->showed_date.month); get_month_length(ext->showed_date.year, ext->showed_date.month);
} }
return true; return true;
} else { }
else {
return false; return false;
} }
} }
@@ -688,7 +704,7 @@ static void draw_header(lv_obj_t * calendar, const lv_area_t * mask)
lv_draw_label_dsc_init(&label_dsc); lv_draw_label_dsc_init(&label_dsc);
lv_obj_init_draw_label_dsc(calendar, LV_CALENDAR_PART_HEADER, &label_dsc); lv_obj_init_draw_label_dsc(calendar, LV_CALENDAR_PART_HEADER, &label_dsc);
label_dsc.flag = LV_TXT_FLAG_CENTER; label_dsc.flag = LV_TXT_FLAG_CENTER;
lv_draw_label(&header_area, mask, &label_dsc,txt_buf, NULL); lv_draw_label(&header_area, mask, &label_dsc, txt_buf, NULL);
calendar->state = state_ori; /*Restore the state*/ calendar->state = state_ori; /*Restore the state*/
@@ -708,7 +724,8 @@ static void draw_header(lv_obj_t * calendar, const lv_area_t * mask)
if(ext->btn_pressing > 0) calendar->state |= LV_STATE_PRESSED; if(ext->btn_pressing > 0) calendar->state |= LV_STATE_PRESSED;
else calendar->state &= ~(LV_STATE_PRESSED); else calendar->state &= ~(LV_STATE_PRESSED);
header_area.x1 = header_area.x2 - header_right - lv_txt_get_width(LV_SYMBOL_RIGHT, (uint16_t)strlen(LV_SYMBOL_RIGHT), font, 0, LV_TXT_FLAG_NONE); header_area.x1 = header_area.x2 - header_right - lv_txt_get_width(LV_SYMBOL_RIGHT, (uint16_t)strlen(LV_SYMBOL_RIGHT),
font, 0, LV_TXT_FLAG_NONE);
lv_draw_label_dsc_init(&label_dsc); lv_draw_label_dsc_init(&label_dsc);
lv_obj_init_draw_label_dsc(calendar, LV_CALENDAR_PART_HEADER, &label_dsc); lv_obj_init_draw_label_dsc(calendar, LV_CALENDAR_PART_HEADER, &label_dsc);
@@ -805,7 +822,8 @@ static void draw_dates(lv_obj_t * calendar, const lv_area_t * clip_area)
day_cnt = 1; day_cnt = 1;
draw_state = DAY_DRAW_ACT_MONTH; draw_state = DAY_DRAW_ACT_MONTH;
month_state = 0; month_state = 0;
} else { }
else {
draw_state = DAY_DRAW_PREV_MONTH; draw_state = DAY_DRAW_PREV_MONTH;
day_cnt = get_month_length(ext->showed_date.year, ext->showed_date.month - 1); /*Length of the previous month*/ day_cnt = get_month_length(ext->showed_date.year, ext->showed_date.month - 1); /*Length of the previous month*/
day_cnt -= month_start_day - 1; /*First visible number of the previous month*/ day_cnt -= month_start_day - 1; /*First visible number of the previous month*/
@@ -923,7 +941,8 @@ static bool is_highlighted(lv_obj_t * calendar, day_draw_state_t draw_state, int
if(draw_state == DAY_DRAW_PREV_MONTH) { if(draw_state == DAY_DRAW_PREV_MONTH) {
year -= month == 1 ? 1 : 0; year -= month == 1 ? 1 : 0;
month = month == 1 ? 12 : month - 1; month = month == 1 ? 12 : month - 1;
} else if(draw_state == DAY_DRAW_NEXT_MONTH) { }
else if(draw_state == DAY_DRAW_NEXT_MONTH) {
year += month == 12 ? 1 : 0; year += month == 12 ? 1 : 0;
month = month == 12 ? 1 : month + 1; month = month == 12 ? 1 : month + 1;
} }
@@ -956,7 +975,8 @@ static bool is_pressed(lv_obj_t * calendar, day_draw_state_t draw_state, int32_t
if(draw_state == DAY_DRAW_PREV_MONTH) { if(draw_state == DAY_DRAW_PREV_MONTH) {
year -= month == 1 ? 1 : 0; year -= month == 1 ? 1 : 0;
month = month == 1 ? 12 : month - 1; month = month == 1 ? 12 : month - 1;
} else if(draw_state == DAY_DRAW_NEXT_MONTH) { }
else if(draw_state == DAY_DRAW_NEXT_MONTH) {
year += month == 12 ? 1 : 0; year += month == 12 ? 1 : 0;
month = month == 12 ? 1 : month + 1; month = month == 12 ? 1 : month + 1;
} }

View File

@@ -30,16 +30,14 @@ extern "C" {
/** /**
* Represents a date on the calendar object (platform-agnostic). * Represents a date on the calendar object (platform-agnostic).
*/ */
typedef struct typedef struct {
{
uint16_t year; uint16_t year;
int8_t month; int8_t month;
int8_t day; int8_t day;
} lv_calendar_date_t; } lv_calendar_date_t;
/*Data of calendar*/ /*Data of calendar*/
typedef struct typedef struct {
{
/*None*/ /*Ext. of ancestor*/ /*None*/ /*Ext. of ancestor*/
/*New data for this type */ /*New data for this type */
lv_calendar_date_t today; /*Date of today*/ lv_calendar_date_t today; /*Date of today*/

View File

@@ -31,7 +31,8 @@
static lv_res_t lv_canvas_signal(lv_obj_t * canvas, lv_signal_t sign, void * param); static lv_res_t lv_canvas_signal(lv_obj_t * canvas, lv_signal_t sign, void * param);
static void set_set_px_cb(lv_disp_drv_t * disp_drv, lv_img_cf_t cf); static void set_set_px_cb(lv_disp_drv_t * disp_drv, lv_img_cf_t cf);
static void set_px_true_color_alpha(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, static void set_px_true_color_alpha(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y,
lv_color_t color, lv_opa_t opa); lv_color_t color, lv_opa_t opa);
static void set_px_cb_alpha1(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, static void set_px_cb_alpha1(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y,
@@ -274,7 +275,8 @@ void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t x, l
* Set to `source height / 2` to rotate around the center * Set to `source height / 2` to rotate around the center
* @param antialias apply anti-aliasing during the transformation. Looks better but slower. * @param antialias apply anti-aliasing during the transformation. Looks better but slower.
*/ */
void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, uint16_t zoom, lv_coord_t offset_x, lv_coord_t offset_y, void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, uint16_t zoom, lv_coord_t offset_x,
lv_coord_t offset_y,
int32_t pivot_x, int32_t pivot_y, bool antialias) int32_t pivot_x, int32_t pivot_y, bool antialias)
{ {
LV_ASSERT_OBJ(canvas, LV_OBJX_NAME); LV_ASSERT_OBJ(canvas, LV_OBJX_NAME);
@@ -314,7 +316,8 @@ void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, u
/*If the image has no alpha channel just simple set the result color on the canvas*/ /*If the image has no alpha channel just simple set the result color on the canvas*/
if(lv_img_cf_has_alpha(img->header.cf) == false) { if(lv_img_cf_has_alpha(img->header.cf) == false) {
lv_img_buf_set_px_color(&ext_dst->dsc, x + offset_x, y + offset_y, dsc.res.color); lv_img_buf_set_px_color(&ext_dst->dsc, x + offset_x, y + offset_y, dsc.res.color);
} else { }
else {
lv_color_t bg_color = lv_img_buf_get_px_color(&ext_dst->dsc, x + offset_x, y + offset_y, dsc.cfg.color); lv_color_t bg_color = lv_img_buf_get_px_color(&ext_dst->dsc, x + offset_x, y + offset_y, dsc.cfg.color);
/*If the canvas has no alpha but the image has mix the image's color with /*If the canvas has no alpha but the image has mix the image's color with
@@ -384,7 +387,8 @@ void lv_canvas_blur_hor(lv_obj_t * canvas, const lv_area_t * area, uint16_t r)
if(a.y1 < 0) a.y1 = 0; if(a.y1 < 0) a.y1 = 0;
if(a.x2 > ext->dsc.header.w - 1) a.x2 = ext->dsc.header.w - 1; if(a.x2 > ext->dsc.header.w - 1) a.x2 = ext->dsc.header.w - 1;
if(a.y2 > ext->dsc.header.h - 1) a.y2 = ext->dsc.header.h - 1; if(a.y2 > ext->dsc.header.h - 1) a.y2 = ext->dsc.header.h - 1;
} else { }
else {
a.x1 = 0; a.x1 = 0;
a.y1 = 0; a.y1 = 0;
a.x2 = ext->dsc.header.w - 1; a.x2 = ext->dsc.header.w - 1;
@@ -425,7 +429,7 @@ void lv_canvas_blur_hor(lv_obj_t * canvas, const lv_area_t * area, uint16_t r)
memcpy(line_buf, &ext->dsc.data[y * line_w], line_w); memcpy(line_buf, &ext->dsc.data[y * line_w], line_w);
for(x = a.x1 -r_back; x <= a.x1 + r_front; x++) { for(x = a.x1 - r_back; x <= a.x1 + r_front; x++) {
x_safe = x < 0 ? 0 : x; x_safe = x < 0 ? 0 : x;
x_safe = x_safe > ext->dsc.header.w - 1 ? ext->dsc.header.w - 1 : x_safe; x_safe = x_safe > ext->dsc.header.w - 1 ? ext->dsc.header.w - 1 : x_safe;
@@ -519,7 +523,8 @@ void lv_canvas_blur_ver(lv_obj_t * canvas, const lv_area_t * area, uint16_t r)
if(a.y1 < 0) a.y1 = 0; if(a.y1 < 0) a.y1 = 0;
if(a.x2 > ext->dsc.header.w - 1) a.x2 = ext->dsc.header.w - 1; if(a.x2 > ext->dsc.header.w - 1) a.x2 = ext->dsc.header.w - 1;
if(a.y2 > ext->dsc.header.h - 1) a.y2 = ext->dsc.header.h - 1; if(a.y2 > ext->dsc.header.h - 1) a.y2 = ext->dsc.header.h - 1;
} else { }
else {
a.x1 = 0; a.x1 = 0;
a.y1 = 0; a.y1 = 0;
a.x2 = ext->dsc.header.w - 1; a.x2 = ext->dsc.header.w - 1;
@@ -557,7 +562,7 @@ void lv_canvas_blur_ver(lv_obj_t * canvas, const lv_area_t * area, uint16_t r)
lv_color_t c; lv_color_t c;
lv_opa_t opa = LV_OPA_COVER; lv_opa_t opa = LV_OPA_COVER;
for(y = a.y1 -r_back; y <= a.y1 + r_front; y++) { for(y = a.y1 - r_back; y <= a.y1 + r_front; y++) {
y_safe = y < 0 ? 0 : y; y_safe = y < 0 ? 0 : y;
y_safe = y_safe > ext->dsc.header.h - 1 ? ext->dsc.header.h - 1 : y_safe; y_safe = y_safe > ext->dsc.header.h - 1 ? ext->dsc.header.h - 1 : y_safe;
@@ -714,8 +719,7 @@ void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord
/*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/ /*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/
lv_color_t ctransp = LV_COLOR_TRANSP; lv_color_t ctransp = LV_COLOR_TRANSP;
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED && if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED &&
rect_dsc->bg_color.full == ctransp.full) rect_dsc->bg_color.full == ctransp.full) {
{
disp.driver.antialiasing = 0; disp.driver.antialiasing = 0;
} }
#endif #endif
@@ -740,7 +744,8 @@ void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord
* @param txt text to display * @param txt text to display
* @param align align of the text (`LV_LABEL_ALIGN_LEFT/RIGHT/CENTER`) * @param align align of the text (`LV_LABEL_ALIGN_LEFT/RIGHT/CENTER`)
*/ */
void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t max_w, lv_draw_label_dsc_t * label_draw_dsc, void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t max_w,
lv_draw_label_dsc_t * label_draw_dsc,
const char * txt, lv_label_align_t align) const char * txt, lv_label_align_t align)
{ {
LV_ASSERT_OBJ(canvas, LV_OBJX_NAME); LV_ASSERT_OBJ(canvas, LV_OBJX_NAME);
@@ -786,10 +791,18 @@ void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord
lv_txt_flag_t flag; lv_txt_flag_t flag;
switch(align) { switch(align) {
case LV_LABEL_ALIGN_LEFT: flag = LV_TXT_FLAG_NONE; break; case LV_LABEL_ALIGN_LEFT:
case LV_LABEL_ALIGN_RIGHT: flag = LV_TXT_FLAG_RIGHT; break; flag = LV_TXT_FLAG_NONE;
case LV_LABEL_ALIGN_CENTER: flag = LV_TXT_FLAG_CENTER; break; break;
default: flag = LV_TXT_FLAG_NONE; break; case LV_LABEL_ALIGN_RIGHT:
flag = LV_TXT_FLAG_RIGHT;
break;
case LV_LABEL_ALIGN_CENTER:
flag = LV_TXT_FLAG_CENTER;
break;
default:
flag = LV_TXT_FLAG_NONE;
break;
} }
label_draw_dsc->flag = flag; label_draw_dsc->flag = flag;
@@ -807,7 +820,8 @@ void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord
* @param src image source. Can be a pointer an `lv_img_dsc_t` variable or a path an image. * @param src image source. Can be a pointer an `lv_img_dsc_t` variable or a path an image.
* @param style style of the image (`image` properties are used) * @param style style of the image (`image` properties are used)
*/ */
void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const void * src, lv_draw_img_dsc_t * img_draw_dsc) void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const void * src,
lv_draw_img_dsc_t * img_draw_dsc)
{ {
LV_ASSERT_OBJ(canvas, LV_OBJX_NAME); LV_ASSERT_OBJ(canvas, LV_OBJX_NAME);
@@ -871,7 +885,8 @@ void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const voi
* @param point_cnt number of points * @param point_cnt number of points
* @param style style of the line (`line` properties are used) * @param style style of the line (`line` properties are used)
*/ */
void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, lv_draw_line_dsc_t * line_draw_dsc) void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt,
lv_draw_line_dsc_t * line_draw_dsc)
{ {
LV_ASSERT_OBJ(canvas, LV_OBJX_NAME); LV_ASSERT_OBJ(canvas, LV_OBJX_NAME);
@@ -908,8 +923,7 @@ void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t
/*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/ /*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/
lv_color_t ctransp = LV_COLOR_TRANSP; lv_color_t ctransp = LV_COLOR_TRANSP;
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED && if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED &&
line_draw_dsc->color.full == ctransp.full) line_draw_dsc->color.full == ctransp.full) {
{
disp.driver.antialiasing = 0; disp.driver.antialiasing = 0;
} }
#endif #endif
@@ -934,7 +948,8 @@ void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t
* @param point_cnt number of points * @param point_cnt number of points
* @param style style of the polygon (`body.main_color` and `body.opa` is used) * @param style style of the polygon (`body.main_color` and `body.opa` is used)
*/ */
void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, lv_draw_rect_dsc_t * poly_draw_dsc) void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt,
lv_draw_rect_dsc_t * poly_draw_dsc)
{ {
LV_ASSERT_OBJ(canvas, LV_OBJX_NAME); LV_ASSERT_OBJ(canvas, LV_OBJX_NAME);
@@ -972,8 +987,7 @@ void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32
/*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/ /*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/
lv_color_t ctransp = LV_COLOR_TRANSP; lv_color_t ctransp = LV_COLOR_TRANSP;
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED && if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED &&
poly_draw_dsc->bg_color.full == ctransp.full) poly_draw_dsc->bg_color.full == ctransp.full) {
{
disp.driver.antialiasing = 0; disp.driver.antialiasing = 0;
} }
#endif #endif
@@ -981,7 +995,7 @@ void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32
lv_disp_t * refr_ori = lv_refr_get_disp_refreshing(); lv_disp_t * refr_ori = lv_refr_get_disp_refreshing();
lv_refr_set_disp_refreshing(&disp); lv_refr_set_disp_refreshing(&disp);
// lv_draw_polygon(points, point_cnt, &mask, poly_draw_dsc); // lv_draw_polygon(points, point_cnt, &mask, poly_draw_dsc);
lv_refr_set_disp_refreshing(refr_ori); lv_refr_set_disp_refreshing(refr_ori);
@@ -1037,8 +1051,7 @@ void lv_canvas_draw_arc(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_
/*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/ /*Disable anti-aliasing if drawing with transparent color to chroma keyed canvas*/
lv_color_t ctransp = LV_COLOR_TRANSP; lv_color_t ctransp = LV_COLOR_TRANSP;
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED && if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED &&
arc_draw_dsc->color.full == ctransp.full) arc_draw_dsc->color.full == ctransp.full) {
{
disp.driver.antialiasing = 0; disp.driver.antialiasing = 0;
} }
#endif #endif
@@ -1083,12 +1096,23 @@ static lv_res_t lv_canvas_signal(lv_obj_t * canvas, lv_signal_t sign, void * par
static void set_set_px_cb(lv_disp_drv_t * disp_drv, lv_img_cf_t cf) static void set_set_px_cb(lv_disp_drv_t * disp_drv, lv_img_cf_t cf)
{ {
switch(cf) { switch(cf) {
case LV_IMG_CF_TRUE_COLOR_ALPHA: disp_drv->set_px_cb = set_px_true_color_alpha; break; case LV_IMG_CF_TRUE_COLOR_ALPHA:
case LV_IMG_CF_ALPHA_1BIT: disp_drv->set_px_cb = set_px_cb_alpha1; break; disp_drv->set_px_cb = set_px_true_color_alpha;
case LV_IMG_CF_ALPHA_2BIT: disp_drv->set_px_cb = set_px_cb_alpha2; break; break;
case LV_IMG_CF_ALPHA_4BIT: disp_drv->set_px_cb = set_px_cb_alpha4; break; case LV_IMG_CF_ALPHA_1BIT:
case LV_IMG_CF_ALPHA_8BIT: disp_drv->set_px_cb = set_px_cb_alpha8; break; disp_drv->set_px_cb = set_px_cb_alpha1;
default: disp_drv->set_px_cb = NULL; break;
case LV_IMG_CF_ALPHA_2BIT:
disp_drv->set_px_cb = set_px_cb_alpha2;
break;
case LV_IMG_CF_ALPHA_4BIT:
disp_drv->set_px_cb = set_px_cb_alpha4;
break;
case LV_IMG_CF_ALPHA_8BIT:
disp_drv->set_px_cb = set_px_cb_alpha8;
break;
default:
disp_drv->set_px_cb = NULL;
} }
} }
@@ -1163,7 +1187,8 @@ static void set_px_alpha_generic(lv_img_dsc_t * d, lv_coord_t x, lv_coord_t y, l
} }
static void set_px_true_color_alpha(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, static void set_px_true_color_alpha(lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x,
lv_coord_t y,
lv_color_t color, lv_opa_t opa) lv_color_t color, lv_opa_t opa)
{ {
(void) disp_drv; /*Unused*/ (void) disp_drv; /*Unused*/

View File

@@ -29,8 +29,7 @@ extern "C" {
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
/*Data of canvas*/ /*Data of canvas*/
typedef struct typedef struct {
{
lv_img_ext_t img; /*Ext. of ancestor*/ lv_img_ext_t img; /*Ext. of ancestor*/
/*New data for this type */ /*New data for this type */
lv_img_dsc_t dsc; lv_img_dsc_t dsc;
@@ -145,7 +144,8 @@ void lv_canvas_copy_buf(lv_obj_t * canvas, const void * to_copy, lv_coord_t x, l
* Set to `source height / 2` to rotate around the center * Set to `source height / 2` to rotate around the center
* @param antialias apply anti-aliasing during the transformation. Looks better but slower. * @param antialias apply anti-aliasing during the transformation. Looks better but slower.
*/ */
void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, uint16_t zoom, lv_coord_t offset_x, lv_coord_t offset_y, void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, uint16_t zoom, lv_coord_t offset_x,
lv_coord_t offset_y,
int32_t pivot_x, int32_t pivot_y, bool antialias); int32_t pivot_x, int32_t pivot_y, bool antialias);
@@ -194,7 +194,8 @@ void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord
* @param txt text to display * @param txt text to display
* @param align align of the text (`LV_LABEL_ALIGN_LEFT/RIGHT/CENTER`) * @param align align of the text (`LV_LABEL_ALIGN_LEFT/RIGHT/CENTER`)
*/ */
void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t max_w, lv_draw_label_dsc_t * label_draw_dsc, void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t max_w,
lv_draw_label_dsc_t * label_draw_dsc,
const char * txt, lv_label_align_t align); const char * txt, lv_label_align_t align);
/** /**
@@ -203,7 +204,8 @@ void lv_canvas_draw_text(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord
* @param src image source. Can be a pointer an `lv_img_dsc_t` variable or a path an image. * @param src image source. Can be a pointer an `lv_img_dsc_t` variable or a path an image.
* @param style style of the image (`image` properties are used) * @param style style of the image (`image` properties are used)
*/ */
void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const void * src, lv_draw_img_dsc_t * img_draw_dsc); void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const void * src,
lv_draw_img_dsc_t * img_draw_dsc);
/** /**
* Draw a line on the canvas * Draw a line on the canvas
@@ -212,7 +214,8 @@ void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const voi
* @param point_cnt number of points * @param point_cnt number of points
* @param style style of the line (`line` properties are used) * @param style style of the line (`line` properties are used)
*/ */
void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, lv_draw_line_dsc_t * line_draw_dsc); void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt,
lv_draw_line_dsc_t * line_draw_dsc);
/** /**
* Draw a polygon on the canvas * Draw a polygon on the canvas
@@ -221,7 +224,8 @@ void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t
* @param point_cnt number of points * @param point_cnt number of points
* @param style style of the polygon (`body.main_color` and `body.opa` is used) * @param style style of the polygon (`body.main_color` and `body.opa` is used)
*/ */
void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt, lv_draw_rect_dsc_t * poly_draw_dsc); void lv_canvas_draw_polygon(lv_obj_t * canvas, const lv_point_t * points, uint32_t point_cnt,
lv_draw_rect_dsc_t * poly_draw_dsc);
/** /**
* Draw an arc on the canvas * Draw an arc on the canvas

View File

@@ -134,7 +134,8 @@ lv_obj_t * lv_chart_create(lv_obj_t * par, const lv_obj_t * copy)
lv_theme_apply(chart, LV_THEME_CHART); lv_theme_apply(chart, LV_THEME_CHART);
} else { }
else {
lv_chart_ext_t * ext_copy = lv_obj_get_ext_attr(copy); lv_chart_ext_t * ext_copy = lv_obj_get_ext_attr(copy);
lv_style_list_copy(&ext->style_series, &ext_copy->style_series); lv_style_list_copy(&ext->style_series, &ext_copy->style_series);
@@ -301,8 +302,7 @@ void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt)
if(point_cnt < 1) point_cnt = 1; if(point_cnt < 1) point_cnt = 1;
LV_LL_READ_BACK(ext->series_ll, ser) LV_LL_READ_BACK(ext->series_ll, ser) {
{
if(ser->start_point != 0) { if(ser->start_point != 0) {
lv_coord_t * new_points = lv_mem_alloc(sizeof(lv_coord_t) * point_cnt); lv_coord_t * new_points = lv_mem_alloc(sizeof(lv_coord_t) * point_cnt);
LV_ASSERT_MEM(new_points); LV_ASSERT_MEM(new_points);
@@ -316,7 +316,8 @@ void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt)
for(i = point_cnt_old; i < point_cnt; i++) { for(i = point_cnt_old; i < point_cnt; i++) {
new_points[i] = def; /*Fill up the rest with default value*/ new_points[i] = def; /*Fill up the rest with default value*/
} }
} else { }
else {
for(i = 0; i < point_cnt; i++) { for(i = 0; i < point_cnt; i++) {
new_points[i] = new_points[i] =
ser->points[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/ ser->points[(i + ser->start_point) % point_cnt_old]; /*Copy old contents to new array*/
@@ -326,7 +327,8 @@ void lv_chart_set_point_count(lv_obj_t * chart, uint16_t point_cnt)
/*Switch over pointer from old to new*/ /*Switch over pointer from old to new*/
lv_mem_free(ser->points); lv_mem_free(ser->points);
ser->points = new_points; ser->points = new_points;
} else { }
else {
ser->points = lv_mem_realloc(ser->points, sizeof(lv_coord_t) * point_cnt); ser->points = lv_mem_realloc(ser->points, sizeof(lv_coord_t) * point_cnt);
LV_ASSERT_MEM(ser->points); LV_ASSERT_MEM(ser->points);
if(ser->points == NULL) return; if(ser->points == NULL) return;
@@ -400,7 +402,8 @@ void lv_chart_set_next(lv_obj_t * chart, lv_chart_series_t * ser, lv_coord_t y)
y; /*This was the place of the former left most value, after shifting it is the rightmost*/ y; /*This was the place of the former left most value, after shifting it is the rightmost*/
ser->start_point = (ser->start_point + 1) % ext->point_cnt; ser->start_point = (ser->start_point + 1) % ext->point_cnt;
lv_chart_refresh(chart); lv_chart_refresh(chart);
} else if(ext->update_mode == LV_CHART_UPDATE_MODE_CIRCULAR) { }
else if(ext->update_mode == LV_CHART_UPDATE_MODE_CIRCULAR) {
ser->points[ser->start_point] = y; ser->points[ser->start_point] = y;
if(ext->type & LV_CHART_TYPE_LINE) invalidate_lines(chart, ser->start_point); if(ext->type & LV_CHART_TYPE_LINE) invalidate_lines(chart, ser->start_point);
@@ -600,7 +603,8 @@ static lv_design_res_t lv_chart_design(lv_obj_t * chart, const lv_area_t * clip_
{ {
if(mode == LV_DESIGN_COVER_CHK) { if(mode == LV_DESIGN_COVER_CHK) {
return ancestor_design(chart, clip_area, mode); return ancestor_design(chart, clip_area, mode);
} else if(mode == LV_DESIGN_DRAW_MAIN) { }
else if(mode == LV_DESIGN_DRAW_MAIN) {
/*Draw the background*/ /*Draw the background*/
lv_draw_rect_dsc_t bg_dsc; lv_draw_rect_dsc_t bg_dsc;
lv_draw_rect_dsc_init(&bg_dsc); lv_draw_rect_dsc_init(&bg_dsc);
@@ -647,8 +651,7 @@ static lv_res_t lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param
if(sign == LV_SIGNAL_CLEANUP) { if(sign == LV_SIGNAL_CLEANUP) {
lv_coord_t ** datal; lv_coord_t ** datal;
LV_LL_READ(ext->series_ll, datal) LV_LL_READ(ext->series_ll, datal) {
{
lv_mem_free(*datal); lv_mem_free(*datal);
} }
lv_ll_clear(&ext->series_ll); lv_ll_clear(&ext->series_ll);
@@ -725,7 +728,8 @@ static void draw_series_bg(lv_obj_t * chart, const lv_area_t * series_area, cons
if(bg_dsc.border_width != 0) { if(bg_dsc.border_width != 0) {
div_i_start = 1; div_i_start = 1;
div_i_end = ext->hdiv_cnt; div_i_end = ext->hdiv_cnt;
} else { }
else {
div_i_start = 0; div_i_start = 0;
div_i_end = ext->hdiv_cnt + 1; div_i_end = ext->hdiv_cnt + 1;
} }
@@ -745,7 +749,8 @@ static void draw_series_bg(lv_obj_t * chart, const lv_area_t * series_area, cons
if(bg_dsc.border_width != 0) { if(bg_dsc.border_width != 0) {
div_i_start = 1; div_i_start = 1;
div_i_end = ext->vdiv_cnt; div_i_end = ext->vdiv_cnt;
} else { }
else {
div_i_start = 0; div_i_start = 0;
div_i_end = ext->vdiv_cnt + 1; div_i_end = ext->vdiv_cnt + 1;
} }
@@ -797,7 +802,8 @@ static void draw_series_line(lv_obj_t * chart, const lv_area_t * series_area, co
has_fade = area_dsc.bg_grad_dir == LV_GRAD_DIR_VER ? true : false; has_fade = area_dsc.bg_grad_dir == LV_GRAD_DIR_VER ? true : false;
if(has_fade) { if(has_fade) {
lv_draw_mask_fade_init(&mask_fade_p, &chart->coords, area_dsc.bg_main_color_stop, chart->coords.y1, area_dsc.bg_grad_color_stop, chart->coords.y2); lv_draw_mask_fade_init(&mask_fade_p, &chart->coords, area_dsc.bg_main_color_stop, chart->coords.y1,
area_dsc.bg_grad_color_stop, chart->coords.y2);
} }
} }
@@ -809,8 +815,7 @@ static void draw_series_line(lv_obj_t * chart, const lv_area_t * series_area, co
lv_coord_t point_radius = lv_obj_get_style_size(chart, LV_CHART_PART_SERIES); lv_coord_t point_radius = lv_obj_get_style_size(chart, LV_CHART_PART_SERIES);
/*Go through all data lines*/ /*Go through all data lines*/
LV_LL_READ_BACK(ext->series_ll, ser) LV_LL_READ_BACK(ext->series_ll, ser) {
{
line_dsc.color = ser->color; line_dsc.color = ser->color;
point_dsc.bg_color = ser->color; point_dsc.bg_color = ser->color;
area_dsc.bg_color = ser->color; area_dsc.bg_color = ser->color;
@@ -942,8 +947,7 @@ static void draw_series_column(lv_obj_t * chart, const lv_area_t * series_area,
x_act += series_area->x1 + x_ofs; x_act += series_area->x1 + x_ofs;
/*Draw the current point of all data line*/ /*Draw the current point of all data line*/
LV_LL_READ_BACK(ext->series_ll, ser) LV_LL_READ_BACK(ext->series_ll, ser) {
{
lv_coord_t start_point = ext->update_mode == LV_CHART_UPDATE_MODE_SHIFT ? ser->start_point : 0; lv_coord_t start_point = ext->update_mode == LV_CHART_UPDATE_MODE_SHIFT ? ser->start_point : 0;
col_a.x1 = x_act; col_a.x1 = x_act;
@@ -1054,7 +1058,8 @@ static lv_chart_label_iterator_t create_axis_label_iter(const char * list, uint8
if(iterator_dir == LV_CHART_LABEL_ITERATOR_FORWARD) { if(iterator_dir == LV_CHART_LABEL_ITERATOR_FORWARD) {
iterator.is_reverse_iter = 0; iterator.is_reverse_iter = 0;
iterator.current_pos = list; iterator.current_pos = list;
} else { }
else {
iterator.is_reverse_iter = 1; iterator.is_reverse_iter = 1;
// -1 to skip '\0' at the end of the string // -1 to skip '\0' at the end of the string
iterator.current_pos = list + j - 1; iterator.current_pos = list + j - 1;
@@ -1071,10 +1076,10 @@ static lv_chart_label_iterator_t create_axis_label_iter(const char * list, uint8
static void get_next_axis_label(lv_chart_label_iterator_t * iterator, char * buf) static void get_next_axis_label(lv_chart_label_iterator_t * iterator, char * buf)
{ {
uint8_t label_len = 0; uint8_t label_len = 0;
if (iterator->is_reverse_iter) { if(iterator->is_reverse_iter) {
const char * label_start; const char * label_start;
/* count the length of the current label*/ /* count the length of the current label*/
while ((*iterator->current_pos != '\n') && while((*iterator->current_pos != '\n') &&
(iterator->current_pos != iterator->list_start)) { (iterator->current_pos != iterator->list_start)) {
iterator->current_pos--; iterator->current_pos--;
label_len++; label_len++;
@@ -1082,23 +1087,25 @@ static void get_next_axis_label(lv_chart_label_iterator_t * iterator, char * buf
label_start = iterator->current_pos; label_start = iterator->current_pos;
if (*iterator->current_pos == '\n') { if(*iterator->current_pos == '\n') {
/* do not copy \n symbol, +1 to skip it*/ /* do not copy \n symbol, +1 to skip it*/
label_start++; label_start++;
/* skip newline*/ /* skip newline*/
iterator->current_pos--; iterator->current_pos--;
} else { }
else {
/* it is last label in list (first one from the beginning )*/ /* it is last label in list (first one from the beginning )*/
label_len++; label_len++;
} }
/* do not allow output buffer overflow */ /* do not allow output buffer overflow */
if (label_len > LV_CHART_AXIS_TICK_LABEL_MAX_LEN) { if(label_len > LV_CHART_AXIS_TICK_LABEL_MAX_LEN) {
label_len = LV_CHART_AXIS_TICK_LABEL_MAX_LEN; label_len = LV_CHART_AXIS_TICK_LABEL_MAX_LEN;
} }
strncpy(buf, label_start, label_len); strncpy(buf, label_start, label_len);
} else { }
else {
/* search for tick string */ /* search for tick string */
while(iterator->current_pos[label_len] != '\n' && while(iterator->current_pos[label_len] != '\n' &&
iterator->current_pos[label_len] != '\0') { iterator->current_pos[label_len] != '\0') {
@@ -1106,7 +1113,8 @@ static void get_next_axis_label(lv_chart_label_iterator_t * iterator, char * buf
if(label_len < LV_CHART_AXIS_TICK_LABEL_MAX_LEN) { if(label_len < LV_CHART_AXIS_TICK_LABEL_MAX_LEN) {
buf[label_len] = iterator->current_pos[label_len]; buf[label_len] = iterator->current_pos[label_len];
label_len++; label_len++;
} else { }
else {
label_len++; label_len++;
} }
} }
@@ -1114,7 +1122,7 @@ static void get_next_axis_label(lv_chart_label_iterator_t * iterator, char * buf
iterator->current_pos += label_len; iterator->current_pos += label_len;
/* do not allow output buffer overflow */ /* do not allow output buffer overflow */
if (label_len > LV_CHART_AXIS_TICK_LABEL_MAX_LEN) { if(label_len > LV_CHART_AXIS_TICK_LABEL_MAX_LEN) {
label_len = LV_CHART_AXIS_TICK_LABEL_MAX_LEN; label_len = LV_CHART_AXIS_TICK_LABEL_MAX_LEN;
} }
@@ -1183,7 +1191,8 @@ static void draw_y_ticks(lv_obj_t * chart, const lv_area_t * series_area, const
minor_tick_len *= -1; minor_tick_len *= -1;
} }
iter_dir = (y_axis->options & LV_CHART_AXIS_INVERSE_LABELS_ORDER) ? LV_CHART_LABEL_ITERATOR_REVERSE : LV_CHART_LABEL_ITERATOR_FORWARD; iter_dir = (y_axis->options & LV_CHART_AXIS_INVERSE_LABELS_ORDER) ? LV_CHART_LABEL_ITERATOR_REVERSE :
LV_CHART_LABEL_ITERATOR_FORWARD;
iter = create_axis_label_iter(y_axis->list_of_values, iter_dir); iter = create_axis_label_iter(y_axis->list_of_values, iter_dir);
/*determine the number of options */ /*determine the number of options */
@@ -1214,7 +1223,7 @@ static void draw_y_ticks(lv_obj_t * chart, const lv_area_t * series_area, const
p1.x = x_ofs; p1.x = x_ofs;
/* move extra pixel out of chart boundary */ /* move extra pixel out of chart boundary */
if (which_axis == LV_CHART_AXIS_PRIMARY_Y) if(which_axis == LV_CHART_AXIS_PRIMARY_Y)
p1.x--; p1.x--;
else else
p1.x++; p1.x++;
@@ -1235,7 +1244,8 @@ static void draw_y_ticks(lv_obj_t * chart, const lv_area_t * series_area, const
lv_draw_line(&p1, &p2, mask, &line_dsc); lv_draw_line(&p1, &p2, mask, &line_dsc);
else if((y_axis->options & LV_CHART_AXIS_DRAW_LAST_TICK) != 0) else if((y_axis->options & LV_CHART_AXIS_DRAW_LAST_TICK) != 0)
lv_draw_line(&p1, &p2, mask, &line_dsc); lv_draw_line(&p1, &p2, mask, &line_dsc);
} else { }
else {
if(i != num_scale_ticks) if(i != num_scale_ticks)
lv_draw_line(&p1, &p2, mask, &line_dsc); lv_draw_line(&p1, &p2, mask, &line_dsc);
else if((y_axis->options & LV_CHART_AXIS_DRAW_LAST_TICK) != 0) else if((y_axis->options & LV_CHART_AXIS_DRAW_LAST_TICK) != 0)
@@ -1260,7 +1270,8 @@ static void draw_y_ticks(lv_obj_t * chart, const lv_area_t * series_area, const
if(which_axis == LV_CHART_AXIS_PRIMARY_Y) { if(which_axis == LV_CHART_AXIS_PRIMARY_Y) {
a.x1 = p2.x - size.x - label_dist; a.x1 = p2.x - size.x - label_dist;
a.x2 = p2.x - label_dist; a.x2 = p2.x - label_dist;
} else { }
else {
a.x1 = p2.x + label_dist; a.x1 = p2.x + label_dist;
a.x2 = p2.x + size.x + label_dist; a.x2 = p2.x + size.x + label_dist;
} }
@@ -1356,7 +1367,8 @@ static void draw_x_ticks(lv_obj_t * chart, const lv_area_t * series_area, const
/* set the area at some distance of the major tick len under of the tick */ /* set the area at some distance of the major tick len under of the tick */
lv_area_t a = {(p2.x - size.x / 2), (p2.y + label_dist), (p2.x + size.x / 2), lv_area_t a = {(p2.x - size.x / 2), (p2.y + label_dist), (p2.x + size.x / 2),
(p2.y + size.y + label_dist)}; (p2.y + size.y + label_dist)
};
lv_draw_label(&a, mask, &label_dsc, buf, NULL); lv_draw_label(&a, mask, &label_dsc, buf, NULL);
} }
} }

View File

@@ -52,8 +52,7 @@ enum {
}; };
typedef uint8_t lv_chart_update_mode_t; typedef uint8_t lv_chart_update_mode_t;
typedef struct typedef struct {
{
lv_coord_t * points; lv_coord_t * points;
lv_color_t color; lv_color_t color;
uint16_t start_point; uint16_t start_point;
@@ -67,8 +66,7 @@ enum {
}; };
typedef uint8_t lv_chart_axis_options_t; typedef uint8_t lv_chart_axis_options_t;
typedef struct typedef struct {
{
const char * list_of_values; const char * list_of_values;
lv_chart_axis_options_t options; lv_chart_axis_options_t options;
uint8_t num_tick_marks; uint8_t num_tick_marks;
@@ -77,8 +75,7 @@ typedef struct
} lv_chart_axis_cfg_t; } lv_chart_axis_cfg_t;
/*Data of chart */ /*Data of chart */
typedef struct typedef struct {
{
/*No inherited ext*/ /*Ext. of ancestor*/ /*No inherited ext*/ /*Ext. of ancestor*/
/*New data for this type */ /*New data for this type */
lv_ll_t series_ll; /*Linked list for the data line pointers (stores lv_chart_dl_t)*/ lv_ll_t series_ll; /*Linked list for the data line pointers (stores lv_chart_dl_t)*/

View File

@@ -85,13 +85,14 @@ lv_obj_t * lv_checkbox_create(lv_obj_t * par, const lv_obj_t * copy)
lv_theme_apply(cb, LV_THEME_CHECKBOX); lv_theme_apply(cb, LV_THEME_CHECKBOX);
} else { }
else {
lv_checkbox_ext_t * copy_ext = lv_obj_get_ext_attr(copy); lv_checkbox_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
ext->bullet = lv_obj_create(cb, copy_ext->bullet); ext->bullet = lv_obj_create(cb, copy_ext->bullet);
ext->label = lv_label_create(cb, copy_ext->label); ext->label = lv_label_create(cb, copy_ext->label);
/*Refresh the style with new signal function*/ /*Refresh the style with new signal function*/
// lv_obj_refresh_style(cb); // lv_obj_refresh_style(cb);
} }
LV_LOG_INFO("check box created"); LV_LOG_INFO("check box created");
@@ -181,10 +182,12 @@ static lv_res_t lv_checkbox_signal(lv_obj_t * cb, lv_signal_t sign, void * param
lv_coord_t line_height = lv_font_get_line_height(font); lv_coord_t line_height = lv_font_get_line_height(font);
lv_obj_set_size(ext->bullet, line_height, line_height); lv_obj_set_size(ext->bullet, line_height, line_height);
lv_obj_set_state(ext->bullet, lv_obj_get_state(cb, LV_CHECKBOX_PART_BG)); lv_obj_set_state(ext->bullet, lv_obj_get_state(cb, LV_CHECKBOX_PART_BG));
} else if(sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST || }
else if(sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST ||
sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS) { sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS) {
lv_obj_set_state(ext->bullet, lv_obj_get_state(cb, LV_CHECKBOX_PART_BG)); lv_obj_set_state(ext->bullet, lv_obj_get_state(cb, LV_CHECKBOX_PART_BG));
} else if(sign == LV_SIGNAL_CONTROL) { }
else if(sign == LV_SIGNAL_CONTROL) {
char c = *((char *)param); char c = *((char *)param);
if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN || c == LV_KEY_LEFT || c == LV_KEY_UP) { if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN || c == LV_KEY_LEFT || c == LV_KEY_UP) {
/*Follow the backgrounds state with the bullet*/ /*Follow the backgrounds state with the bullet*/

View File

@@ -39,8 +39,7 @@ extern "C" {
**********************/ **********************/
/*Data of check box*/ /*Data of check box*/
typedef struct typedef struct {
{
lv_btn_ext_t bg_btn; /*Ext. of ancestor*/ lv_btn_ext_t bg_btn; /*Ext. of ancestor*/
/*New data for this type */ /*New data for this type */
lv_obj_t * bullet; /*Pointer to button*/ lv_obj_t * bullet; /*Pointer to button*/
@@ -93,7 +92,7 @@ void lv_checkbox_set_static_text(lv_obj_t * cb, const char * txt);
*/ */
static inline void lv_checkbox_set_checked(lv_obj_t * cb, bool checked) static inline void lv_checkbox_set_checked(lv_obj_t * cb, bool checked)
{ {
lv_btn_set_state(cb, checked ? LV_BTN_STATE_CHECKED_RELEASED: LV_BTN_STATE_RELEASED); lv_btn_set_state(cb, checked ? LV_BTN_STATE_CHECKED_RELEASED : LV_BTN_STATE_RELEASED);
} }
/** /**
@@ -141,7 +140,7 @@ static inline bool lv_checkbox_is_checked(const lv_obj_t * cb)
*/ */
static inline bool lv_checkbox_is_inactive(const lv_obj_t * cb) static inline bool lv_checkbox_is_inactive(const lv_obj_t * cb)
{ {
return lv_btn_get_state(cb) == LV_BTN_STATE_DISABLED ? true :false; return lv_btn_get_state(cb) == LV_BTN_STATE_DISABLED ? true : false;
} }

View File

@@ -76,7 +76,7 @@ lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy)
if(cont == NULL) return NULL; if(cont == NULL) return NULL;
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(cont); if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(cont);
if(ancestor_design == NULL) ancestor_design= lv_obj_get_design_cb(cont); if(ancestor_design == NULL) ancestor_design = lv_obj_get_design_cb(cont);
lv_obj_allocate_ext_attr(cont, sizeof(lv_cont_ext_t)); lv_obj_allocate_ext_attr(cont, sizeof(lv_cont_ext_t));
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont); lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
@@ -270,15 +270,18 @@ static lv_res_t lv_cont_signal(lv_obj_t * cont, lv_signal_t sign, void * param)
if(sign == LV_SIGNAL_STYLE_CHG) { /*Recalculate the padding if the style changed*/ if(sign == LV_SIGNAL_STYLE_CHG) { /*Recalculate the padding if the style changed*/
lv_cont_refr_layout(cont); lv_cont_refr_layout(cont);
lv_cont_refr_autofit(cont); lv_cont_refr_autofit(cont);
} else if(sign == LV_SIGNAL_CHILD_CHG) { }
else if(sign == LV_SIGNAL_CHILD_CHG) {
lv_cont_refr_layout(cont); lv_cont_refr_layout(cont);
lv_cont_refr_autofit(cont); lv_cont_refr_autofit(cont);
} else if(sign == LV_SIGNAL_COORD_CHG) { }
else if(sign == LV_SIGNAL_COORD_CHG) {
if(lv_obj_get_width(cont) != lv_area_get_width(param) || lv_obj_get_height(cont) != lv_area_get_height(param)) { if(lv_obj_get_width(cont) != lv_area_get_width(param) || lv_obj_get_height(cont) != lv_area_get_height(param)) {
lv_cont_refr_layout(cont); lv_cont_refr_layout(cont);
lv_cont_refr_autofit(cont); lv_cont_refr_autofit(cont);
} }
} else if(sign == LV_SIGNAL_PARENT_SIZE_CHG) { }
else if(sign == LV_SIGNAL_PARENT_SIZE_CHG) {
/*FLOOD and FILL fit needs to be refreshed if the parent's size has changed*/ /*FLOOD and FILL fit needs to be refreshed if the parent's size has changed*/
lv_cont_refr_autofit(cont); lv_cont_refr_autofit(cont);
} }
@@ -316,13 +319,17 @@ static void lv_cont_refr_layout(lv_obj_t * cont)
if(type == LV_LAYOUT_CENTER) { if(type == LV_LAYOUT_CENTER) {
lv_cont_layout_center(cont); lv_cont_layout_center(cont);
} else if(type == LV_LAYOUT_COLUMN_LEFT || type == LV_LAYOUT_COLUMN_MID || type == LV_LAYOUT_COLUMN_RIGHT) { }
else if(type == LV_LAYOUT_COLUMN_LEFT || type == LV_LAYOUT_COLUMN_MID || type == LV_LAYOUT_COLUMN_RIGHT) {
lv_cont_layout_col(cont); lv_cont_layout_col(cont);
} else if(type == LV_LAYOUT_ROW_TOP || type == LV_LAYOUT_ROW_MID || type == LV_LAYOUT_ROW_BOTTOM) { }
else if(type == LV_LAYOUT_ROW_TOP || type == LV_LAYOUT_ROW_MID || type == LV_LAYOUT_ROW_BOTTOM) {
lv_cont_layout_row(cont); lv_cont_layout_row(cont);
} else if(type == LV_LAYOUT_PRETTY_MID || type == LV_LAYOUT_PRETTY_TOP || type == LV_LAYOUT_PRETTY_BOTTOM) { }
else if(type == LV_LAYOUT_PRETTY_MID || type == LV_LAYOUT_PRETTY_TOP || type == LV_LAYOUT_PRETTY_BOTTOM) {
lv_cont_layout_pretty(cont); lv_cont_layout_pretty(cont);
} else if(type == LV_LAYOUT_GRID) { }
else if(type == LV_LAYOUT_GRID) {
lv_cont_layout_grid(cont); lv_cont_layout_grid(cont);
} }
} }
@@ -369,8 +376,7 @@ static void lv_cont_layout_col(lv_obj_t * cont)
lv_obj_add_protect(cont, LV_PROTECT_CHILD_CHG); lv_obj_add_protect(cont, LV_PROTECT_CHILD_CHG);
/* Align the children */ /* Align the children */
lv_coord_t last_cord = top; lv_coord_t last_cord = top;
LV_LL_READ_BACK(cont->child_ll, child) LV_LL_READ_BACK(cont->child_ll, child) {
{
if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue;
lv_obj_align(child, cont, align, hpad_corr, last_cord); lv_obj_align(child, cont, align, hpad_corr, last_cord);
@@ -401,11 +407,11 @@ static void lv_cont_layout_row(lv_obj_t * cont)
break; break;
case LV_LAYOUT_ROW_MID: case LV_LAYOUT_ROW_MID:
vpad_corr = 0; vpad_corr = 0;
align = base_dir == LV_BIDI_DIR_RTL ? LV_ALIGN_IN_RIGHT_MID: LV_ALIGN_IN_LEFT_MID; align = base_dir == LV_BIDI_DIR_RTL ? LV_ALIGN_IN_RIGHT_MID : LV_ALIGN_IN_LEFT_MID;
break; break;
case LV_LAYOUT_ROW_BOTTOM: case LV_LAYOUT_ROW_BOTTOM:
vpad_corr = -lv_obj_get_style_pad_bottom(cont, LV_CONT_PART_MAIN); vpad_corr = -lv_obj_get_style_pad_bottom(cont, LV_CONT_PART_MAIN);
align = base_dir == LV_BIDI_DIR_RTL ? LV_ALIGN_IN_BOTTOM_RIGHT: LV_ALIGN_IN_BOTTOM_LEFT; align = base_dir == LV_BIDI_DIR_RTL ? LV_ALIGN_IN_BOTTOM_RIGHT : LV_ALIGN_IN_BOTTOM_LEFT;
break; break;
default: default:
vpad_corr = 0; vpad_corr = 0;
@@ -424,8 +430,7 @@ static void lv_cont_layout_row(lv_obj_t * cont)
lv_coord_t inner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN); lv_coord_t inner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN);
LV_LL_READ_BACK(cont->child_ll, child) LV_LL_READ_BACK(cont->child_ll, child) {
{
if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue;
if(base_dir == LV_BIDI_DIR_RTL) lv_obj_align(child, cont, align, -last_cord, vpad_corr); if(base_dir == LV_BIDI_DIR_RTL) lv_obj_align(child, cont, align, -last_cord, vpad_corr);
@@ -448,8 +453,7 @@ static void lv_cont_layout_center(lv_obj_t * cont)
lv_coord_t h_tot = 0; lv_coord_t h_tot = 0;
lv_coord_t inner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN); lv_coord_t inner = lv_obj_get_style_pad_inner(cont, LV_CONT_PART_MAIN);
LV_LL_READ(cont->child_ll, child) LV_LL_READ(cont->child_ll, child) {
{
if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue;
h_tot += lv_obj_get_height(child) + inner; h_tot += lv_obj_get_height(child) + inner;
obj_num++; obj_num++;
@@ -465,8 +469,7 @@ static void lv_cont_layout_center(lv_obj_t * cont)
/* Align the children */ /* Align the children */
lv_coord_t last_cord = -(h_tot / 2); lv_coord_t last_cord = -(h_tot / 2);
LV_LL_READ_BACK(cont->child_ll, child) LV_LL_READ_BACK(cont->child_ll, child) {
{
if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue;
lv_obj_align(child, cont, LV_ALIGN_CENTER, 0, last_cord + lv_obj_get_height(child) / 2); lv_obj_align(child, cont, LV_ALIGN_CENTER, 0, last_cord + lv_obj_get_height(child) / 2);
@@ -622,7 +625,8 @@ static void lv_cont_layout_grid(lv_obj_t * cont)
lv_coord_t x_ofs; lv_coord_t x_ofs;
if(obj_row > 1) { if(obj_row > 1) {
x_ofs = w_obj + (w_fit - (obj_row * w_obj)) / (obj_row - 1); x_ofs = w_obj + (w_fit - (obj_row * w_obj)) / (obj_row - 1);
} else { }
else {
x_ofs = w_tot / 2 - w_obj / 2; x_ofs = w_tot / 2 - w_obj / 2;
} }
lv_coord_t y_ofs = h_obj + inner; lv_coord_t y_ofs = h_obj + inner;
@@ -636,14 +640,14 @@ static void lv_cont_layout_grid(lv_obj_t * cont)
lv_coord_t act_x = left; lv_coord_t act_x = left;
lv_coord_t act_y = lv_obj_get_style_pad_top(cont, LV_CONT_PART_MAIN); lv_coord_t act_y = lv_obj_get_style_pad_top(cont, LV_CONT_PART_MAIN);
uint16_t obj_cnt = 0; uint16_t obj_cnt = 0;
LV_LL_READ_BACK(cont->child_ll, child) LV_LL_READ_BACK(cont->child_ll, child) {
{
if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue; if(lv_obj_get_hidden(child) != false || lv_obj_is_protected(child, LV_PROTECT_POS) != false) continue;
if(obj_row > 1) { if(obj_row > 1) {
lv_obj_set_pos(child, act_x, act_y); lv_obj_set_pos(child, act_x, act_y);
act_x += x_ofs; act_x += x_ofs;
} else { }
else {
lv_obj_set_pos(child, x_ofs, act_y); lv_obj_set_pos(child, x_ofs, act_y);
} }
obj_cnt++; obj_cnt++;
@@ -695,8 +699,7 @@ static void lv_cont_refr_autofit(lv_obj_t * cont)
tight_area.x2 = LV_COORD_MIN; tight_area.x2 = LV_COORD_MIN;
tight_area.y2 = LV_COORD_MIN; tight_area.y2 = LV_COORD_MIN;
LV_LL_READ(cont->child_ll, child_i) LV_LL_READ(cont->child_ll, child_i) {
{
if(lv_obj_get_hidden(child_i) != false) continue; if(lv_obj_get_hidden(child_i) != false) continue;
tight_area.x1 = LV_MATH_MIN(tight_area.x1, child_i->coords.x1); tight_area.x1 = LV_MATH_MIN(tight_area.x1, child_i->coords.x1);
tight_area.y1 = LV_MATH_MIN(tight_area.y1, child_i->coords.y1); tight_area.y1 = LV_MATH_MIN(tight_area.y1, child_i->coords.y1);
@@ -714,31 +717,59 @@ static void lv_cont_refr_autofit(lv_obj_t * cont)
lv_area_copy(&new_area, &ori); lv_area_copy(&new_area, &ori);
switch(ext->fit_left) { switch(ext->fit_left) {
case LV_FIT_TIGHT: new_area.x1 = tight_area.x1; break; case LV_FIT_TIGHT:
case LV_FIT_PARENT: new_area.x1 = flood_area.x1; break; new_area.x1 = tight_area.x1;
case LV_FIT_MAX: new_area.x1 = has_children ? LV_MATH_MIN(tight_area.x1, flood_area.x1) : flood_area.x1; break; break;
default: break; case LV_FIT_PARENT:
new_area.x1 = flood_area.x1;
break;
case LV_FIT_MAX:
new_area.x1 = has_children ? LV_MATH_MIN(tight_area.x1, flood_area.x1) : flood_area.x1;
break;
default:
break;
} }
switch(ext->fit_right) { switch(ext->fit_right) {
case LV_FIT_TIGHT: new_area.x2 = tight_area.x2; break; case LV_FIT_TIGHT:
case LV_FIT_PARENT: new_area.x2 = flood_area.x2; break; new_area.x2 = tight_area.x2;
case LV_FIT_MAX: new_area.x2 = has_children ? LV_MATH_MAX(tight_area.x2, flood_area.x2) : flood_area.x2; break; break;
default: break; case LV_FIT_PARENT:
new_area.x2 = flood_area.x2;
break;
case LV_FIT_MAX:
new_area.x2 = has_children ? LV_MATH_MAX(tight_area.x2, flood_area.x2) : flood_area.x2;
break;
default:
break;
} }
switch(ext->fit_top) { switch(ext->fit_top) {
case LV_FIT_TIGHT: new_area.y1 = tight_area.y1; break; case LV_FIT_TIGHT:
case LV_FIT_PARENT: new_area.y1 = flood_area.y1; break; new_area.y1 = tight_area.y1;
case LV_FIT_MAX: new_area.y1 = has_children ? LV_MATH_MIN(tight_area.y1, flood_area.y1) : flood_area.y1; break; break;
default: break; case LV_FIT_PARENT:
new_area.y1 = flood_area.y1;
break;
case LV_FIT_MAX:
new_area.y1 = has_children ? LV_MATH_MIN(tight_area.y1, flood_area.y1) : flood_area.y1;
break;
default:
break;
} }
switch(ext->fit_bottom) { switch(ext->fit_bottom) {
case LV_FIT_TIGHT: new_area.y2 = tight_area.y2; break; case LV_FIT_TIGHT:
case LV_FIT_PARENT: new_area.y2 = flood_area.y2; break; new_area.y2 = tight_area.y2;
case LV_FIT_MAX: new_area.y2 = has_children ? LV_MATH_MAX(tight_area.y2, flood_area.y2) : flood_area.y2; break; break;
default: break; case LV_FIT_PARENT:
new_area.y2 = flood_area.y2;
break;
case LV_FIT_MAX:
new_area.y2 = has_children ? LV_MATH_MAX(tight_area.y2, flood_area.y2) : flood_area.y2;
break;
default:
break;
} }
/*Do nothing if the coordinates are not changed*/ /*Do nothing if the coordinates are not changed*/

View File

@@ -97,8 +97,7 @@ enum {
}; };
typedef uint8_t lv_fit_t; typedef uint8_t lv_fit_t;
typedef struct typedef struct {
{
/*Inherited from 'base_obj' so no inherited ext. */ /*Ext. of ancestor*/ /*Inherited from 'base_obj' so no inherited ext. */ /*Ext. of ancestor*/
/*New data for this type */ /*New data for this type */
lv_layout_t layout : 4; /*A layout from 'lv_layout_t' enum*/ lv_layout_t layout : 4; /*A layout from 'lv_layout_t' enum*/

View File

@@ -23,27 +23,27 @@
#define LV_OBJX_NAME "lv_cpicker" #define LV_OBJX_NAME "lv_cpicker"
#ifndef LV_CPICKER_DEF_TYPE #ifndef LV_CPICKER_DEF_TYPE
#define LV_CPICKER_DEF_TYPE LV_CPICKER_TYPE_DISC #define LV_CPICKER_DEF_TYPE LV_CPICKER_TYPE_DISC
#endif #endif
#ifndef LV_CPICKER_DEF_HUE #ifndef LV_CPICKER_DEF_HUE
#define LV_CPICKER_DEF_HUE 0 #define LV_CPICKER_DEF_HUE 0
#endif #endif
#ifndef LV_CPICKER_DEF_SATURATION #ifndef LV_CPICKER_DEF_SATURATION
#define LV_CPICKER_DEF_SATURATION 100 #define LV_CPICKER_DEF_SATURATION 100
#endif #endif
#ifndef LV_CPICKER_DEF_VALUE #ifndef LV_CPICKER_DEF_VALUE
#define LV_CPICKER_DEF_VALUE 100 #define LV_CPICKER_DEF_VALUE 100
#endif #endif
#ifndef LV_CPICKER_DEF_HSV #ifndef LV_CPICKER_DEF_HSV
#define LV_CPICKER_DEF_HSV ((lv_color_hsv_t){LV_CPICKER_DEF_HUE, LV_CPICKER_DEF_SATURATION, LV_CPICKER_DEF_VALUE}) #define LV_CPICKER_DEF_HSV ((lv_color_hsv_t){LV_CPICKER_DEF_HUE, LV_CPICKER_DEF_SATURATION, LV_CPICKER_DEF_VALUE})
#endif #endif
#ifndef LV_CPICKER_DEF_QF /*quantization factor*/ #ifndef LV_CPICKER_DEF_QF /*quantization factor*/
#define LV_CPICKER_DEF_QF 3 #define LV_CPICKER_DEF_QF 3
#endif #endif
#define TRI_OFFSET 2 #define TRI_OFFSET 2
@@ -225,19 +225,19 @@ bool lv_cpicker_set_hsv(lv_obj_t * cpicker, lv_color_hsv_t hsv)
{ {
LV_ASSERT_OBJ(cpicker, LV_OBJX_NAME); LV_ASSERT_OBJ(cpicker, LV_OBJX_NAME);
if (hsv.h > 360) hsv.h %= 360; if(hsv.h > 360) hsv.h %= 360;
if (hsv.s > 100) hsv.s = 100; if(hsv.s > 100) hsv.s = 100;
if (hsv.v > 100) hsv.v = 100; if(hsv.v > 100) hsv.v = 100;
lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker);
if (ext->hsv.h == hsv.h && ext->hsv.s == hsv.s && ext->hsv.v == hsv.v) return false; if(ext->hsv.h == hsv.h && ext->hsv.s == hsv.s && ext->hsv.v == hsv.v) return false;
ext->hsv = hsv; ext->hsv = hsv;
refr_indic_pos(cpicker); refr_indic_pos(cpicker);
if (ext->type == LV_CPICKER_TYPE_DISC) { if(ext->type == LV_CPICKER_TYPE_DISC) {
lv_obj_invalidate(cpicker); lv_obj_invalidate(cpicker);
} }
@@ -452,7 +452,8 @@ static lv_design_res_t lv_cpicker_design(lv_obj_t * cpicker, const lv_area_t * c
if(ext->type == LV_CPICKER_TYPE_DISC) { if(ext->type == LV_CPICKER_TYPE_DISC) {
draw_disc_grad(cpicker, clip_area); draw_disc_grad(cpicker, clip_area);
} else if(ext->type == LV_CPICKER_TYPE_RECT) { }
else if(ext->type == LV_CPICKER_TYPE_RECT) {
draw_rect_grad(cpicker, clip_area); draw_rect_grad(cpicker, clip_area);
} }
@@ -482,14 +483,14 @@ static void draw_disc_grad(lv_obj_t * cpicker, const lv_area_t * mask)
uint16_t i; uint16_t i;
lv_coord_t cir_w = lv_obj_get_style_scale_width(cpicker, LV_CPICKER_PART_MAIN); lv_coord_t cir_w = lv_obj_get_style_scale_width(cpicker, LV_CPICKER_PART_MAIN);
for(i = 0; i <= 360; i+= LV_CPICKER_DEF_QF) { for(i = 0; i <= 360; i += LV_CPICKER_DEF_QF) {
line_dsc.color = angle_to_mode_color(cpicker, i); line_dsc.color = angle_to_mode_color(cpicker, i);
lv_point_t p[2]; lv_point_t p[2];
p[0].x = cx + (r * lv_trigo_sin(i) >> LV_TRIGO_SHIFT); p[0].x = cx + (r * lv_trigo_sin(i) >> LV_TRIGO_SHIFT);
p[0].y = cy + (r * lv_trigo_sin(i+ 90) >> LV_TRIGO_SHIFT); p[0].y = cy + (r * lv_trigo_sin(i + 90) >> LV_TRIGO_SHIFT);
p[1].x = cx + ((r-cir_w) * lv_trigo_sin(i) >> LV_TRIGO_SHIFT); p[1].x = cx + ((r - cir_w) * lv_trigo_sin(i) >> LV_TRIGO_SHIFT);
p[1].y = cy + ((r-cir_w) * lv_trigo_sin(i+ 90) >> LV_TRIGO_SHIFT); p[1].y = cy + ((r - cir_w) * lv_trigo_sin(i + 90) >> LV_TRIGO_SHIFT);
lv_draw_line(&p[0], &p[1], mask, &line_dsc); lv_draw_line(&p[0], &p[1], mask, &line_dsc);
} }
@@ -662,7 +663,8 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p
if(sign == LV_SIGNAL_CLEANUP) { if(sign == LV_SIGNAL_CLEANUP) {
lv_obj_clean_style_list(cpicker, LV_CPICKER_PART_INDIC); lv_obj_clean_style_list(cpicker, LV_CPICKER_PART_INDIC);
} else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { }
else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) {
lv_style_int_t left = lv_obj_get_style_pad_left(cpicker, LV_CPICKER_PART_INDIC); lv_style_int_t left = lv_obj_get_style_pad_left(cpicker, LV_CPICKER_PART_INDIC);
lv_style_int_t right = lv_obj_get_style_pad_right(cpicker, LV_CPICKER_PART_INDIC); lv_style_int_t right = lv_obj_get_style_pad_right(cpicker, LV_CPICKER_PART_INDIC);
lv_style_int_t top = lv_obj_get_style_pad_top(cpicker, LV_CPICKER_PART_INDIC); lv_style_int_t top = lv_obj_get_style_pad_top(cpicker, LV_CPICKER_PART_INDIC);
@@ -672,11 +674,13 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p
if(ext->type == LV_CPICKER_TYPE_DISC) { if(ext->type == LV_CPICKER_TYPE_DISC) {
cpicker->ext_draw_pad = LV_MATH_MAX(cpicker->ext_draw_pad, indic_pad); cpicker->ext_draw_pad = LV_MATH_MAX(cpicker->ext_draw_pad, indic_pad);
} else { }
else {
indic_pad += lv_obj_get_height(cpicker) / 2; indic_pad += lv_obj_get_height(cpicker) / 2;
cpicker->ext_draw_pad = LV_MATH_MAX(cpicker->ext_draw_pad, indic_pad); cpicker->ext_draw_pad = LV_MATH_MAX(cpicker->ext_draw_pad, indic_pad);
} }
} else if(sign == LV_SIGNAL_COORD_CHG) { }
else if(sign == LV_SIGNAL_COORD_CHG) {
/*Refresh extended draw area to make knob visible*/ /*Refresh extended draw area to make knob visible*/
if(lv_obj_get_width(cpicker) != lv_area_get_width(param) || if(lv_obj_get_width(cpicker) != lv_area_get_width(param) ||
lv_obj_get_height(cpicker) != lv_area_get_height(param)) { lv_obj_get_height(cpicker) != lv_area_get_height(param)) {
@@ -684,7 +688,8 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p
refr_indic_pos(cpicker); refr_indic_pos(cpicker);
lv_obj_invalidate(cpicker); lv_obj_invalidate(cpicker);
} }
} else if(sign == LV_SIGNAL_STYLE_CHG) { }
else if(sign == LV_SIGNAL_STYLE_CHG) {
/*Refresh extended draw area to make knob visible*/ /*Refresh extended draw area to make knob visible*/
lv_obj_refresh_ext_draw_pad(cpicker); lv_obj_refresh_ext_draw_pad(cpicker);
refr_indic_pos(cpicker); refr_indic_pos(cpicker);
@@ -708,7 +713,7 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p
break; break;
} }
if (lv_cpicker_set_hsv(cpicker, hsv_cur)) { if(lv_cpicker_set_hsv(cpicker, hsv_cur)) {
res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL); res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
} }
@@ -719,17 +724,17 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p
switch(ext->color_mode) { switch(ext->color_mode) {
case LV_CPICKER_COLOR_MODE_HUE: case LV_CPICKER_COLOR_MODE_HUE:
hsv_cur.h = ext->hsv.h > 0?(ext->hsv.h - 1) : 360; hsv_cur.h = ext->hsv.h > 0 ? (ext->hsv.h - 1) : 360;
break; break;
case LV_CPICKER_COLOR_MODE_SATURATION: case LV_CPICKER_COLOR_MODE_SATURATION:
hsv_cur.s = ext->hsv.s > 0?(ext->hsv.s - 1) : 100; hsv_cur.s = ext->hsv.s > 0 ? (ext->hsv.s - 1) : 100;
break; break;
case LV_CPICKER_COLOR_MODE_VALUE: case LV_CPICKER_COLOR_MODE_VALUE:
hsv_cur.v = ext->hsv.v > 0?(ext->hsv.v - 1) : 100; hsv_cur.v = ext->hsv.v > 0 ? (ext->hsv.v - 1) : 100;
break; break;
} }
if (lv_cpicker_set_hsv(cpicker, hsv_cur)) { if(lv_cpicker_set_hsv(cpicker, hsv_cur)) {
res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL); res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
} }
@@ -740,7 +745,8 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p
lv_indev_get_point(lv_indev_get_act(), &ext->last_press_point); lv_indev_get_point(lv_indev_get_act(), &ext->last_press_point);
res = double_click_reset(cpicker); res = double_click_reset(cpicker);
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
} else if(sign == LV_SIGNAL_PRESSING) { }
else if(sign == LV_SIGNAL_PRESSING) {
lv_indev_t * indev = lv_indev_get_act(); lv_indev_t * indev = lv_indev_get_act();
if(indev == NULL) return res; if(indev == NULL) return res;
@@ -775,7 +781,8 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p
if(angle < 0) angle = 0; if(angle < 0) angle = 0;
if(angle >= 360) angle = 359; if(angle >= 360) angle = 359;
} else if(ext->type == LV_CPICKER_TYPE_DISC) { }
else if(ext->type == LV_CPICKER_TYPE_DISC) {
lv_style_int_t scale_w = lv_obj_get_style_scale_width(cpicker, LV_CPICKER_PART_MAIN); lv_style_int_t scale_w = lv_obj_get_style_scale_width(cpicker, LV_CPICKER_PART_MAIN);
lv_coord_t r_in = w / 2; lv_coord_t r_in = w / 2;
@@ -823,12 +830,13 @@ static lv_res_t lv_cpicker_signal(lv_obj_t * cpicker, lv_signal_t sign, void * p
break; break;
} }
if (lv_cpicker_set_hsv(cpicker, hsv_cur)) { if(lv_cpicker_set_hsv(cpicker, hsv_cur)) {
res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL); res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
} }
} else if(sign == LV_SIGNAL_HIT_TEST) { }
lv_hit_test_info_t *info = param; else if(sign == LV_SIGNAL_HIT_TEST) {
lv_hit_test_info_t * info = param;
info->result = lv_cpicker_hit(cpicker, info->point); info->result = lv_cpicker_hit(cpicker, info->point);
} }
@@ -911,7 +919,8 @@ static void refr_indic_pos(lv_obj_t * cpicker)
ext->indic.pos.x = ind_pos; ext->indic.pos.x = ind_pos;
ext->indic.pos.y = h / 2; ext->indic.pos.y = h / 2;
} else if(ext->type == LV_CPICKER_TYPE_DISC) { }
else if(ext->type == LV_CPICKER_TYPE_DISC) {
lv_style_int_t scale_w = lv_obj_get_style_scale_width(cpicker, LV_CPICKER_PART_MAIN); lv_style_int_t scale_w = lv_obj_get_style_scale_width(cpicker, LV_CPICKER_PART_MAIN);
lv_coord_t r = (w - scale_w) / 2; lv_coord_t r = (w - scale_w) / 2;
uint16_t angle = get_angle(cpicker); uint16_t angle = get_angle(cpicker);
@@ -947,7 +956,7 @@ static lv_res_t double_click_reset(lv_obj_t * cpicker)
lv_indev_wait_release(indev); lv_indev_wait_release(indev);
if (lv_cpicker_set_hsv(cpicker, hsv_cur)) { if(lv_cpicker_set_hsv(cpicker, hsv_cur)) {
lv_res_t res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL); lv_res_t res = lv_event_send(cpicker, LV_EVENT_VALUE_CHANGED, NULL);
if(res != LV_RES_OK) return res; if(res != LV_RES_OK) return res;
} }
@@ -961,8 +970,7 @@ static lv_color_t angle_to_mode_color(lv_obj_t * cpicker, uint16_t angle)
{ {
lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker);
lv_color_t color; lv_color_t color;
switch(ext->color_mode) switch(ext->color_mode) {
{
default: default:
case LV_CPICKER_COLOR_MODE_HUE: case LV_CPICKER_COLOR_MODE_HUE:
color = lv_color_hsv_to_rgb(angle % 360, ext->hsv.s, ext->hsv.v); color = lv_color_hsv_to_rgb(angle % 360, ext->hsv.s, ext->hsv.v);
@@ -981,8 +989,7 @@ static uint16_t get_angle(lv_obj_t * cpicker)
{ {
lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker); lv_cpicker_ext_t * ext = lv_obj_get_ext_attr(cpicker);
uint16_t angle; uint16_t angle;
switch(ext->color_mode) switch(ext->color_mode) {
{
default: default:
case LV_CPICKER_COLOR_MODE_HUE: case LV_CPICKER_COLOR_MODE_HUE:
angle = ext->hsv.h; angle = ext->hsv.h;

View File

@@ -48,15 +48,15 @@ typedef struct {
struct { struct {
lv_style_list_t style_list; lv_style_list_t style_list;
lv_point_t pos; lv_point_t pos;
uint8_t colored :1; uint8_t colored : 1;
} indic; } indic;
uint32_t last_click_time; uint32_t last_click_time;
uint32_t last_change_time; uint32_t last_change_time;
lv_point_t last_press_point; lv_point_t last_press_point;
lv_cpicker_color_mode_t color_mode :2; lv_cpicker_color_mode_t color_mode : 2;
uint8_t color_mode_fixed :1; uint8_t color_mode_fixed : 1;
lv_cpicker_type_t type :1; lv_cpicker_type_t type : 1;
} lv_cpicker_ext_t; } lv_cpicker_ext_t;
/*Parts*/ /*Parts*/

View File

@@ -25,8 +25,8 @@
#define LV_OBJX_NAME "lv_dropdown" #define LV_OBJX_NAME "lv_dropdown"
#if LV_USE_ANIMATION == 0 #if LV_USE_ANIMATION == 0
#undef LV_DROPDOWN_DEF_ANIM_TIME #undef LV_DROPDOWN_DEF_ANIM_TIME
#define LV_DROPDOWN_DEF_ANIM_TIME 0 /*No animation*/ #define LV_DROPDOWN_DEF_ANIM_TIME 0 /*No animation*/
#endif #endif
#define LV_DROPDOWN_PR_NONE 0xFFFF #define LV_DROPDOWN_PR_NONE 0xFFFF
@@ -34,11 +34,10 @@
/********************** /**********************
* TYPEDEFS * TYPEDEFS
**********************/ **********************/
typedef struct typedef struct {
{
lv_page_ext_t page; lv_page_ext_t page;
lv_obj_t * ddlist; /*Pointer to the ddlist where the page belongs*/ lv_obj_t * ddlist; /*Pointer to the ddlist where the page belongs*/
}lv_dropdown_page_ext_t; } lv_dropdown_page_ext_t;
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
@@ -57,8 +56,8 @@ static uint16_t get_id_on_point(lv_obj_t * ddlist, lv_coord_t x, lv_coord_t y);
static void pos_selected(lv_obj_t * ddlist); static void pos_selected(lv_obj_t * ddlist);
static lv_obj_t * get_label(const lv_obj_t * ddlist); static lv_obj_t * get_label(const lv_obj_t * ddlist);
#if LV_USE_ANIMATION #if LV_USE_ANIMATION
static void list_anim(void * p, lv_anim_value_t v); static void list_anim(void * p, lv_anim_value_t v);
static void close_anim_ready(lv_anim_t * a); static void close_anim_ready(lv_anim_t * a);
#endif #endif
/********************** /**********************
@@ -237,7 +236,8 @@ void lv_dropdown_set_max_height(lv_obj_t * ddlist, lv_coord_t h)
if(ext->page) { if(ext->page) {
if(h == 0) { if(h == 0) {
lv_cont_set_fit(ext->page, LV_FIT_TIGHT); lv_cont_set_fit(ext->page, LV_FIT_TIGHT);
} else { }
else {
lv_cont_set_fit2(ext->page, LV_FIT_TIGHT, LV_FIT_NONE); lv_cont_set_fit2(ext->page, LV_FIT_TIGHT, LV_FIT_NONE);
lv_obj_set_height(ext->page, h); lv_obj_set_height(ext->page, h);
} }
@@ -539,7 +539,8 @@ void lv_dropdown_close(lv_obj_t * ddlist, lv_anim_enable_t anim)
#endif #endif
lv_obj_del(ext->page); lv_obj_del(ext->page);
ext->page = NULL; ext->page = NULL;
} else { }
else {
#if LV_USE_ANIMATION #if LV_USE_ANIMATION
if(ext->dir != LV_DROPDOWN_DIR_UP) { if(ext->dir != LV_DROPDOWN_DIR_UP) {
lv_anim_t a; lv_anim_t a;
@@ -550,7 +551,8 @@ void lv_dropdown_close(lv_obj_t * ddlist, lv_anim_enable_t anim)
lv_anim_set_time(&a, ext->anim_time); lv_anim_set_time(&a, ext->anim_time);
lv_anim_set_ready_cb(&a, close_anim_ready); lv_anim_set_ready_cb(&a, close_anim_ready);
lv_anim_start(&a); lv_anim_start(&a);
} else { }
else {
lv_anim_del(ddlist, list_anim); lv_anim_del(ddlist, list_anim);
lv_obj_del(ext->page); lv_obj_del(ext->page);
ext->page = NULL; ext->page = NULL;
@@ -608,7 +610,8 @@ static lv_design_res_t lv_dropdown_design(lv_obj_t * ddlist, const lv_area_t * c
txt = ext->dir != LV_DROPDOWN_DIR_LEFT ? opt_txt : ext->symbol; txt = ext->dir != LV_DROPDOWN_DIR_LEFT ? opt_txt : ext->symbol;
if(txt) { if(txt) {
lv_txt_get_size(&txt_size, txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, label_dsc.flag); lv_txt_get_size(&txt_size, txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX,
label_dsc.flag);
txt_area.y1 = ddlist->coords.y1 + top; txt_area.y1 = ddlist->coords.y1 + top;
txt_area.y2 = txt_area.y1 + txt_size.y; txt_area.y2 = txt_area.y1 + txt_size.y;
@@ -617,7 +620,8 @@ static lv_design_res_t lv_dropdown_design(lv_obj_t * ddlist, const lv_area_t * c
if(ext->symbol == NULL && txt == opt_txt) { if(ext->symbol == NULL && txt == opt_txt) {
txt_area.x1 = ddlist->coords.x1 + (lv_obj_get_width(ddlist) - txt_size.x) / 2; txt_area.x1 = ddlist->coords.x1 + (lv_obj_get_width(ddlist) - txt_size.x) / 2;
txt_area.x2 = txt_area.x1 + txt_size.x; txt_area.x2 = txt_area.x1 + txt_size.x;
} else { }
else {
txt_area.x1 = ddlist->coords.x1 + left; txt_area.x1 = ddlist->coords.x1 + left;
txt_area.x2 = txt_area.x1 + txt_size.x; txt_area.x2 = txt_area.x1 + txt_size.x;
} }
@@ -626,7 +630,8 @@ static lv_design_res_t lv_dropdown_design(lv_obj_t * ddlist, const lv_area_t * c
txt = ext->dir != LV_DROPDOWN_DIR_LEFT ? ext->symbol : opt_txt; txt = ext->dir != LV_DROPDOWN_DIR_LEFT ? ext->symbol : opt_txt;
if(txt) { if(txt) {
lv_txt_get_size(&txt_size, txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, label_dsc.flag); lv_txt_get_size(&txt_size, txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX,
label_dsc.flag);
txt_area.y1 = ddlist->coords.y1 + top; txt_area.y1 = ddlist->coords.y1 + top;
txt_area.y2 = txt_area.y1 + txt_size.y; txt_area.y2 = txt_area.y1 + txt_size.y;
@@ -634,7 +639,8 @@ static lv_design_res_t lv_dropdown_design(lv_obj_t * ddlist, const lv_area_t * c
if(ext->symbol == NULL && txt == opt_txt) { if(ext->symbol == NULL && txt == opt_txt) {
txt_area.x1 = ddlist->coords.x1 + (lv_obj_get_width(ddlist) - txt_size.x) / 2; txt_area.x1 = ddlist->coords.x1 + (lv_obj_get_width(ddlist) - txt_size.x) / 2;
txt_area.x2 = txt_area.x1 + txt_size.x; txt_area.x2 = txt_area.x1 + txt_size.x;
} else { }
else {
txt_area.x1 = ddlist->coords.x2 - right - txt_size.x; txt_area.x1 = ddlist->coords.x2 - right - txt_size.x;
txt_area.x2 = txt_area.x1 + txt_size.x; txt_area.x2 = txt_area.x1 + txt_size.x;
} }
@@ -646,7 +652,8 @@ static lv_design_res_t lv_dropdown_design(lv_obj_t * ddlist, const lv_area_t * c
lv_mem_buf_release((char *)opt_txt); lv_mem_buf_release((char *)opt_txt);
} }
} else if(mode == LV_DESIGN_DRAW_POST) { }
else if(mode == LV_DESIGN_DRAW_POST) {
ancestor_design(ddlist, clip_area, mode); ancestor_design(ddlist, clip_area, mode);
} }
@@ -771,7 +778,8 @@ static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * p
lv_dropdown_close(ddlist, LV_ANIM_ON); lv_dropdown_close(ddlist, LV_ANIM_ON);
} }
#endif #endif
} else if(sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_LEAVE) { }
else if(sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_LEAVE) {
lv_dropdown_close(ddlist, LV_ANIM_ON); lv_dropdown_close(ddlist, LV_ANIM_ON);
} }
else if(sign == LV_SIGNAL_RELEASED) { else if(sign == LV_SIGNAL_RELEASED) {
@@ -782,7 +790,8 @@ static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * p
ext->sel_opt_id_orig = ext->sel_opt_id; ext->sel_opt_id_orig = ext->sel_opt_id;
lv_obj_invalidate(ddlist); lv_obj_invalidate(ddlist);
} }
} else { }
else {
lv_dropdown_open(ddlist, LV_ANIM_ON); lv_dropdown_open(ddlist, LV_ANIM_ON);
} }
} }
@@ -807,24 +816,28 @@ static lv_res_t lv_dropdown_signal(lv_obj_t * ddlist, lv_signal_t sign, void * p
if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN) { if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN) {
if(ext->page == NULL) { if(ext->page == NULL) {
lv_dropdown_open(ddlist, LV_ANIM_ON); lv_dropdown_open(ddlist, LV_ANIM_ON);
} else if(ext->sel_opt_id + 1 < ext->option_cnt) { }
else if(ext->sel_opt_id + 1 < ext->option_cnt) {
ext->sel_opt_id++; ext->sel_opt_id++;
pos_selected(ddlist); pos_selected(ddlist);
} }
} else if(c == LV_KEY_LEFT || c == LV_KEY_UP) { }
else if(c == LV_KEY_LEFT || c == LV_KEY_UP) {
if(ext->page == NULL) { if(ext->page == NULL) {
lv_dropdown_open(ddlist, LV_ANIM_ON); lv_dropdown_open(ddlist, LV_ANIM_ON);
} else if(ext->sel_opt_id > 0) { }
else if(ext->sel_opt_id > 0) {
ext->sel_opt_id--; ext->sel_opt_id--;
pos_selected(ddlist); pos_selected(ddlist);
} }
} else if(c == LV_KEY_ESC) { }
else if(c == LV_KEY_ESC) {
ext->sel_opt_id = ext->sel_opt_id_orig; ext->sel_opt_id = ext->sel_opt_id_orig;
lv_dropdown_close(ddlist, LV_ANIM_ON); lv_dropdown_close(ddlist, LV_ANIM_ON);
} }
} }
else if(sign == LV_SIGNAL_GET_EDITABLE) { else if(sign == LV_SIGNAL_GET_EDITABLE) {
bool * editable = (bool *)param; bool * editable = (bool *)param;
*editable = true; *editable = true;
} }
@@ -859,13 +872,16 @@ static lv_res_t lv_dropdown_page_signal(lv_obj_t * page, lv_signal_t sign, void
lv_style_int_t right = lv_obj_get_style_pad_right(ddlist, LV_DROPDOWN_PART_LIST); lv_style_int_t right = lv_obj_get_style_pad_right(ddlist, LV_DROPDOWN_PART_LIST);
lv_obj_t * scrl = lv_page_get_scrl(page); lv_obj_t * scrl = lv_page_get_scrl(page);
scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, LV_MATH_MAX(left, right)); scrl->ext_draw_pad = LV_MATH_MAX(scrl->ext_draw_pad, LV_MATH_MAX(left, right));
} else if(sign == LV_SIGNAL_RELEASED) { }
else if(sign == LV_SIGNAL_RELEASED) {
if(lv_indev_is_dragging(lv_indev_get_act()) == false) { if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
page_release_handler(page); page_release_handler(page);
} }
} else if(sign == LV_SIGNAL_PRESSED) { }
else if(sign == LV_SIGNAL_PRESSED) {
page_press_handler(page); page_press_handler(page);
} else if(sign == LV_SIGNAL_CLEANUP) { }
else if(sign == LV_SIGNAL_CLEANUP) {
lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist); lv_dropdown_ext_t * ext = lv_obj_get_ext_attr(ddlist);
ext->page = NULL; /*The page is just being deleted*/ ext->page = NULL; /*The page is just being deleted*/
} }
@@ -898,9 +914,11 @@ static lv_res_t lv_dropdown_page_scrl_signal(lv_obj_t * scrl, lv_signal_t sign,
if(lv_indev_is_dragging(lv_indev_get_act()) == false) { if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
page_release_handler(page); page_release_handler(page);
} }
} else if(sign == LV_SIGNAL_PRESSED) { }
else if(sign == LV_SIGNAL_PRESSED) {
page_press_handler(page); page_press_handler(page);
} else if(sign == LV_SIGNAL_DRAG_BEGIN) { }
else if(sign == LV_SIGNAL_DRAG_BEGIN) {
ext->pr_opt_id = LV_DROPDOWN_PR_NONE; ext->pr_opt_id = LV_DROPDOWN_PR_NONE;
lv_obj_invalidate(page); lv_obj_invalidate(page);
} }
@@ -997,7 +1015,8 @@ static void draw_box_label(lv_obj_t * ddlist, const lv_area_t * clip_area, uint1
lv_draw_label_dsc_t label_dsc; lv_draw_label_dsc_t label_dsc;
lv_draw_label_dsc_init(&label_dsc); lv_draw_label_dsc_init(&label_dsc);
lv_obj_init_draw_label_dsc(ddlist, LV_DROPDOWN_PART_SELECTED, &label_dsc); lv_obj_init_draw_label_dsc(ddlist, LV_DROPDOWN_PART_SELECTED, &label_dsc);
label_dsc.line_space = lv_obj_get_style_text_line_space(ddlist, LV_DROPDOWN_PART_LIST); /*Line space should come from the page*/ label_dsc.line_space = lv_obj_get_style_text_line_space(ddlist,
LV_DROPDOWN_PART_LIST); /*Line space should come from the page*/
lv_coord_t font_h = lv_font_get_line_height(label_dsc.font); lv_coord_t font_h = lv_font_get_line_height(label_dsc.font);
lv_obj_t * label = get_label(ddlist); lv_obj_t * label = get_label(ddlist);

Some files were not shown because too many files have changed in this diff Show More