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

move 'corner mask' to style.body

This commit is contained in:
Gabor Kiss-Vamosi 2019-10-16 20:25:53 +02:00
parent a6f68e5387
commit 1521aad41e
5 changed files with 24 additions and 45 deletions

View File

@ -2337,12 +2337,15 @@ static void lv_obj_del_async_cb(void * obj)
static lv_design_res_t lv_obj_design(lv_obj_t * obj, const lv_area_t * clip_area, lv_design_mode_t mode) static lv_design_res_t lv_obj_design(lv_obj_t * obj, const lv_area_t * clip_area, lv_design_mode_t mode)
{ {
if(mode == LV_DESIGN_COVER_CHK) { if(mode == LV_DESIGN_COVER_CHK) {
/*Most trivial test. Is the mask fully IN the object? If no it surely doesn't cover it*/ /*Most trivial test. Is the mask fully IN the object? If no it surely doesn't cover it*/
if(lv_area_is_in(clip_area, &obj->coords) == false) return LV_DESIGN_RES_NOT_COVER; if(lv_area_is_in(clip_area, &obj->coords) == false) return LV_DESIGN_RES_NOT_COVER;
/*Can cover the area only if fully solid (no opacity)*/
const lv_style_t * style = lv_obj_get_style(obj); const lv_style_t * style = lv_obj_get_style(obj);
if(style->body.corner_mask) return LV_DESIGN_RES_MASKED;
/*Can cover the area only if fully solid (no opacity)*/
if(style->body.opa < LV_OPA_MAX) return LV_DESIGN_RES_NOT_COVER; if(style->body.opa < LV_OPA_MAX) return LV_DESIGN_RES_NOT_COVER;
/* Because of the radius it is not sure the area is covered /* Because of the radius it is not sure the area is covered
@ -2367,9 +2370,22 @@ static lv_design_res_t lv_obj_design(lv_obj_t * obj, const lv_area_t * clip_area
return LV_DESIGN_RES_COVER; return LV_DESIGN_RES_COVER;
} else if(mode == LV_DESIGN_DRAW_MAIN) { }
else if(mode == LV_DESIGN_DRAW_MAIN) {
const lv_style_t * style = lv_obj_get_style(obj); const lv_style_t * style = lv_obj_get_style(obj);
lv_draw_rect(&obj->coords, clip_area, style, lv_obj_get_opa_scale(obj)); lv_draw_rect(&obj->coords, clip_area, style, lv_obj_get_opa_scale(obj));
if(style->body.corner_mask) {
lv_draw_mask_param_t mp;
lv_draw_mask_radius_init(&mp, &obj->coords, style->body.radius, false);
lv_draw_mask_add(&mp, obj + 4);
}
}
else if(mode == LV_DESIGN_DRAW_POST) {
const lv_style_t * style = lv_obj_get_style(obj);
if(style->body.corner_mask) {
lv_draw_mask_remove_custom(obj+ 4);
}
} }
return LV_DESIGN_RES_OK; return LV_DESIGN_RES_OK;

View File

@ -73,7 +73,9 @@ typedef struct
lv_opa_t main_color_stop; lv_opa_t main_color_stop;
lv_opa_t grad_color_stop; lv_opa_t grad_color_stop;
lv_blend_mode_t blend_mode :3; lv_blend_mode_t blend_mode :3;
lv_grad_dir_t grad_dir; lv_grad_dir_t grad_dir :2;
uint8_t corner_mask :1;
struct struct

View File

@ -34,7 +34,6 @@
/********************** /**********************
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static lv_design_res_t lv_cont_design(lv_obj_t * cont, const lv_area_t * clip_area, lv_design_mode_t mode);
static lv_res_t lv_cont_signal(lv_obj_t * cont, lv_signal_t sign, void * param); static lv_res_t lv_cont_signal(lv_obj_t * cont, lv_signal_t sign, void * param);
static void lv_cont_refr_layout(lv_obj_t * cont); static void lv_cont_refr_layout(lv_obj_t * cont);
static void lv_cont_layout_col(lv_obj_t * cont); static void lv_cont_layout_col(lv_obj_t * cont);
@ -89,7 +88,6 @@ lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy)
ext->layout = LV_LAYOUT_OFF; ext->layout = LV_LAYOUT_OFF;
lv_obj_set_signal_cb(new_cont, lv_cont_signal); lv_obj_set_signal_cb(new_cont, lv_cont_signal);
lv_obj_set_design_cb(new_cont, lv_cont_design);
/*Init the new container*/ /*Init the new container*/
if(copy == NULL) { if(copy == NULL) {
@ -244,41 +242,6 @@ lv_fit_t lv_cont_get_fit_bottom(const lv_obj_t * cont)
* STATIC FUNCTIONS * STATIC FUNCTIONS
**********************/ **********************/
/**
* Handle the drawing related tasks of the drop down lists
* @param btn pointer to an object
* @param mask the object will be drawn only in this area
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
* (return 'true' if yes)
* LV_DESIGN_DRAW: draw the object (always return 'true')
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
* @param return an element of `lv_design_res_t`
*/
static lv_design_res_t lv_cont_design(lv_obj_t * cont, const lv_area_t * clip_area, lv_design_mode_t mode)
{
if(mode == LV_DESIGN_COVER_CHK) {
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
if(ext->masked) return LV_DESIGN_RES_MASKED;
else return ancestor_design(cont, clip_area, mode);
} else if(mode == LV_DESIGN_DRAW_MAIN) {
ancestor_design(cont, clip_area, mode);
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
if(ext->masked) {
const lv_style_t * style = lv_cont_get_style(cont, LV_CONT_STYLE_MAIN);
lv_draw_mask_param_t mp;
lv_draw_mask_radius_init(&mp, &cont->coords, style->body.radius, false);
lv_draw_mask_add(&mp, cont + 4);
}
} else if(mode == LV_DESIGN_DRAW_POST) {
lv_cont_ext_t * ext = lv_obj_get_ext_attr(cont);
if(ext->masked) {
lv_draw_mask_remove_custom(cont + 4);
}
}
return LV_DESIGN_RES_OK;
}
/** /**
* Signal function of the container * Signal function of the container
* @param cont pointer to a container object * @param cont pointer to a container object

View File

@ -69,7 +69,6 @@ typedef struct
lv_fit_t fit_right : 2; /*A fit type from `lv_fit_t` enum */ lv_fit_t fit_right : 2; /*A fit type from `lv_fit_t` enum */
lv_fit_t fit_top : 2; /*A fit type from `lv_fit_t` enum */ lv_fit_t fit_top : 2; /*A fit type from `lv_fit_t` enum */
lv_fit_t fit_bottom : 2; /*A fit type from `lv_fit_t` enum */ lv_fit_t fit_bottom : 2; /*A fit type from `lv_fit_t` enum */
uint8_t masked :1; /*Automatically a draw mask to to mask out the corners*/
} lv_cont_ext_t; } lv_cont_ext_t;
/*Styles*/ /*Styles*/

View File

@ -111,7 +111,6 @@ lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy)
/*Init the new page object*/ /*Init the new page object*/
if(copy == NULL) { if(copy == NULL) {
ext->bg.masked = 0;
ext->scrl = lv_cont_create(new_page, NULL); ext->scrl = lv_cont_create(new_page, NULL);
lv_obj_set_signal_cb(ext->scrl, lv_page_scrollable_signal); lv_obj_set_signal_cb(ext->scrl, lv_page_scrollable_signal);
lv_obj_set_design_cb(ext->scrl, lv_scrl_design); lv_obj_set_design_cb(ext->scrl, lv_scrl_design);
@ -706,7 +705,7 @@ static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_ar
lv_draw_rect(&page->coords, clip_area, &style_tmp, lv_obj_get_opa_scale(page)); lv_draw_rect(&page->coords, clip_area, &style_tmp, lv_obj_get_opa_scale(page));
lv_page_ext_t * ext = lv_obj_get_ext_attr(page); lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
if(ext->bg.masked) { if(style->body.corner_mask) {
const lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG); const lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG);
lv_draw_mask_param_t mp; lv_draw_mask_param_t mp;
lv_draw_mask_radius_init(&mp, &page->coords, style->body.radius, false); lv_draw_mask_radius_init(&mp, &page->coords, style->body.radius, false);
@ -782,7 +781,7 @@ static lv_design_res_t lv_page_design(lv_obj_t * page, const lv_area_t * clip_ar
} }
} }
if(ext->bg.masked) { if(style->body.corner_mask) {
lv_draw_mask_remove_custom(page + 4); lv_draw_mask_remove_custom(page + 4);
} }
#endif #endif