mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
add PATTERN_REPEAT again
It's good complementer of VALUE. PATTERN can be an image on a button and VALUE can be any extra text
This commit is contained in:
parent
0dd6de58b4
commit
0381cc60c5
@ -2737,6 +2737,7 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t
|
||||
if(draw_dsc->pattern_opa > LV_OPA_MIN) {
|
||||
draw_dsc->pattern_blend_mode = lv_obj_get_style_pattern_blend_mode(obj, part);
|
||||
draw_dsc->pattern_recolor_opa = lv_obj_get_style_pattern_recolor_opa(obj, part);
|
||||
draw_dsc->pattern_repeat = lv_obj_get_style_pattern_repeat(obj, part);
|
||||
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_font = lv_obj_get_style_font(obj, part);
|
||||
|
@ -930,6 +930,7 @@ LV_OBJ_STYLE_SET_GET_DECLARE(SHADOW_SPREAD, shadow_spread, lv_style_int_t, _int)
|
||||
LV_OBJ_STYLE_SET_GET_DECLARE(SHADOW_BLEND_MODE, shadow_blend_mode, lv_blend_mode_t, _int );
|
||||
LV_OBJ_STYLE_SET_GET_DECLARE(SHADOW_COLOR, shadow_color, lv_color_t, _color);
|
||||
LV_OBJ_STYLE_SET_GET_DECLARE(SHADOW_OPA, shadow_opa, lv_opa_t, _opa);
|
||||
LV_OBJ_STYLE_SET_GET_DECLARE(PATTERN_REPEAT, pattern_repeat, bool, _int );
|
||||
LV_OBJ_STYLE_SET_GET_DECLARE(PATTERN_BLEND_MODE, pattern_blend_mode, lv_blend_mode_t, _int );
|
||||
LV_OBJ_STYLE_SET_GET_DECLARE(PATTERN_RECOLOR, pattern_recolor, lv_color_t, _color);
|
||||
LV_OBJ_STYLE_SET_GET_DECLARE(PATTERN_OPA, pattern_opa, lv_opa_t, _opa);
|
||||
|
@ -111,6 +111,7 @@ enum {
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_SHADOW_OPA, 0x4, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE),
|
||||
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_BLEND_MODE, 0x5, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_REPEAT, 0x5, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_RECOLOR, 0x5, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_OPA, 0x5, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE),
|
||||
LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_RECOLOR_OPA, 0x5, LV_STYLE_ID_OPA + 1, LV_STYLE_ATTR_NONE),
|
||||
|
@ -1115,25 +1115,55 @@ static void draw_pattern(const lv_area_t * coords, const lv_area_t * clip, lv_dr
|
||||
|
||||
lv_area_t coords_tmp;
|
||||
|
||||
lv_draw_mask_radius_param_t radius_mask_param;
|
||||
lv_draw_mask_radius_init(&radius_mask_param, coords, dsc->radius, false);
|
||||
int16_t radius_mask_id = lv_draw_mask_add(&radius_mask_param, NULL);
|
||||
if(dsc->pattern_repeat) {
|
||||
lv_draw_mask_radius_param_t radius_mask_param;
|
||||
lv_draw_mask_radius_init(&radius_mask_param, coords, dsc->radius, false);
|
||||
int16_t radius_mask_id = lv_draw_mask_add(&radius_mask_param, NULL);
|
||||
|
||||
/*Align the pattern to the middle*/
|
||||
int32_t ofs_x = (lv_area_get_width(coords) - (lv_area_get_width(coords) / img_w) * img_w) / 2;
|
||||
int32_t ofs_y = (lv_area_get_height(coords) - (lv_area_get_height(coords) / img_h) * img_h) / 2;
|
||||
/*Align the pattern to the middle*/
|
||||
int32_t ofs_x = (lv_area_get_width(coords) - (lv_area_get_width(coords) / img_w) * img_w) / 2;
|
||||
int32_t ofs_y = (lv_area_get_height(coords) - (lv_area_get_height(coords) / img_h) * img_h) / 2;
|
||||
|
||||
coords_tmp.y1 = coords->y1 - ofs_y;
|
||||
coords_tmp.y2 = coords_tmp.y1 + img_h - 1;
|
||||
for(; coords_tmp.y1 <= coords->y2; coords_tmp.y1 += img_h, coords_tmp.y2 += img_h) {
|
||||
coords_tmp.x1 = coords->x1 - ofs_x;
|
||||
coords_tmp.x2 = coords_tmp.x1 + img_w - 1;
|
||||
for(; coords_tmp.x1 <= coords->x2; coords_tmp.x1 += img_w, coords_tmp.x2 += img_w) {
|
||||
if(src_type == LV_IMG_SRC_SYMBOL) lv_draw_label(&coords_tmp, clip, &label_dsc, dsc->pattern_image, NULL);
|
||||
else lv_draw_img(&coords_tmp, clip, dsc->pattern_image, &img_dsc);
|
||||
coords_tmp.y1 = coords->y1 - ofs_y;
|
||||
coords_tmp.y2 = coords_tmp.y1 + img_h - 1;
|
||||
for(; coords_tmp.y1 <= coords->y2; coords_tmp.y1 += img_h, coords_tmp.y2 += img_h) {
|
||||
coords_tmp.x1 = coords->x1 - ofs_x;
|
||||
coords_tmp.x2 = coords_tmp.x1 + img_w - 1;
|
||||
for(; coords_tmp.x1 <= coords->x2; coords_tmp.x1 += img_w, coords_tmp.x2 += img_w) {
|
||||
if(src_type == LV_IMG_SRC_SYMBOL) lv_draw_label(&coords_tmp, clip, &label_dsc, dsc->pattern_image, NULL);
|
||||
else lv_draw_img(&coords_tmp, clip, dsc->pattern_image, &img_dsc);
|
||||
}
|
||||
}
|
||||
lv_draw_mask_remove_id(radius_mask_id);
|
||||
} else {
|
||||
int32_t obj_w = lv_area_get_width(coords);
|
||||
int32_t obj_h = lv_area_get_height(coords);
|
||||
coords_tmp.x1 = coords->x1 + (obj_w - img_w) / 2;
|
||||
coords_tmp.y1 = coords->y1 + (obj_h - img_h) / 2;
|
||||
coords_tmp.x2 = coords_tmp.x1 + img_w - 1;
|
||||
coords_tmp.y2 = coords_tmp.y1 + img_h - 1;
|
||||
|
||||
/* If the (obj_h - img_h) is odd there is a rounding error when divided by 2.
|
||||
* It's better round up in case of symbols because probably there is some extra space in the bottom
|
||||
* due to the base line of font*/
|
||||
if(src_type == LV_IMG_SRC_SYMBOL) {
|
||||
int32_t y_corr = (obj_h - img_h) & 0x1;
|
||||
coords_tmp.y1 += y_corr;
|
||||
coords_tmp.y2 += y_corr;
|
||||
}
|
||||
|
||||
int16_t radius_mask_id = LV_MASK_ID_INV;
|
||||
if(lv_area_is_in(&coords_tmp, coords, dsc->radius) == false) {
|
||||
lv_draw_mask_radius_param_t radius_mask_param;
|
||||
lv_draw_mask_radius_init(&radius_mask_param, coords, dsc->radius, false);
|
||||
radius_mask_id = lv_draw_mask_add(&radius_mask_param, NULL);
|
||||
}
|
||||
|
||||
if(src_type == LV_IMG_SRC_SYMBOL) lv_draw_label(&coords_tmp, clip, &label_dsc, dsc->pattern_image, NULL);
|
||||
else lv_draw_img(&coords_tmp, clip, dsc->pattern_image, &img_dsc);
|
||||
|
||||
lv_draw_mask_remove_id(radius_mask_id);
|
||||
}
|
||||
lv_draw_mask_remove_id(radius_mask_id);
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,6 +55,7 @@ typedef struct {
|
||||
/*Pattern*/
|
||||
const void * pattern_image;
|
||||
const lv_font_t * pattern_font;
|
||||
bool pattern_repeat;
|
||||
lv_opa_t pattern_opa;
|
||||
lv_opa_t pattern_recolor_opa;
|
||||
lv_color_t pattern_recolor;
|
||||
|
Loading…
x
Reference in New Issue
Block a user