mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(line, triangle): add float support for points
This commit is contained in:
parent
e08314df94
commit
9d993bd15f
@ -407,7 +407,7 @@ static void image_recolored_cb(lv_obj_t * parent)
|
||||
}
|
||||
|
||||
|
||||
static lv_obj_t * line_obj_create(lv_obj_t * parent, lv_coord_t col, lv_coord_t row, lv_point_t p[])
|
||||
static lv_obj_t * line_obj_create(lv_obj_t * parent, lv_coord_t col, lv_coord_t row, lv_point_precise_t p[])
|
||||
{
|
||||
lv_obj_t * obj = lv_line_create(parent);
|
||||
lv_obj_remove_style_all(obj);
|
||||
@ -423,7 +423,7 @@ static lv_obj_t * line_obj_create(lv_obj_t * parent, lv_coord_t col, lv_coord_t
|
||||
static void line_cb(lv_obj_t * parent)
|
||||
{
|
||||
|
||||
static lv_point_t points[][2] = {
|
||||
static lv_point_precise_t points[][2] = {
|
||||
{{5, DEF_HEIGHT / 2}, {DEF_WIDTH - 5, DEF_HEIGHT / 2}}, /* - */
|
||||
{{5, DEF_HEIGHT / 2}, {DEF_WIDTH - 5, DEF_HEIGHT / 2 + 1}}, /* - */
|
||||
{{5, DEF_HEIGHT / 2}, {DEF_WIDTH - 5, DEF_HEIGHT / 2 - 1}}, /* - */
|
||||
|
@ -1420,17 +1420,17 @@ static void chart_event_cb(lv_event_t * e)
|
||||
lv_draw_triangle_dsc_t tri_dsc;
|
||||
|
||||
lv_draw_triangle_dsc_init(&tri_dsc);
|
||||
tri_dsc.p[0].x = draw_line_dsc->p1.x;
|
||||
tri_dsc.p[0].y = draw_line_dsc->p1.y;
|
||||
tri_dsc.p[1].x = draw_line_dsc->p2.x;
|
||||
tri_dsc.p[1].y = draw_line_dsc->p2.y;
|
||||
tri_dsc.p[2].x = draw_line_dsc->p1.y < draw_line_dsc->p2.y ? draw_line_dsc->p1.x : draw_line_dsc->p2.x;
|
||||
tri_dsc.p[2].y = LV_MAX(draw_line_dsc->p1.y, draw_line_dsc->p2.y);
|
||||
tri_dsc.p[0].x = (int32_t)draw_line_dsc->p1_x;
|
||||
tri_dsc.p[0].y = (int32_t)draw_line_dsc->p1_y;
|
||||
tri_dsc.p[1].x = (int32_t)draw_line_dsc->p2_x;
|
||||
tri_dsc.p[1].y = (int32_t)draw_line_dsc->p2_y;
|
||||
tri_dsc.p[2].x = (int32_t)(draw_line_dsc->p1_y < draw_line_dsc->p2_y ? draw_line_dsc->p1_x : draw_line_dsc->p2_x);
|
||||
tri_dsc.p[2].y = (int32_t)LV_MAX(draw_line_dsc->p1_y, draw_line_dsc->p2_y);
|
||||
tri_dsc.bg_grad.dir = LV_GRAD_DIR_VER;
|
||||
|
||||
lv_coord_t full_h = lv_obj_get_height(obj);
|
||||
lv_coord_t fract_uppter = (LV_MIN(draw_line_dsc->p1.y, draw_line_dsc->p2.y) - obj->coords.y1) * 255 / full_h;
|
||||
lv_coord_t fract_lower = (LV_MAX(draw_line_dsc->p1.y, draw_line_dsc->p2.y) - obj->coords.y1) * 255 / full_h;
|
||||
lv_coord_t fract_uppter = (int32_t)(LV_MIN(draw_line_dsc->p1_y, draw_line_dsc->p2_y) - obj->coords.y1) * 255 / full_h;
|
||||
lv_coord_t fract_lower = (int32_t)(LV_MAX(draw_line_dsc->p1_y, draw_line_dsc->p2_y) - obj->coords.y1) * 255 / full_h;
|
||||
tri_dsc.bg_grad.stops[0].color = ser->color;
|
||||
tri_dsc.bg_grad.stops[0].opa = 255 - fract_uppter;
|
||||
tri_dsc.bg_grad.stops[0].frac = 0;
|
||||
@ -1451,10 +1451,10 @@ static void chart_event_cb(lv_event_t * e)
|
||||
rect_dsc.bg_grad.stops[1].opa = 0;
|
||||
|
||||
lv_area_t rect_area;
|
||||
rect_area.x1 = draw_line_dsc->p1.x;
|
||||
rect_area.x2 = draw_line_dsc->p2.x;
|
||||
rect_area.y1 = LV_MAX(draw_line_dsc->p1.y, draw_line_dsc->p2.y) - 1;
|
||||
rect_area.y2 = obj->coords.y2;
|
||||
rect_area.x1 = (int32_t)draw_line_dsc->p1_x;
|
||||
rect_area.x2 = (int32_t)draw_line_dsc->p2_x;
|
||||
rect_area.y1 = (int32_t)LV_MAX(draw_line_dsc->p1_y, draw_line_dsc->p2_y) + 1;
|
||||
rect_area.y2 = (int32_t)obj->coords.y2;
|
||||
lv_draw_rect(base_dsc->layer, &rect_dsc, &rect_area);
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ void lv_example_style_9(void)
|
||||
lv_obj_t * obj = lv_line_create(lv_screen_active());
|
||||
lv_obj_add_style(obj, &style, 0);
|
||||
|
||||
static lv_point_t p[] = {{10, 30}, {30, 50}, {100, 0}};
|
||||
static lv_point_precise_t p[] = {{10, 30}, {30, 50}, {100, 0}};
|
||||
lv_line_set_points(obj, p, 3);
|
||||
|
||||
lv_obj_center(obj);
|
||||
|
@ -27,10 +27,10 @@ void lv_example_canvas_7(void)
|
||||
dsc.width = 4;
|
||||
dsc.round_end = 1;
|
||||
dsc.round_start = 1;
|
||||
dsc.p1.x = 15;
|
||||
dsc.p1.y = 15;
|
||||
dsc.p2.x = 35;
|
||||
dsc.p2.y = 10;
|
||||
dsc.p1_x = 15;
|
||||
dsc.p1_y = 15;
|
||||
dsc.p2_x = 35;
|
||||
dsc.p2_y = 10;
|
||||
lv_draw_line(&layer, &dsc);
|
||||
|
||||
lv_canvas_finish_layer(canvas, &layer);
|
||||
|
@ -62,17 +62,17 @@ static void add_faded_area(lv_event_t * e)
|
||||
lv_draw_triangle_dsc_t tri_dsc;
|
||||
|
||||
lv_draw_triangle_dsc_init(&tri_dsc);
|
||||
tri_dsc.p[0].x = draw_line_dsc->p1.x;
|
||||
tri_dsc.p[0].y = draw_line_dsc->p1.y;
|
||||
tri_dsc.p[1].x = draw_line_dsc->p2.x;
|
||||
tri_dsc.p[1].y = draw_line_dsc->p2.y;
|
||||
tri_dsc.p[2].x = draw_line_dsc->p1.y < draw_line_dsc->p2.y ? draw_line_dsc->p1.x : draw_line_dsc->p2.x;
|
||||
tri_dsc.p[2].y = LV_MAX(draw_line_dsc->p1.y, draw_line_dsc->p2.y);
|
||||
tri_dsc.p[0].x = draw_line_dsc->p1_x;
|
||||
tri_dsc.p[0].y = draw_line_dsc->p1_y;
|
||||
tri_dsc.p[1].x = draw_line_dsc->p2_x;
|
||||
tri_dsc.p[1].y = draw_line_dsc->p2_y;
|
||||
tri_dsc.p[2].x = draw_line_dsc->p1_y < draw_line_dsc->p2_y ? draw_line_dsc->p1_x : draw_line_dsc->p2_x;
|
||||
tri_dsc.p[2].y = LV_MAX(draw_line_dsc->p1_y, draw_line_dsc->p2_y);
|
||||
tri_dsc.bg_grad.dir = LV_GRAD_DIR_VER;
|
||||
|
||||
lv_coord_t full_h = lv_obj_get_height(obj);
|
||||
lv_coord_t fract_uppter = (LV_MIN(draw_line_dsc->p1.y, draw_line_dsc->p2.y) - obj->coords.y1) * 255 / full_h;
|
||||
lv_coord_t fract_lower = (LV_MAX(draw_line_dsc->p1.y, draw_line_dsc->p2.y) - obj->coords.y1) * 255 / full_h;
|
||||
lv_coord_t fract_uppter = (int32_t)(LV_MIN(draw_line_dsc->p1_y, draw_line_dsc->p2_y) - obj->coords.y1) * 255 / full_h;
|
||||
lv_coord_t fract_lower = (int32_t)(LV_MAX(draw_line_dsc->p1_y, draw_line_dsc->p2_y) - obj->coords.y1) * 255 / full_h;
|
||||
tri_dsc.bg_grad.stops[0].color = ser->color;
|
||||
tri_dsc.bg_grad.stops[0].opa = 255 - fract_uppter;
|
||||
tri_dsc.bg_grad.stops[0].frac = 0;
|
||||
@ -94,10 +94,10 @@ static void add_faded_area(lv_event_t * e)
|
||||
rect_dsc.bg_grad.stops[1].opa = 0;
|
||||
|
||||
lv_area_t rect_area;
|
||||
rect_area.x1 = draw_line_dsc->p1.x;
|
||||
rect_area.x2 = draw_line_dsc->p2.x - 1;
|
||||
rect_area.y1 = LV_MAX(draw_line_dsc->p1.y, draw_line_dsc->p2.y) - 1;
|
||||
rect_area.y2 = obj->coords.y2;
|
||||
rect_area.x1 = (int32_t)draw_line_dsc->p1_x;
|
||||
rect_area.x2 = (int32_t)draw_line_dsc->p2_x - 1;
|
||||
rect_area.y1 = (int32_t)LV_MAX(draw_line_dsc->p1_y, draw_line_dsc->p2_y) - 1;
|
||||
rect_area.y2 = (int32_t)obj->coords.y2;
|
||||
lv_draw_rect(base_dsc->layer, &rect_dsc, &rect_area);
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ static void hook_division_lines(lv_event_t * e)
|
||||
lv_draw_line_dsc_t * line_dsc = draw_task->draw_dsc;
|
||||
|
||||
/*Vertical line*/
|
||||
if(line_dsc->p1.x == line_dsc->p2.x) {
|
||||
if(line_dsc->p1_x == line_dsc->p2_x) {
|
||||
line_dsc->color = lv_palette_lighten(LV_PALETTE_GREY, 1);
|
||||
if(base_dsc->id1 == 3) {
|
||||
line_dsc->width = 2;
|
||||
|
@ -4,7 +4,7 @@
|
||||
void lv_example_line_1(void)
|
||||
{
|
||||
/*Create an array for the points of the line*/
|
||||
static lv_point_t line_points[] = { {5, 5}, {70, 70}, {120, 10}, {180, 60}, {240, 10} };
|
||||
static lv_point_precise_t line_points[] = { {5, 5}, {70, 70}, {120, 10}, {180, 60}, {240, 10} };
|
||||
|
||||
/*Create style*/
|
||||
static lv_style_t style_line;
|
||||
|
@ -47,10 +47,10 @@ LV_ATTRIBUTE_FAST_MEM void lv_draw_line(struct _lv_layer_t * layer, const lv_dra
|
||||
{
|
||||
LV_PROFILER_BEGIN;
|
||||
lv_area_t a;
|
||||
a.x1 = LV_MIN(dsc->p1.x, dsc->p2.x) - dsc->width;
|
||||
a.x2 = LV_MAX(dsc->p1.x, dsc->p2.x) + dsc->width;
|
||||
a.y1 = LV_MIN(dsc->p1.y, dsc->p2.y) - dsc->width;
|
||||
a.y2 = LV_MAX(dsc->p1.y, dsc->p2.y) + dsc->width;
|
||||
a.x1 = (int32_t)LV_MIN(dsc->p1_x, dsc->p2_x) - dsc->width;
|
||||
a.x2 = (int32_t)LV_MAX(dsc->p1_x, dsc->p2_x) + dsc->width;
|
||||
a.y1 = (int32_t)LV_MIN(dsc->p1_y, dsc->p2_y) - dsc->width;
|
||||
a.y2 = (int32_t)LV_MAX(dsc->p1_y, dsc->p2_y) + dsc->width;
|
||||
|
||||
lv_draw_task_t * t = lv_draw_add_task(layer, &a);
|
||||
|
||||
|
@ -28,8 +28,10 @@ extern "C" {
|
||||
typedef struct {
|
||||
lv_draw_dsc_base_t base;
|
||||
|
||||
lv_point_t p1;
|
||||
lv_point_t p2;
|
||||
lv_value_precise_t p1_x;
|
||||
lv_value_precise_t p1_y;
|
||||
lv_value_precise_t p2_x;
|
||||
lv_value_precise_t p2_y;
|
||||
lv_color_t color;
|
||||
lv_coord_t width;
|
||||
lv_coord_t dash_width;
|
||||
|
@ -53,10 +53,10 @@ void lv_draw_triangle(struct _lv_layer_t * layer, const lv_draw_triangle_dsc_t *
|
||||
{
|
||||
LV_PROFILER_BEGIN;
|
||||
lv_area_t a;
|
||||
a.x1 = LV_MIN3(dsc->p[0].x, dsc->p[1].x, dsc->p[2].x);
|
||||
a.y1 = LV_MIN3(dsc->p[0].y, dsc->p[1].y, dsc->p[2].y);
|
||||
a.x2 = LV_MAX3(dsc->p[0].x, dsc->p[1].x, dsc->p[2].x);
|
||||
a.y2 = LV_MAX3(dsc->p[0].y, dsc->p[1].y, dsc->p[2].y);
|
||||
a.x1 = (int32_t)LV_MIN3(dsc->p[0].x, dsc->p[1].x, dsc->p[2].x);
|
||||
a.y1 = (int32_t)LV_MIN3(dsc->p[0].y, dsc->p[1].y, dsc->p[2].y);
|
||||
a.x2 = (int32_t)LV_MAX3(dsc->p[0].x, dsc->p[1].x, dsc->p[2].x);
|
||||
a.y2 = (int32_t)LV_MAX3(dsc->p[0].y, dsc->p[1].y, dsc->p[2].y);
|
||||
|
||||
lv_draw_task_t * t = lv_draw_add_task(layer, &a);
|
||||
|
||||
|
@ -29,7 +29,7 @@ typedef struct {
|
||||
lv_color_t bg_color;
|
||||
lv_grad_dsc_t bg_grad;
|
||||
|
||||
lv_point_t p[3];
|
||||
lv_point_precise_t p[3];
|
||||
} lv_draw_triangle_dsc_t;
|
||||
|
||||
/**********************
|
||||
|
@ -54,20 +54,20 @@ LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_line(lv_draw_unit_t * draw_unit, const lv_
|
||||
if(dsc->width == 0) return;
|
||||
if(dsc->opa <= LV_OPA_MIN) return;
|
||||
|
||||
if(dsc->p1.x == dsc->p2.x && dsc->p1.y == dsc->p2.y) return;
|
||||
if(dsc->p1_x == dsc->p2_x && dsc->p1_y == dsc->p2_y) return;
|
||||
|
||||
lv_area_t clip_line;
|
||||
clip_line.x1 = LV_MIN(dsc->p1.x, dsc->p2.x) - dsc->width / 2;
|
||||
clip_line.x2 = LV_MAX(dsc->p1.x, dsc->p2.x) + dsc->width / 2;
|
||||
clip_line.y1 = LV_MIN(dsc->p1.y, dsc->p2.y) - dsc->width / 2;
|
||||
clip_line.y2 = LV_MAX(dsc->p1.y, dsc->p2.y) + dsc->width / 2;
|
||||
clip_line.x1 = (int32_t)LV_MIN(dsc->p1_x, dsc->p2_x) - dsc->width / 2;
|
||||
clip_line.x2 = (int32_t)LV_MAX(dsc->p1_x, dsc->p2_x) + dsc->width / 2;
|
||||
clip_line.y1 = (int32_t)LV_MIN(dsc->p1_y, dsc->p2_y) - dsc->width / 2;
|
||||
clip_line.y2 = (int32_t)LV_MAX(dsc->p1_y, dsc->p2_y) + dsc->width / 2;
|
||||
|
||||
bool is_common;
|
||||
is_common = _lv_area_intersect(&clip_line, &clip_line, draw_unit->clip_area);
|
||||
if(!is_common) return;
|
||||
|
||||
if(dsc->p1.y == dsc->p2.y) draw_line_hor(draw_unit, dsc);
|
||||
else if(dsc->p1.x == dsc->p2.x) draw_line_ver(draw_unit, dsc);
|
||||
if(dsc->p1_y == dsc->p2_y) draw_line_hor(draw_unit, dsc);
|
||||
else if(dsc->p1_x == dsc->p2_x) draw_line_ver(draw_unit, dsc);
|
||||
else draw_line_skew(draw_unit, dsc);
|
||||
|
||||
if(dsc->round_end || dsc->round_start) {
|
||||
@ -82,18 +82,18 @@ LV_ATTRIBUTE_FAST_MEM void lv_draw_sw_line(lv_draw_unit_t * draw_unit, const lv_
|
||||
lv_area_t cir_area;
|
||||
|
||||
if(dsc->round_start) {
|
||||
cir_area.x1 = dsc->p1.x - r;
|
||||
cir_area.y1 = dsc->p1.y - r;
|
||||
cir_area.x2 = dsc->p1.x + r - r_corr;
|
||||
cir_area.y2 = dsc->p1.y + r - r_corr ;
|
||||
cir_area.x1 = (int32_t)dsc->p1_x - r;
|
||||
cir_area.y1 = (int32_t)dsc->p1_y - r;
|
||||
cir_area.x2 = (int32_t)dsc->p1_x + r - r_corr;
|
||||
cir_area.y2 = (int32_t)dsc->p1_y + r - r_corr ;
|
||||
lv_draw_sw_fill(draw_unit, &cir_dsc, &cir_area);
|
||||
}
|
||||
|
||||
if(dsc->round_end) {
|
||||
cir_area.x1 = dsc->p2.x - r;
|
||||
cir_area.y1 = dsc->p2.y - r;
|
||||
cir_area.x2 = dsc->p2.x + r - r_corr;
|
||||
cir_area.y2 = dsc->p2.y + r - r_corr ;
|
||||
cir_area.x1 = (int32_t)dsc->p2_x - r;
|
||||
cir_area.y1 = (int32_t)dsc->p2_y - r;
|
||||
cir_area.x2 = (int32_t)dsc->p2_x + r - r_corr;
|
||||
cir_area.y2 = (int32_t)dsc->p2_y + r - r_corr ;
|
||||
lv_draw_sw_fill(draw_unit, &cir_dsc, &cir_area);
|
||||
}
|
||||
}
|
||||
@ -109,10 +109,10 @@ LV_ATTRIBUTE_FAST_MEM static void draw_line_hor(lv_draw_unit_t * draw_unit, cons
|
||||
int32_t w_half1 = w_half0 + (w & 0x1); /*Compensate rounding error*/
|
||||
|
||||
lv_area_t blend_area;
|
||||
blend_area.x1 = LV_MIN(dsc->p1.x, dsc->p2.x);
|
||||
blend_area.x2 = LV_MAX(dsc->p1.x, dsc->p2.x) - 1;
|
||||
blend_area.y1 = dsc->p1.y - w_half1;
|
||||
blend_area.y2 = dsc->p1.y + w_half0;
|
||||
blend_area.x1 = (int32_t)LV_MIN(dsc->p1_x, dsc->p2_x);
|
||||
blend_area.x2 = (int32_t)LV_MAX(dsc->p1_x, dsc->p2_x) - 1;
|
||||
blend_area.y1 = (int32_t)dsc->p1_y - w_half1;
|
||||
blend_area.y2 = (int32_t)dsc->p1_y + w_half0;
|
||||
|
||||
bool is_common;
|
||||
is_common = _lv_area_intersect(&blend_area, &blend_area, draw_unit->clip_area);
|
||||
@ -184,10 +184,10 @@ LV_ATTRIBUTE_FAST_MEM static void draw_line_ver(lv_draw_unit_t * draw_unit, cons
|
||||
int32_t w_half1 = w_half0 + (w & 0x1); /*Compensate rounding error*/
|
||||
|
||||
lv_area_t blend_area;
|
||||
blend_area.x1 = dsc->p1.x - w_half1;
|
||||
blend_area.x2 = dsc->p1.x + w_half0;
|
||||
blend_area.y1 = LV_MIN(dsc->p1.y, dsc->p2.y);
|
||||
blend_area.y2 = LV_MAX(dsc->p1.y, dsc->p2.y) - 1;
|
||||
blend_area.x1 = (int32_t)dsc->p1_x - w_half1;
|
||||
blend_area.x2 = (int32_t)dsc->p1_x + w_half0;
|
||||
blend_area.y1 = (int32_t)LV_MIN(dsc->p1_y, dsc->p2_y);
|
||||
blend_area.y2 = (int32_t)LV_MAX(dsc->p1_y, dsc->p2_y) - 1;
|
||||
|
||||
bool is_common;
|
||||
is_common = _lv_area_intersect(&blend_area, &blend_area, draw_unit->clip_area);
|
||||
@ -255,17 +255,17 @@ LV_ATTRIBUTE_FAST_MEM static void draw_line_skew(lv_draw_unit_t * draw_unit, con
|
||||
/*Keep the great y in p1*/
|
||||
lv_point_t p1;
|
||||
lv_point_t p2;
|
||||
if(dsc->p1.y < dsc->p2.y) {
|
||||
p1.y = dsc->p1.y;
|
||||
p2.y = dsc->p2.y;
|
||||
p1.x = dsc->p1.x;
|
||||
p2.x = dsc->p2.x;
|
||||
if(dsc->p1_y < dsc->p2_y) {
|
||||
p1.y = (int32_t)dsc->p1_y;
|
||||
p2.y = (int32_t)dsc->p2_y;
|
||||
p1.x = (int32_t)dsc->p1_x;
|
||||
p2.x = (int32_t)dsc->p2_x;
|
||||
}
|
||||
else {
|
||||
p1.y = dsc->p2.y;
|
||||
p2.y = dsc->p1.y;
|
||||
p1.x = dsc->p2.x;
|
||||
p2.x = dsc->p1.x;
|
||||
p1.y = (int32_t)dsc->p2_y;
|
||||
p2.y = (int32_t)dsc->p1_y;
|
||||
p1.x = (int32_t)dsc->p2_x;
|
||||
p2.x = (int32_t)dsc->p1_x;
|
||||
}
|
||||
|
||||
int32_t xdiff = p2.x - p1.x;
|
||||
|
@ -28,6 +28,7 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static lv_point_t point_to_normal(const lv_point_precise_t * p);
|
||||
static void point_swap(lv_point_t * p1, lv_point_t * p2);
|
||||
|
||||
/**********************
|
||||
@ -46,10 +47,10 @@ void lv_draw_sw_triangle(lv_draw_unit_t * draw_unit, const lv_draw_triangle_dsc_
|
||||
{
|
||||
#if LV_DRAW_SW_COMPLEX
|
||||
lv_area_t tri_area;
|
||||
tri_area.x1 = LV_MIN3(dsc->p[0].x, dsc->p[1].x, dsc->p[2].x);
|
||||
tri_area.y1 = LV_MIN3(dsc->p[0].y, dsc->p[1].y, dsc->p[2].y);
|
||||
tri_area.x2 = LV_MAX3(dsc->p[0].x, dsc->p[1].x, dsc->p[2].x);
|
||||
tri_area.y2 = LV_MAX3(dsc->p[0].y, dsc->p[1].y, dsc->p[2].y);
|
||||
tri_area.x1 = (int32_t)LV_MIN3(dsc->p[0].x, dsc->p[1].x, dsc->p[2].x);
|
||||
tri_area.y1 = (int32_t)LV_MIN3(dsc->p[0].y, dsc->p[1].y, dsc->p[2].y);
|
||||
tri_area.x2 = (int32_t)LV_MAX3(dsc->p[0].x, dsc->p[1].x, dsc->p[2].x);
|
||||
tri_area.y2 = (int32_t)LV_MAX3(dsc->p[0].y, dsc->p[1].y, dsc->p[2].y);
|
||||
|
||||
bool is_common;
|
||||
lv_area_t draw_area;
|
||||
@ -59,24 +60,24 @@ void lv_draw_sw_triangle(lv_draw_unit_t * draw_unit, const lv_draw_triangle_dsc_
|
||||
lv_point_t p[3];
|
||||
/*If there is a vertical side use it as p[0] and p[1]*/
|
||||
if(dsc->p[0].x == dsc->p[1].x) {
|
||||
p[0] = dsc->p[0];
|
||||
p[1] = dsc->p[1];
|
||||
p[2] = dsc->p[2];
|
||||
p[0] = point_to_normal(&dsc->p[0]);
|
||||
p[1] = point_to_normal(&dsc->p[1]);
|
||||
p[2] = point_to_normal(&dsc->p[2]);
|
||||
}
|
||||
else if(dsc->p[0].x == dsc->p[2].x) {
|
||||
p[0] = dsc->p[0];
|
||||
p[1] = dsc->p[2];
|
||||
p[2] = dsc->p[1];
|
||||
p[0] = point_to_normal(&dsc->p[0]);
|
||||
p[1] = point_to_normal(&dsc->p[2]);
|
||||
p[2] = point_to_normal(&dsc->p[1]);
|
||||
}
|
||||
else if(dsc->p[1].x == dsc->p[2].x) {
|
||||
p[0] = dsc->p[1];
|
||||
p[1] = dsc->p[2];
|
||||
p[2] = dsc->p[0];
|
||||
p[0] = point_to_normal(&dsc->p[1]);
|
||||
p[1] = point_to_normal(&dsc->p[2]);
|
||||
p[2] = point_to_normal(&dsc->p[0]);
|
||||
}
|
||||
else {
|
||||
p[0] = dsc->p[0];
|
||||
p[1] = dsc->p[1];
|
||||
p[2] = dsc->p[2];
|
||||
p[0] = point_to_normal(&dsc->p[0]);
|
||||
p[1] = point_to_normal(&dsc->p[1]);
|
||||
p[2] = point_to_normal(&dsc->p[2]);
|
||||
|
||||
/*Set the smallest y as p[0]*/
|
||||
if(p[0].y > p[1].y) point_swap(&p[0], &p[1]);
|
||||
@ -189,6 +190,15 @@ void lv_draw_sw_triangle(lv_draw_unit_t * draw_unit, const lv_draw_triangle_dsc_
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
static lv_point_t point_to_normal(const lv_point_precise_t * p)
|
||||
{
|
||||
lv_point_t p_out;
|
||||
p_out.x = (int32_t)p->x;
|
||||
p_out.y = (int32_t)p->y;
|
||||
|
||||
return p_out;
|
||||
}
|
||||
|
||||
static void point_swap(lv_point_t * p1, lv_point_t * p2)
|
||||
{
|
||||
lv_point_t tmp = *p1;
|
||||
|
@ -39,6 +39,11 @@ typedef struct {
|
||||
lv_coord_t y;
|
||||
} lv_point_t;
|
||||
|
||||
typedef struct {
|
||||
lv_value_precise_t x;
|
||||
lv_value_precise_t y;
|
||||
} lv_point_precise_t;
|
||||
|
||||
/** Represents an area of the screen.*/
|
||||
typedef struct {
|
||||
lv_coord_t x1;
|
||||
|
@ -749,8 +749,8 @@ static void draw_div_lines(lv_obj_t * obj, lv_layer_t * layer)
|
||||
lv_coord_t scroll_top = lv_obj_get_scroll_top(obj);
|
||||
if(chart->hdiv_cnt != 0) {
|
||||
lv_coord_t y_ofs = obj->coords.y1 + pad_top - scroll_top;
|
||||
line_dsc.p1.x = obj->coords.x1;
|
||||
line_dsc.p2.x = obj->coords.x2;
|
||||
line_dsc.p1_x = obj->coords.x1;
|
||||
line_dsc.p2_x = obj->coords.x2;
|
||||
|
||||
i_start = 0;
|
||||
i_end = chart->hdiv_cnt;
|
||||
@ -760,9 +760,9 @@ static void draw_div_lines(lv_obj_t * obj, lv_layer_t * layer)
|
||||
}
|
||||
|
||||
for(i = i_start; i < i_end; i++) {
|
||||
line_dsc.p1.y = (int32_t)((int32_t)h * i) / (chart->hdiv_cnt - 1);
|
||||
line_dsc.p1.y += y_ofs;
|
||||
line_dsc.p2.y = line_dsc.p1.y;
|
||||
line_dsc.p1_y = (int32_t)((int32_t)h * i) / (chart->hdiv_cnt - 1);
|
||||
line_dsc.p1_y += y_ofs;
|
||||
line_dsc.p2_y = line_dsc.p1_y;
|
||||
line_dsc.base.id1 = i;
|
||||
|
||||
lv_draw_line(layer, &line_dsc);
|
||||
@ -771,8 +771,8 @@ static void draw_div_lines(lv_obj_t * obj, lv_layer_t * layer)
|
||||
|
||||
if(chart->vdiv_cnt != 0) {
|
||||
lv_coord_t x_ofs = obj->coords.x1 + pad_left - scroll_left;
|
||||
line_dsc.p1.y = obj->coords.y1;
|
||||
line_dsc.p2.y = obj->coords.y2;
|
||||
line_dsc.p1_y = obj->coords.y1;
|
||||
line_dsc.p2_y = obj->coords.y2;
|
||||
i_start = 0;
|
||||
i_end = chart->vdiv_cnt;
|
||||
if(border_opa > LV_OPA_MIN && border_w > 0) {
|
||||
@ -781,9 +781,9 @@ static void draw_div_lines(lv_obj_t * obj, lv_layer_t * layer)
|
||||
}
|
||||
|
||||
for(i = i_start; i < i_end; i++) {
|
||||
line_dsc.p1.x = (int32_t)((int32_t)w * i) / (chart->vdiv_cnt - 1);
|
||||
line_dsc.p1.x += x_ofs;
|
||||
line_dsc.p2.x = line_dsc.p1.x;
|
||||
line_dsc.p1_x = (int32_t)((int32_t)w * i) / (chart->vdiv_cnt - 1);
|
||||
line_dsc.p1_x += x_ofs;
|
||||
line_dsc.p2_x = line_dsc.p1_x;
|
||||
line_dsc.base.id1 = i;
|
||||
|
||||
lv_draw_line(layer, &line_dsc);
|
||||
@ -846,32 +846,32 @@ static void draw_series_line(lv_obj_t * obj, lv_layer_t * layer)
|
||||
|
||||
lv_coord_t start_point = chart->update_mode == LV_CHART_UPDATE_MODE_SHIFT ? ser->start_point : 0;
|
||||
|
||||
line_dsc.p1.x = x_ofs;
|
||||
line_dsc.p2.x = x_ofs;
|
||||
line_dsc.p1_x = x_ofs;
|
||||
line_dsc.p2_x = x_ofs;
|
||||
|
||||
lv_coord_t p_act = start_point;
|
||||
lv_coord_t p_prev = start_point;
|
||||
int32_t y_tmp = (int32_t)((int32_t)ser->y_points[p_prev] - chart->ymin[ser->y_axis_sec]) * h;
|
||||
y_tmp = y_tmp / (chart->ymax[ser->y_axis_sec] - chart->ymin[ser->y_axis_sec]);
|
||||
line_dsc.p2.y = h - y_tmp + y_ofs;
|
||||
line_dsc.p2_y = h - y_tmp + y_ofs;
|
||||
|
||||
lv_coord_t y_min = line_dsc.p2.y;
|
||||
lv_coord_t y_max = line_dsc.p2.y;
|
||||
lv_value_precise_t y_min = line_dsc.p2_y;
|
||||
lv_value_precise_t y_max = line_dsc.p2_y;
|
||||
|
||||
for(i = 0; i < chart->point_cnt; i++) {
|
||||
line_dsc.p1.x = line_dsc.p2.x;
|
||||
line_dsc.p1.y = line_dsc.p2.y;
|
||||
line_dsc.p1_x = line_dsc.p2_x;
|
||||
line_dsc.p1_y = line_dsc.p2_y;
|
||||
|
||||
if(line_dsc.p1.x > clip_area_ori.x2 + point_w + 1) break;
|
||||
line_dsc.p2.x = ((w * i) / (chart->point_cnt - 1)) + x_ofs;
|
||||
if(line_dsc.p1_x > clip_area_ori.x2 + point_w + 1) break;
|
||||
line_dsc.p2_x = (lv_value_precise_t)((w * i) / (chart->point_cnt - 1)) + x_ofs;
|
||||
|
||||
p_act = (start_point + i) % chart->point_cnt;
|
||||
|
||||
y_tmp = (int32_t)((int32_t)ser->y_points[p_act] - chart->ymin[ser->y_axis_sec]) * h;
|
||||
y_tmp = y_tmp / (chart->ymax[ser->y_axis_sec] - chart->ymin[ser->y_axis_sec]);
|
||||
line_dsc.p2.y = h - y_tmp + y_ofs;
|
||||
line_dsc.p2_y = h - y_tmp + y_ofs;
|
||||
|
||||
if(line_dsc.p2.x < clip_area_ori.x1 - point_w - 1) {
|
||||
if(line_dsc.p2_x < clip_area_ori.x1 - point_w - 1) {
|
||||
p_prev = p_act;
|
||||
continue;
|
||||
}
|
||||
@ -881,17 +881,17 @@ static void draw_series_line(lv_obj_t * obj, lv_layer_t * layer)
|
||||
if(crowded_mode) {
|
||||
if(ser->y_points[p_prev] != LV_CHART_POINT_NONE && ser->y_points[p_act] != LV_CHART_POINT_NONE) {
|
||||
/*Draw only one vertical line between the min and max y-values on the same x-value*/
|
||||
y_max = LV_MAX(y_max, line_dsc.p2.y);
|
||||
y_min = LV_MIN(y_min, line_dsc.p2.y);
|
||||
if(line_dsc.p1.x != line_dsc.p2.x) {
|
||||
lv_coord_t y_cur = line_dsc.p2.y;
|
||||
line_dsc.p2.x--; /*It's already on the next x value*/
|
||||
line_dsc.p1.x = line_dsc.p2.x;
|
||||
line_dsc.p1.y = y_min;
|
||||
line_dsc.p2.y = y_max;
|
||||
if(line_dsc.p1.y == line_dsc.p2.y) line_dsc.p2.y++; /*If they are the same no line will be drawn*/
|
||||
y_max = LV_MAX(y_max, line_dsc.p2_y);
|
||||
y_min = LV_MIN(y_min, line_dsc.p2_y);
|
||||
if(line_dsc.p1_x != line_dsc.p2_x) {
|
||||
lv_value_precise_t y_cur = line_dsc.p2_y;
|
||||
line_dsc.p2_x--; /*It's already on the next x value*/
|
||||
line_dsc.p1_x = line_dsc.p2_x;
|
||||
line_dsc.p1_y = y_min;
|
||||
line_dsc.p2_y = y_max;
|
||||
if(line_dsc.p1_y == line_dsc.p2_y) line_dsc.p2_y++; /*If they are the same no line will be drawn*/
|
||||
lv_draw_line(layer, &line_dsc);
|
||||
line_dsc.p2.x++; /*Compensate the previous x--*/
|
||||
line_dsc.p2_x++; /*Compensate the previous x--*/
|
||||
y_min = y_cur; /*Start the line of the next x from the current last y*/
|
||||
y_max = y_cur;
|
||||
}
|
||||
@ -899,10 +899,10 @@ static void draw_series_line(lv_obj_t * obj, lv_layer_t * layer)
|
||||
}
|
||||
else {
|
||||
lv_area_t point_area;
|
||||
point_area.x1 = line_dsc.p1.x - point_w;
|
||||
point_area.x2 = line_dsc.p1.x + point_w;
|
||||
point_area.y1 = line_dsc.p1.y - point_h;
|
||||
point_area.y2 = line_dsc.p1.y + point_h;
|
||||
point_area.x1 = (int32_t)line_dsc.p1_x - point_w;
|
||||
point_area.x2 = (int32_t)line_dsc.p1_x + point_w;
|
||||
point_area.y1 = (int32_t)line_dsc.p1_y - point_h;
|
||||
point_area.y2 = (int32_t)line_dsc.p1_y + point_h;
|
||||
|
||||
if(ser->y_points[p_prev] != LV_CHART_POINT_NONE && ser->y_points[p_act] != LV_CHART_POINT_NONE) {
|
||||
line_dsc.base.id2 = i;
|
||||
@ -924,10 +924,10 @@ static void draw_series_line(lv_obj_t * obj, lv_layer_t * layer)
|
||||
|
||||
if(ser->y_points[p_act] != LV_CHART_POINT_NONE) {
|
||||
lv_area_t point_area;
|
||||
point_area.x1 = line_dsc.p2.x - point_w;
|
||||
point_area.x2 = line_dsc.p2.x + point_w;
|
||||
point_area.y1 = line_dsc.p2.y - point_h;
|
||||
point_area.y2 = line_dsc.p2.y + point_h;
|
||||
point_area.x1 = (int32_t)line_dsc.p2_x - point_w;
|
||||
point_area.x2 = (int32_t)line_dsc.p2_x + point_w;
|
||||
point_area.y1 = (int32_t)line_dsc.p2_y - point_h;
|
||||
point_area.y2 = (int32_t)line_dsc.p2_y + point_h;
|
||||
point_dsc_default.base.id2 = i - 1;
|
||||
lv_draw_rect(layer, &point_dsc_default, &point_area);
|
||||
}
|
||||
@ -984,36 +984,36 @@ static void draw_series_scatter(lv_obj_t * obj, lv_layer_t * layer)
|
||||
|
||||
lv_coord_t start_point = chart->update_mode == LV_CHART_UPDATE_MODE_SHIFT ? ser->start_point : 0;
|
||||
|
||||
line_dsc.p1.x = x_ofs;
|
||||
line_dsc.p2.x = x_ofs;
|
||||
line_dsc.p1_x = x_ofs;
|
||||
line_dsc.p2_x = x_ofs;
|
||||
|
||||
lv_coord_t p_act = start_point;
|
||||
lv_coord_t p_prev = start_point;
|
||||
if(ser->y_points[p_act] != LV_CHART_POINT_CNT_DEF) {
|
||||
line_dsc.p2.x = lv_map(ser->x_points[p_act], chart->xmin[ser->x_axis_sec], chart->xmax[ser->x_axis_sec], 0, w);
|
||||
line_dsc.p2.x += x_ofs;
|
||||
line_dsc.p2_x = lv_map(ser->x_points[p_act], chart->xmin[ser->x_axis_sec], chart->xmax[ser->x_axis_sec], 0, w);
|
||||
line_dsc.p2_x += x_ofs;
|
||||
|
||||
line_dsc.p2.y = lv_map(ser->y_points[p_act], chart->ymin[ser->y_axis_sec], chart->ymax[ser->y_axis_sec], 0, h);
|
||||
line_dsc.p2.y = h - line_dsc.p2.y;
|
||||
line_dsc.p2.y += y_ofs;
|
||||
line_dsc.p2_y = lv_map(ser->y_points[p_act], chart->ymin[ser->y_axis_sec], chart->ymax[ser->y_axis_sec], 0, h);
|
||||
line_dsc.p2_y = h - line_dsc.p2_y;
|
||||
line_dsc.p2_y += y_ofs;
|
||||
}
|
||||
else {
|
||||
line_dsc.p2.x = LV_COORD_MIN;
|
||||
line_dsc.p2.y = LV_COORD_MIN;
|
||||
line_dsc.p2_x = (lv_value_precise_t)LV_COORD_MIN;
|
||||
line_dsc.p2_y = (lv_value_precise_t)LV_COORD_MIN;
|
||||
}
|
||||
|
||||
for(i = 0; i < chart->point_cnt; i++) {
|
||||
line_dsc.p1.x = line_dsc.p2.x;
|
||||
line_dsc.p1.y = line_dsc.p2.y;
|
||||
line_dsc.p1_x = line_dsc.p2_x;
|
||||
line_dsc.p1_y = line_dsc.p2_y;
|
||||
|
||||
p_act = (start_point + i) % chart->point_cnt;
|
||||
if(ser->y_points[p_act] != LV_CHART_POINT_NONE) {
|
||||
line_dsc.p2.y = lv_map(ser->y_points[p_act], chart->ymin[ser->y_axis_sec], chart->ymax[ser->y_axis_sec], 0, h);
|
||||
line_dsc.p2.y = h - line_dsc.p2.y;
|
||||
line_dsc.p2.y += y_ofs;
|
||||
line_dsc.p2_y = lv_map(ser->y_points[p_act], chart->ymin[ser->y_axis_sec], chart->ymax[ser->y_axis_sec], 0, h);
|
||||
line_dsc.p2_y = h - line_dsc.p2_y;
|
||||
line_dsc.p2_y += y_ofs;
|
||||
|
||||
line_dsc.p2.x = lv_map(ser->x_points[p_act], chart->xmin[ser->x_axis_sec], chart->xmax[ser->x_axis_sec], 0, w);
|
||||
line_dsc.p2.x += x_ofs;
|
||||
line_dsc.p2_x = lv_map(ser->x_points[p_act], chart->xmin[ser->x_axis_sec], chart->xmax[ser->x_axis_sec], 0, w);
|
||||
line_dsc.p2_x += x_ofs;
|
||||
}
|
||||
else {
|
||||
p_prev = p_act;
|
||||
@ -1023,10 +1023,10 @@ static void draw_series_scatter(lv_obj_t * obj, lv_layer_t * layer)
|
||||
/*Don't draw the first point. A second point is also required to draw the line*/
|
||||
if(i != 0) {
|
||||
lv_area_t point_area;
|
||||
point_area.x1 = line_dsc.p1.x - point_w;
|
||||
point_area.x2 = line_dsc.p1.x + point_w;
|
||||
point_area.y1 = line_dsc.p1.y - point_h;
|
||||
point_area.y2 = line_dsc.p1.y + point_h;
|
||||
point_area.x1 = (int32_t)line_dsc.p1_x - point_w;
|
||||
point_area.x2 = (int32_t)line_dsc.p1_x + point_w;
|
||||
point_area.y1 = (int32_t)line_dsc.p1_y - point_h;
|
||||
point_area.y2 = (int32_t)line_dsc.p1_y + point_h;
|
||||
|
||||
if(ser->y_points[p_prev] != LV_CHART_POINT_NONE && ser->y_points[p_act] != LV_CHART_POINT_NONE) {
|
||||
line_dsc.base.id2 = i;
|
||||
@ -1045,10 +1045,10 @@ static void draw_series_scatter(lv_obj_t * obj, lv_layer_t * layer)
|
||||
|
||||
if(ser->y_points[p_act] != LV_CHART_POINT_NONE) {
|
||||
lv_area_t point_area;
|
||||
point_area.x1 = line_dsc.p2.x - point_w;
|
||||
point_area.x2 = line_dsc.p2.x + point_w;
|
||||
point_area.y1 = line_dsc.p2.y - point_h;
|
||||
point_area.y2 = line_dsc.p2.y + point_h;
|
||||
point_area.x1 = (int32_t)line_dsc.p2_x - point_w;
|
||||
point_area.x2 = (int32_t)line_dsc.p2_x + point_w;
|
||||
point_area.y1 = (int32_t)line_dsc.p2_y - point_h;
|
||||
point_area.y2 = (int32_t)line_dsc.p2_y + point_h;
|
||||
|
||||
point_dsc_default.base.id2 = i;
|
||||
lv_draw_rect(layer, &point_dsc_default, &point_area);
|
||||
@ -1195,10 +1195,10 @@ static void draw_cursors(lv_obj_t * obj, lv_layer_t * layer)
|
||||
point_area.y2 = cy + point_h;
|
||||
|
||||
if(cursor->dir & LV_DIR_HOR) {
|
||||
line_dsc.p1.x = cursor->dir & LV_DIR_LEFT ? obj->coords.x1 : cx;
|
||||
line_dsc.p1.y = cy;
|
||||
line_dsc.p2.x = cursor->dir & LV_DIR_RIGHT ? obj->coords.x2 : cx;
|
||||
line_dsc.p2.y = line_dsc.p1.y;
|
||||
line_dsc.p1_x = cursor->dir & LV_DIR_LEFT ? obj->coords.x1 : cx;
|
||||
line_dsc.p1_y = cy;
|
||||
line_dsc.p2_x = cursor->dir & LV_DIR_RIGHT ? obj->coords.x2 : cx;
|
||||
line_dsc.p2_y = line_dsc.p1_y;
|
||||
|
||||
line_dsc.base.id2 = 0;
|
||||
point_dsc_tmp.base.id2 = 0;
|
||||
@ -1211,10 +1211,10 @@ static void draw_cursors(lv_obj_t * obj, lv_layer_t * layer)
|
||||
}
|
||||
|
||||
if(cursor->dir & LV_DIR_VER) {
|
||||
line_dsc.p1.x = cx;
|
||||
line_dsc.p1.y = cursor->dir & LV_DIR_TOP ? obj->coords.y1 : cy;
|
||||
line_dsc.p2.x = line_dsc.p1.x;
|
||||
line_dsc.p2.y = cursor->dir & LV_DIR_BOTTOM ? obj->coords.y2 : cy;
|
||||
line_dsc.p1_x = cx;
|
||||
line_dsc.p1_y = cursor->dir & LV_DIR_TOP ? obj->coords.y1 : cy;
|
||||
line_dsc.p2_x = line_dsc.p1_x;
|
||||
line_dsc.p2_y = cursor->dir & LV_DIR_BOTTOM ? obj->coords.y2 : cy;
|
||||
|
||||
line_dsc.base.id2 = 1;
|
||||
point_dsc_tmp.base.id2 = 1;
|
||||
|
@ -64,7 +64,7 @@ lv_obj_t * lv_line_create(lv_obj_t * parent)
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
void lv_line_set_points(lv_obj_t * obj, const lv_point_t points[], uint32_t point_num)
|
||||
void lv_line_set_points(lv_obj_t * obj, const lv_point_precise_t points[], uint32_t point_num)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
||||
@ -122,10 +122,10 @@ static void lv_line_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
|
||||
LV_TRACE_OBJ_CREATE("finished");
|
||||
}
|
||||
|
||||
static inline lv_coord_t resolve_point_coord(lv_coord_t coord, lv_coord_t max)
|
||||
static inline lv_value_precise_t resolve_point_coord(lv_value_precise_t coord, lv_coord_t max)
|
||||
{
|
||||
if(LV_COORD_IS_PCT(coord)) {
|
||||
return LV_CLAMP(0, max * LV_COORD_GET_PCT(coord) / 100, max);
|
||||
if(LV_COORD_IS_PCT((int32_t)coord)) {
|
||||
return LV_CLAMP(0, max * LV_COORD_GET_PCT((int32_t)coord) / 100, max);
|
||||
}
|
||||
else {
|
||||
return coord;
|
||||
@ -162,12 +162,12 @@ static void lv_line_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; i < line->point_num; i++) {
|
||||
if(!LV_COORD_IS_PCT(line->point_array[i].x)) {
|
||||
w = LV_MAX(line->point_array[i].x, w);
|
||||
if(!LV_COORD_IS_PCT((int32_t)line->point_array[i].x)) {
|
||||
w = (int32_t)LV_MAX(line->point_array[i].x, w);
|
||||
}
|
||||
|
||||
if(!LV_COORD_IS_PCT(line->point_array[i].y)) {
|
||||
h = LV_MAX(line->point_array[i].y, h);
|
||||
if(!LV_COORD_IS_PCT((int32_t)line->point_array[i].y)) {
|
||||
h = (int32_t)LV_MAX(line->point_array[i].y, h);
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,19 +195,19 @@ static void lv_line_event(const lv_obj_class_t * class_p, lv_event_t * e)
|
||||
lv_coord_t w = lv_obj_get_width(obj);
|
||||
lv_coord_t h = lv_obj_get_height(obj);
|
||||
|
||||
line_dsc.p1.x = resolve_point_coord(line->point_array[i].x, w) + x_ofs;
|
||||
line_dsc.p1.y = resolve_point_coord(line->point_array[i].y, h);
|
||||
line_dsc.p1_x = resolve_point_coord(line->point_array[i].x, w) + x_ofs;
|
||||
line_dsc.p1_y = resolve_point_coord(line->point_array[i].y, h);
|
||||
|
||||
line_dsc.p2.x = resolve_point_coord(line->point_array[i + 1].x, w) + x_ofs;
|
||||
line_dsc.p2.y = resolve_point_coord(line->point_array[i + 1].y, h);
|
||||
line_dsc.p2_x = resolve_point_coord(line->point_array[i + 1].x, w) + x_ofs;
|
||||
line_dsc.p2_y = resolve_point_coord(line->point_array[i + 1].y, h);
|
||||
|
||||
if(line->y_inv == 0) {
|
||||
line_dsc.p1.y = line_dsc.p1.y + y_ofs;
|
||||
line_dsc.p2.y = line_dsc.p2.y + y_ofs;
|
||||
line_dsc.p1_y = line_dsc.p1_y + y_ofs;
|
||||
line_dsc.p2_y = line_dsc.p2_y + y_ofs;
|
||||
}
|
||||
else {
|
||||
line_dsc.p1.y = h - line_dsc.p1.y + y_ofs;
|
||||
line_dsc.p2.y = h - line_dsc.p2.y + y_ofs;
|
||||
line_dsc.p1_y = h - line_dsc.p1_y + y_ofs;
|
||||
line_dsc.p2_y = h - line_dsc.p2_y + y_ofs;
|
||||
}
|
||||
|
||||
lv_draw_line(layer, &line_dsc);
|
||||
|
@ -27,7 +27,7 @@ extern "C" {
|
||||
/*Data of line*/
|
||||
typedef struct {
|
||||
lv_obj_t obj;
|
||||
const lv_point_t * point_array; /**< Pointer to an array with the points of the line*/
|
||||
const lv_point_precise_t * point_array; /**< Pointer to an array with the points of the line*/
|
||||
uint32_t point_num; /**< Number of points in 'point_array'*/
|
||||
uint32_t y_inv : 1; /**< 1: y == 0 will be on the bottom*/
|
||||
} lv_line_t;
|
||||
@ -55,7 +55,7 @@ lv_obj_t * lv_line_create(lv_obj_t * parent);
|
||||
* @param points an array of points. Only the address is saved, so the array needs to be alive while the line exists
|
||||
* @param point_num number of points in 'point_a'
|
||||
*/
|
||||
void lv_line_set_points(lv_obj_t * obj, const lv_point_t points[], uint32_t point_num);
|
||||
void lv_line_set_points(lv_obj_t * obj, const lv_point_precise_t points[], uint32_t point_num);
|
||||
|
||||
/**
|
||||
* Enable (or disable) the y coordinate inversion.
|
||||
|
@ -450,13 +450,17 @@ static void scale_draw_indicator(lv_obj_t * obj, lv_event_t * event)
|
||||
tick_value, tick_idx, &tick_point_a);
|
||||
|
||||
if(is_major_tick) {
|
||||
major_tick_dsc.p1 = tick_point_a;
|
||||
major_tick_dsc.p2 = tick_point_b;
|
||||
major_tick_dsc.p1_x = tick_point_a.x;
|
||||
major_tick_dsc.p1_y = tick_point_a.y;
|
||||
major_tick_dsc.p2_x = tick_point_b.x;
|
||||
major_tick_dsc.p2_y = tick_point_b.y;
|
||||
lv_draw_line(layer, &major_tick_dsc);
|
||||
}
|
||||
else {
|
||||
minor_tick_dsc.p1 = tick_point_a;
|
||||
minor_tick_dsc.p2 = tick_point_b;
|
||||
minor_tick_dsc.p1_x = tick_point_a.x;
|
||||
minor_tick_dsc.p1_y = tick_point_a.y;
|
||||
minor_tick_dsc.p2_x = tick_point_b.x;
|
||||
minor_tick_dsc.p2_y = tick_point_b.y;
|
||||
lv_draw_line(layer, &minor_tick_dsc);
|
||||
}
|
||||
}
|
||||
@ -553,13 +557,17 @@ static void scale_draw_indicator(lv_obj_t * obj, lv_event_t * event)
|
||||
scale_store_main_line_tick_width_compensation(obj, tick_idx, is_major_tick, major_tick_dsc.width, minor_tick_dsc.width);
|
||||
|
||||
if(is_major_tick) {
|
||||
major_tick_dsc.p1 = tick_point_a;
|
||||
major_tick_dsc.p2 = tick_point_b;
|
||||
major_tick_dsc.p1_x = tick_point_a.x;
|
||||
major_tick_dsc.p1_y = tick_point_a.y;
|
||||
major_tick_dsc.p2_x = tick_point_b.x;
|
||||
major_tick_dsc.p2_y = tick_point_b.y;
|
||||
lv_draw_line(layer, &major_tick_dsc);
|
||||
}
|
||||
else {
|
||||
minor_tick_dsc.p1 = tick_point_a;
|
||||
minor_tick_dsc.p2 = tick_point_b;
|
||||
minor_tick_dsc.p1_x = tick_point_a.x;
|
||||
minor_tick_dsc.p1_y = tick_point_a.y;
|
||||
minor_tick_dsc.p2_x = tick_point_b.x;
|
||||
minor_tick_dsc.p2_y = tick_point_b.y;
|
||||
lv_draw_line(layer, &minor_tick_dsc);
|
||||
}
|
||||
}
|
||||
@ -636,8 +644,10 @@ static void scale_draw_main(lv_obj_t * obj, lv_event_t * event)
|
||||
main_line_point_b.x += scale->first_tick_width / 2U;
|
||||
}
|
||||
|
||||
line_dsc.p1 = main_line_point_a;
|
||||
line_dsc.p2 = main_line_point_b;
|
||||
line_dsc.p1_x = main_line_point_a.x;
|
||||
line_dsc.p1_y = main_line_point_a.y;
|
||||
line_dsc.p2_x = main_line_point_b.x;
|
||||
line_dsc.p2_y = main_line_point_b.y;
|
||||
lv_draw_line(layer, &line_dsc);
|
||||
|
||||
lv_scale_section_t * section;
|
||||
@ -676,8 +686,10 @@ static void scale_draw_main(lv_obj_t * obj, lv_event_t * event)
|
||||
|
||||
scale_set_line_properties(obj, &main_line_section_dsc, section->main_style, LV_PART_MAIN);
|
||||
|
||||
main_line_section_dsc.p1 = main_point_a;
|
||||
main_line_section_dsc.p2 = main_point_b;
|
||||
main_line_section_dsc.p1_x = main_point_a.x;
|
||||
main_line_section_dsc.p1_y = main_point_a.y;
|
||||
main_line_section_dsc.p2_x = main_point_b.x;
|
||||
main_line_section_dsc.p2_y = main_point_b.y;
|
||||
lv_draw_line(layer, &main_line_section_dsc);
|
||||
}
|
||||
}
|
||||
|
@ -1032,18 +1032,18 @@ static void lv_draw_span(lv_obj_t * obj, lv_layer_t * layer)
|
||||
line_dsc.blend_mode = label_draw_dsc.blend_mode;
|
||||
|
||||
if(decor & LV_TEXT_DECOR_STRIKETHROUGH) {
|
||||
line_dsc.p1.x = txt_pos.x;
|
||||
line_dsc.p1.y = pos.y + ((pinfo->line_h - line_space) >> 1) + (line_dsc.width >> 1);
|
||||
line_dsc.p2.x = pos.x;
|
||||
line_dsc.p2.y = line_dsc.p1.y;
|
||||
line_dsc.p1_x = txt_pos.x;
|
||||
line_dsc.p1_y = pos.y + ((pinfo->line_h - line_space) >> 1) + (line_dsc.width >> 1);
|
||||
line_dsc.p2_x = pos.x;
|
||||
line_dsc.p2_y = line_dsc.p1_y;
|
||||
lv_draw_line(layer, &line_dsc);
|
||||
}
|
||||
|
||||
if(decor & LV_TEXT_DECOR_UNDERLINE) {
|
||||
line_dsc.p1.x = txt_pos.x;
|
||||
line_dsc.p1.y = pos.y + pinfo->line_h - line_space - pinfo->font->base_line - pinfo->font->underline_position;
|
||||
line_dsc.p2.x = pos.x;
|
||||
line_dsc.p2.y = line_dsc.p1.y;
|
||||
line_dsc.p1_x = txt_pos.x;
|
||||
line_dsc.p1_y = pos.y + pinfo->line_h - line_space - pinfo->font->base_line - pinfo->font->underline_position;
|
||||
line_dsc.p2_x = pos.x;
|
||||
line_dsc.p2_y = line_dsc.p1_y;
|
||||
lv_draw_line(layer, &line_dsc);
|
||||
}
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ void test_line_should_return_valid_y_invert(void)
|
||||
|
||||
void test_line_size_should_be_updated_after_adding_points(void)
|
||||
{
|
||||
static lv_point_t points[] = { {5, 5} };
|
||||
uint16_t point_cnt = (uint16_t) sizeof(points) / sizeof(lv_point_t);
|
||||
static lv_point_precise_t points[] = { {5, 5} };
|
||||
uint16_t point_cnt = (uint16_t) sizeof(points) / sizeof(lv_point_precise_t);
|
||||
lv_line_set_points(line, points, point_cnt);
|
||||
|
||||
lv_coord_t calculated_width = 0;
|
||||
@ -51,8 +51,8 @@ void test_line_size_should_be_updated_after_adding_points(void)
|
||||
/* Get the biggest coordinate on both axis */
|
||||
uint16_t point_idx = 0;
|
||||
for(point_idx = 0; point_idx < point_cnt; point_idx++) {
|
||||
calculated_width = LV_MAX(points[point_idx].x, calculated_width);
|
||||
calculated_height = LV_MAX(points[point_idx].y, calculated_height);
|
||||
calculated_width = (int32_t)LV_MAX(points[point_idx].x, calculated_width);
|
||||
calculated_height = (int32_t)LV_MAX(points[point_idx].y, calculated_height);
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL_UINT16(calculated_width, lv_obj_get_self_width(line));
|
||||
@ -91,13 +91,13 @@ void test_line_should_update_extra_draw_size_based_on_style(void)
|
||||
|
||||
void test_line_basic_render(void)
|
||||
{
|
||||
static lv_point_t points[] = { {5, 5},
|
||||
static lv_point_precise_t points[] = { {5, 5},
|
||||
{100, 5}, /*Horizontal*/
|
||||
{100, 100}, /*Vertical*/
|
||||
{120, 5}, /*Steep*/
|
||||
{200, 20}, /*Flat*/
|
||||
};
|
||||
uint16_t point_cnt = (uint16_t) sizeof(points) / sizeof(lv_point_t);
|
||||
uint16_t point_cnt = (uint16_t) sizeof(points) / sizeof(lv_point_precise_t);
|
||||
lv_line_set_points(line, points, point_cnt);
|
||||
lv_obj_set_pos(line, 10, 10);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user