mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
Merge branch 'dev-6.0' of https://github.com/littlevgl/lvgl into font
This commit is contained in:
commit
f692e00ffe
@ -20,11 +20,14 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
void tri_draw_flat(const lv_point_t * points, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa);
|
||||
void tri_draw_tall(const lv_point_t * points, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa);
|
||||
static void point_swap(lv_point_t * p1, lv_point_t * p2);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
static void point_swap(lv_point_t * p1, lv_point_t * p2);
|
||||
static uint8_t corr_value;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@ -42,7 +45,55 @@ static void point_swap(lv_point_t * p1, lv_point_t * p2);
|
||||
* @param opa_scale scale down all opacities by the factor
|
||||
*/
|
||||
void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, const lv_style_t * style,
|
||||
lv_opa_t opa_scale)
|
||||
lv_opa_t opa_scale)
|
||||
{
|
||||
/*Return is the triangle is degenerated*/
|
||||
if(points[0].x == points[1].x && points[0].y == points[1].y) return;
|
||||
if(points[1].x == points[2].x && points[1].y == points[2].y) return;
|
||||
if(points[0].x == points[2].x && points[0].y == points[2].y) return;
|
||||
|
||||
if(points[0].x == points[1].x && points[1].x == points[2].x) return;
|
||||
if(points[0].y == points[1].y && points[1].y == points[2].y) return;
|
||||
|
||||
lv_opa_t opa = opa_scale == LV_OPA_COVER
|
||||
? style->body.opa
|
||||
: (uint16_t)((uint16_t)style->body.opa * opa_scale) >> 8;
|
||||
|
||||
/*Is the triangle flat or tall?*/
|
||||
lv_coord_t x_min = LV_MATH_MIN(LV_MATH_MIN(points[0].x, points[1].x), points[2].x);
|
||||
lv_coord_t x_max = LV_MATH_MAX(LV_MATH_MAX(points[0].x, points[1].x), points[2].x);
|
||||
lv_coord_t y_min = LV_MATH_MIN(LV_MATH_MIN(points[0].y, points[1].y), points[2].y);
|
||||
lv_coord_t y_max = LV_MATH_MAX(LV_MATH_MAX(points[0].y, points[1].y), points[2].y);
|
||||
|
||||
if(opa < LV_OPA_MAX) {
|
||||
/*Simply draw the triangles with opacity */
|
||||
corr_value = 1;
|
||||
tri_draw_tall(points, mask, style, opa);
|
||||
} else {
|
||||
/* Draw the tall rectangles from vertical lines
|
||||
* and from the flat triangles from horizontal lines
|
||||
* to minimize the number of lines.
|
||||
* Some pixels are overdrawn on the common edges of the triangles
|
||||
* so use it only if the triangle has no opacity*/
|
||||
|
||||
corr_value = 0;
|
||||
|
||||
/* Draw from horizontal lines*/
|
||||
if(x_max - x_min < y_max - y_min) {
|
||||
tri_draw_tall(points, mask, style, opa);
|
||||
}
|
||||
/*Else flat so draw from vertical lines*/
|
||||
else {
|
||||
tri_draw_flat(points, mask, style, opa);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
void tri_draw_flat(const lv_point_t * points, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa)
|
||||
{
|
||||
/*Return if the points are out of the mask*/
|
||||
if(points[0].x < mask->x1 &&
|
||||
@ -78,14 +129,6 @@ void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, const l
|
||||
if(tri[2].y < tri[1].y) point_swap(&tri[2], &tri[1]);
|
||||
if(tri[1].y < tri[0].y) point_swap(&tri[1], &tri[0]);
|
||||
|
||||
/*Return is the triangle is degenerated*/
|
||||
if(tri[0].x == tri[1].x && tri[0].y == tri[1].y) return;
|
||||
if(tri[1].x == tri[2].x && tri[1].y == tri[2].y) return;
|
||||
if(tri[0].x == tri[2].x && tri[0].y == tri[2].y) return;
|
||||
|
||||
if(tri[0].x == tri[1].x && tri[1].x == tri[2].x) return;
|
||||
if(tri[0].y == tri[1].y && tri[1].y == tri[2].y) return;
|
||||
|
||||
/*Draw the triangle*/
|
||||
lv_point_t edge1;
|
||||
lv_coord_t dx1 = LV_MATH_ABS(tri[0].x - tri[1].x);
|
||||
@ -113,22 +156,19 @@ void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, const l
|
||||
lv_area_t act_area;
|
||||
lv_area_t draw_area;
|
||||
|
||||
lv_opa_t opa = opa_scale == LV_OPA_COVER
|
||||
? style->body.opa
|
||||
: (uint16_t)((uint16_t)style->body.opa * opa_scale) >> 8;
|
||||
|
||||
while(1) {
|
||||
act_area.x1 = edge1.x;
|
||||
act_area.x2 = edge2.x;
|
||||
act_area.y1 = edge1.y;
|
||||
act_area.y2 = edge2.y;
|
||||
|
||||
/* Get the area of a line.
|
||||
* Adjust it a little bit to perfectly match (no redrawn pixels) with the adjacent triangles*/
|
||||
draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2);
|
||||
draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2);
|
||||
draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2) - corr_value;
|
||||
draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2);
|
||||
draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2);
|
||||
draw_area.x2--; /*Do not draw most right pixel because it will be drawn by the adjacent
|
||||
triangle*/
|
||||
|
||||
lv_draw_fill(&draw_area, mask, style->body.main_color, opa);
|
||||
|
||||
/*Calc. the next point of edge1*/
|
||||
@ -141,8 +181,9 @@ void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, const l
|
||||
dy1 = LV_MATH_ABS(tri[1].y - tri[2].y);
|
||||
sy1 = tri[1].y < tri[2].y ? 1 : -1;
|
||||
err1 = (dx1 > dy1 ? dx1 : -dy1) / 2;
|
||||
} else if(edge1.x == tri[2].x && edge1.y == tri[2].y)
|
||||
} else if(edge1.x == tri[2].x && edge1.y == tri[2].y) {
|
||||
return;
|
||||
}
|
||||
err_tmp1 = err1;
|
||||
if(err_tmp1 > -dx1) {
|
||||
err1 -= dy1;
|
||||
@ -157,7 +198,7 @@ void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, const l
|
||||
/*Calc. the next point of edge2*/
|
||||
y2_tmp = edge2.y;
|
||||
do {
|
||||
if(edge2.x == tri[2].x && edge2.y == tri[2].y) return;
|
||||
if(edge2.x == tri[2].x && edge2.y == tri[2].y) return;
|
||||
err_tmp2 = err2;
|
||||
if(err_tmp2 > -dx2) {
|
||||
err2 -= dy2;
|
||||
@ -171,9 +212,111 @@ void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, const l
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
void tri_draw_tall(const lv_point_t * points, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa)
|
||||
{
|
||||
/*
|
||||
* Better to draw from vertical lines
|
||||
* |\
|
||||
* | |
|
||||
* | |
|
||||
* | \
|
||||
* | |
|
||||
* |___|
|
||||
*/
|
||||
|
||||
lv_point_t tri[3];
|
||||
|
||||
memcpy(tri, points, sizeof(tri));
|
||||
|
||||
/*Sort the vertices according to their x coordinate (0: x max, 1: x mid, 2:x min)*/
|
||||
if(tri[1].x < tri[0].x) point_swap(&tri[1], &tri[0]);
|
||||
if(tri[2].x < tri[1].x) point_swap(&tri[2], &tri[1]);
|
||||
if(tri[1].x < tri[0].x) point_swap(&tri[1], &tri[0]);
|
||||
|
||||
/*Draw the triangle*/
|
||||
lv_point_t edge1;
|
||||
lv_coord_t dx1 = LV_MATH_ABS(tri[0].x - tri[1].x);
|
||||
lv_coord_t sx1 = tri[0].x < tri[1].x ? 1 : -1;
|
||||
lv_coord_t dy1 = LV_MATH_ABS(tri[0].y - tri[1].y);
|
||||
lv_coord_t sy1 = tri[0].y < tri[1].y ? 1 : -1;
|
||||
lv_coord_t err1 = (dx1 > dy1 ? dx1 : -dy1) / 2;
|
||||
lv_coord_t err_tmp1;
|
||||
|
||||
lv_point_t edge2;
|
||||
lv_coord_t dx2 = LV_MATH_ABS(tri[0].x - tri[2].x);
|
||||
lv_coord_t sx2 = tri[0].x < tri[2].x ? 1 : -1;
|
||||
lv_coord_t dy2 = LV_MATH_ABS(tri[0].y - tri[2].y);
|
||||
lv_coord_t sy2 = tri[0].y < tri[2].y ? 1 : -1;
|
||||
lv_coord_t err2 = (dx1 > dy2 ? dx2 : -dy2) / 2;
|
||||
lv_coord_t err_tmp2;
|
||||
|
||||
lv_coord_t x1_tmp;
|
||||
lv_coord_t x2_tmp;
|
||||
|
||||
edge1.x = tri[0].x;
|
||||
edge1.y = tri[0].y;
|
||||
edge2.x = tri[0].x;
|
||||
edge2.y = tri[0].y;
|
||||
lv_area_t act_area;
|
||||
lv_area_t draw_area;
|
||||
|
||||
while(1) {
|
||||
act_area.x1 = edge1.x;
|
||||
act_area.x2 = edge2.x;
|
||||
act_area.y1 = edge1.y;
|
||||
act_area.y2 = edge2.y;
|
||||
|
||||
draw_area.x1 = LV_MATH_MIN(act_area.x1, act_area.x2);
|
||||
draw_area.x2 = LV_MATH_MAX(act_area.x1, act_area.x2);
|
||||
draw_area.y1 = LV_MATH_MIN(act_area.y1, act_area.y2);
|
||||
draw_area.y2 = LV_MATH_MAX(act_area.y1, act_area.y2) - corr_value;
|
||||
|
||||
lv_draw_fill(&draw_area, mask, style->body.main_color, opa);
|
||||
|
||||
/*Calc. the next point of edge1*/
|
||||
x1_tmp = edge1.x;
|
||||
do {
|
||||
if(edge1.y == tri[1].y && edge1.x == tri[1].x) {
|
||||
|
||||
dx1 = LV_MATH_ABS(tri[1].x - tri[2].x);
|
||||
sx1 = tri[1].x < tri[2].x ? 1 : -1;
|
||||
dy1 = LV_MATH_ABS(tri[1].y - tri[2].y);
|
||||
sy1 = tri[1].y < tri[2].y ? 1 : -1;
|
||||
err1 = (dx1 > dy1 ? dx1 : -dy1) / 2;
|
||||
} else if(edge1.y == tri[2].y && edge1.x == tri[2].x) {
|
||||
return;
|
||||
}
|
||||
err_tmp1 = err1;
|
||||
if(err_tmp1 > -dx1) {
|
||||
err1 -= dy1;
|
||||
edge1.x += sx1;
|
||||
}
|
||||
if(err_tmp1 < dy1) {
|
||||
err1 += dx1;
|
||||
edge1.y += sy1;
|
||||
}
|
||||
} while(edge1.x == x1_tmp);
|
||||
|
||||
/*Calc. the next point of edge2*/
|
||||
x2_tmp = edge2.x;
|
||||
do {
|
||||
if(edge2.y == tri[2].y && edge2.x == tri[2].x) {
|
||||
return;
|
||||
}
|
||||
|
||||
err_tmp2 = err2;
|
||||
if(err_tmp2 > -dx2) {
|
||||
err2 -= dy2;
|
||||
edge2.x += sx2;
|
||||
}
|
||||
if(err_tmp2 < dy2) {
|
||||
err2 += dx2;
|
||||
edge2.y += sy2;
|
||||
}
|
||||
} while(edge2.x == x2_tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Swap two points
|
||||
|
@ -354,7 +354,7 @@ static const uint8_t * lv_img_decoder_built_in_open(lv_img_decoder_t * decoder,
|
||||
}
|
||||
|
||||
lv_img_decoder_built_in_data_t * user_data = dsc->user_data;
|
||||
user_data->palette = lv_mem_alloc(sizeof(palette_size * sizeof(lv_color_t)));
|
||||
user_data->palette = lv_mem_alloc(palette_size * sizeof(lv_color_t));
|
||||
if(user_data->palette == NULL) {
|
||||
LV_LOG_ERROR("img_decoder_built_in_open: out of memory");
|
||||
#if LV_USE_FILESYSTEM
|
||||
|
@ -974,6 +974,7 @@ static void lv_chart_draw_areas(lv_obj_t * chart, const lv_area_t * mask)
|
||||
LV_LL_READ_BACK(ext->series_ll, ser) {
|
||||
lv_coord_t start_point = ext->update_mode == LV_CHART_UPDATE_MODE_SHIFT ? ser->start_point : 0;
|
||||
style.body.main_color = ser->color;
|
||||
style.body.opa = ext->series.opa;
|
||||
|
||||
p2.x = 0 + x_ofs;
|
||||
|
||||
|
@ -115,7 +115,7 @@ lv_obj_t * lv_ta_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
ext->label = NULL;
|
||||
ext->placeholder = NULL;
|
||||
|
||||
#if LV_USE_ANIMATION
|
||||
#if LV_USE_ANIMATION == 0
|
||||
ext->pwd_show_time = 0;
|
||||
ext->cursor.blink_time = 0;
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user