From fa683200b5c794451051ae58f3f987656595e97f Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Thu, 20 Sep 2018 22:47:32 +0200 Subject: [PATCH] preloader and arc theme and design updates --- lv_objx/lv_arc.c | 35 ++++++++++++++++++----------------- lv_objx/lv_preload.c | 33 ++++++++++++++++++--------------- lv_themes/lv_theme_alien.c | 30 ++++++++++++++++++++++++++++++ lv_themes/lv_theme_material.c | 4 ++++ lv_themes/lv_theme_nemo.c | 27 +++++++++++++++++++++++++++ lv_themes/lv_theme_zen.c | 3 +++ 6 files changed, 100 insertions(+), 32 deletions(-) diff --git a/lv_objx/lv_arc.c b/lv_objx/lv_arc.c index 779163ecf..f0ef4dbcd 100644 --- a/lv_objx/lv_arc.c +++ b/lv_objx/lv_arc.c @@ -238,31 +238,32 @@ static bool lv_arc_design(lv_obj_t * arc, const lv_area_t * mask, lv_design_mode /*Draw circle on the ends if enabled */ if(style->line.rounded) { - lv_coord_t thick_2 = style->line.width / 2; - lv_coord_t cir_x = ((r - thick_2) * lv_trigo_sin(ext->angle_start) >> LV_TRIGO_SHIFT); - lv_coord_t cir_y = ((r - thick_2) * lv_trigo_sin(ext->angle_start + 90) >> LV_TRIGO_SHIFT); + lv_coord_t thick_half = style->line.width / 2; + lv_coord_t cir_x = ((r - thick_half) * lv_trigo_sin(ext->angle_start) >> LV_TRIGO_SHIFT); + lv_coord_t cir_y = ((r - thick_half) * lv_trigo_sin(ext->angle_start + 90) >> LV_TRIGO_SHIFT); lv_style_t cir_style; - lv_style_copy(&cir_style, style); - cir_style.body.empty = 0; + lv_style_copy(&cir_style, &lv_style_plain); cir_style.body.grad_color = style->line.color; + cir_style.body.main_color = cir_style.body.grad_color; + cir_style.body.radius = LV_RADIUS_CIRCLE; lv_area_t cir_area; - cir_area.x1 = cir_x + x - thick_2; - cir_area.y1 = cir_y + y - thick_2; - cir_area.x2 = cir_x + x + thick_2; - cir_area.y2 = cir_y + y + thick_2; + cir_area.x1 = cir_x + x - thick_half; + cir_area.y1 = cir_y + y - thick_half; + cir_area.x2 = cir_x + x + thick_half; + cir_area.y2 = cir_y + y + thick_half; - lv_draw_rect(&cir_area, mask, &cir_style, lv_obj_get_opa_scale(arc)); + lv_draw_rect(&cir_area, mask, &cir_style, opa_scale); - cir_x = ((r - thick_2) * lv_trigo_sin(ext->angle_end) >> LV_TRIGO_SHIFT); - cir_y = ((r - thick_2) * lv_trigo_sin(ext->angle_end + 90) >> LV_TRIGO_SHIFT); + cir_x = ((r - thick_half) * lv_trigo_sin(ext->angle_end) >> LV_TRIGO_SHIFT); + cir_y = ((r - thick_half) * lv_trigo_sin(ext->angle_end + 90) >> LV_TRIGO_SHIFT); - cir_area.x1 = cir_x + x - thick_2; - cir_area.y1 = cir_y + y - thick_2; - cir_area.x2 = cir_x + x + thick_2; - cir_area.y2 = cir_y + y + thick_2; + cir_area.x1 = cir_x + x - thick_half; + cir_area.y1 = cir_y + y - thick_half; + cir_area.x2 = cir_x + x + thick_half; + cir_area.y2 = cir_y + y + thick_half; - lv_draw_rect(&cir_area, mask, &cir_style, lv_obj_get_opa_scale(arc)); + lv_draw_rect(&cir_area, mask, &cir_style, opa_scale); } } diff --git a/lv_objx/lv_preload.c b/lv_objx/lv_preload.c index 51d5d83ae..13e49c702 100644 --- a/lv_objx/lv_preload.c +++ b/lv_objx/lv_preload.c @@ -278,25 +278,28 @@ static bool lv_preload_design(lv_obj_t * preload, const lv_area_t * mask, lv_des /*Draw a circle as background*/ lv_style_t * style = lv_arc_get_style(preload, LV_ARC_STYLE_MAIN); - lv_coord_t r = (LV_MATH_MIN(lv_obj_get_width(preload), lv_obj_get_height(preload))) / 2; - lv_coord_t x = preload->coords.x1 + lv_obj_get_width(preload) / 2; - lv_coord_t y = preload->coords.y1 + lv_obj_get_height(preload) / 2; + if(style->body.border.width > 0) { + lv_coord_t r = (LV_MATH_MIN(lv_obj_get_width(preload), lv_obj_get_height(preload))) / 2; + r -= LV_MATH_MIN(style->body.padding.hor, style->body.padding.ver); - lv_style_t bg_style; - lv_style_copy(&bg_style, &lv_style_plain); - bg_style.body.empty = 1; - bg_style.body.radius = LV_RADIUS_CIRCLE; - bg_style.body.border.color = style->body.border.color; - bg_style.body.border.width = style->body.border.width; + lv_coord_t x = preload->coords.x1 + lv_obj_get_width(preload) / 2; + lv_coord_t y = preload->coords.y1 + lv_obj_get_height(preload) / 2; - lv_area_t bg_area; - bg_area.x1 = x - r; - bg_area.y1 = y - r; - bg_area.x2 = x + r; - bg_area.y2 = y + r; + lv_style_t bg_style; + lv_style_copy(&bg_style, &lv_style_plain); + bg_style.body.empty = 1; + bg_style.body.radius = LV_RADIUS_CIRCLE; + bg_style.body.border.color = style->body.border.color; + bg_style.body.border.width = style->body.border.width; - if(style->body.empty == 0) lv_draw_rect(&bg_area, mask, &bg_style, lv_obj_get_opa_scale(preload)); + lv_area_t bg_area; + bg_area.x1 = x - r; + bg_area.y1 = y - r; + bg_area.x2 = x + r; + bg_area.y2 = y + r; + lv_draw_rect(&bg_area, mask, &bg_style, lv_obj_get_opa_scale(preload)); + } /*Draw the arc above the background circle */ ancestor_design(preload, mask, mode); } diff --git a/lv_themes/lv_theme_alien.c b/lv_themes/lv_theme_alien.c index 1922cb345..ec9a7f841 100644 --- a/lv_themes/lv_theme_alien.c +++ b/lv_themes/lv_theme_alien.c @@ -379,6 +379,34 @@ static void gauge_init(void) #endif } +static void arc_init(void) +{ +#if USE_LV_ARC != 0 + + static lv_style_t arc; + lv_style_copy(&arc, &def); + arc.line.width = 8; + arc.line.color = lv_color_hsv_to_rgb(_hue, 70, 90); + arc.line.rounded = 1; + + /*For preloader*/ + arc.body.border.width = 2; + arc.body.border.color = LV_COLOR_HEX3(0x555); + arc.body.padding.hor = 3; + arc.body.padding.ver = 3; + + theme.arc = &arc; +#endif +} + +static void preload_init(void) +{ +#if USE_LV_PRELOAD != 0 + + theme.preload = theme.arc; +#endif +} + static void chart_init(void) { #if USE_LV_CHART @@ -767,6 +795,8 @@ lv_theme_t * lv_theme_alien_init(uint16_t hue, lv_font_t * font) sw_init(); lmeter_init(); gauge_init(); + arc_init(); + preload_init(); chart_init(); calendar_init(); cb_init(); diff --git a/lv_themes/lv_theme_material.c b/lv_themes/lv_theme_material.c index 3fb0ef006..40f0fc55f 100644 --- a/lv_themes/lv_theme_material.c +++ b/lv_themes/lv_theme_material.c @@ -322,8 +322,12 @@ static void arc_init(void) lv_style_copy(&arc, &def); arc.line.width = 10; arc.line.color = lv_color_hsv_to_rgb(_hue, 90, 90); + + /*For prelaoder*/ arc.body.border.width = 10; arc.body.border.color = lv_color_hsv_to_rgb(_hue, 30, 90); + arc.body.padding.hor = 0; + arc.body.padding.ver = 0; theme.arc = &arc; #endif diff --git a/lv_themes/lv_theme_nemo.c b/lv_themes/lv_theme_nemo.c index 88fa8ec72..799de5d93 100644 --- a/lv_themes/lv_theme_nemo.c +++ b/lv_themes/lv_theme_nemo.c @@ -382,6 +382,31 @@ static void gauge_init(void) #endif } +static void arc_init(void) +{ +#if USE_LV_ARC != 0 + + static lv_style_t arc; + lv_style_copy(&arc, &def); + arc.line.width = 10; + arc.line.color = lv_color_hsv_to_rgb(_hue, 70, 90); + arc.line.rounded = 1; + + /*For preloader*/ + arc.body.border.width = 0; + + theme.arc = &arc; +#endif +} + +static void preload_init(void) +{ +#if USE_LV_PRELOAD != 0 + + theme.preload = theme.arc; +#endif +} + static void chart_init(void) { #if USE_LV_CHART @@ -761,6 +786,8 @@ lv_theme_t * lv_theme_nemo_init(uint16_t hue, lv_font_t *font) sw_init(); lmeter_init(); gauge_init(); + arc_init(); + preload_init(); chart_init(); calendar_init(); cb_init(); diff --git a/lv_themes/lv_theme_zen.c b/lv_themes/lv_theme_zen.c index 1e6c30571..4fc8df6e6 100644 --- a/lv_themes/lv_theme_zen.c +++ b/lv_themes/lv_theme_zen.c @@ -300,6 +300,9 @@ static void arc_init(void) lv_style_copy(&arc, &def); arc.line.width = 10; arc.line.color = lv_color_hsv_to_rgb(_hue, 40, 90); + arc.line.rounded = 1; + + /*For preloader*/ arc.body.border.width = 0; theme.arc = &arc;