diff --git a/lv_appx/lv_app_sysmon.c b/lv_appx/lv_app_sysmon.c index 53704b683..1377710b5 100644 --- a/lv_appx/lv_app_sysmon.c +++ b/lv_appx/lv_app_sysmon.c @@ -187,12 +187,16 @@ static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc) lv_bar_set_style_indic(sc_data->bar_cpu, &cpu_bars); lv_obj_set_click(sc_data->bar_cpu, false); lv_bar_set_range(sc_data->bar_cpu, 0, 100); - lv_bar_set_format_str(sc_data->bar_cpu, "C\nP\nU"); + lv_obj_t * label = lv_label_create(sc_data->bar_cpu, NULL); + lv_label_set_text(label, "C\nP\nU"); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); sc_data->bar_mem = lv_bar_create(sc, sc_data->bar_cpu); lv_obj_align(sc_data->bar_mem, sc_data->bar_cpu, LV_ALIGN_OUT_RIGHT_MID, w, 0); lv_bar_set_style_indic(sc_data->bar_mem, &mem_bars); - lv_bar_set_format_str(sc_data->bar_mem, "M\ne\nm"); + label = lv_label_create(sc_data->bar_mem, NULL); + lv_label_set_text(label, "M\nE\nM"); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); lv_app_sysmon_refr(); } @@ -237,7 +241,7 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win) /*Create a label for the details of Memory and CPU usage*/ win_data->label = lv_label_create(win, NULL); lv_label_set_recolor(win_data->label, true); - lv_obj_align(win_data->label, win_data->chart, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 4, 0); + lv_obj_align(win_data->label, win_data->chart, LV_ALIGN_OUT_RIGHT_TOP, LV_DPI / 4, 0); lv_app_sysmon_refr(); diff --git a/lv_draw/lv_draw.c b/lv_draw/lv_draw.c index 3323e71a7..c5ed1cb59 100644 --- a/lv_draw/lv_draw.c +++ b/lv_draw/lv_draw.c @@ -47,6 +47,7 @@ static void lv_draw_rect_main_mid(const area_t * cords_p, const area_t * mask_p, static void lv_draw_rect_main_corner(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style_p); static void lv_draw_rect_border_straight(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style_p); static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style); +static void lv_draw_rect_shadow(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style); static uint16_t lv_draw_rect_radius_corr(uint16_t r, cord_t w, cord_t h); #endif /*USE_LV_RECT != 0*/ @@ -103,6 +104,10 @@ void lv_draw_rect(const area_t * cords_p, const area_t * mask_p, const lv_style_ lv_draw_rect_border_corner(cords_p, mask_p, style_p); } } + + if(style_p->swidth != 0) { + lv_draw_rect_shadow(cords_p, mask_p, style_p); + } } #endif /*USE_LV_RECT != 0*/ @@ -1035,6 +1040,55 @@ static void lv_draw_rect_border_corner(const area_t * cords_p, const area_t * ma } +/** + * Draw a shadow + * @param rect pointer to rectangle object + * @param mask pointer to a mask area (from the design functions) + */ +static void lv_draw_rect_shadow(const area_t * cords_p, const area_t * mask_p, const lv_style_t * style) +{ + cord_t swidth = style->swidth; + if(swidth == 0) return; + uint8_t res = LV_DOWNSCALE * 2; + if(swidth < res) return; + + area_t shadow_area; + lv_style_t shadow_style; + memcpy(&shadow_area, cords_p, sizeof(area_t)); + + memcpy(&shadow_style, style, sizeof(lv_style_t)); + + shadow_style.empty = 1; + shadow_style.bwidth = swidth; + shadow_style.radius = style->radius; + if(shadow_style.radius == LV_RECT_CIRCLE) { + shadow_style.radius = MATH_MIN(area_get_width(cords_p), area_get_height(cords_p)); + } + shadow_style.radius += swidth + 1; + shadow_style.bcolor = style->scolor; + shadow_style.bopa = 100; + + shadow_area.x1 -= swidth; + shadow_area.y1 -= swidth; + shadow_area.x2 += swidth; + shadow_area.y2 += swidth; + + cord_t i; + shadow_style.opa = style->opa / (swidth / res); + + for(i = 1; i < swidth; i += res) { + lv_draw_rect_border_straight(&shadow_area, mask_p, &shadow_style); + lv_draw_rect_border_corner(&shadow_area, mask_p, &shadow_style); + shadow_style.radius -= res; + shadow_style.bwidth -= res; + shadow_area.x1 += res; + shadow_area.y1 += res; + shadow_area.x2 -= res; + shadow_area.y2 -= res; + } +} + + static uint16_t lv_draw_rect_radius_corr(uint16_t r, cord_t w, cord_t h) { if(r >= (w >> 1)){ diff --git a/lv_draw/lv_draw.h b/lv_draw/lv_draw.h index 0bc693ef7..cacaa2f5a 100644 --- a/lv_draw/lv_draw.h +++ b/lv_draw/lv_draw.h @@ -16,6 +16,7 @@ /********************* * DEFINES *********************/ +#define LV_RECT_CIRCLE ((cord_t)-1) /*A very big radius to always draw as circle*/ /********************** * TYPEDEFS diff --git a/lv_obj/lv_obj.c b/lv_obj/lv_obj.c index 324ee829f..b1d086a36 100644 --- a/lv_obj/lv_obj.c +++ b/lv_obj/lv_obj.c @@ -8,12 +8,12 @@ *********************/ #include -#include -#include +#include #include #include #include #include +#include "lvgl/lv_draw/lv_draw_rbasic.h" #include #include #include @@ -305,13 +305,20 @@ bool lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param) { bool valid = true; + lv_style_t * style = lv_obj_get_style(obj); switch(sign) { - case LV_SIGNAL_CHILD_CHG: - /*Return 'invalid' if the child change signal is not enabled*/ - if(lv_obj_is_protected(obj, LV_PROTECT_CHILD_CHG) != false) valid = false; - break; - default: - break; + case LV_SIGNAL_CHILD_CHG: + /*Return 'invalid' if the child change signal is not enabled*/ + if(lv_obj_is_protected(obj, LV_PROTECT_CHILD_CHG) != false) valid = false; + break; + case LV_SIGNAL_REFR_EXT_SIZE: + if(style->swidth > obj->ext_size) obj->ext_size = style->swidth; + break; + case LV_SIGNAL_STYLE_CHG: + lv_obj_refr_ext_size(obj); + break; + default: + break; } return valid; @@ -1425,18 +1432,33 @@ void * lv_obj_get_free_p(lv_obj_t * obj) static bool lv_obj_design(lv_obj_t * obj, const area_t * mask_p, lv_design_mode_t mode) { if(mode == LV_DESIGN_COVER_CHK) { - bool cover; - cover = area_is_in(mask_p, &obj->cords); - return cover; + + /* Because of the radius it is not sure the area is covered + * Check the areas where there is no radius*/ + lv_style_t * style = lv_obj_get_style(obj); + if(style->empty != 0) return false; + + uint16_t r = style->radius; + + if(r == LV_RECT_CIRCLE) return false; + + area_t area_tmp; + + /*Check horizontally without radius*/ + lv_obj_get_cords(obj, &area_tmp); + area_tmp.x1 += r; + area_tmp.x2 -= r; + if(area_is_in(mask_p, &area_tmp) != true) return false; + + /*Check vertically without radius*/ + lv_obj_get_cords(obj, &area_tmp); + area_tmp.y1 += r; + area_tmp.y2 -= r; + if(area_is_in(mask_p, &area_tmp) != true) return false; + } else if(mode == LV_DESIGN_DRAW_MAIN) { lv_style_t * style = lv_obj_get_style(obj); - - /*Simply draw a rectangle*/ -#if LV_VDB_SIZE == 0 - lv_rfill(&obj->cords, mask_p, style->color, style->opa); -#else - lv_vfill(&obj->cords, mask_p, style->mcolor, style->opa); -#endif + lv_draw_rect(&obj->cords, mask_p, style); } return true; } diff --git a/lv_obj/lv_style.c b/lv_obj/lv_style.c index dff483701..f7b214247 100644 --- a/lv_obj/lv_style.c +++ b/lv_obj/lv_style.c @@ -61,13 +61,13 @@ void lv_style_init (void) lv_style_set_mcolor(&lv_style_scr, COLOR_WHITE); lv_style_set_gcolor(&lv_style_scr, COLOR_WHITE); - lv_style_set_bcolor(&lv_style_scr, COLOR_MAKE(0x20, 0x20 ,0x20)); + lv_style_set_bcolor(&lv_style_scr, COLOR_WHITE); lv_style_set_scolor(&lv_style_scr, COLOR_GRAY); lv_style_set_radius(&lv_style_scr, 0); lv_style_set_bwidth(&lv_style_scr, 0); lv_style_set_swidth(&lv_style_scr, 0); lv_style_set_vpad(&lv_style_scr, LV_DPI / 6); - lv_style_set_hpad(&lv_style_scr, LV_DPI / 6); + lv_style_set_hpad(&lv_style_scr, LV_DPI / 4); lv_style_set_opad(&lv_style_scr, LV_DPI / 6); lv_style_set_bopa(&lv_style_scr, OPA_COVER); lv_style_set_empty(&lv_style_scr, false); @@ -86,21 +86,27 @@ void lv_style_init (void) /*Plain color style*/ memcpy(&lv_style_plain_color, &lv_style_plain, sizeof(lv_style_t)); - lv_style_set_ccolor(&lv_style_plain_color, COLOR_MAKE(0xf0, 0xf0, 0xf0)); + lv_style_set_ccolor(&lv_style_plain_color, COLOR_RED);//MAKE(0xf0, 0xf0, 0xf0)); lv_style_set_mcolor(&lv_style_plain_color, COLOR_MAKE(0x40, 0x60, 0x80)); lv_style_set_gcolor(&lv_style_plain_color, COLOR_MAKE(0x40, 0x60, 0x80)); /*Pretty style */ memcpy(&lv_style_pretty, &lv_style_plain, sizeof(lv_style_t)); lv_style_set_mcolor(&lv_style_pretty, COLOR_WHITE); - lv_style_set_mcolor(&lv_style_pretty, COLOR_SILVER); + lv_style_set_gcolor(&lv_style_pretty, COLOR_SILVER); + lv_style_set_bcolor(&lv_style_pretty, COLOR_GRAY); lv_style_set_radius(&lv_style_pretty, LV_DPI / 10); lv_style_set_bwidth(&lv_style_pretty, LV_DPI / 20 >= 1 ? LV_DPI / 30 >= 1 : 1); +// lv_style_set_swidth(&lv_style_pretty, LV_DPI / 6); +// lv_style_set_scolor(&lv_style_pretty, COLOR_BLACK); /*Pretty color style*/ memcpy(&lv_style_pretty_color, &lv_style_pretty, sizeof(lv_style_t)); + lv_style_set_ccolor(&lv_style_pretty_color, COLOR_RED);//MAKE(0xf0, 0xf0, 0xf0)); lv_style_set_mcolor(&lv_style_pretty_color, COLOR_WHITE); - lv_style_set_mcolor(&lv_style_pretty_color, COLOR_CYAN); + lv_style_set_gcolor(&lv_style_pretty_color, COLOR_CYAN); + lv_style_set_scolor(&lv_style_pretty_color, COLOR_BLACK); + lv_style_set_swidth(&lv_style_pretty_color, LV_DPI / 2); /*Transparent style*/ memcpy(&lv_style_transp, &lv_style_plain, sizeof(lv_style_t)); diff --git a/lv_objx/lv_bar.c b/lv_objx/lv_bar.c index 8ea7e4f9f..e0377fc76 100644 --- a/lv_objx/lv_bar.c +++ b/lv_objx/lv_bar.c @@ -18,8 +18,6 @@ /********************* * DEFINES *********************/ -#define LV_BAR_TXT_MAX_LENGTH 64 -#define LV_BAR_DEF_FORMAT "%d %%" #define LV_BAR_DEF_WIDTH (LV_DPI * 2) #define LV_BAR_DEF_HEIGHT (LV_DPI / 2) @@ -58,7 +56,7 @@ static lv_design_f_t ancestor_design_f; lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy) { /*Create the ancestor basic object*/ - lv_obj_t * new_bar = lv_rect_create(par, copy); + lv_obj_t * new_bar = lv_obj_create(par, copy); dm_assert(new_bar); /*Allocate the object type specific extended data*/ @@ -67,8 +65,6 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy) ext->min_value = 0; ext->max_value = 100; ext->act_value = 0; - ext->format_str = NULL; - ext->label = NULL; ext->style_indic = lv_style_get(LV_STYLE_PRETTY_COLOR, NULL); /* Save the rectangle design function. @@ -80,14 +76,6 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new bar object*/ if(copy == NULL) { - - - ext->format_str = dm_alloc(strlen(LV_BAR_DEF_FORMAT) + 1); - strcpy(ext->format_str, LV_BAR_DEF_FORMAT); - - ext->label = lv_label_create(new_bar, NULL); - - lv_rect_set_layout(new_bar, LV_RECT_LAYOUT_CENTER); lv_obj_set_click(new_bar, false); lv_obj_set_size(new_bar, LV_BAR_DEF_WIDTH, LV_BAR_DEF_HEIGHT); lv_obj_set_style(new_bar, lv_style_get(LV_STYLE_PRETTY, NULL)); @@ -95,13 +83,10 @@ lv_obj_t * lv_bar_create(lv_obj_t * par, lv_obj_t * copy) lv_bar_set_value(new_bar, ext->act_value); } else { lv_bar_ext_t * ext_copy = lv_obj_get_ext(copy); - ext->format_str = dm_alloc(strlen(ext_copy->format_str) + 1); - strcpy(ext->format_str, ext_copy->format_str); ext->min_value = ext_copy->min_value; ext->max_value = ext_copy->max_value; ext->act_value = ext_copy->act_value; ext->style_indic = ext_copy->style_indic; - ext->label = lv_label_create(new_bar, ext_copy->label); /*Refresh the style with new signal function*/ lv_obj_refr_style(new_bar); @@ -126,20 +111,7 @@ bool lv_bar_signal(lv_obj_t * bar, lv_signal_t sign, void * param) /* The object can be deleted so check its validity and then * make the object specific signal handling */ if(valid != false) { - lv_bar_ext_t * ext = lv_obj_get_ext(bar); - lv_style_t * style = lv_obj_get_style(bar); - switch(sign) { - case LV_SIGNAL_CLEANUP: - dm_free(ext->format_str); - ext->format_str = NULL; - break; - case LV_SIGNAL_STYLE_CHG: - lv_obj_set_style(ext->label, style); - break; - default: - break; - } } return valid; @@ -160,10 +132,6 @@ void lv_bar_set_value(lv_obj_t * bar, int16_t value) ext->act_value = value > ext->max_value ? ext->max_value : value; ext->act_value = ext->act_value < ext->min_value ? ext->min_value : ext->act_value; - char buf[LV_BAR_TXT_MAX_LENGTH]; - sprintf(buf, ext->format_str, ext->act_value); - lv_label_set_text(ext->label, buf); - lv_obj_inv(bar); } @@ -185,20 +153,6 @@ void lv_bar_set_range(lv_obj_t * bar, int16_t min, int16_t max) lv_obj_inv(bar); } -/** - * Set format string for the label of the bar - * @param bar pointer to bar object - * @param format a printf-like format string with one number (e.g. "Loading (%d)") - */ -void lv_bar_set_format_str(lv_obj_t * bar, const char * format) -{ - lv_bar_ext_t * ext = lv_obj_get_ext(bar); - dm_free(ext->format_str); - ext->format_str = dm_alloc(strlen(format) + 1); - strcpy(ext->format_str, format); - lv_bar_set_value(bar, ext->act_value); -} - /** * Set the style of bar indicator * @param bar pointer to a bar obeject @@ -246,7 +200,6 @@ lv_style_t * lv_bar_get_style_indic(lv_obj_t * bar) * STATIC FUNCTIONS **********************/ - /** * Handle the drawing related tasks of the bars * @param bar pointer to an object @@ -259,8 +212,6 @@ lv_style_t * lv_bar_get_style_indic(lv_obj_t * bar) */ static bool lv_bar_design(lv_obj_t * bar, const area_t * mask, lv_design_mode_t mode) { - if(ancestor_design_f == NULL) return false; - if(mode == LV_DESIGN_COVER_CHK) { /*Return false if the object is not covers the mask_p area*/ return ancestor_design_f(bar, mask, mode); diff --git a/lv_objx/lv_bar.h b/lv_objx/lv_bar.h index 91fed1a2a..98c504f02 100644 --- a/lv_objx/lv_bar.h +++ b/lv_objx/lv_bar.h @@ -37,13 +37,11 @@ /*Data of bar*/ typedef struct { - lv_rect_ext_t rect_ext; /*Ext. of ancestor*/ + /*No inherited ext*/ /*Ext. of ancestor*/ /*New data for this type */ - lv_obj_t * label; /*Pointer to the label on the bar*/ int16_t act_value; /*Current value of the bar*/ int16_t min_value; /*Minimum value of the bar*/ int16_t max_value; /*Maximum value of the bar*/ - char * format_str; /*Format string of the label. E.g. "Progress: %d"*/ lv_style_t * style_indic; /*Style of the indicator*/ }lv_bar_ext_t; diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index 8d40bd7b0..133807e51 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -29,15 +29,14 @@ /********************** * STATIC PROTOTYPES **********************/ +#if 0 static bool lv_btn_design(lv_obj_t * btn, const area_t * mask, lv_design_mode_t mode); - +#endif /********************** * STATIC VARIABLES **********************/ -static lv_design_f_t ancestor_design_f; - /********************** * MACROS **********************/ @@ -74,10 +73,7 @@ lv_obj_t * lv_btn_create(lv_obj_t * par, lv_obj_t * copy) ext->lpr_exec = 0; ext->tgl = 0; - if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_btn); - lv_obj_set_signal_f(new_btn, lv_btn_signal); - lv_obj_set_design_f(new_btn, lv_btn_design); /*If no copy do the basic initialization*/ if(copy == NULL) { @@ -351,6 +347,8 @@ lv_style_t * lv_btn_get_style(lv_obj_t * btn, lv_btn_state_t state) /********************** * STATIC FUNCTIONS **********************/ + +#if 0 /** * Handle the drawing related tasks of the buttons * @param btn pointer to a button object @@ -366,12 +364,12 @@ static bool lv_btn_design(lv_obj_t * btn, const area_t * mask, lv_design_mode_t /* Because of the radius it is not sure the area is covered*/ if(mode == LV_DESIGN_COVER_CHK) { - return ancestor_design_f(btn, mask, mode); /*Draw the rectangle*/ + return false; } else if(mode == LV_DESIGN_DRAW_MAIN || mode == LV_DESIGN_DRAW_POST) { - ancestor_design_f(btn, mask, mode); /*Draw the rectangle*/ + } return true; } - +#endif #endif diff --git a/lv_objx/lv_chart.c b/lv_objx/lv_chart.c index 1b97811fa..4e0d55777 100644 --- a/lv_objx/lv_chart.c +++ b/lv_objx/lv_chart.c @@ -61,13 +61,13 @@ static lv_design_f_t ancestor_design_f; lv_obj_t * lv_chart_create(lv_obj_t * par, lv_obj_t * copy) { /*Create the ancestor basic object*/ - lv_obj_t * new_chart = lv_rect_create(par, copy); + lv_obj_t * new_chart = lv_obj_create(par, copy); dm_assert(new_chart); /*Allocate the object type specific extended data*/ lv_chart_ext_t * ext = lv_obj_alloc_ext(new_chart, sizeof(lv_chart_ext_t)); dm_assert(ext); - ll_init(&ext->dl_ll, sizeof(cord_t *)); + ll_init(&ext->dl_ll, sizeof(lv_chart_dl_t)); ext->dl_num = 0; ext->ymin = LV_CHART_YMIN_DEF; ext->ymax = LV_CHART_YMAX_DEF; @@ -114,7 +114,7 @@ bool lv_chart_signal(lv_obj_t * chart, lv_signal_t sign, void * param) bool valid; /* Include the ancient signal function */ - valid = lv_rect_signal(chart, sign, param); + valid = lv_obj_signal(chart, sign, param); /* The object can be deleted so check its validity and then * make the object specific signal handling */ @@ -147,6 +147,9 @@ lv_chart_dl_t * lv_chart_add_dataline(lv_obj_t * chart, color_t color, cord_t wi if(dl == NULL) return NULL; + dl->width = width; + dl->color = color; + dl->points = dm_alloc(sizeof(cord_t) * ext->pnum); uint16_t i; @@ -352,10 +355,8 @@ static bool lv_chart_design(lv_obj_t * chart, const area_t * mask, lv_design_mod /*Return false if the object is not covers the mask_p area*/ return ancestor_design_f(chart, mask, mode); } else if(mode == LV_DESIGN_DRAW_MAIN) { - /*Draw the rectangle ancient*/ - ancestor_design_f(chart, mask, mode); - - /*Draw the object*/ + /*Draw the background*/ + lv_draw_rect(&chart->cords, mask, lv_obj_get_style(chart)); lv_chart_ext_t * ext = lv_obj_get_ext(chart); diff --git a/lv_objx/lv_chart.h b/lv_objx/lv_chart.h index 9fef90cb9..300799f2e 100644 --- a/lv_objx/lv_chart.h +++ b/lv_objx/lv_chart.h @@ -43,7 +43,7 @@ typedef struct /*Data of chart */ typedef struct { - lv_rect_ext_t bg_rect; /*Ext. of ancestor*/ + /*No inherited ext*/ /*Ext. of ancestor*/ /*New data for this type */ cord_t ymin; /*y min value (used to scale the data)*/ cord_t ymax; /*y max value (used to scale the data)*/ diff --git a/lv_objx/lv_gauge.c b/lv_objx/lv_gauge.c index 536ddcfbd..44448cb6c 100644 --- a/lv_objx/lv_gauge.c +++ b/lv_objx/lv_gauge.c @@ -21,9 +21,9 @@ /********************* * DEFINES *********************/ -#define LV_GAUGE_DEF_WIDTH (150 * LV_DOWNSCALE) -#define LV_GAUGE_DEF_HEIGHT (150 * LV_DOWNSCALE) - +#define LV_GAUGE_DEF_WIDTH (3 * LV_DPI) +#define LV_GAUGE_DEF_HEIGHT (3 * LV_DPI) +#define LV_GAUGE_DEF_NEEDLE_COLOR COLOR_RED /********************** * TYPEDEFS **********************/ @@ -32,15 +32,14 @@ * STATIC PROTOTYPES **********************/ static bool lv_gauge_design(lv_obj_t * gauge, const area_t * mask, lv_design_mode_t mode); -static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask); -static void lv_gauge_draw_needle(lv_obj_t * gauge, const area_t * mask); -static void lv_gauges_init(void); +static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask, lv_style_t * style); +static void lv_gauge_draw_needle(lv_obj_t * gauge, const area_t * mask, lv_style_t * style); /********************** * STATIC VARIABLES **********************/ -static lv_gauges_t lv_gauges_def; /*Default gauge style*/ static lv_design_f_t ancestor_design_f = NULL; + /********************** * MACROS **********************/ @@ -73,9 +72,12 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, lv_obj_t * copy) ext->min = 0; ext->max = 100; ext->needle_num = 0; - ext->low_critical = 0; ext->values = NULL; - ext->txt = NULL; + ext->needle_color = NULL; + ext->low_critical = 0; + ext->scale_angle = 120; + ext->scale_label_num = 6; + ext->style_critical = lv_style_get(LV_STYLE_PRETTY_COLOR, NULL); if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_gauge); @@ -85,10 +87,9 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, lv_obj_t * copy) /*Init the new gauge gauge*/ if(copy == NULL) { - lv_gauge_set_needle_num(new_gauge, 1); - lv_gauge_set_text(new_gauge, "%d"); + lv_gauge_set_needle_num(new_gauge, 1, NULL); lv_obj_set_size(new_gauge, LV_GAUGE_DEF_WIDTH, LV_GAUGE_DEF_HEIGHT); - lv_obj_set_style(new_gauge, lv_gauges_get(LV_GAUGES_DEF, NULL)); + lv_obj_set_style(new_gauge, lv_style_get(LV_STYLE_PRETTY, NULL)); } /*Copy an existing gauge*/ else { @@ -96,8 +97,7 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, lv_obj_t * copy) ext->min = copy_ext->min; ext->max = copy_ext->max; ext->low_critical = copy_ext->low_critical; - lv_gauge_set_needle_num(new_gauge, lv_gauge_get_needle_num(copy)); - lv_gauge_set_text(new_gauge, lv_gauge_get_text(copy)); + lv_gauge_set_needle_num(new_gauge, copy_ext->needle_num, copy_ext->needle_color); uint8_t i; for(i = 0; i < ext->needle_num; i++) { @@ -129,13 +129,13 @@ bool lv_gauge_signal(lv_obj_t * gauge, lv_signal_t sign, void * param) * make the object specific signal handling */ if(valid != false) { lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); - switch(sign) { - case LV_SIGNAL_CLEANUP: - dm_free(ext->values); - ext->values = NULL; - break; - default: - break; + if(sign == LV_SIGNAL_CLEANUP) { + dm_free(ext->values); + ext->values = NULL; + } + else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { + lv_style_t * style_crit = lv_gauge_get_style_crit(gauge); + if(style_crit->swidth > gauge->ext_size) gauge->ext_size = style_crit->swidth; } } @@ -147,11 +147,12 @@ bool lv_gauge_signal(lv_obj_t * gauge, lv_signal_t sign, void * param) *====================*/ /** - * Set the number of needles (should be <= LV_GAUGE_MAX_NEEDLE) + * Set the number of needles * @param gauge pointer to gauge object * @param num number of needles + * @param colors an array of colors for needles (with 'num' elements) */ -void lv_gauge_set_needle_num(lv_obj_t * gauge, uint8_t num) +void lv_gauge_set_needle_num(lv_obj_t * gauge, uint8_t num, color_t * colors) { lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); if(ext->values != NULL) dm_free(ext->values); @@ -164,6 +165,7 @@ void lv_gauge_set_needle_num(lv_obj_t * gauge, uint8_t num) } ext->needle_num = num; + ext->needle_color = colors; lv_obj_inv(gauge); } @@ -204,24 +206,6 @@ void lv_gauge_set_value(lv_obj_t * gauge, uint8_t needle, int16_t value) lv_obj_inv(gauge); } -/** - * Set text on a gauge - * @param gauge pinter to a gauge object - * @param txt a printf like format string - * with 1 place for a number (e.g. "Value: %d"); - */ -void lv_gauge_set_text(lv_obj_t * gauge, const char * txt) -{ - lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); - - if(ext->txt != NULL) dm_free(ext->txt); - - ext->txt = dm_alloc(strlen(txt) + 1); - strcpy(ext->txt, txt); - - lv_obj_inv(gauge); -} - /** * Set which value is more critical (lower or higher) * @param gauge pointer to a gauge object @@ -236,6 +220,33 @@ void lv_gauge_set_low_critical(lv_obj_t * gauge, bool low) lv_obj_inv(gauge); } +/** + * Set the scale settings of a gauge + * @param gauge pointer to a gauge object + * @param angle angle of the scale (0..360) + * @param label_num number of labels on the scale (~5) + */ +void lv_gauge_set_scale(lv_obj_t * gauge, uint16_t angle, uint8_t label_num) +{ + lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); + ext->scale_angle = angle; + ext->scale_label_num = label_num; + + lv_obj_inv(gauge); +} + +/** + * Set the critical style of the gauge + * @param gauge pointer to a gauge object + * @param style pointer to the new critical style + */ +void lv_gauge_set_style_critical(lv_obj_t * gauge, lv_style_t * style) +{ + lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); + ext->style_critical = style; + gauge->signal_f(gauge, LV_SIGNAL_REFR_EXT_SIZE, NULL); + lv_obj_inv(gauge); +} /*===================== * Getter functions @@ -267,18 +278,6 @@ int16_t lv_gauge_get_value(lv_obj_t * gauge, uint8_t needle) return ext->values[needle]; } -/** - * Get the text of a gauge - * @param gauge pointer to gauge - * @return the set text. (not with the current value) - */ -const char * lv_gauge_get_text(lv_obj_t * gauge) -{ - lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); - return ext->txt; - -} - /** * Get which value is more critical (lower or higher) * @param gauge pointer to a gauge object @@ -292,34 +291,17 @@ bool lv_gauge_get_low_critical(lv_obj_t * gauge) } /** - * Return with a pointer to a built-in style and/or copy it to a variable - * @param style a style name from lv_gauges_builtin_t enum - * @param copy copy the style to this variable. (NULL if unused) - * @return pointer to an lv_gauges_t style + * Get the critical style of the gauge + * @param gauge pointer to a gauge object + * @return pointer to the critical style */ -lv_gauges_t * lv_gauges_get(lv_gauges_builtin_t style, lv_gauges_t * copy) +lv_style_t * lv_gauge_get_style_crit(lv_obj_t * gauge) { - static bool style_inited = false; + lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); - /*Make the style initialization if it is not done yet*/ - if(style_inited == false) { - lv_gauges_init(); - style_inited = true; - } + if(ext->style_critical == NULL) return lv_obj_get_style(gauge); - lv_gauges_t *style_p; - - switch(style) { - case LV_GAUGES_DEF: - style_p = &lv_gauges_def; - break; - default: - style_p = &lv_gauges_def; - } - - if(copy != NULL) memcpy(copy, style_p, sizeof(lv_gauges_t)); - - return style_p; + return ext->style_critical; } /********************** @@ -344,13 +326,13 @@ static bool lv_gauge_design(lv_obj_t * gauge, const area_t * mask, lv_design_mod } /*Draw the object*/ else if(mode == LV_DESIGN_DRAW_MAIN) { - lv_gauges_t * style = lv_obj_get_style(gauge); + lv_style_t * style_base = lv_obj_get_style(gauge); + lv_style_t * style_critical = lv_gauge_get_style_crit(gauge); lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); /* Draw the background * Re-color the gauge according to the critical value*/ - color_t mcolor_min = style->bg_rect.base.color; - color_t gcolor_min = style->bg_rect.gcolor; + lv_style_t style_bg; int16_t critical_val = ext->low_critical == 0 ? ext->min : ext->max; uint8_t i; @@ -363,15 +345,22 @@ static bool lv_gauge_design(lv_obj_t * gauge, const area_t * mask, lv_design_mod if(ext->low_critical != 0) ratio = OPA_COVER - ratio; - style->bg_rect.base.color= color_mix(style->critical_mcolor, mcolor_min, ratio); - style->bg_rect.gcolor = color_mix(style->critical_gcolor, gcolor_min, ratio); + /*Mix the normal and the critical style*/ + memcpy(&style_bg, style_base, sizeof(lv_style_t)); + style_bg.ccolor = color_mix(style_critical->ccolor, style_base->ccolor, ratio); + style_bg.mcolor= color_mix(style_critical->mcolor, style_base->mcolor, ratio); + style_bg.gcolor = color_mix(style_critical->gcolor, style_base->gcolor, ratio); + style_bg.bcolor = color_mix(style_critical->bcolor, style_base->bcolor, ratio); + style_bg.scolor = color_mix(style_critical->scolor, style_base->scolor, ratio); + style_bg.swidth = (cord_t)((cord_t)(style_critical->swidth + style_base->swidth) * ratio) >> 8; + + gauge->style_p = &style_bg; ancestor_design_f(gauge, mask, mode); - style->bg_rect.base.color= mcolor_min; - style->bg_rect.gcolor = gcolor_min; + gauge->style_p = style_base; - lv_gauge_draw_scale(gauge, mask); + lv_gauge_draw_scale(gauge, mask, &style_bg); - lv_gauge_draw_needle(gauge, mask); + lv_gauge_draw_needle(gauge, mask, &style_bg); } /*Post draw when the children are drawn*/ else if(mode == LV_DESIGN_DRAW_POST) { @@ -386,22 +375,21 @@ static bool lv_gauge_design(lv_obj_t * gauge, const area_t * mask, lv_design_mod * @param gauge pointer to gauge object * @param mask mask of drawing */ -static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask) +static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask, lv_style_t * style) { - lv_gauges_t * style = lv_obj_get_style(gauge); lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); char scale_txt[16]; - cord_t r = lv_obj_get_width(gauge) / 2 - style->bg_rect.opad; + cord_t r = lv_obj_get_width(gauge) / 2 - style->hpad; cord_t x_ofs = lv_obj_get_width(gauge) / 2 + gauge->cords.x1; cord_t y_ofs = lv_obj_get_height(gauge) / 2 + gauge->cords.y1; - int16_t angle_ofs = 90 + (360 - style->scale_angle) / 2; + int16_t angle_ofs = 90 + (360 - ext->scale_angle) / 2; uint8_t i; - for(i = 0; i < style->scale_label_num; i++) { + for(i = 0; i < ext->scale_label_num; i++) { /*Calculate the position a scale label*/ - int16_t angle = (i * style->scale_angle) / (style->scale_label_num - 1) + angle_ofs; + int16_t angle = (i * ext->scale_angle) / (ext->scale_label_num - 1) + angle_ofs; cord_t y = (int32_t)((int32_t)trigo_sin(angle) * r) / TRIGO_SIN_MAX; y += y_ofs; @@ -409,14 +397,14 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask) cord_t x = (int32_t)((int32_t)trigo_sin(angle + 90) * r) / TRIGO_SIN_MAX; x += x_ofs; - int16_t scale_act = (int32_t)((int32_t)(ext->max - ext->min) * i) / (style->scale_label_num - 1); + int16_t scale_act = (int32_t)((int32_t)(ext->max - ext->min) * i) / (ext->scale_label_num - 1); scale_act += ext->min; sprintf(scale_txt, "%d", scale_act); area_t label_cord; point_t label_size; - txt_get_size(&label_size, scale_txt, style->scale_labels.font, - style->scale_labels.letter_space, style->scale_labels.line_space, + txt_get_size(&label_size, scale_txt, style->font, + style->letter_space, style->line_space, LV_CORD_MAX, TXT_FLAG_NONE); /*Draw the label*/ @@ -425,132 +413,59 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const area_t * mask) label_cord.x2 = label_cord.x1 + label_size.x; label_cord.y2 = label_cord.y1 + label_size.y; - lv_draw_label(&label_cord, mask, &style->scale_labels, scale_txt, TXT_FLAG_NONE); + lv_draw_label(&label_cord, mask, style, scale_txt, TXT_FLAG_NONE); } - - /*Calculate the critical value*/ - int16_t critical_value = ext->low_critical == 0 ? ext->min : ext->max;; - for(i = 0; i < ext->needle_num; i++) { - critical_value = ext->low_critical == 0 ? - MATH_MAX(critical_value, ext->values[i]) : MATH_MIN(critical_value, ext->values[i]); - } - - /*Write the critical value if enabled*/ - if(ext->txt[0] != '\0') { - char value_txt[16]; - sprintf(value_txt, ext->txt, critical_value); - - area_t label_cord; - point_t label_size; - txt_get_size(&label_size, value_txt, style->value_labels.font, - style->value_labels.letter_space, style->value_labels.line_space, - LV_CORD_MAX, TXT_FLAG_NONE); - - /*Draw the label*/ - label_cord.x1 = gauge->cords.x1 + lv_obj_get_width(gauge) / 2 - label_size.x / 2; - label_cord.y1 = gauge->cords.y1 + - (cord_t)style->value_pos * lv_obj_get_height(gauge) / 100 - label_size.y / 2; - - label_cord.x2 = label_cord.x1 + label_size.x; - label_cord.y2 = label_cord.y1 + label_size.y; - - lv_draw_label(&label_cord, mask, &style->value_labels, value_txt, TXT_FLAG_NONE); - } - } /** * Draw the needles of a gauge * @param gauge pointer to gauge object * @param mask mask of drawing */ -static void lv_gauge_draw_needle(lv_obj_t * gauge, const area_t * mask) +static void lv_gauge_draw_needle(lv_obj_t * gauge, const area_t * mask, lv_style_t * style) { - lv_gauges_t * style = lv_obj_get_style(gauge); + lv_style_t style_needle; lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); - cord_t r = lv_obj_get_width(gauge) / 2 - style->bg_rect.opad; + cord_t r = lv_obj_get_width(gauge) / 2 - style->opad; cord_t x_ofs = lv_obj_get_width(gauge) / 2 + gauge->cords.x1; cord_t y_ofs = lv_obj_get_height(gauge) / 2 + gauge->cords.y1; - int16_t angle_ofs = 90 + (360 - style->scale_angle) / 2; + int16_t angle_ofs = 90 + (360 - ext->scale_angle) / 2; point_t p_mid; point_t p_end; uint8_t i; + memcpy(&style_needle, style, sizeof(lv_style_t)); + p_mid.x = x_ofs; p_mid.y = y_ofs; for(i = 0; i < ext->needle_num; i++) { /*Calculate the end point of a needle*/ - int16_t needle_angle = (ext->values[i] - ext->min) * style->scale_angle / + int16_t needle_angle = (ext->values[i] - ext->min) * ext->scale_angle / (ext->max - ext->min) + angle_ofs; p_end.y = (trigo_sin(needle_angle) * r) / TRIGO_SIN_MAX + y_ofs; p_end.x = (trigo_sin(needle_angle + 90) * r) / TRIGO_SIN_MAX + x_ofs; /*Draw the needle with the corresponding color*/ - style->needle_lines.base.color = style->needle_color[i]; - - lv_draw_line(&p_mid, &p_end, mask, &style->needle_lines); + if(ext->needle_color == NULL) style_needle.ccolor = LV_GAUGE_DEF_NEEDLE_COLOR; + else style_needle.ccolor = ext->needle_color[i]; + lv_draw_line(&p_mid, &p_end, mask, &style_needle); } /*Draw the needle middle area*/ - lv_rects_t nm; + lv_style_t style_neddle_mid; + lv_style_get(LV_STYLE_PLAIN, &style_neddle_mid); + style_neddle_mid.mcolor = style->bcolor; + style_neddle_mid.gcolor = style->bcolor; + style_neddle_mid.radius = LV_RECT_CIRCLE; + area_t nm_cord; - lv_rects_get(LV_RECTS_PLAIN, &nm); - nm.bwidth = 0; - nm.radius = LV_RECT_CIRCLE; - nm.base.color = style->needle_mid_color; - nm.gcolor = style->needle_mid_color; + nm_cord.x1 = x_ofs - style->opad; + nm_cord.y1 = y_ofs - style->opad; + nm_cord.x2 = x_ofs + style->opad; + nm_cord.y2 = y_ofs + style->opad; - nm_cord.x1 = x_ofs - style->needle_mid_size; - nm_cord.y1 = y_ofs - style->needle_mid_size; - nm_cord.x2 = x_ofs + style->needle_mid_size; - nm_cord.y2 = y_ofs + style->needle_mid_size; - - lv_draw_rect(&nm_cord, mask, &nm); - -} - -/** - * Initialize the built-in gauge styles - */ -static void lv_gauges_init(void) -{ - /*Default style*/ - lv_rects_get(LV_RECTS_FANCY, &lv_gauges_def.bg_rect); - lv_gauges_def.bg_rect.radius = LV_RECT_CIRCLE; - lv_gauges_def.bg_rect.bwidth = 4 * LV_DOWNSCALE; - lv_gauges_def.bg_rect.base.color = COLOR_MAKE(0x00, 0xaa, 0x00);//GREEN; - lv_gauges_def.bg_rect.gcolor = COLOR_BLACK; - lv_gauges_def.bg_rect.bcolor = COLOR_BLACK; - lv_gauges_def.bg_rect.opad = LV_DPI / 4; - - lv_gauges_def.critical_gcolor = COLOR_BLACK; - lv_gauges_def.critical_mcolor = COLOR_MAKE(0xff, 0x50, 0x50); - - lv_labels_get(LV_LABELS_TXT, &lv_gauges_def.scale_labels); - lv_gauges_def.scale_labels.base.color = COLOR_MAKE(0xd0, 0xd0, 0xd0); - - lv_labels_get(LV_LABELS_TITLE, &lv_gauges_def.value_labels); - lv_gauges_def.value_labels.base.color = COLOR_WHITE; - lv_gauges_def.value_labels.letter_space = 3 * LV_DOWNSCALE; - lv_gauges_def.value_labels.mid = 1; - - lv_gauges_def.value_pos = 75; - - lv_lines_get(LV_LINES_DEF, &lv_gauges_def.needle_lines); - lv_gauges_def.needle_lines.base.color = COLOR_WHITE; /*Overwritten by needle_color[]*/ - lv_gauges_def.needle_lines.base.opa = OPA_80; - lv_gauges_def.needle_lines.width = 3 * LV_DOWNSCALE; - - lv_gauges_def.needle_color[0] = COLOR_SILVER; - lv_gauges_def.needle_color[1] = COLOR_MAKE(0x40, 0x90, 0xe0); - lv_gauges_def.needle_color[2] = COLOR_MAKE(0x50, 0xe0, 0x50); - lv_gauges_def.needle_color[3] = COLOR_MAKE(0xff, 0xff, 0x70); - - lv_gauges_def.needle_mid_size = 5 * LV_DOWNSCALE; - lv_gauges_def.needle_mid_color = COLOR_GRAY; - lv_gauges_def.scale_label_num = 6; - lv_gauges_def.scale_angle = 220; + lv_draw_rect(&nm_cord, mask, &style_neddle_mid); } #endif diff --git a/lv_objx/lv_gauge.h b/lv_objx/lv_gauge.h index 8e694f743..0dc82576c 100644 --- a/lv_objx/lv_gauge.h +++ b/lv_objx/lv_gauge.h @@ -48,48 +48,23 @@ /*Data of gauge*/ typedef struct { - lv_rect_ext_t bg_rect; /*Ext. of ancestor*/ + /*No inherited ext*/ /*Ext. of ancestor*/ /*New data for this type */ int16_t min; /*Minimum value of the scale*/ int16_t max; /*Maximum value of the scale*/ int16_t * values; /*Array of the set values (for needles) */ - char * txt; /*Printf-like text to display with the most critical value (e.g. "Value: %d")*/ + lv_style_t * style_critical;/*Fade to this style nearer to the critical value*/ + color_t * needle_color; /*A color of the needles (color_t my_colors[needle_num])*/ + uint16_t scale_angle; /*Angle of the scale in deg. (e.g. 220)*/ + uint8_t scale_label_num; /*Number of scale labels (~6)*/ uint8_t needle_num; /*Number of needles*/ uint8_t low_critical:1; /*0: the higher value is more critical, 1: the lower value is more critical*/ }lv_gauge_ext_t; -/*Style of gauge*/ -typedef struct -{ - lv_rects_t bg_rect; /*Style of ancestor*/ - /*New style element for this type */ - color_t critical_mcolor; /*Top color at critical value*/ - color_t critical_gcolor; /*Bottom color at critical value*/ - /*Scale settings*/ - uint16_t scale_angle; /*Angle of the scale in deg. (e.g. 220)*/ - lv_labels_t scale_labels; /*Style of the scale labels*/ - uint8_t scale_label_num; /*Number of scale labels (~6)*/ - /*Needle settings*/ - lv_lines_t needle_lines; /*Style of neddles*/ - color_t needle_color[LV_GAUGE_MAX_NEEDLE]; /*Color of needles*/ - color_t needle_mid_color; /*Color of middle where the needles start*/ - cord_t needle_mid_size; /*Size of the needle middle area (circle diameter)*/ - /*Value text settings*/ - lv_labels_t value_labels; /*Style of the value label*/ - uint8_t value_pos; /*Vertical position of the value label in percentage of object height (0..100 %)*/ -}lv_gauges_t; - -/*Built-in styles of gauge*/ -typedef enum -{ - LV_GAUGES_DEF, -}lv_gauges_builtin_t; - /********************** * GLOBAL PROTOTYPES **********************/ - /** * Create a gauge objects * @param par pointer to an object, it will be the parent of the new gauge @@ -112,7 +87,7 @@ bool lv_gauge_signal(lv_obj_t * gauge, lv_signal_t sign, void * param); * @param gauge pointer to gauge object * @param num number of needles */ -void lv_gauge_set_needle_num(lv_obj_t * gauge, uint8_t num); +void lv_gauge_set_needle_num(lv_obj_t * gauge, uint8_t num, color_t * colors); /** * Set the range of a gauge @@ -145,6 +120,7 @@ void lv_gauge_set_text(lv_obj_t * gauge, const char * txt); */ void lv_gauge_set_low_critical(lv_obj_t * gauge, bool low); +void lv_gauge_vet_style_critical(lv_obj_t * gauge, lv_style_t * style); /** * Get the number of needles on a gauge * @param gauge pointer to gauge @@ -174,13 +150,7 @@ const char * lv_gauge_get_text(lv_obj_t * gauge); */ bool lv_gauge_get_low_critical(lv_obj_t * gauge); -/** - * Return with a pointer to a built-in style and/or copy it to a variable - * @param style a style name from lv_gauges_builtin_t enum - * @param copy copy the style to this variable. (NULL if unused) - * @return pointer to an lv_gauges_t style - */ -lv_gauges_t * lv_gauges_get(lv_gauges_builtin_t style, lv_gauges_t * copy); +lv_style_t * lv_gauge_get_style_crit(lv_obj_t * gauge); /********************** * MACROS diff --git a/lv_objx/lv_rect.c b/lv_objx/lv_rect.c index b3ec743cc..cf5825935 100644 --- a/lv_objx/lv_rect.c +++ b/lv_objx/lv_rect.c @@ -35,8 +35,10 @@ /********************** * STATIC PROTOTYPES **********************/ +#if 0 static bool lv_rect_design(lv_obj_t * rect, const area_t * mask, lv_design_mode_t mode); -static void lv_rect_draw_shadow(lv_obj_t * rect, const area_t * mask); +#endif + static void lv_rect_refr_layout(lv_obj_t * rect); static void lv_rect_layout_col(lv_obj_t * rect); static void lv_rect_layout_row(lv_obj_t * rect); @@ -79,7 +81,6 @@ lv_obj_t * lv_rect_create(lv_obj_t * par, lv_obj_t * copy) ext->vpad_en = 0; ext->layout = LV_RECT_LAYOUT_OFF; - lv_obj_set_design_f(new_rect, lv_rect_design); lv_obj_set_signal_f(new_rect, lv_rect_signal); /*Init the new rectangle*/ @@ -124,7 +125,6 @@ bool lv_rect_signal(lv_obj_t * rect, lv_signal_t sign, void * param) case LV_SIGNAL_STYLE_CHG: /*Recalculate the padding if the style changed*/ lv_rect_refr_layout(rect); lv_rect_refr_autofit(rect); - lv_obj_refr_ext_size(rect); break; case LV_SIGNAL_CHILD_CHG: lv_rect_refr_layout(rect); @@ -137,9 +137,6 @@ bool lv_rect_signal(lv_obj_t * rect, lv_signal_t sign, void * param) lv_rect_refr_autofit(rect); } break; - case LV_SIGNAL_REFR_EXT_SIZE: - if(style->swidth > rect->ext_size) rect->ext_size = style->swidth; - break; default: break; } @@ -228,7 +225,7 @@ bool lv_rect_get_vfit(lv_obj_t * rect) /********************** * STATIC FUNCTIONS **********************/ - +#if 0 /** * Handle the drawing related tasks of the rectangles * @param rect pointer to an object @@ -242,91 +239,18 @@ bool lv_rect_get_vfit(lv_obj_t * rect) static bool lv_rect_design(lv_obj_t * rect, const area_t * mask, lv_design_mode_t mode) { if(mode == LV_DESIGN_COVER_CHK) { - /* Because of the radius it is not sure the area is covered - * Check the areas where there is no radius*/ - if(rect->style_p->empty != 0) return false; - - uint16_t r = rect->style_p->radius; - - if(r == LV_RECT_CIRCLE) return false; - - area_t area_tmp; - - /*Check horizontally without radius*/ - lv_obj_get_cords(rect, &area_tmp); - area_tmp.x1 += r; - area_tmp.x2 -= r; - if(area_is_in(mask, &area_tmp) == true) return true; - - /*Check vertically without radius*/ - lv_obj_get_cords(rect, &area_tmp); - area_tmp.y1 += r; - area_tmp.y2 -= r; - if(area_is_in(mask, &area_tmp) == true) return true; return false; } else if(mode == LV_DESIGN_DRAW_MAIN) { - lv_style_t * style = lv_obj_get_style(rect); - area_t area; - lv_obj_get_cords(rect, &area); - /*Draw the rectangle*/ - lv_draw_rect(&area, mask, style); - lv_rect_draw_shadow(rect, mask); } else if(mode == LV_DESIGN_DRAW_POST) { } return true; } +#endif -/** - * Draw a shadow around the object - * @param rect pointer to rectangle object - * @param mask pointer to a mask area (from the design functions) - */ -static void lv_rect_draw_shadow(lv_obj_t * rect, const area_t * mask) -{ - lv_style_t * style = lv_obj_get_style(rect); - cord_t swidth = style->swidth; - if(swidth == 0) return; - uint8_t res = LV_DOWNSCALE * 2; - if(swidth < res) return; - - area_t shadow_area; - lv_style_t shadow_style; - lv_obj_get_cords(rect, &shadow_area); - - memcpy(&shadow_style, style, sizeof(lv_style_t)); - - shadow_style.empty = 1; - shadow_style.bwidth = swidth; - shadow_style.radius = style->radius; - if(shadow_style.radius == LV_RECT_CIRCLE) { - shadow_style.radius = MATH_MIN(lv_obj_get_width(rect), lv_obj_get_height(rect)); - } - shadow_style.radius += swidth + 1; - shadow_style.bcolor = style->scolor; - shadow_style.bopa = 100; - - shadow_area.x1 -= swidth; - shadow_area.y1 -= swidth; - shadow_area.x2 += swidth; - shadow_area.y2 += swidth; - - cord_t i; - shadow_style.opa = style->opa / (swidth / res); - - for(i = 1; i < swidth; i += res) { - lv_draw_rect(&shadow_area, mask, &shadow_style); - shadow_style.radius -= res; - shadow_style.bwidth -= res; - shadow_area.x1 += res; - shadow_area.y1 += res; - shadow_area.x2 -= res; - shadow_area.y2 -= res; - } -} /** * Refresh the layout of a rectangle diff --git a/lv_objx/lv_rect.h b/lv_objx/lv_rect.h index a57c79933..da06b273a 100644 --- a/lv_objx/lv_rect.h +++ b/lv_objx/lv_rect.h @@ -18,7 +18,6 @@ /********************* * DEFINES *********************/ -#define LV_RECT_CIRCLE ((cord_t)-1) /*A very big radius to always draw as circle*/ /********************** * TYPEDEFS