From 1dc043882702d3d84f857735f3c9afb0a9a63abf Mon Sep 17 00:00:00 2001 From: Kiss-Vamosi Gabor Date: Tue, 10 Jan 2017 08:36:12 +0100 Subject: [PATCH] lv_gauge: updated, math_base: min max rename --- lv_draw/lv_draw.c | 32 ++--- lv_misc/area.c | 16 +-- lv_misc/text.c | 2 +- lv_objx/lv_gauge.c | 287 +++++++++++++++++++++++++++++++++------------ lv_objx/lv_gauge.h | 28 +++-- lv_objx/lv_img.c | 1 + lv_objx/lv_line.c | 4 +- lv_objx/lv_page.c | 8 +- lv_objx/lv_rect.c | 10 +- 9 files changed, 272 insertions(+), 116 deletions(-) diff --git a/lv_draw/lv_draw.c b/lv_draw/lv_draw.c index ddb69216a..5628e9370 100644 --- a/lv_draw/lv_draw.c +++ b/lv_draw/lv_draw.c @@ -322,10 +322,10 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, last_y = act_point.y; last_x = act_point.x; - draw_area.x1 = min(act_area.x1, act_area.x2); - draw_area.x2 = max(act_area.x1, act_area.x2); - draw_area.y1 = min(act_area.y1, act_area.y2); - draw_area.y2 = max(act_area.y1, act_area.y2); + draw_area.x1 = MATH_MIN(act_area.x1, act_area.x2); + draw_area.x2 = MATH_MAX(act_area.x1, act_area.x2); + draw_area.y1 = MATH_MIN(act_area.y1, act_area.y2); + draw_area.y2 = MATH_MAX(act_area.y1, act_area.y2); fill_fp(&draw_area, mask_p, lines_p->objs.color, opa); } if (hor == false && last_x != act_point.x) { @@ -338,10 +338,10 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, last_y = act_point.y; last_x = act_point.x; - draw_area.x1 = min(act_area.x1, act_area.x2); - draw_area.x2 = max(act_area.x1, act_area.x2); - draw_area.y1 = min(act_area.y1, act_area.y2); - draw_area.y2 = max(act_area.y1, act_area.y2); + draw_area.x1 = MATH_MIN(act_area.x1, act_area.x2); + draw_area.x2 = MATH_MAX(act_area.x1, act_area.x2); + draw_area.y1 = MATH_MIN(act_area.y1, act_area.y2); + draw_area.y2 = MATH_MAX(act_area.y1, act_area.y2); fill_fp(&draw_area, mask_p, lines_p->objs.color, opa); } @@ -366,10 +366,10 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, act_area.y1 = last_y - width_half ; act_area.y2 = act_point.y + width_half + width_1; - draw_area.x1 = min(act_area.x1, act_area.x2); - draw_area.x2 = max(act_area.x1, act_area.x2); - draw_area.y1 = min(act_area.y1, act_area.y2); - draw_area.y2 = max(act_area.y1, act_area.y2); + draw_area.x1 = MATH_MIN(act_area.x1, act_area.x2); + draw_area.x2 = MATH_MAX(act_area.x1, act_area.x2); + draw_area.y1 = MATH_MIN(act_area.y1, act_area.y2); + draw_area.y2 = MATH_MAX(act_area.y1, act_area.y2); fill_fp(&draw_area, mask_p, lines_p->objs.color, opa); } if (hor == false) { @@ -380,10 +380,10 @@ void lv_draw_line(const point_t * p1, const point_t * p2, const area_t * mask_p, act_area.y1 = last_y; act_area.y2 = act_point.y; - draw_area.x1 = min(act_area.x1, act_area.x2); - draw_area.x2 = max(act_area.x1, act_area.x2); - draw_area.y1 = min(act_area.y1, act_area.y2); - draw_area.y2 = max(act_area.y1, act_area.y2); + draw_area.x1 = MATH_MIN(act_area.x1, act_area.x2); + draw_area.x2 = MATH_MAX(act_area.x1, act_area.x2); + draw_area.y1 = MATH_MIN(act_area.y1, act_area.y2); + draw_area.y2 = MATH_MAX(act_area.y1, act_area.y2); fill_fp(&draw_area, mask_p, lines_p->objs.color, opa); } } diff --git a/lv_misc/area.c b/lv_misc/area.c index 92482de73..4ebbcbed6 100644 --- a/lv_misc/area.c +++ b/lv_misc/area.c @@ -94,10 +94,10 @@ uint32_t area_get_size(const area_t * area_p) bool area_union(area_t * res_p, const area_t * a1_p, const area_t * a2_p) { /* Get the smaller area from 'a1_p' and 'a2_p' */ - res_p->x1 = max(a1_p->x1, a2_p->x1); - res_p->y1 = max(a1_p->y1, a2_p->y1); - res_p->x2 = min(a1_p->x2, a2_p->x2); - res_p->y2 = min(a1_p->y2, a2_p->y2); + res_p->x1 = MATH_MAX(a1_p->x1, a2_p->x1); + res_p->y1 = MATH_MAX(a1_p->y1, a2_p->y1); + res_p->x2 = MATH_MIN(a1_p->x2, a2_p->x2); + res_p->y2 = MATH_MIN(a1_p->y2, a2_p->y2); /*If x1 or y1 greater then x2 or y2 then the areas union is empty*/ bool union_ok = true; @@ -117,10 +117,10 @@ bool area_union(area_t * res_p, const area_t * a1_p, const area_t * a2_p) */ void area_join(area_t * a_res_p, const area_t * a1_p, const area_t * a2_p) { - a_res_p->x1 = min(a1_p->x1, a2_p->x1); - a_res_p->y1 = min(a1_p->y1, a2_p->y1); - a_res_p->x2 = max(a1_p->x2, a2_p->x2); - a_res_p->y2 = max(a1_p->y2, a2_p->y2); + a_res_p->x1 = MATH_MIN(a1_p->x1, a2_p->x1); + a_res_p->y1 = MATH_MIN(a1_p->y1, a2_p->y1); + a_res_p->x2 = MATH_MAX(a1_p->x2, a2_p->x2); + a_res_p->y2 = MATH_MAX(a1_p->y2, a2_p->y2); } /** diff --git a/lv_misc/text.c b/lv_misc/text.c index b0a4be7fd..7fd982943 100644 --- a/lv_misc/text.c +++ b/lv_misc/text.c @@ -56,7 +56,7 @@ void txt_get_size(point_t * size_res, const char * text, const font_t * font, act_line_length = txt_get_width(&text[line_start], new_line_start - line_start, font, letter_space); - size_res->x = max(act_line_length, size_res->x); + size_res->x = MATH_MAX(act_line_length, size_res->x); line_start = new_line_start; } diff --git a/lv_objx/lv_gauge.c b/lv_objx/lv_gauge.c index 592dd8fed..7691c73eb 100644 --- a/lv_objx/lv_gauge.c +++ b/lv_objx/lv_gauge.c @@ -15,6 +15,7 @@ #include "../lv_draw/lv_draw.h" #include "../lv_misc/text.h" #include "misc/math/trigo.h" +#include "misc/math/math_base.h" /********************* * DEFINES @@ -30,6 +31,8 @@ * 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); /********************** @@ -68,24 +71,31 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, lv_obj_t * copy) /*Initialize the allocated 'ext' */ ext->min = 0; ext->max = 100; - ext->value = 90 ; - + ext->needle_num = 3; + ext->values = NULL; if(ancestor_design_f == NULL) ancestor_design_f = lv_obj_get_design_f(new_gauge); - /*The signal and design functions are not copied so set them here*/ lv_obj_set_signal_f(new_gauge, lv_gauge_signal); lv_obj_set_design_f(new_gauge, lv_gauge_design); /*Init the new gauge gauge*/ if(copy == NULL) { + lv_gauge_set_needle_num(new_gauge, 1); 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)); } /*Copy an existing gauge*/ else { lv_gauge_ext_t * copy_ext = lv_obj_get_ext(copy); + ext->min = copy_ext->min; + ext->max = copy_ext->max; + ext->needle_num = copy_ext->needle_num; + uint8_t i; + for(i = 0; i < ext->needle_num; i++) { + ext->values[i] = copy_ext->values[i]; + } /*Refresh the style with new signal function*/ lv_obj_refr_style(new_gauge); @@ -111,9 +121,11 @@ bool lv_gauge_signal(lv_obj_t * gauge, 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_gauge_ext_t * ext = lv_obj_get_ext(gauge); switch(sign) { case LV_SIGNAL_CLEANUP: - /*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/ + dm_free(ext->values); + ext->values = NULL; break; default: break; @@ -127,13 +139,54 @@ bool lv_gauge_signal(lv_obj_t * gauge, lv_signal_t sign, void * param) * Setter functions *====================*/ -void lv_gauge_set_value(lv_obj_t * gauge, int16_t value) +/** + * Set the number of needles (should be <= LV_GAUGE_MAX_NEEDLE) + * @param gauge pointer to gauge object + * @param num number of needles + */ +void lv_gauge_set_needle_num(lv_obj_t * gauge, uint8_t num) { lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); + if(ext->values != NULL) dm_free(ext->values); + + ext->values = dm_alloc(num * sizeof(int16_t)); + + ext->needle_num = num; + lv_obj_inv(gauge); +} + +/** + * Set the range of a gauge + * @param gauge pointer to gauge object + * @param min min value + * @param max max value + */ +void lv_gauge_set_range(lv_obj_t * gauge, int16_t min, int16_t max) +{ + lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); + + /*Be sure the smaller value is min and the greater is max*/ + ext->min = MATH_MIN(min, max); + ext->max = MATH_MAX(min, max); + +} + +/** + * Set the value of a needle + * @param gauge pointer to gauge + * @param value the new value + * @param needle the id of the needle + */ +void lv_gauge_set_value(lv_obj_t * gauge, int16_t value, uint8_t needle) +{ + lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); + + if(needle >= ext->needle_num) return; + if(value > ext->max) value = ext->max; if(value < ext->min) value = ext->min; - ext->value = value; + ext->values[needle] = value; lv_obj_inv(gauge); } @@ -142,6 +195,33 @@ void lv_gauge_set_value(lv_obj_t * gauge, int16_t value) * Getter functions *====================*/ +/** + * Get the number of needles on a gauge + * @param gauge pointer to gauge + * @return number of needles + */ +uint8_t lv_gauge_get_needle_num(lv_obj_t * gauge) +{ + lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); + return ext->needle_num; +} + +/** + * Get the value of a needle + * @param gauge pointer to gauge object + * @param needle the id of the needle + * @return the value of the needle [min,max] + */ +int16_t lv_gauge_get_value(lv_obj_t * gauge, uint8_t needle) +{ + lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); + + if(needle >= ext->needle_num) return 0; + + + return ext->values[needle]; +} + /** * 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 @@ -180,7 +260,6 @@ lv_gauges_t * lv_gauges_get(lv_gauges_builtin_t style, lv_gauges_t * copy) * STATIC FUNCTIONS **********************/ - /** * Handle the drawing related tasks of the gauges * @param gauge pointer to an object @@ -202,75 +281,27 @@ static bool lv_gauge_design(lv_obj_t * gauge, const area_t * mask, lv_design_mod lv_gauges_t * style = lv_obj_get_style(gauge); lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); - ancestor_design_f(gauge, mask, mode); - - char scale_txt[16]; - area_t label_cord; - point_t label_size; + /* Draw the background + * Recolor the gauge according to the greatest value*/ + color_t mcolor_min = style->rects.objs.color; + color_t gcolor_min = style->rects.gcolor; + int16_t max_val = ext->min; uint8_t i; - cord_t r = lv_obj_get_width(gauge) / 2 - style->label_pad; - cord_t x; - cord_t y; - 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; - int16_t angle_ofs = 90 + (360 - style->angle) / 2; - int16_t scale_act; - for(i = 0; i < style->label_num; i++) { - angle = (i * style->angle) / (style->label_num - 1) + angle_ofs; - y = (int32_t)((int32_t)trigo_sin(angle) * r) / TRIGO_SIN_MAX; - y += y_ofs; + for(i = 0; i < ext->needle_num; i++) max_val = MATH_MAX(max_val, ext->values[i]); - x = (int32_t)((int32_t)trigo_sin(angle + 90) * r) / TRIGO_SIN_MAX; - x += x_ofs; + opa_t ratio = ((max_val - ext->min) * OPA_COVER) / (ext->max - ext->min); - scale_act = (int32_t)((int32_t)(ext->max - ext->min) * i) / (style->label_num - 1); - scale_act += ext->min; - sprintf(scale_txt, "%d", scale_act); + style->rects.objs.color= color_mix(style->mcolor_max, mcolor_min, ratio); + style->rects.gcolor = color_mix(style->gcolor_max, gcolor_min, ratio); + ancestor_design_f(gauge, mask, mode); + style->rects.objs.color= mcolor_min; + style->rects.gcolor = gcolor_min; - txt_get_size(&label_size, scale_txt, font_get(style->scale_labels.font), - style->scale_labels.letter_space, style->scale_labels.line_space, LV_CORD_MAX); - - - label_cord.x1 = x - label_size.x / 2; - label_cord.y1 = y - 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->scale_labels, OPA_COVER, scale_txt); - } - - point_t p_mid; - point_t p_end; - - int16_t needle_angle = ext->value * 220 / (ext->max - ext->min) + angle_ofs; - int16_t needle_y = (trigo_sin(needle_angle) * r) / TRIGO_SIN_MAX; - int16_t needle_x = (trigo_sin(needle_angle + 90) * r) / TRIGO_SIN_MAX; - - p_mid.x = x_ofs; - p_mid.y = y_ofs; - p_end.x = needle_x + x_ofs; - p_end.y = needle_y + y_ofs; - - lv_draw_line(&p_mid, &p_end, mask, &style->needle_lines, OPA_50); - - lv_rects_t nm; - area_t nm_cord; - lv_rects_get(LV_RECTS_DEF, &nm); - nm.bwidth = 0; - nm.round = LV_RECT_CIRCLE; - nm.objs.color = COLOR_GRAY;//style->needle_lines.objs.color; - nm.gcolor = COLOR_GRAY;//style->needle_lines.objs.color; - - nm_cord.x1 = x_ofs - 5 * LV_DOWNSCALE; - nm_cord.y1 = y_ofs - 5 * LV_DOWNSCALE; - nm_cord.x2 = x_ofs + 5 * LV_DOWNSCALE; - nm_cord.y2 = y_ofs + 5 * LV_DOWNSCALE; - - lv_draw_rect(&nm_cord, mask, &nm, OPA_100); + lv_gauge_draw_scale(gauge, mask); + lv_gauge_draw_needle(gauge, mask); } /*Post draw when the children are drawn*/ else if(mode == LV_DESIGN_DRAW_POST) { @@ -280,6 +311,101 @@ static bool lv_gauge_design(lv_obj_t * gauge, const area_t * mask, lv_design_mod return true; } +/** + * Draw the scale of a gauge + * @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) +{ + 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->scale_pad; + 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; + + uint8_t i; + for(i = 0; i < style->scale_label_num; i++) { + /*Calculate the position a scale label*/ + int16_t angle = (i * style->scale_angle) / (style->scale_label_num - 1) + angle_ofs; + + cord_t y = (int32_t)((int32_t)trigo_sin(angle) * r) / TRIGO_SIN_MAX; + y += y_ofs; + + 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); + 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, font_get(style->scale_labels.font), + style->scale_labels.letter_space, style->scale_labels.line_space, LV_CORD_MAX); + + /*Draw the label*/ + label_cord.x1 = x - label_size.x / 2; + label_cord.y1 = y - 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->scale_labels, OPA_COVER, scale_txt); + } +} +/** + * 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) +{ + lv_gauges_t * style = lv_obj_get_style(gauge); + lv_gauge_ext_t * ext = lv_obj_get_ext(gauge); + + cord_t r = lv_obj_get_width(gauge) / 2 - style->scale_pad; + 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; + point_t p_mid; + point_t p_end; + uint8_t i; + + 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] * style->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.objs.color = style->needle_color[i]; + + lv_draw_line(&p_mid, &p_end, mask, &style->needle_lines, style->needle_opa); + } + + /*Draw the needle middle area*/ + lv_rects_t nm; + area_t nm_cord; + lv_rects_get(LV_RECTS_DEF, &nm); + nm.bwidth = 0; + nm.round = LV_RECT_CIRCLE; + nm.objs.color = style->needle_mid_color; + nm.gcolor = style->needle_mid_color; + + nm_cord.x1 = x_ofs - style->needle_mid_r; + nm_cord.y1 = y_ofs - style->needle_mid_r; + nm_cord.x2 = x_ofs + style->needle_mid_r; + nm_cord.y2 = y_ofs + style->needle_mid_r; + + lv_draw_rect(&nm_cord, mask, &nm, OPA_100); + +} /** * Initialize the built-in gauge styles @@ -290,17 +416,32 @@ static void lv_gauges_init(void) lv_rects_get(LV_RECTS_DEF, &lv_gauges_def.rects); lv_gauges_def.rects.round = LV_RECT_CIRCLE; lv_gauges_def.rects.bwidth = 6 * LV_DOWNSCALE; - lv_gauges_def.rects.gcolor = COLOR_RED; + lv_gauges_def.rects.objs.color = COLOR_SILVER;//MAKE(0x80, 0xFF, 0x80);//GREEN; + lv_gauges_def.rects.gcolor = COLOR_BLACK; + lv_gauges_def.rects.bcolor = COLOR_BLACK; + + lv_gauges_def.gcolor_max = COLOR_BLACK; + lv_gauges_def.mcolor_max = COLOR_MAKE(0xff, 0x50, 0x50); lv_labels_get(LV_RECTS_DEF, &lv_gauges_def.scale_labels); + lv_gauges_def.scale_labels.objs.color = COLOR_WHITE; lv_lines_get(LV_LINES_DEF, &lv_gauges_def.needle_lines); lv_gauges_def.needle_lines.objs.color = COLOR_WHITE; lv_gauges_def.needle_lines.width = 3 * LV_DOWNSCALE; - lv_gauges_def.label_pad = 20 * LV_DOWNSCALE; - lv_gauges_def.label_num = 5; - lv_gauges_def.angle = 220; + + lv_gauges_def.needle_color[0] = COLOR_WHITE; + 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_r = 5 * LV_DOWNSCALE; + lv_gauges_def.needle_mid_color = COLOR_GRAY; + lv_gauges_def.scale_pad = 20 * LV_DOWNSCALE; + lv_gauges_def.scale_label_num = 6; + lv_gauges_def.scale_angle = 240; + lv_gauges_def.needle_opa = OPA_70; } #endif diff --git a/lv_objx/lv_gauge.h b/lv_objx/lv_gauge.h index eb49556c4..78b4f98c1 100644 --- a/lv_objx/lv_gauge.h +++ b/lv_objx/lv_gauge.h @@ -27,6 +27,7 @@ /********************* * DEFINES *********************/ +#define LV_GAUGE_MAX_NEEDLE 4 /*Max number of needles. Used in the style.*/ /********************** * TYPEDEFS @@ -37,11 +38,19 @@ typedef struct { lv_rects_t rects; /*Style of ancestor*/ /*New style element for this type */ - lv_labels_t scale_labels; - lv_lines_t needle_lines; - cord_t label_pad; - uint16_t angle; - uint8_t label_num; + color_t mcolor_max; /*Top color at max.*/ + color_t gcolor_max; /*Bootom color at max*/ + /*Scale settings*/ + uint16_t scale_angle; /*Angle of the scale in deg. (~220)*/ + lv_labels_t scale_labels; /*Style of the labels*/ + cord_t scale_pad; /*Padding of scale labels from the edge*/ + 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_r; /*Radius of the needle middle area*/ + opa_t needle_opa; /*Opacity of the needles*/ }lv_gauges_t; /*Built-in styles of gauge*/ @@ -57,7 +66,8 @@ typedef struct /*New data for this type */ int16_t min; int16_t max; - int16_t value; + int16_t * values; + uint8_t needle_num; }lv_gauge_ext_t; /********************** @@ -67,7 +77,11 @@ lv_obj_t * lv_gauge_create(lv_obj_t * par, lv_obj_t * copy); bool lv_gauge_signal(lv_obj_t * gauge, lv_signal_t sign, void * param); lv_gauges_t * lv_gauges_get(lv_gauges_builtin_t style, lv_gauges_t * copy); -void lv_gauge_set_value(lv_obj_t * gauge, int16_t value); +void lv_gauge_set_value(lv_obj_t * gauge, int16_t value, uint8_t needle); +void lv_gauge_set_needle_num(lv_obj_t * gauge, uint8_t num); + +uint8_t lv_gauge_get_needle_num(lv_obj_t * gauge); +int16_t lv_gauge_get_value(lv_obj_t * gauge, uint8_t needle); /********************** * MACROS diff --git a/lv_objx/lv_img.c b/lv_objx/lv_img.c index 7325e5f57..f9ff7b21d 100644 --- a/lv_objx/lv_img.c +++ b/lv_objx/lv_img.c @@ -311,6 +311,7 @@ static bool lv_img_design(lv_obj_t * img, const area_t * mask, lv_design_mode_t } else return false; } else if(mode == LV_DESIGN_DRAW_MAIN) { + if(ext->h == 0 || ext->w == 0) return true; area_t cords; lv_obj_get_cords(img, &cords); diff --git a/lv_objx/lv_line.c b/lv_objx/lv_line.c index aa869f8cd..16bf56f16 100644 --- a/lv_objx/lv_line.c +++ b/lv_objx/lv_line.c @@ -145,8 +145,8 @@ void lv_line_set_points(lv_obj_t * line, const point_t * point_a, uint16_t point cord_t xmax = LV_CORD_MIN; cord_t ymax = LV_CORD_MIN; for(i = 0; i < point_num; i++) { - xmax = max(point_a[i].x * us, xmax); - ymax = max(point_a[i].y * us, ymax); + xmax = MATH_MAX(point_a[i].x * us, xmax); + ymax = MATH_MAX(point_a[i].y * us, ymax); } lv_lines_t * lines = lv_obj_get_style(line); diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index 95011178b..b5d04a87b 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -277,8 +277,8 @@ static bool lv_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void* param) case LV_SIGNAL_DRAG_BEGIN: if(style->sb_mode == LV_PAGE_SB_MODE_DRAG ) { - cord_t sbh_pad = max(style->sb_width, style->bg_rects.hpad); - cord_t sbv_pad = max(style->sb_width, style->bg_rects.vpad); + cord_t sbh_pad = MATH_MAX(style->sb_width, style->bg_rects.hpad); + cord_t sbv_pad = MATH_MAX(style->sb_width, style->bg_rects.vpad); if(area_get_height(&page_ext->sbv) < lv_obj_get_height(scrl) - 2 * sbv_pad) { page_ext->sbv_draw = 1; } @@ -565,8 +565,8 @@ static void lv_page_sb_refresh(lv_obj_t * page) cord_t vpad = style->bg_rects.vpad; cord_t obj_w = lv_obj_get_width(page); cord_t obj_h = lv_obj_get_height(page); - cord_t sbh_pad = max(style->sb_width, style->bg_rects.hpad); - cord_t sbv_pad = max(style->sb_width, style->bg_rects.vpad); + cord_t sbh_pad = MATH_MAX(style->sb_width, style->bg_rects.hpad); + cord_t sbv_pad = MATH_MAX(style->sb_width, style->bg_rects.vpad); if(style->sb_mode == LV_PAGE_SB_MODE_OFF) return; diff --git a/lv_objx/lv_rect.c b/lv_objx/lv_rect.c index 243e70e99..4ff2eeafd 100644 --- a/lv_objx/lv_rect.c +++ b/lv_objx/lv_rect.c @@ -563,7 +563,7 @@ static void lv_rect_layout_pretty(lv_obj_t * rect) lv_obj_is_protected(child_rc, LV_PROTECT_POS) == false) { if(w_row + lv_obj_get_width(child_rc) > w_obj) break; /*If the next object is already not fit then break*/ w_row += lv_obj_get_width(child_rc) + style->opad; /*Add the object width + opad*/ - h_row = max(h_row, lv_obj_get_height(child_rc)); /*Search the highest object*/ + h_row = MATH_MAX(h_row, lv_obj_get_height(child_rc)); /*Search the highest object*/ obj_num ++; } child_rc = ll_get_prev(&rect->child_ll, child_rc); /*Load the next object*/ @@ -690,10 +690,10 @@ void lv_rect_refr_autofit(lv_obj_t * rect) LL_READ(rect->child_ll, i) { if(lv_obj_get_hidden(i) != false) continue; - new_cords.x1 = min(new_cords.x1, i->cords.x1); - new_cords.y1 = min(new_cords.y1, i->cords.y1); - new_cords.x2 = max(new_cords.x2, i->cords.x2); - new_cords.y2 = max(new_cords.y2, i->cords.y2); + new_cords.x1 = MATH_MIN(new_cords.x1, i->cords.x1); + new_cords.y1 = MATH_MIN(new_cords.y1, i->cords.y1); + new_cords.x2 = MATH_MAX(new_cords.x2, i->cords.x2); + new_cords.y2 = MATH_MAX(new_cords.y2, i->cords.y2); } /*If the value is not the init value then the page has >=1 child.*/