From 1521aad41e6dbc35ee54187ac6db5611180727c3 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 16 Oct 2019 20:25:53 +0200 Subject: [PATCH] move 'corner mask' to style.body --- src/lv_core/lv_obj.c | 22 +++++++++++++++++++--- src/lv_core/lv_style.h | 4 +++- src/lv_objx/lv_cont.c | 37 ------------------------------------- src/lv_objx/lv_cont.h | 1 - src/lv_objx/lv_page.c | 5 ++--- 5 files changed, 24 insertions(+), 45 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 264e78688..5069bee7f 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -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) { if(mode == LV_DESIGN_COVER_CHK) { - /*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; - /*Can cover the area only if fully solid (no opacity)*/ + 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; /* 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; - } else if(mode == LV_DESIGN_DRAW_MAIN) { + } + else if(mode == LV_DESIGN_DRAW_MAIN) { const lv_style_t * style = lv_obj_get_style(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; diff --git a/src/lv_core/lv_style.h b/src/lv_core/lv_style.h index c3174aa55..d2c5c1a8b 100644 --- a/src/lv_core/lv_style.h +++ b/src/lv_core/lv_style.h @@ -73,7 +73,9 @@ typedef struct lv_opa_t main_color_stop; lv_opa_t grad_color_stop; 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 diff --git a/src/lv_objx/lv_cont.c b/src/lv_objx/lv_cont.c index 922daf91e..239329a5a 100644 --- a/src/lv_objx/lv_cont.c +++ b/src/lv_objx/lv_cont.c @@ -34,7 +34,6 @@ /********************** * 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 void lv_cont_refr_layout(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; lv_obj_set_signal_cb(new_cont, lv_cont_signal); - lv_obj_set_design_cb(new_cont, lv_cont_design); /*Init the new container*/ if(copy == NULL) { @@ -244,41 +242,6 @@ lv_fit_t lv_cont_get_fit_bottom(const lv_obj_t * cont) * 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 * @param cont pointer to a container object diff --git a/src/lv_objx/lv_cont.h b/src/lv_objx/lv_cont.h index 6a7aec299..a2346c6ff 100644 --- a/src/lv_objx/lv_cont.h +++ b/src/lv_objx/lv_cont.h @@ -69,7 +69,6 @@ typedef struct 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_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; /*Styles*/ diff --git a/src/lv_objx/lv_page.c b/src/lv_objx/lv_page.c index 0cf6aea73..4ce6142ad 100644 --- a/src/lv_objx/lv_page.c +++ b/src/lv_objx/lv_page.c @@ -111,7 +111,6 @@ lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy) /*Init the new page object*/ if(copy == NULL) { - ext->bg.masked = 0; ext->scrl = lv_cont_create(new_page, NULL); lv_obj_set_signal_cb(ext->scrl, lv_page_scrollable_signal); 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_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); lv_draw_mask_param_t mp; 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); } #endif