remove btn ink effect
It was too specific and probably can't be used directly in real life projects
This commit is contained in:
@@ -36,27 +36,12 @@
|
||||
static lv_design_res_t lv_btn_design(lv_obj_t * btn, const lv_area_t * clip_area, lv_design_mode_t mode);
|
||||
static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param);
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
static void lv_btn_ink_effect_anim(lv_obj_t * btn, lv_anim_value_t val);
|
||||
static void lv_btn_ink_effect_anim_ready(lv_anim_t * a);
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static lv_signal_cb_t ancestor_signal;
|
||||
static lv_design_cb_t ancestor_design;
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
static lv_coord_t ink_act_value;
|
||||
static lv_obj_t * ink_obj;
|
||||
static lv_btn_state_t ink_bg_state;
|
||||
static lv_btn_state_t ink_top_state;
|
||||
static bool ink_ready;
|
||||
static bool ink_playback;
|
||||
static lv_point_t ink_point;
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
@@ -94,12 +79,6 @@ lv_obj_t * lv_btn_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
|
||||
ext->toggle = 0;
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
ext->ink_in_time = 0;
|
||||
ext->ink_wait_time = 0;
|
||||
ext->ink_out_time = 0;
|
||||
#endif
|
||||
|
||||
lv_obj_set_signal_cb(new_btn, lv_btn_signal);
|
||||
lv_obj_set_design_cb(new_btn, lv_btn_design);
|
||||
|
||||
@@ -120,11 +99,7 @@ lv_obj_t * lv_btn_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
else {
|
||||
lv_btn_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
||||
ext->toggle = copy_ext->toggle;
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
ext->ink_in_time = copy_ext->ink_in_time;
|
||||
ext->ink_wait_time = copy_ext->ink_wait_time;
|
||||
ext->ink_out_time = copy_ext->ink_out_time;
|
||||
#endif
|
||||
|
||||
// memcpy((void*) ext->styles, copy_ext->styles, sizeof(ext->styles));
|
||||
|
||||
/*Refresh the style with new signal function*/
|
||||
@@ -196,67 +171,6 @@ void lv_btn_toggle(lv_obj_t * btn)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set time of the ink effect (draw a circle on click to animate in the new state)
|
||||
* @param btn pointer to a button object
|
||||
* @param time the time of the ink animation
|
||||
*/
|
||||
void lv_btn_set_ink_in_time(lv_obj_t * btn, uint16_t time)
|
||||
{
|
||||
LV_ASSERT_OBJ(btn, LV_OBJX_NAME);
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
|
||||
ext->ink_in_time = time;
|
||||
#else
|
||||
(void)btn; /*Unused*/
|
||||
(void)time; /*Unused*/
|
||||
LV_LOG_WARN("`lv_btn_set_ink_ink_time` has no effect if LV_BTN_INK_EFEFCT or LV_USE_ANIMATION "
|
||||
"is disabled")
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the wait time before the ink disappears
|
||||
* @param btn pointer to a button object
|
||||
* @param time the time of the ink animation
|
||||
*/
|
||||
void lv_btn_set_ink_wait_time(lv_obj_t * btn, uint16_t time)
|
||||
{
|
||||
LV_ASSERT_OBJ(btn, LV_OBJX_NAME);
|
||||
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
|
||||
ext->ink_wait_time = time;
|
||||
#else
|
||||
(void)btn; /*Unused*/
|
||||
(void)time; /*Unused*/
|
||||
LV_LOG_WARN("`lv_btn_set_ink_wait_time` has no effect if LV_BTN_INK_EFEFCT or LV_USE_ANIMATION "
|
||||
"is disabled")
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Set time of the ink out effect (animate to the released state)
|
||||
* @param btn pointer to a button object
|
||||
* @param time the time of the ink animation
|
||||
*/
|
||||
void lv_btn_set_ink_out_time(lv_obj_t * btn, uint16_t time)
|
||||
{
|
||||
LV_ASSERT_OBJ(btn, LV_OBJX_NAME);
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
|
||||
ext->ink_out_time = time;
|
||||
#else
|
||||
(void)btn; /*Unused*/
|
||||
(void)time; /*Unused*/
|
||||
LV_LOG_WARN("`lv_btn_set_ink_out_time` has no effect if LV_BTN_INK_EFEFCT or LV_USE_ANIMATION "
|
||||
"is disabled")
|
||||
#endif
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@@ -296,59 +210,6 @@ bool lv_btn_get_toggle(const lv_obj_t * btn)
|
||||
return ext->toggle != 0 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get time of the ink in effect (draw a circle on click to animate in the new state)
|
||||
* @param btn pointer to a button object
|
||||
* @return the time of the ink animation
|
||||
*/
|
||||
uint16_t lv_btn_get_ink_in_time(const lv_obj_t * btn)
|
||||
{
|
||||
LV_ASSERT_OBJ(btn, LV_OBJX_NAME);
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
|
||||
return ext->ink_in_time;
|
||||
#else
|
||||
(void)btn; /*Unused*/
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wait time before the ink disappears
|
||||
* @param btn pointer to a button object
|
||||
* @return the time of the ink animation
|
||||
*/
|
||||
uint16_t lv_btn_get_ink_wait_time(const lv_obj_t * btn)
|
||||
{
|
||||
LV_ASSERT_OBJ(btn, LV_OBJX_NAME);
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
|
||||
return ext->ink_wait_time;
|
||||
#else
|
||||
(void)btn; /*Unused*/
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
/**
|
||||
* Get time of the ink out effect (animate to the releases state)
|
||||
* @param btn pointer to a button object
|
||||
* @return the time of the ink animation
|
||||
*/
|
||||
uint16_t lv_btn_get_ink_out_time(const lv_obj_t * btn)
|
||||
{
|
||||
LV_ASSERT_OBJ(btn, LV_OBJX_NAME);
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
|
||||
return ext->ink_out_time;
|
||||
#else
|
||||
(void)btn; /*Unused*/
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
lv_style_dsc_t * lv_btn_get_style(lv_obj_t * cont, uint8_t type)
|
||||
{
|
||||
lv_style_dsc_t * style_dsc_p;
|
||||
@@ -383,67 +244,6 @@ static lv_design_res_t lv_btn_design(lv_obj_t * btn, const lv_area_t * clip_area
|
||||
return ancestor_design(btn, clip_area, mode);
|
||||
} else if(mode == LV_DESIGN_DRAW_MAIN) {
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
if(btn != ink_obj) {
|
||||
ancestor_design(btn, clip_area, mode);
|
||||
} else {
|
||||
lv_opa_t opa_scale = lv_obj_get_opa_scale(btn);
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(btn);
|
||||
|
||||
/*Draw the normal button*/
|
||||
if(ink_playback == false) {
|
||||
lv_style_t style_tmp;
|
||||
lv_style_copy(&style_tmp, ext->styles[ink_bg_state]);
|
||||
style_tmp.body.shadow.width = ext->styles[ink_top_state]->body.shadow.width;
|
||||
lv_draw_rect(&btn->coords, clip_area, &style_tmp, opa_scale);
|
||||
|
||||
lv_coord_t w = lv_obj_get_width(btn);
|
||||
lv_coord_t h = lv_obj_get_height(btn);
|
||||
lv_coord_t r_max = LV_MATH_MIN(w, h) / 2;
|
||||
|
||||
/*In the first part of the animation increase the size of the circle (ink effect) */
|
||||
lv_area_t cir_area;
|
||||
|
||||
lv_coord_t coord_state =
|
||||
ink_act_value < LV_BTN_INK_VALUE_MAX / 2 ? ink_act_value : LV_BTN_INK_VALUE_MAX / 2;
|
||||
lv_point_t p_act;
|
||||
p_act.x = ink_point.x;
|
||||
p_act.y = ink_point.y;
|
||||
lv_coord_t x_err = (btn->coords.x1 + w / 2) - p_act.x;
|
||||
lv_coord_t y_err = (btn->coords.y1 + h / 2) - p_act.y;
|
||||
|
||||
p_act.x += (x_err * coord_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1);
|
||||
p_act.y += (y_err * coord_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1);
|
||||
|
||||
lv_coord_t half_side = LV_MATH_MAX(w, h) / 2;
|
||||
cir_area.x1 = p_act.x - ((half_side * coord_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1));
|
||||
cir_area.y1 = p_act.y - ((half_side * coord_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1));
|
||||
cir_area.x2 = p_act.x + ((half_side * coord_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1));
|
||||
cir_area.y2 = p_act.y + ((half_side * coord_state) >> (LV_BTN_INK_VALUE_MAX_SHIFT - 1));
|
||||
|
||||
lv_area_intersect(&cir_area, &btn->coords,
|
||||
&cir_area); /*Limit the area. (It might be too big on the smaller side)*/
|
||||
|
||||
/*In the second part animate the radius. Circle -> body.radius*/
|
||||
lv_coord_t r_state =
|
||||
ink_act_value > LV_BTN_INK_VALUE_MAX / 2 ? ink_act_value - LV_BTN_INK_VALUE_MAX / 2 : 0;
|
||||
|
||||
lv_style_copy(&style_tmp, ext->styles[ink_top_state]);
|
||||
style_tmp.body.radius = r_max + (((ext->styles[ink_bg_state]->body.radius - r_max) * r_state) >>
|
||||
(LV_BTN_INK_VALUE_MAX_SHIFT - 1));
|
||||
style_tmp.body.border.width = 0;
|
||||
|
||||
/*Draw the circle*/
|
||||
lv_draw_rect(&cir_area, clip_area, &style_tmp, opa_scale);
|
||||
} else {
|
||||
lv_style_t res;
|
||||
lv_style_copy(&res, ext->styles[ink_bg_state]);
|
||||
lv_style_mix(ext->styles[ink_bg_state], ext->styles[ink_top_state], &res, ink_act_value);
|
||||
lv_draw_rect(&btn->coords, clip_area, &res, opa_scale);
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
lv_draw_rect_dsc_t draw_dsc;
|
||||
lv_draw_rect_dsc_init(&draw_dsc);
|
||||
lv_obj_init_draw_rect_dsc(btn, LV_OBJ_PART_MAIN, &draw_dsc);
|
||||
@@ -458,7 +258,6 @@ static lv_design_res_t lv_btn_design(lv_obj_t * btn, const lv_area_t * clip_area
|
||||
/*Add the mask and use `obj+8` as custom id. Don't use `obj` directly because it might be used by the user*/
|
||||
lv_draw_mask_add(mp, btn + 8);
|
||||
}
|
||||
#endif
|
||||
} else if(mode == LV_DESIGN_DRAW_POST) {
|
||||
ancestor_design(btn, clip_area, mode);
|
||||
}
|
||||
@@ -488,48 +287,9 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
|
||||
/*Refresh the state*/
|
||||
if(state == LV_BTN_STATE_REL) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_PR);
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
ink_bg_state = LV_BTN_STATE_REL;
|
||||
ink_top_state = LV_BTN_STATE_PR;
|
||||
#endif
|
||||
} else if(state == LV_BTN_STATE_TGL_REL) {
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_PR);
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
ink_bg_state = LV_BTN_STATE_TGL_REL;
|
||||
ink_top_state = LV_BTN_STATE_TGL_PR;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
/*Forget the old inked button*/
|
||||
if(ink_obj != NULL && ink_obj != btn) {
|
||||
lv_anim_del(ink_obj, (lv_anim_exec_xcb_t)lv_btn_ink_effect_anim);
|
||||
lv_obj_invalidate(ink_obj);
|
||||
ink_obj = NULL;
|
||||
}
|
||||
/*Save the new data for inking and start it's animation if enabled*/
|
||||
if(ext->ink_in_time > 0) {
|
||||
ink_obj = btn;
|
||||
ink_playback = false;
|
||||
ink_ready = false;
|
||||
lv_indev_get_point(lv_indev_get_act(), &ink_point);
|
||||
|
||||
lv_anim_t a;
|
||||
a.var = btn;
|
||||
a.start = 0;
|
||||
a.end = LV_BTN_INK_VALUE_MAX;
|
||||
a.exec_cb = (lv_anim_exec_xcb_t)lv_btn_ink_effect_anim;
|
||||
a.path_cb = lv_anim_path_linear;
|
||||
a.ready_cb = lv_btn_ink_effect_anim_ready;
|
||||
a.act_time = 0;
|
||||
a.time = ext->ink_in_time;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
lv_anim_create(&a);
|
||||
}
|
||||
#endif
|
||||
} else if(sign == LV_SIGNAL_PRESS_LOST) {
|
||||
/*Refresh the state*/
|
||||
if(state == LV_BTN_STATE_PR)
|
||||
@@ -574,35 +334,6 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
|
||||
lv_btn_set_state(btn, LV_BTN_STATE_TGL_REL);
|
||||
}
|
||||
}
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
/*Draw the toggled state in the inking instead*/
|
||||
if(ext->toggle) {
|
||||
ink_top_state = ext->state;
|
||||
}
|
||||
/*If not a toggle button and the "IN" inking is ready then start an "OUT" inking*/
|
||||
else if(ink_ready && ext->ink_out_time > 0) {
|
||||
ink_obj = btn;
|
||||
ink_playback = true; /*It is the playback. If not set `lv_btn_ink_effect_anim_ready`
|
||||
will start its own playback*/
|
||||
lv_indev_get_point(lv_indev_get_act(), &ink_point);
|
||||
|
||||
lv_anim_t a;
|
||||
a.var = ink_obj;
|
||||
a.start = LV_BTN_INK_VALUE_MAX;
|
||||
a.end = 0;
|
||||
a.exec_cb = (lv_anim_exec_xcb_t)lv_btn_ink_effect_anim;
|
||||
a.path_cb = lv_anim_path_linear;
|
||||
a.ready_cb = lv_btn_ink_effect_anim_ready;
|
||||
a.act_time = 0;
|
||||
a.time = ext->ink_out_time;
|
||||
a.playback = 0;
|
||||
a.playback_pause = 0;
|
||||
a.repeat = 0;
|
||||
a.repeat_pause = 0;
|
||||
lv_anim_create(&a);
|
||||
}
|
||||
#endif
|
||||
} else if(sign == LV_SIGNAL_CONTROL) {
|
||||
char c = *((char *)param);
|
||||
if(c == LV_KEY_RIGHT || c == LV_KEY_UP) {
|
||||
@@ -623,68 +354,9 @@ static lv_res_t lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * param)
|
||||
if(res != LV_RES_OK) return res;
|
||||
}
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_CLEANUP) {
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
if(btn == ink_obj) {
|
||||
lv_anim_del(ink_obj, (lv_anim_exec_xcb_t)lv_btn_ink_effect_anim);
|
||||
ink_obj = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#if LV_USE_ANIMATION && LV_BTN_INK_EFFECT
|
||||
|
||||
/**
|
||||
* The animator function of inking. CAlled to increase the radius of ink
|
||||
* @param btn pointer to the animated button
|
||||
* @param val the new radius
|
||||
*/
|
||||
static void lv_btn_ink_effect_anim(lv_obj_t * btn, lv_anim_value_t val)
|
||||
{
|
||||
if(btn) {
|
||||
ink_act_value = val;
|
||||
lv_obj_invalidate(btn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to clean up when the ink animation is ready
|
||||
* @param a unused
|
||||
*/
|
||||
static void lv_btn_ink_effect_anim_ready(lv_anim_t * a)
|
||||
{
|
||||
(void)a; /*Unused*/
|
||||
|
||||
lv_btn_ext_t * ext = lv_obj_get_ext_attr(ink_obj);
|
||||
lv_btn_state_t state = lv_btn_get_state(ink_obj);
|
||||
|
||||
lv_obj_invalidate(ink_obj);
|
||||
ink_ready = true;
|
||||
|
||||
if((state == LV_BTN_STATE_REL || state == LV_BTN_STATE_TGL_REL) && ext->toggle == 0 && ink_playback == false) {
|
||||
lv_anim_t new_a;
|
||||
new_a.var = ink_obj;
|
||||
new_a.start = LV_BTN_INK_VALUE_MAX;
|
||||
new_a.end = 0;
|
||||
new_a.exec_cb = (lv_anim_exec_xcb_t)lv_btn_ink_effect_anim;
|
||||
new_a.path_cb = lv_anim_path_linear;
|
||||
new_a.ready_cb = lv_btn_ink_effect_anim_ready;
|
||||
new_a.act_time = -ext->ink_wait_time;
|
||||
new_a.time = ext->ink_out_time;
|
||||
new_a.playback = 0;
|
||||
new_a.playback_pause = 0;
|
||||
new_a.repeat = 0;
|
||||
new_a.repeat_pause = 0;
|
||||
lv_anim_create(&new_a);
|
||||
|
||||
ink_playback = true;
|
||||
} else {
|
||||
ink_obj = NULL;
|
||||
}
|
||||
}
|
||||
#endif /*LV_USE_ANIMATION*/
|
||||
|
||||
#endif
|
||||
|
||||
@@ -218,11 +218,9 @@ lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y)
|
||||
LV_ASSERT_OBJ(canvas, LV_OBJX_NAME);
|
||||
|
||||
lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas);
|
||||
const lv_style_t * style = lv_canvas_get_style(canvas, LV_CANVAS_STYLE_MAIN);
|
||||
lv_color_t color = lv_obj_get_style_color(canvas, LV_CANVAS_PART_MAIN, LV_STYLE_IMAGE_RECOLOR);
|
||||
|
||||
if(style == NULL) style = &lv_style_scr;
|
||||
|
||||
return lv_img_buf_get_px_color(&ext->dsc, x, y, style->image.color);
|
||||
return lv_img_buf_get_px_color(&ext->dsc, x, y, color);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,26 +237,6 @@ lv_img_dsc_t * lv_canvas_get_img(lv_obj_t * canvas)
|
||||
return &ext->dsc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get style of a canvas.
|
||||
* @param canvas pointer to canvas object
|
||||
* @param type which style should be get
|
||||
* @return style pointer to the style
|
||||
*/
|
||||
const lv_style_t * lv_canvas_get_style(const lv_obj_t * canvas, lv_canvas_style_t type)
|
||||
{
|
||||
LV_ASSERT_OBJ(canvas, LV_OBJX_NAME);
|
||||
|
||||
const lv_style_t * style = NULL;
|
||||
|
||||
switch(type) {
|
||||
case LV_CANVAS_STYLE_MAIN: style = lv_img_get_style(canvas, LV_IMG_STYLE_MAIN); break;
|
||||
default: style = NULL;
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
@@ -317,7 +295,7 @@ void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, u
|
||||
LV_ASSERT_NULL(img);
|
||||
|
||||
lv_canvas_ext_t * ext_dst = lv_obj_get_ext_attr(canvas);
|
||||
const lv_style_t * style = lv_canvas_get_style(canvas, LV_CANVAS_STYLE_MAIN);
|
||||
lv_color_t color = lv_obj_get_style_color(canvas, LV_CANVAS_PART_MAIN, LV_STYLE_IMAGE_RECOLOR);
|
||||
|
||||
int32_t dest_width = ext_dst->dsc.header.w;
|
||||
int32_t dest_height = ext_dst->dsc.header.h;
|
||||
@@ -335,7 +313,7 @@ void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, u
|
||||
dsc.cfg.cf = img->header.cf;
|
||||
dsc.cfg.pivot_x = pivot_x;
|
||||
dsc.cfg.pivot_y = pivot_y;
|
||||
dsc.cfg.color = style->image.color;
|
||||
dsc.cfg.color = color;
|
||||
dsc.cfg.antialias = antialias;
|
||||
lv_img_buf_transform_init(&dsc);
|
||||
|
||||
@@ -351,7 +329,7 @@ void lv_canvas_transform(lv_obj_t * canvas, lv_img_dsc_t * img, int16_t angle, u
|
||||
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);
|
||||
} else {
|
||||
lv_color_t bg_color = lv_img_buf_get_px_color(&ext_dst->dsc, x + offset_x, y + offset_y, style->image.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
|
||||
* canvas*/
|
||||
@@ -427,7 +405,7 @@ void lv_canvas_blur_hor(lv_obj_t * canvas, const lv_area_t * area, uint16_t r)
|
||||
a.y2 = ext->dsc.header.h - 1;
|
||||
}
|
||||
|
||||
const lv_style_t * style = lv_canvas_get_style(canvas, LV_CANVAS_STYLE_MAIN);
|
||||
lv_color_t color = lv_obj_get_style_color(canvas, LV_CANVAS_PART_MAIN, LV_STYLE_IMAGE_RECOLOR);
|
||||
|
||||
uint16_t r_back = r / 2;
|
||||
uint16_t r_front = r / 2;
|
||||
@@ -465,7 +443,7 @@ void lv_canvas_blur_hor(lv_obj_t * canvas, const lv_area_t * area, uint16_t r)
|
||||
x_safe = x < 0 ? 0 : x;
|
||||
x_safe = x_safe > ext->dsc.header.w - 1 ? ext->dsc.header.w - 1 : x_safe;
|
||||
|
||||
c = lv_img_buf_get_px_color(&line_img, x_safe, 0, style->image.color);
|
||||
c = lv_img_buf_get_px_color(&line_img, x_safe, 0, color);
|
||||
if(has_alpha) opa = lv_img_buf_get_px_alpha(&line_img, x_safe, 0);
|
||||
|
||||
rsum += c.ch.red;
|
||||
@@ -501,7 +479,7 @@ void lv_canvas_blur_hor(lv_obj_t * canvas, const lv_area_t * area, uint16_t r)
|
||||
|
||||
x_safe = x - r_back;
|
||||
x_safe = x_safe < 0 ? 0 : x_safe;
|
||||
c = lv_img_buf_get_px_color(&line_img, x_safe, 0, style->image.color);
|
||||
c = lv_img_buf_get_px_color(&line_img, x_safe, 0, color);
|
||||
if(has_alpha) opa = lv_img_buf_get_px_alpha(&line_img, x_safe, 0);
|
||||
|
||||
rsum -= c.ch.red;
|
||||
@@ -562,7 +540,7 @@ void lv_canvas_blur_ver(lv_obj_t * canvas, const lv_area_t * area, uint16_t r)
|
||||
a.y2 = ext->dsc.header.h - 1;
|
||||
}
|
||||
|
||||
const lv_style_t * style = lv_canvas_get_style(canvas, LV_CANVAS_STYLE_MAIN);
|
||||
lv_color_t color = lv_obj_get_style_color(canvas, LV_CANVAS_PART_MAIN, LV_STYLE_IMAGE_RECOLOR);
|
||||
|
||||
uint16_t r_back = r / 2;
|
||||
uint16_t r_front = r / 2;
|
||||
@@ -597,7 +575,7 @@ void lv_canvas_blur_ver(lv_obj_t * canvas, const lv_area_t * area, uint16_t r)
|
||||
y_safe = y < 0 ? 0 : y;
|
||||
y_safe = y_safe > ext->dsc.header.h - 1 ? ext->dsc.header.h - 1 : y_safe;
|
||||
|
||||
c = lv_img_buf_get_px_color(&ext->dsc, x, y_safe, style->image.color);
|
||||
c = lv_img_buf_get_px_color(&ext->dsc, x, y_safe, color);
|
||||
if(has_alpha) opa = lv_img_buf_get_px_alpha(&ext->dsc, x, y_safe);
|
||||
|
||||
lv_img_buf_set_px_color(&line_img, 0, y_safe, c);
|
||||
@@ -635,7 +613,7 @@ void lv_canvas_blur_ver(lv_obj_t * canvas, const lv_area_t * area, uint16_t r)
|
||||
|
||||
y_safe = y - r_back;
|
||||
y_safe = y_safe < 0 ? 0 : y_safe;
|
||||
c = lv_img_buf_get_px_color(&line_img, 0, y_safe, style->image.color);
|
||||
c = lv_img_buf_get_px_color(&line_img, 0, y_safe, color);
|
||||
if(has_alpha) opa = lv_img_buf_get_px_alpha(&line_img, 0, y_safe);
|
||||
|
||||
rsum -= c.ch.red;
|
||||
@@ -650,7 +628,7 @@ void lv_canvas_blur_ver(lv_obj_t * canvas, const lv_area_t * area, uint16_t r)
|
||||
y_safe = y + 1 + r_front;
|
||||
y_safe = y_safe > ext->dsc.header.h - 1 ? ext->dsc.header.h - 1 : y_safe;
|
||||
|
||||
c = lv_img_buf_get_px_color(&ext->dsc, x, y_safe, style->image.color);
|
||||
c = lv_img_buf_get_px_color(&ext->dsc, x, y_safe, color);
|
||||
if(has_alpha) opa = lv_img_buf_get_px_alpha(&ext->dsc, x, y_safe);
|
||||
|
||||
lv_img_buf_set_px_color(&line_img, 0, y_safe, c);
|
||||
@@ -703,10 +681,9 @@ void lv_canvas_fill_bg(lv_obj_t * canvas, lv_color_t color, lv_opa_t opa)
|
||||
* @param style style of the rectangle (`body` properties are used except `padding`)
|
||||
*/
|
||||
void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord_t w, lv_coord_t h,
|
||||
const lv_style_t * style)
|
||||
lv_draw_rect_dsc_t * rect_dsc)
|
||||
{
|
||||
LV_ASSERT_OBJ(canvas, LV_OBJX_NAME);
|
||||
LV_ASSERT_NULL(style);
|
||||
|
||||
lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);
|
||||
|
||||
@@ -749,8 +726,8 @@ 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*/
|
||||
lv_color_t ctransp = LV_COLOR_TRANSP;
|
||||
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED &&
|
||||
style->body.main_color.full == ctransp.full &&
|
||||
style->body.grad_color.full == ctransp.full)
|
||||
rect_dsc->bg_color.full == ctransp.full &&
|
||||
rect_dsc->bg_grad_color.full == ctransp.full)
|
||||
{
|
||||
disp.driver.antialiasing = 0;
|
||||
}
|
||||
@@ -759,7 +736,7 @@ void lv_canvas_draw_rect(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_coord
|
||||
lv_disp_t * refr_ori = lv_refr_get_disp_refreshing();
|
||||
lv_refr_set_disp_refreshing(&disp);
|
||||
|
||||
lv_draw_rect(&coords, &mask, style, LV_OPA_COVER);
|
||||
lv_draw_rect(&coords, &mask, rect_dsc);
|
||||
|
||||
lv_refr_set_disp_refreshing(refr_ori);
|
||||
}
|
||||
@@ -838,7 +815,7 @@ 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 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, const lv_style_t * style)
|
||||
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_NULL(style);
|
||||
@@ -889,7 +866,7 @@ void lv_canvas_draw_img(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, const voi
|
||||
lv_disp_t * refr_ori = lv_refr_get_disp_refreshing();
|
||||
lv_refr_set_disp_refreshing(&disp);
|
||||
|
||||
lv_draw_img(&coords, &mask, src, style, 0, NULL, LV_IMG_ZOOM_NONE, false, LV_OPA_COVER);
|
||||
lv_draw_img(&coords, &mask, src, img_draw_dsc);
|
||||
|
||||
lv_refr_set_disp_refreshing(refr_ori);
|
||||
}
|
||||
@@ -901,10 +878,9 @@ 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 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, const lv_style_t * style)
|
||||
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_NULL(style);
|
||||
|
||||
lv_img_dsc_t * dsc = lv_canvas_get_img(canvas);
|
||||
|
||||
@@ -939,8 +915,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*/
|
||||
lv_color_t ctransp = LV_COLOR_TRANSP;
|
||||
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED &&
|
||||
style->body.main_color.full == ctransp.full &&
|
||||
style->body.grad_color.full == ctransp.full)
|
||||
line_draw_dsc->color == ctransp.full)
|
||||
{
|
||||
disp.driver.antialiasing = 0;
|
||||
}
|
||||
@@ -949,35 +924,9 @@ void lv_canvas_draw_line(lv_obj_t * canvas, const lv_point_t * points, uint32_t
|
||||
lv_disp_t * refr_ori = lv_refr_get_disp_refreshing();
|
||||
lv_refr_set_disp_refreshing(&disp);
|
||||
|
||||
lv_style_t circle_style_tmp; /*If rounded...*/
|
||||
if(style->line.rounded) {
|
||||
lv_style_copy(&circle_style_tmp, style);
|
||||
circle_style_tmp.body.radius = LV_RADIUS_CIRCLE;
|
||||
circle_style_tmp.body.main_color = style->line.color;
|
||||
circle_style_tmp.body.grad_color = style->line.color;
|
||||
circle_style_tmp.body.opa = style->line.opa;
|
||||
}
|
||||
lv_area_t circle_area;
|
||||
uint32_t i;
|
||||
for(i = 0; i < point_cnt - 1; i++) {
|
||||
lv_draw_line(&points[i], &points[i + 1], &mask, style, LV_OPA_COVER);
|
||||
|
||||
/*Draw circle on the joints if enabled*/
|
||||
if(style->line.rounded) {
|
||||
circle_area.x1 = points[i].x - ((style->line.width - 1) >> 1) - ((style->line.width - 1) & 0x1);
|
||||
circle_area.y1 = points[i].y - ((style->line.width - 1) >> 1) - ((style->line.width - 1) & 0x1);
|
||||
circle_area.x2 = points[i].x + ((style->line.width - 1) >> 1);
|
||||
circle_area.y2 = points[i].y + ((style->line.width - 1) >> 1);
|
||||
lv_draw_rect(&circle_area, &mask, &circle_style_tmp, LV_OPA_COVER);
|
||||
}
|
||||
}
|
||||
/*Draw circle on the last point too if enabled*/
|
||||
if(style->line.rounded) {
|
||||
circle_area.x1 = points[i].x - ((style->line.width - 1) >> 1) - ((style->line.width - 1) & 0x1);
|
||||
circle_area.y1 = points[i].y - ((style->line.width - 1) >> 1) - ((style->line.width - 1) & 0x1);
|
||||
circle_area.x2 = points[i].x + ((style->line.width - 1) >> 1);
|
||||
circle_area.y2 = points[i].y + ((style->line.width - 1) >> 1);
|
||||
lv_draw_rect(&circle_area, &mask, &circle_style_tmp, LV_OPA_COVER);
|
||||
lv_draw_line(&points[i], &points[i + 1], &mask, line_draw_dsc);
|
||||
}
|
||||
|
||||
lv_refr_set_disp_refreshing(refr_ori);
|
||||
|
||||
@@ -36,11 +36,11 @@ typedef struct
|
||||
lv_img_dsc_t dsc;
|
||||
} lv_canvas_ext_t;
|
||||
|
||||
/*Styles*/
|
||||
/*Canvas part*/
|
||||
enum {
|
||||
LV_CANVAS_STYLE_MAIN,
|
||||
LV_CANVAS_PART_MAIN,
|
||||
};
|
||||
typedef uint8_t lv_canvas_style_t;
|
||||
typedef uint8_t lv_canvas_part_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
@@ -93,14 +93,6 @@ void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t
|
||||
*/
|
||||
void lv_canvas_set_palette(lv_obj_t * canvas, uint8_t id, lv_color_t c);
|
||||
|
||||
/**
|
||||
* Set a style of a canvas.
|
||||
* @param canvas pointer to canvas object
|
||||
* @param type which style should be set
|
||||
* @param style pointer to a style
|
||||
*/
|
||||
void lv_canvas_set_style(lv_obj_t * canvas, lv_canvas_style_t type, const lv_style_t * style);
|
||||
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
@@ -121,14 +113,6 @@ lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y);
|
||||
*/
|
||||
lv_img_dsc_t * lv_canvas_get_img(lv_obj_t * canvas);
|
||||
|
||||
/**
|
||||
* Get style of a canvas.
|
||||
* @param canvas pointer to canvas object
|
||||
* @param type which style should be get
|
||||
* @return style pointer to the style
|
||||
*/
|
||||
const lv_style_t * lv_canvas_get_style(const lv_obj_t * canvas, lv_canvas_style_t type);
|
||||
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
Reference in New Issue
Block a user