diff --git a/demos/ebike/lv_demo_ebike_stats.c b/demos/ebike/lv_demo_ebike_stats.c index 849f1d1124..7a88e274cf 100644 --- a/demos/ebike/lv_demo_ebike_stats.c +++ b/demos/ebike/lv_demo_ebike_stats.c @@ -360,17 +360,17 @@ static void chart_draw_task_event_cb(lv_event_t * e) 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; + tri_dsc.grad.dir = LV_GRAD_DIR_VER; int32_t full_h = lv_obj_get_height(obj); int32_t fract_upper = (int32_t)(LV_MIN(draw_line_dsc->p1.y, draw_line_dsc->p2.y) - obj->coords.y1) * 255 / full_h; int32_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 = lv_color_hex(0x3987CF); - tri_dsc.bg_grad.stops[0].opa = 200 * (255 - fract_upper) / 256; - tri_dsc.bg_grad.stops[0].frac = 0; - tri_dsc.bg_grad.stops[1].color = lv_color_hex(0x3987CF); - tri_dsc.bg_grad.stops[1].opa = 200 * (255 - fract_lower) / 256; - tri_dsc.bg_grad.stops[1].frac = 255; + tri_dsc.grad.stops[0].color = lv_color_hex(0x3987CF); + tri_dsc.grad.stops[0].opa = 200 * (255 - fract_upper) / 256; + tri_dsc.grad.stops[0].frac = 0; + tri_dsc.grad.stops[1].color = lv_color_hex(0x3987CF); + tri_dsc.grad.stops[1].opa = 200 * (255 - fract_lower) / 256; + tri_dsc.grad.stops[1].frac = 255; lv_draw_triangle(base_dsc->layer, &tri_dsc); diff --git a/demos/music/lv_demo_music_main.c b/demos/music/lv_demo_music_main.c index 2d036e950a..dd304e7d2c 100644 --- a/demos/music/lv_demo_music_main.c +++ b/demos/music/lv_demo_music_main.c @@ -809,7 +809,7 @@ static void spectrum_draw_event_cb(lv_event_t * e) lv_draw_triangle_dsc_t draw_dsc; lv_draw_triangle_dsc_init(&draw_dsc); - draw_dsc.bg_opa = LV_OPA_COVER; + draw_dsc.opa = LV_OPA_COVER; uint16_t r[64]; uint32_t i; @@ -865,12 +865,12 @@ static void spectrum_draw_event_cb(lv_event_t * e) v = (r[k] * animv + r[j] * (amax - animv)) / amax; } - if(v < BAR_COLOR1_STOP) draw_dsc.bg_color = BAR_COLOR1; - else if(v > (uint32_t)BAR_COLOR3_STOP) draw_dsc.bg_color = BAR_COLOR3; - else if(v > BAR_COLOR2_STOP) draw_dsc.bg_color = lv_color_mix(BAR_COLOR3, BAR_COLOR2, - ((v - BAR_COLOR2_STOP) * 255) / (BAR_COLOR3_STOP - BAR_COLOR2_STOP)); - else draw_dsc.bg_color = lv_color_mix(BAR_COLOR2, BAR_COLOR1, - ((v - BAR_COLOR1_STOP) * 255) / (BAR_COLOR2_STOP - BAR_COLOR1_STOP)); + if(v < BAR_COLOR1_STOP) draw_dsc.color = BAR_COLOR1; + else if(v > (uint32_t)BAR_COLOR3_STOP) draw_dsc.color = BAR_COLOR3; + else if(v > BAR_COLOR2_STOP) draw_dsc.color = lv_color_mix(BAR_COLOR3, BAR_COLOR2, + ((v - BAR_COLOR2_STOP) * 255) / (BAR_COLOR3_STOP - BAR_COLOR2_STOP)); + else draw_dsc.color = lv_color_mix(BAR_COLOR2, BAR_COLOR1, + ((v - BAR_COLOR1_STOP) * 255) / (BAR_COLOR2_STOP - BAR_COLOR1_STOP)); uint32_t di = deg + deg_space; diff --git a/demos/render/lv_demo_render.c b/demos/render/lv_demo_render.c index a827fe0361..8a822be241 100644 --- a/demos/render/lv_demo_render.c +++ b/demos/render/lv_demo_render.c @@ -543,17 +543,17 @@ static void triangle_draw_event_cb(lv_event_t * e) dsc.p[2].y = p_rel[2].y + coords.y1 + 2; lv_opa_t opa = lv_obj_get_style_opa(obj, 0); - dsc.bg_grad.dir = lv_obj_get_style_bg_grad_dir(obj, 0); - dsc.bg_grad.stops[0].color = lv_obj_get_style_bg_color(obj, 0); - dsc.bg_grad.stops[0].frac = lv_obj_get_style_bg_main_stop(obj, 0); - dsc.bg_grad.stops[0].opa = LV_OPA_MIX2(lv_obj_get_style_bg_main_opa(obj, 0), opa); - dsc.bg_grad.stops[1].color = lv_obj_get_style_bg_grad_color(obj, 0); - dsc.bg_grad.stops[1].frac = lv_obj_get_style_bg_grad_stop(obj, 0); - dsc.bg_grad.stops[1].opa = LV_OPA_MIX2(lv_obj_get_style_bg_grad_opa(obj, 0), opa); - dsc.bg_grad.stops_count = 2; + dsc.grad.dir = lv_obj_get_style_bg_grad_dir(obj, 0); + dsc.grad.stops[0].color = lv_obj_get_style_bg_color(obj, 0); + dsc.grad.stops[0].frac = lv_obj_get_style_bg_main_stop(obj, 0); + dsc.grad.stops[0].opa = LV_OPA_MIX2(lv_obj_get_style_bg_main_opa(obj, 0), opa); + dsc.grad.stops[1].color = lv_obj_get_style_bg_grad_color(obj, 0); + dsc.grad.stops[1].frac = lv_obj_get_style_bg_grad_stop(obj, 0); + dsc.grad.stops[1].opa = LV_OPA_MIX2(lv_obj_get_style_bg_grad_opa(obj, 0), opa); + dsc.grad.stops_count = 2; - dsc.bg_color = dsc.bg_grad.stops[0].color; - dsc.bg_opa = dsc.bg_grad.stops[0].opa; + dsc.color = dsc.grad.stops[0].color; + dsc.opa = dsc.grad.stops[0].opa; lv_draw_triangle(lv_event_get_layer(e), &dsc); } diff --git a/demos/widgets/lv_demo_widgets.c b/demos/widgets/lv_demo_widgets.c index 986493fb0b..3851fe0290 100644 --- a/demos/widgets/lv_demo_widgets.c +++ b/demos/widgets/lv_demo_widgets.c @@ -1427,17 +1427,17 @@ static void chart_event_cb(lv_event_t * e) 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; + tri_dsc.grad.dir = LV_GRAD_DIR_VER; int32_t full_h = lv_obj_get_height(obj); int32_t fract_uppter = (int32_t)(LV_MIN(draw_line_dsc->p1.y, draw_line_dsc->p2.y) - obj_coords.y1) * 255 / full_h; int32_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 = lv_chart_get_series_color(obj, ser); - tri_dsc.bg_grad.stops[0].opa = 255 - fract_uppter; - tri_dsc.bg_grad.stops[0].frac = 0; - tri_dsc.bg_grad.stops[1].color = lv_chart_get_series_color(obj, ser); - tri_dsc.bg_grad.stops[1].opa = 255 - fract_lower; - tri_dsc.bg_grad.stops[1].frac = 255; + tri_dsc.grad.stops[0].color = lv_chart_get_series_color(obj, ser); + tri_dsc.grad.stops[0].opa = 255 - fract_uppter; + tri_dsc.grad.stops[0].frac = 0; + tri_dsc.grad.stops[1].color = lv_chart_get_series_color(obj, ser); + tri_dsc.grad.stops[1].opa = 255 - fract_lower; + tri_dsc.grad.stops[1].frac = 255; lv_draw_triangle(base_dsc->layer, &tri_dsc); diff --git a/examples/widgets/canvas/index.rst b/examples/widgets/canvas/index.rst index ac345b7ede..8212146814 100644 --- a/examples/widgets/canvas/index.rst +++ b/examples/widgets/canvas/index.rst @@ -52,14 +52,20 @@ Draw a vector graphic to the canvas .. lv_example:: widgets/canvas/lv_example_canvas_8 :language: c -Draw Fancy Letter Effects -------------------------- +Draw a triangle to the canvas +----------------------------- .. lv_example:: widgets/canvas/lv_example_canvas_9 :language: c -Draw Fancy Letter Effects 2 ---------------------------- +Draw Fancy Letter Effects +------------------------- .. lv_example:: widgets/canvas/lv_example_canvas_10 - :language: c +:language: c + + +Draw Fancy Letter Effects 2 +--------------------------- +.. lv_example:: widgets/canvas/lv_example_canvas_11 +:language: c diff --git a/examples/widgets/canvas/lv_example_canvas_10.c b/examples/widgets/canvas/lv_example_canvas_10.c index 017af3b92c..29b4729aac 100644 --- a/examples/widgets/canvas/lv_example_canvas_10.c +++ b/examples/widgets/canvas/lv_example_canvas_10.c @@ -7,8 +7,8 @@ static void timer_cb(lv_timer_t * timer) { static int16_t counter = 0; - const char * string = "windstorrrrrrrrrrrrrrrrm~>>>"; - const int16_t string_len = (int16_t)lv_strlen(string); + const char * string = "lol~ I'm wavvvvvvving~>>>"; + const int16_t string_len = lv_strlen(string); lv_obj_t * canvas = (lv_obj_t *)lv_timer_get_user_data(timer); lv_layer_t layer; @@ -22,15 +22,15 @@ static void timer_cb(lv_timer_t * timer) letter_dsc.font = lv_font_get_default(); { -#define CURVE2_X(t) ((t) * 2 + lv_trigo_cos((t) * 5) * 40 / 32767 - 10) -#define CURVE2_Y(t, T) ((t) * lv_trigo_sin(((t) + (T)) * 5) * 40 / 32767 / 80 + CANVAS_HEIGHT / 2) +#define CURVE2_X(t) (t * 2 + 10) +#define CURVE2_Y(t) (lv_trigo_sin((t) * 5) * 40 / 32767 + CANVAS_HEIGHT / 2) int32_t pre_x = CURVE2_X(-1); - int32_t pre_y = CURVE2_Y(-1, 0); + int32_t pre_y = CURVE2_Y(-1); for(int16_t i = 0; i < string_len; i++) { const int16_t angle = (int16_t)(i * 5); const int32_t x = CURVE2_X(angle); - const int32_t y = CURVE2_Y(angle + 30, counter / 2); + const int32_t y = CURVE2_Y(angle + counter / 2); const lv_point_t point = { .x = x, .y = y }; letter_dsc.unicode = (uint32_t)string[i % string_len]; diff --git a/examples/widgets/canvas/lv_example_canvas_11.c b/examples/widgets/canvas/lv_example_canvas_11.c new file mode 100644 index 0000000000..fb304e5c4b --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_11.c @@ -0,0 +1,68 @@ +#include "../../lv_examples.h" +#if LV_USE_CANVAS && LV_BUILD_EXAMPLES + +#define CANVAS_WIDTH 300 +#define CANVAS_HEIGHT 200 + +static void timer_cb(lv_timer_t * timer) +{ + static int32_t counter = 0; + const char * string = "windstorrrrrrrrrrrrrrrrm~>>>"; + const int16_t string_len = lv_strlen(string); + + lv_obj_t * canvas = (lv_obj_t *) lv_timer_get_user_data(timer); + lv_layer_t layer; + lv_canvas_init_layer(canvas, &layer); + + lv_canvas_fill_bg(canvas, lv_color_white(), LV_OPA_COVER); + + lv_draw_letter_dsc_t letter_dsc; + lv_draw_letter_dsc_init(&letter_dsc); + letter_dsc.color = lv_color_hex(0xff0000); + letter_dsc.font = lv_font_get_default(); + + { +#define CURVE2_X(t) ((t) * 2 + lv_trigo_cos((t) * 5) * 40 / 32767 - 10) +#define CURVE2_Y(t, T) ((t) * lv_trigo_sin(((t) + (T)) * 5) * 40 / 32767 / 80 + CANVAS_HEIGHT / 2) + + int32_t pre_x = CURVE2_X(-1); + int32_t pre_y = CURVE2_Y(-1, 0); + for(int16_t i = 0; i < string_len; i++) { + const int32_t angle = i * 5; + const int32_t x = CURVE2_X(angle); + const int32_t y = CURVE2_Y(angle + 30, counter / 2); + + letter_dsc.unicode = (uint32_t)string[i % string_len]; + letter_dsc.rotation = lv_atan2(y - pre_y, x - pre_x) * 10; + letter_dsc.color = lv_color_hsv_to_rgb(i * 10, 100, 100); + lv_draw_letter(&layer, &letter_dsc, &(lv_point_t) { + .x = x, .y = y + }); + + pre_x = x; + pre_y = y; + } + } + + lv_canvas_finish_layer(canvas, &layer); + + counter++; +} + +void lv_example_canvas_11(void) +{ + /*Create a buffer for the canvas*/ + LV_DRAW_BUF_DEFINE_STATIC(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); + LV_DRAW_BUF_INIT_STATIC(draw_buf); + + lv_obj_t * canvas = lv_canvas_create(lv_screen_active()); + lv_obj_set_size(canvas, CANVAS_WIDTH, CANVAS_HEIGHT); + + lv_obj_center(canvas); + + lv_canvas_set_draw_buf(canvas, &draw_buf); + + lv_timer_create(timer_cb, 16, canvas); +} + +#endif diff --git a/examples/widgets/canvas/lv_example_canvas_9.c b/examples/widgets/canvas/lv_example_canvas_9.c index c3a182216e..d6769d3e47 100644 --- a/examples/widgets/canvas/lv_example_canvas_9.c +++ b/examples/widgets/canvas/lv_example_canvas_9.c @@ -1,67 +1,51 @@ #include "../../lv_examples.h" #if LV_USE_CANVAS && LV_BUILD_EXAMPLES -#define CANVAS_WIDTH 300 -#define CANVAS_HEIGHT 200 -static void timer_cb(lv_timer_t * timer) -{ - static int16_t counter = 0; - const char * string = "lol~ I'm wavvvvvvving~>>>"; - const int16_t string_len = (int16_t)lv_strlen(string); - - lv_obj_t * canvas = (lv_obj_t *)lv_timer_get_user_data(timer); - lv_layer_t layer; - lv_canvas_init_layer(canvas, &layer); - - lv_canvas_fill_bg(canvas, lv_color_white(), LV_OPA_COVER); - - lv_draw_letter_dsc_t letter_dsc; - lv_draw_letter_dsc_init(&letter_dsc); - letter_dsc.color = lv_color_hex(0xff0000); - letter_dsc.font = lv_font_get_default(); - - { -#define CURVE2_X(t) (t * 2 + 10) -#define CURVE2_Y(t) (lv_trigo_sin((t) * 5) * 40 / 32767 + CANVAS_HEIGHT / 2) - - int32_t pre_x = CURVE2_X(-1); - int32_t pre_y = CURVE2_Y(-1); - for(int16_t i = 0; i < string_len; i++) { - const int16_t angle = (int16_t)(i * 5); - const int32_t x = CURVE2_X(angle); - const int32_t y = CURVE2_Y(angle + counter / 2); - const lv_point_t point = { .x = x, .y = y }; - - letter_dsc.unicode = (uint32_t)string[i % string_len]; - letter_dsc.rotation = lv_atan2(y - pre_y, x - pre_x) * 10; - letter_dsc.color = lv_color_hsv_to_rgb(i * 10, 100, 100); - lv_draw_letter(&layer, &letter_dsc, &point); - - pre_x = x; - pre_y = y; - } - } - - lv_canvas_finish_layer(canvas, &layer); - - counter++; -} +#define CANVAS_WIDTH 150 +#define CANVAS_HEIGHT 150 +/** + * Draw a triangle to the canvas + */ void lv_example_canvas_9(void) { /*Create a buffer for the canvas*/ LV_DRAW_BUF_DEFINE_STATIC(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888); LV_DRAW_BUF_INIT_STATIC(draw_buf); + /*Create a canvas and initialize its palette*/ lv_obj_t * canvas = lv_canvas_create(lv_screen_active()); - lv_obj_set_size(canvas, CANVAS_WIDTH, CANVAS_HEIGHT); - + lv_canvas_set_draw_buf(canvas, &draw_buf); + lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER); lv_obj_center(canvas); - lv_canvas_set_draw_buf(canvas, &draw_buf); + lv_layer_t layer; + lv_canvas_init_layer(canvas, &layer); - lv_timer_create(timer_cb, 16, canvas); + lv_draw_triangle_dsc_t tri_dsc; + lv_draw_triangle_dsc_init(&tri_dsc); + tri_dsc.p[0].x = 10; + tri_dsc.p[0].y = 10; + tri_dsc.p[1].x = 100; + tri_dsc.p[1].y = 30; + tri_dsc.p[2].x = 50; + tri_dsc.p[2].y = 100; + + tri_dsc.grad.stops_count = 2; + tri_dsc.grad.dir = LV_GRAD_DIR_VER; + tri_dsc.grad.stops[0].color = lv_color_hex(0xff0000); + tri_dsc.grad.stops[0].frac = 64; /*Start at 25%*/ + tri_dsc.grad.stops[0].opa = LV_OPA_COVER; + tri_dsc.grad.stops[1].color = lv_color_hex(0x0000ff); + tri_dsc.grad.stops[1].opa = LV_OPA_TRANSP; + tri_dsc.grad.stops[1].frac = 3 * 64; /*End at 75%*/ + + tri_dsc.opa = 128; /*Set the overall opacity to 50%*/ + + lv_draw_triangle(&layer, &tri_dsc); + + lv_canvas_finish_layer(canvas, &layer); } #endif diff --git a/examples/widgets/chart/lv_example_chart_5.c b/examples/widgets/chart/lv_example_chart_5.c index 08095e725d..eb71c62892 100644 --- a/examples/widgets/chart/lv_example_chart_5.c +++ b/examples/widgets/chart/lv_example_chart_5.c @@ -71,17 +71,18 @@ static void add_faded_area(lv_event_t * e) 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; + tri_dsc.grad.dir = LV_GRAD_DIR_VER; int32_t full_h = lv_obj_get_height(obj); int32_t fract_uppter = (int32_t)(LV_MIN(draw_line_dsc->p1.y, draw_line_dsc->p2.y) - coords.y1) * 255 / full_h; int32_t fract_lower = (int32_t)(LV_MAX(draw_line_dsc->p1.y, draw_line_dsc->p2.y) - coords.y1) * 255 / full_h; - tri_dsc.bg_grad.stops[0].color = ser_color; - tri_dsc.bg_grad.stops[0].opa = (lv_opa_t)(255 - fract_uppter); - tri_dsc.bg_grad.stops[0].frac = 0; - tri_dsc.bg_grad.stops[1].color = ser_color; - tri_dsc.bg_grad.stops[1].opa = (lv_opa_t)(255 - fract_lower); - tri_dsc.bg_grad.stops[1].frac = 255; + tri_dsc.grad.stops[0].color = ser_color; + tri_dsc.grad.stops[0].opa = (lv_opa_t)(255 - fract_uppter); + tri_dsc.grad.stops[0].opa = 255 - fract_uppter; + tri_dsc.grad.stops[0].frac = 0; + tri_dsc.grad.stops[1].color = ser_color; + tri_dsc.grad.stops[1].opa = (lv_opa_t)(255 - fract_lower); + tri_dsc.grad.stops[1].frac = 255; lv_draw_triangle(base_dsc->layer, &tri_dsc); diff --git a/examples/widgets/dropdown/lv_example_dropdown_1.c b/examples/widgets/dropdown/lv_example_dropdown_1.c index 337140f03d..8e794f948b 100644 --- a/examples/widgets/dropdown/lv_example_dropdown_1.c +++ b/examples/widgets/dropdown/lv_example_dropdown_1.c @@ -32,4 +32,5 @@ void lv_example_dropdown_1(void) lv_obj_add_event_cb(dd, event_handler, LV_EVENT_ALL, NULL); } + #endif diff --git a/examples/widgets/lv_example_widgets.h b/examples/widgets/lv_example_widgets.h index ee9cd34d3c..e6929d978c 100644 --- a/examples/widgets/lv_example_widgets.h +++ b/examples/widgets/lv_example_widgets.h @@ -59,6 +59,7 @@ void lv_example_canvas_7(void); void lv_example_canvas_8(void); void lv_example_canvas_9(void); void lv_example_canvas_10(void); +void lv_example_canvas_11(void); void lv_example_chart_1(void); void lv_example_chart_2(void); diff --git a/src/core/lv_obj_draw.c b/src/core/lv_obj_draw.c index 45a63d8021..56fa3f95ea 100644 --- a/src/core/lv_obj_draw.c +++ b/src/core/lv_obj_draw.c @@ -189,7 +189,6 @@ void lv_obj_init_draw_label_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_label_ds draw_dsc->letter_space = lv_obj_get_style_text_letter_space(obj, part); draw_dsc->line_space = lv_obj_get_style_text_line_space(obj, part); draw_dsc->decor = lv_obj_get_style_text_decor(obj, part); - if(part != LV_PART_MAIN) draw_dsc->blend_mode = lv_obj_get_style_blend_mode(obj, part); draw_dsc->font = lv_obj_get_style_text_font(obj, part); @@ -278,7 +277,6 @@ void lv_obj_init_draw_line_dsc(lv_obj_t * obj, lv_part_t part, lv_draw_line_dsc_ draw_dsc->round_start = lv_obj_get_style_line_rounded(obj, part); draw_dsc->round_end = draw_dsc->round_start; - if(part != LV_PART_MAIN) draw_dsc->blend_mode = lv_obj_get_style_blend_mode(obj, part); LV_PROFILER_DRAW_END; } diff --git a/src/core/lv_obj_draw.h b/src/core/lv_obj_draw.h index c0dbee4311..9df48c5eb7 100644 --- a/src/core/lv_obj_draw.h +++ b/src/core/lv_obj_draw.h @@ -19,6 +19,7 @@ extern "C" { #include "../draw/lv_draw_image.h" #include "../draw/lv_draw_line.h" #include "../draw/lv_draw_arc.h" +#include "../draw/lv_draw_triangle.h" /********************* * DEFINES @@ -28,9 +29,23 @@ extern "C" { * TYPEDEFS **********************/ +/** Store the type of layer required to render a widget.*/ typedef enum { + /**No layer is needed. */ LV_LAYER_TYPE_NONE, + + /**Simple layer means that the layer can be rendered in chunks. + * For example with opa_layered = 140 it's possible to render only 10 lines + * from the layer. When it's ready go the the next 10 lines. + * It avoids large memory allocations for the layer buffer. + * The buffer size for a chunk can be set by `LV_DRAW_LAYER_SIMPLE_BUF_SIZE` in lv_conf.h.*/ LV_LAYER_TYPE_SIMPLE, + + /**The widget is transformed and cannot be rendered in chunks. + * It's because - due to the transformations - pixel outside of + * a given area will also contribute to the final image. + * In this case there is no limitation on the buffer size. + * LVGL will allocate as large buffer as needed to render the transformed area.*/ LV_LAYER_TYPE_TRANSFORM, } lv_layer_type_t; diff --git a/src/draw/lv_draw.h b/src/draw/lv_draw.h index 83a9a96fbd..44b2c7e8dd 100644 --- a/src/draw/lv_draw.h +++ b/src/draw/lv_draw.h @@ -117,12 +117,25 @@ struct _lv_layer_t { }; typedef struct { + /**The widget for which draw descriptor was created */ lv_obj_t * obj; + + /**The widget part for which draw descriptor was created */ lv_part_t part; + + /**A widget type specific ID (e.g. table row index). See the docs of the given widget.*/ uint32_t id1; + + /**A widget type specific ID (e.g. table column index). See the docs of the given widget.*/ uint32_t id2; + + /**The target layer */ lv_layer_t * layer; + + /**Size of the specific draw descriptor into which this base descriptor is embedded*/ size_t dsc_size; + + /**Any custom user data*/ void * user_data; } lv_draw_dsc_base_t; diff --git a/src/draw/lv_draw_arc.h b/src/draw/lv_draw_arc.h index 726bd68c89..1178ecb3ae 100644 --- a/src/draw/lv_draw_arc.h +++ b/src/draw/lv_draw_arc.h @@ -29,14 +29,33 @@ extern "C" { typedef struct { lv_draw_dsc_base_t base; + /**The color of the arc*/ lv_color_t color; + + /**The width (thickness) of the arc */ int32_t width; + + /**The start angle in 1 degree units (if `LV_USE_FLOAT` is enabled a float number can be also used) + * 0° is the 3 o'clock position, 90° is the 6 o'clock, etc. */ lv_value_precise_t start_angle; + + /**The end angle, similarly to start_angle. */ lv_value_precise_t end_angle; + + /**The center point of the arc. */ lv_point_t center; + + /**The outer radius of the arc*/ uint16_t radius; + + /**An image source to be used instead of `color`. `NULL` if unused*/ const void * img_src; + + /**Opacity of the arc in 0...255 range. + * LV_OPA_TRANSP, LV_OPA_10, LV_OPA_20, .. LV_OPA_COVER can be used as well*/ lv_opa_t opa; + + /**1: Make the arc ends rounded*/ uint8_t rounded : 1; } lv_draw_arc_dsc_t; diff --git a/src/draw/lv_draw_image.c b/src/draw/lv_draw_image.c index a2f1df4d78..c8f787bd99 100644 --- a/src/draw/lv_draw_image.c +++ b/src/draw/lv_draw_image.c @@ -75,8 +75,9 @@ void lv_draw_layer(lv_layer_t * layer, const lv_draw_image_dsc_t * dsc, const lv lv_draw_task_t * t = lv_draw_add_task(layer, coords); - t->draw_dsc = lv_malloc(sizeof(*dsc)); - LV_ASSERT_MALLOC(t->draw_dsc); + lv_draw_image_dsc_t * new_image_dsc = lv_malloc(sizeof(*dsc)); + LV_ASSERT_MALLOC(new_image_dsc); + t->draw_dsc = new_image_dsc; lv_memcpy(t->draw_dsc, dsc, sizeof(*dsc)); t->type = LV_DRAW_TASK_TYPE_LAYER; t->state = LV_DRAW_TASK_STATE_WAITING; @@ -85,6 +86,11 @@ void lv_draw_layer(lv_layer_t * layer, const lv_draw_image_dsc_t * dsc, const lv dsc->rotation, dsc->scale_x, dsc->scale_y, &dsc->pivot); lv_area_move(&t->_real_area, coords->x1, coords->y1); + /*If the image_area is not set assume that it's the same as the rendering area */ + if(new_image_dsc->image_area.x2 == LV_COORD_MIN) { + new_image_dsc->image_area = *coords; + } + lv_layer_t * layer_to_draw = (lv_layer_t *)dsc->src; layer_to_draw->all_tasks_added = true; @@ -119,6 +125,11 @@ void lv_draw_image(lv_layer_t * layer, const lv_draw_image_dsc_t * dsc, const lv return; } + /*If the image_area is not set assume that it's the same as the rendering area */ + if(new_image_dsc->image_area.x2 == LV_COORD_MIN) { + new_image_dsc->image_area = *image_coords; + } + /*Typical case, draw the image as bitmap*/ if(!(new_image_dsc->header.flags & LV_IMAGE_FLAGS_CUSTOM_DRAW)) { lv_draw_task_t * t = lv_draw_add_task(layer, image_coords); @@ -179,7 +190,6 @@ void lv_draw_image(lv_layer_t * layer, const lv_draw_image_dsc_t * dsc, const lv lv_free(new_image_dsc); } - LV_PROFILER_DRAW_END; } diff --git a/src/draw/lv_draw_image.h b/src/draw/lv_draw_image.h index 293a47b0be..6a41883802 100644 --- a/src/draw/lv_draw_image.h +++ b/src/draw/lv_draw_image.h @@ -29,35 +29,71 @@ extern "C" { struct _lv_draw_image_dsc_t { lv_draw_dsc_base_t base; + /**The image source: pointer to `lv_image_dsc_t` or a path to a file*/ const void * src; + + /**The header of the image. Initialized internally in `lv_draw_image` */ lv_image_header_t header; + /**Clip the corner of the image with this radius. Use `LV_RADIUS_CIRCLE` for max. radius */ + int32_t clip_radius; + + /**The rotation of the image in 0.1 degree unit. E.g. 234 means 23.4° */ int32_t rotation; + + /**Horizontal scale (zoom) of the image. + * 256 (LV_SCALE_NONE): means no zoom, 512 double size, 128 half size.*/ int32_t scale_x; + + /**Same as `scale_y` but vertically*/ int32_t scale_y; + + /**Parallelogram like transformation of the image horizontally in 0.1 degree unit. E.g. 456 means 45.6°.*/ int32_t skew_x; + + /**Same as `skew_x` but vertically*/ int32_t skew_y; + + /**The pivot point of transformation (scale and rotation). + * 0;0 is the top left corner of the image. Can be outside of the image too.*/ lv_point_t pivot; + /**Mix this color to the images. In case of `LV_COLOR_FORMAT_A8` it will be the color of the visible pixels*/ lv_color_t recolor; + + /**The intensity of recoloring. 0 means, no recolor, 255 means full cover (transparent pixels remain transparent)*/ lv_opa_t recolor_opa; + /**Opacity in 0...255 range. + * LV_OPA_TRANSP, LV_OPA_10, LV_OPA_20, .. LV_OPA_COVER can be used as well*/ lv_opa_t opa; + + /**Describes how to blend the pixels of the image to the background. + * See `lv_blend_mode_t` for more details. + */ lv_blend_mode_t blend_mode : 3; + /**1: perform the transformation with anti-alaising */ uint16_t antialias : 1; + + /**If the image is smaller than the `image_area` field of `lv_draw_image_dsc_t` + * tile the image (repeat is both horizontally and vertically) to fill the + * `image_area` area*/ uint16_t tile : 1; + + /**Used internally to store some information about the palette or the color of A8 images*/ lv_draw_image_sup_t * sup; /** Used to indicate the entire original, non-clipped area where the image is to be drawn. * This is important for: - * 1. Layer rendering, where it might happen that only a smaller area of the layer is rendered. + * 1. Layer rendering, where it might happen that only a smaller area of the layer is rendered and e.g. + * `clip_radius` needs to know what the original image was. * 2. Tiled images, where the target draw area is larger than the image to be tiled. */ lv_area_t image_area; - int32_t clip_radius; - + /**Pointer to an A8 or L8 image descriptor to mask the image with. + * The mask is always center aligned. */ const lv_image_dsc_t * bitmap_mask_src; }; @@ -105,7 +141,7 @@ void lv_draw_image(lv_layer_t * layer, const lv_draw_image_dsc_t * dsc, const lv /** * Create a draw task to blend a layer to another layer * @param layer pointer to a layer - * @param dsc pointer to an initialized draw descriptor + * @param dsc pointer to an initialized draw descriptor. `src` must be set to the layer to blend * @param coords the coordinates of the layer. * @note `coords` can be small than the total widget area from which the layer is created * (if only a part of the widget was rendered to a layer) diff --git a/src/draw/lv_draw_label.h b/src/draw/lv_draw_label.h index e3b0ed7636..5d7db01ff5 100644 --- a/src/draw/lv_draw_label.h +++ b/src/draw/lv_draw_label.h @@ -32,39 +32,73 @@ extern "C" { typedef struct { lv_draw_dsc_base_t base; + /**The text to draw*/ const char * text; - uint32_t text_length; + + /**The font to use. Fallback fonts are also handled.*/ const lv_font_t * font; - uint32_t sel_start; - uint32_t sel_end; + + /**Color of the text*/ lv_color_t color; - lv_color_t sel_color; - lv_color_t sel_bg_color; + + /**Extra space between the lines*/ int32_t line_space; + + /**Extra space between the characters*/ int32_t letter_space; + + /**Offset the text with this value horizontally*/ int32_t ofs_x; + + /**Offset the text with this value vertically*/ int32_t ofs_y; + + /**Rotation of the letters in 0.1 degree unit*/ int32_t rotation; + + /**The first characters index for selection (not byte index). `LV_DRAW_LABEL_NO_TXT_SEL` for no selection*/ + uint32_t sel_start; + + /**The last characters's index for selection (not byte index). `LV_DRAW_LABEL_NO_TXT_SEL` for no selection*/ + uint32_t sel_end; + + /**Color of the selected characters*/ + lv_color_t sel_color; + + /**Background color of the selected characters*/ + lv_color_t sel_bg_color; + + /**The number of characters to render. 0: means render until reaching the `\0` termination.*/ + uint32_t text_length; + + /**Opacity of the text in 0...255 range. + * LV_OPA_TRANSP, LV_OPA_10, LV_OPA_20, .. LV_OPA_COVER can be used as well*/ lv_opa_t opa; - lv_base_dir_t bidi_dir; + + /**The alignment of the text `LV_TEXT_ALIGN_LEFT/RIGHT/CENTER`*/ lv_text_align_t align; - lv_text_flag_t flag; + + /**The base direction. Used when type setting Right-to-left (e.g. Arabic) texts*/ + lv_base_dir_t bidi_dir; + + /**Text decoration, e.g. underline*/ lv_text_decor_t decor : 3; - lv_blend_mode_t blend_mode : 3; - /** - * < 1: malloc buffer and copy `text` there. - * 0: `text` is const and it's pointer will be valid during rendering.*/ + + /**Some flags to control type setting*/ + lv_text_flag_t flag : 5; + + /**1: malloc a buffer and copy `text` there. + * 0: `text` will be valid during rendering.*/ uint8_t text_local : 1; - /** - * Indicate that the text is constant and its pointer can be safely saved e.g. in a cache. - */ + /**Indicate that the text is constant and its pointer can be safely saved e.g. in a cache.*/ uint8_t text_static : 1; - /** - * 1: already executed lv_bidi_process_paragraph. + /**1: already executed lv_bidi_process_paragraph. * 0: has not been executed lv_bidi_process_paragraph.*/ uint8_t has_bided : 1; + + /**Pointer to an externally stored struct where some data can be cached to speed up rendering*/ lv_draw_label_hint_t * hint; } lv_draw_label_dsc_t; diff --git a/src/draw/lv_draw_line.h b/src/draw/lv_draw_line.h index d47e883dd4..79cc4f954f 100644 --- a/src/draw/lv_draw_line.h +++ b/src/draw/lv_draw_line.h @@ -28,17 +28,36 @@ extern "C" { typedef struct { lv_draw_dsc_base_t base; + /**The first point of the line. If `LV_USE_FLOAT` is enabled float number can be also used*/ lv_point_precise_t p1; + + /**The second point of the line. If `LV_USE_FLOAT` is enabled float number can be also used*/ lv_point_precise_t p2; + + /**The color of the line*/ lv_color_t color; + + /**The width (thickness) of the line*/ int32_t width; + + /** The length of a dash (0: don't dash)*/ int32_t dash_width; + + /** The length of the gaps between dashes (0: don't dash)*/ int32_t dash_gap; + + /**Opacity of the line in 0...255 range. + * LV_OPA_TRANSP, LV_OPA_10, LV_OPA_20, .. LV_OPA_COVER can be used as well*/ lv_opa_t opa; - lv_blend_mode_t blend_mode : 3; + + /**Make the line start rounded*/ uint8_t round_start : 1; + + /**Make the line end rounded*/ uint8_t round_end : 1; - uint8_t raw_end : 1; /**< Do not bother with perpendicular line ending if it's not visible for any reason */ + + /**1: Do not bother with line ending (if it's not visible for any reason) */ + uint8_t raw_end : 1; } lv_draw_line_dsc_t; /********************** diff --git a/src/draw/lv_draw_mask_private.h b/src/draw/lv_draw_mask_private.h index 9863e365f6..c3b4e61bba 100644 --- a/src/draw/lv_draw_mask_private.h +++ b/src/draw/lv_draw_mask_private.h @@ -31,8 +31,15 @@ extern "C" { struct _lv_draw_mask_rect_dsc_t { lv_draw_dsc_base_t base; + /**The area t mask.*/ lv_area_t area; + + /**The radius of masking*/ int32_t radius; + + /**0: clear the content out of the `area`. + * 1: don't touch the area out of `area`*/ + uint32_t keep_outside : 1; }; diff --git a/src/draw/lv_draw_rect.c b/src/draw/lv_draw_rect.c index ae90da1cd5..dd47f13d5b 100644 --- a/src/draw/lv_draw_rect.c +++ b/src/draw/lv_draw_rect.c @@ -63,11 +63,29 @@ void lv_draw_fill_dsc_init(lv_draw_fill_dsc_t * dsc) dsc->base.dsc_size = sizeof(lv_draw_fill_dsc_t); } + + lv_draw_fill_dsc_t * lv_draw_task_get_fill_dsc(lv_draw_task_t * task) { return task->type == LV_DRAW_TASK_TYPE_FILL ? (lv_draw_fill_dsc_t *)task->draw_dsc : NULL; } +void lv_draw_fill(lv_layer_t * layer, const lv_draw_fill_dsc_t * dsc, const lv_area_t * coords) +{ + if(dsc->opa <= LV_OPA_MIN) return; + + LV_PROFILER_DRAW_BEGIN; + lv_draw_task_t * t = lv_draw_add_task(layer, coords); + + t->draw_dsc = lv_malloc(sizeof(*dsc)); + LV_ASSERT_MALLOC(t->draw_dsc); + lv_memcpy(t->draw_dsc, dsc, sizeof(*dsc)); + t->type = LV_DRAW_TASK_TYPE_FILL; + + lv_draw_finalize_task_creation(layer, t); + LV_PROFILER_DRAW_END; +} + void lv_draw_border_dsc_init(lv_draw_border_dsc_t * dsc) { lv_memzero(dsc, sizeof(*dsc)); @@ -81,6 +99,22 @@ lv_draw_border_dsc_t * lv_draw_task_get_border_dsc(lv_draw_task_t * task) return task->type == LV_DRAW_TASK_TYPE_BORDER ? (lv_draw_border_dsc_t *)task->draw_dsc : NULL; } +void lv_draw_border(lv_layer_t * layer, const lv_draw_border_dsc_t * dsc, const lv_area_t * coords) +{ + if(dsc->opa <= LV_OPA_MIN) return; + + LV_PROFILER_DRAW_BEGIN; + lv_draw_task_t * t = lv_draw_add_task(layer, coords); + + t->draw_dsc = lv_malloc(sizeof(*dsc)); + LV_ASSERT_MALLOC(t->draw_dsc); + lv_memcpy(t->draw_dsc, dsc, sizeof(*dsc)); + t->type = LV_DRAW_TASK_TYPE_BORDER; + + lv_draw_finalize_task_creation(layer, t); + LV_PROFILER_DRAW_END; +} + void lv_draw_box_shadow_dsc_init(lv_draw_box_shadow_dsc_t * dsc) { lv_memzero(dsc, sizeof(*dsc)); @@ -93,6 +127,22 @@ lv_draw_box_shadow_dsc_t * lv_draw_task_get_box_shadow_dsc(lv_draw_task_t * task return task->type == LV_DRAW_TASK_TYPE_BOX_SHADOW ? (lv_draw_box_shadow_dsc_t *)task->draw_dsc : NULL; } +void lv_draw_box_shadow(lv_layer_t * layer, const lv_draw_box_shadow_dsc_t * dsc, const lv_area_t * coords) +{ + if(dsc->opa <= LV_OPA_MIN) return; + + LV_PROFILER_DRAW_BEGIN; + lv_draw_task_t * t = lv_draw_add_task(layer, coords); + + t->draw_dsc = lv_malloc(sizeof(*dsc)); + LV_ASSERT_MALLOC(t->draw_dsc); + lv_memcpy(t->draw_dsc, dsc, sizeof(*dsc)); + t->type = LV_DRAW_TASK_TYPE_BOX_SHADOW; + + lv_draw_finalize_task_creation(layer, t); + LV_PROFILER_DRAW_END; +} + void lv_draw_rect(lv_layer_t * layer, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords) { diff --git a/src/draw/lv_draw_rect.h b/src/draw/lv_draw_rect.h index a6b61300c9..85ec3af171 100644 --- a/src/draw/lv_draw_rect.h +++ b/src/draw/lv_draw_rect.h @@ -71,21 +71,41 @@ typedef struct { typedef struct { lv_draw_dsc_base_t base; + /**Radius, LV_RADIUS_CIRCLE for max. radius */ int32_t radius; + /**Opacity in 0...255 range. + * LV_OPA_TRANSP, LV_OPA_10, LV_OPA_20, .. LV_OPA_COVER can be used as well*/ lv_opa_t opa; + + /**The color of the rectangle. + * If the gradient is set (grad.dir!=LV_GRAD_DIR_NONE) it's ignored. */ lv_color_t color; + + /**Describe a gradient. If `grad.dir` is not `LV_GRAD_DIR_NONE` `color` will be ignored*/ lv_grad_dsc_t grad; } lv_draw_fill_dsc_t; typedef struct { lv_draw_dsc_base_t base; + /**Radius, LV_RADIUS_CIRCLE for max. radius */ int32_t radius; + /**The color of the border. */ lv_color_t color; + + + /**The width of the border in pixels */ int32_t width; + + /**Opacity in 0...255 range. + * LV_OPA_TRANSP, LV_OPA_10, LV_OPA_20, .. LV_OPA_COVER can be used as well*/ lv_opa_t opa; + + /**LV_BORDER_SIDE_NONE/LEFT/RIGHT/TOP/BOTTOM/FULL. + * LV_BORDER_SIDE_INTERNAL is an information for upper layers + * and shouldn't be used here. */ lv_border_side_t side : 5; } lv_draw_border_dsc_t; @@ -93,14 +113,30 @@ typedef struct { typedef struct { lv_draw_dsc_base_t base; + /**Radius, LV_RADIUS_CIRCLE for max. radius */ int32_t radius; + /**Color of the the shadow */ lv_color_t color; + + /**Width of the shadow. (radius of the blur)*/ int32_t width; + + /**Make the rectangle larger with this value in all directions. Can be negative too. */ int32_t spread; + + /**Offset the rectangle horizontally.*/ int32_t ofs_x; + + /**Offset the rectangle vertically.*/ int32_t ofs_y; + + /**Opacity in 0...255 range. + * LV_OPA_TRANSP, LV_OPA_10, LV_OPA_20, .. LV_OPA_COVER can be used as well*/ lv_opa_t opa; + + /**Set `bg_cover` to 1 if the background will cover the shadow. + * It's a hint to the renderer about it might skip some masking.*/ uint8_t bg_cover : 1; } lv_draw_box_shadow_dsc_t; @@ -127,6 +163,14 @@ void lv_draw_fill_dsc_init(lv_draw_fill_dsc_t * dsc); */ lv_draw_fill_dsc_t * lv_draw_task_get_fill_dsc(lv_draw_task_t * task); +/** + * Fill an area + * @param layer pointer to a layer + * @param dsc pointer to an initialized draw descriptor variable + * @param coords the coordinates of the rectangle + */ +void lv_draw_fill(lv_layer_t * layer, const lv_draw_fill_dsc_t * dsc, const lv_area_t * coords); + /** * Initialize a border draw descriptor. * @param dsc pointer to a draw descriptor @@ -140,6 +184,14 @@ void lv_draw_border_dsc_init(lv_draw_border_dsc_t * dsc); */ lv_draw_border_dsc_t * lv_draw_task_get_border_dsc(lv_draw_task_t * task); +/** + * Draw a border + * @param layer pointer to a layer + * @param dsc pointer to an initialized draw descriptor variable + * @param coords the coordinates of the rectangle + */ +void lv_draw_border(lv_layer_t * layer, const lv_draw_border_dsc_t * dsc, const lv_area_t * coords); + /** * Initialize a box shadow draw descriptor. * @param dsc pointer to a draw descriptor @@ -153,6 +205,14 @@ void lv_draw_box_shadow_dsc_init(lv_draw_box_shadow_dsc_t * dsc); */ lv_draw_box_shadow_dsc_t * lv_draw_task_get_box_shadow_dsc(lv_draw_task_t * task); +/** + * Draw a box shadow + * @param layer pointer to a layer + * @param dsc pointer to an initialized draw descriptor variable + * @param coords the coordinates of the rectangle + */ +void lv_draw_box_shadow(lv_layer_t * layer, const lv_draw_box_shadow_dsc_t * dsc, const lv_area_t * coords); + /** * The rectangle is a wrapper for fill, border, bg. image and box shadow. * Internally fill, border, image and box shadow draw tasks will be created. diff --git a/src/draw/lv_draw_triangle.c b/src/draw/lv_draw_triangle.c index 37aa00a9ea..0885d60fc3 100644 --- a/src/draw/lv_draw_triangle.c +++ b/src/draw/lv_draw_triangle.c @@ -42,12 +42,12 @@ void lv_draw_triangle_dsc_init(lv_draw_triangle_dsc_t * dsc) { LV_PROFILER_DRAW_BEGIN; lv_memzero(dsc, sizeof(lv_draw_triangle_dsc_t)); - dsc->bg_color = lv_color_white(); - dsc->bg_grad.stops[0].color = lv_color_white(); - dsc->bg_grad.stops[1].color = lv_color_black(); - dsc->bg_grad.stops[1].frac = 0xFF; - dsc->bg_grad.stops_count = 2; - dsc->bg_opa = LV_OPA_COVER; + dsc->color = lv_color_white(); + dsc->grad.stops[0].color = lv_color_white(); + dsc->grad.stops[1].color = lv_color_black(); + dsc->grad.stops[1].frac = 0xFF; + dsc->grad.stops_count = 2; + dsc->opa = LV_OPA_COVER; dsc->base.dsc_size = sizeof(lv_draw_triangle_dsc_t); LV_PROFILER_DRAW_END; } @@ -59,7 +59,7 @@ lv_draw_triangle_dsc_t * lv_draw_task_get_triangle_dsc(lv_draw_task_t * task) void lv_draw_triangle(lv_layer_t * layer, const lv_draw_triangle_dsc_t * dsc) { - if(dsc->bg_opa <= LV_OPA_MIN) return; + if(dsc->opa <= LV_OPA_MIN) return; LV_PROFILER_DRAW_BEGIN; diff --git a/src/draw/lv_draw_triangle.h b/src/draw/lv_draw_triangle.h index b1ad8e58b9..db53d4795e 100644 --- a/src/draw/lv_draw_triangle.h +++ b/src/draw/lv_draw_triangle.h @@ -25,11 +25,19 @@ extern "C" { typedef struct { lv_draw_dsc_base_t base; - lv_opa_t bg_opa; - lv_color_t bg_color; - lv_grad_dsc_t bg_grad; - + /**Points of the triangle. If `LV_USE_FLOAT` is enabled floats can be used here*/ lv_point_precise_t p[3]; + + /**Color of the triangle*/ + lv_color_t color; + + /**Opacity of the arc in 0...255 range. + * LV_OPA_TRANSP, LV_OPA_10, LV_OPA_20, .. LV_OPA_COVER can be used as well*/ + lv_opa_t opa; + + /**Describe a gradient. If `grad.dir` is not `LV_GRAD_DIR_NONE` `color` will be ignored*/ + lv_grad_dsc_t grad; + } lv_draw_triangle_dsc_t; /********************** diff --git a/src/draw/sw/lv_draw_sw_mask_rect.c b/src/draw/sw/lv_draw_sw_mask_rect.c index 46e43a623a..221cc647f3 100644 --- a/src/draw/sw/lv_draw_sw_mask_rect.c +++ b/src/draw/sw/lv_draw_sw_mask_rect.c @@ -56,27 +56,29 @@ void lv_draw_sw_mask_rect(lv_draw_task_t * t, const lv_draw_mask_rect_dsc_t * ds void * draw_buf = target_layer->draw_buf; - /*Clear the top part*/ - lv_area_set(&clear_area, t->clip_area.x1, t->clip_area.y1, t->clip_area.x2, - dsc->area.y1 - 1); - lv_area_move(&clear_area, -buf_area->x1, -buf_area->y1); - lv_draw_buf_clear(draw_buf, &clear_area); + if(dsc->keep_outside == 0) { + /*Clear the top part*/ + lv_area_set(&clear_area, t->clip_area.x1, t->clip_area.y1, t->clip_area.x2, + dsc->area.y1 - 1); + lv_area_move(&clear_area, -buf_area->x1, -buf_area->y1); + lv_draw_buf_clear(draw_buf, &clear_area); - /*Clear the bottom part*/ - lv_area_set(&clear_area, t->clip_area.x1, dsc->area.y2 + 1, t->clip_area.x2, - t->clip_area.y2); - lv_area_move(&clear_area, -buf_area->x1, -buf_area->y1); - lv_draw_buf_clear(draw_buf, &clear_area); + /*Clear the bottom part*/ + lv_area_set(&clear_area, t->clip_area.x1, dsc->area.y2 + 1, t->clip_area.x2, + t->clip_area.y2); + lv_area_move(&clear_area, -buf_area->x1, -buf_area->y1); + lv_draw_buf_clear(draw_buf, &clear_area); - /*Clear the left part*/ - lv_area_set(&clear_area, t->clip_area.x1, dsc->area.y1, dsc->area.x1 - 1, dsc->area.y2); - lv_area_move(&clear_area, -buf_area->x1, -buf_area->y1); - lv_draw_buf_clear(draw_buf, &clear_area); + /*Clear the left part*/ + lv_area_set(&clear_area, t->clip_area.x1, dsc->area.y1, dsc->area.x1 - 1, dsc->area.y2); + lv_area_move(&clear_area, -buf_area->x1, -buf_area->y1); + lv_draw_buf_clear(draw_buf, &clear_area); - /*Clear the right part*/ - lv_area_set(&clear_area, dsc->area.x2 + 1, dsc->area.y1, t->clip_area.x2, dsc->area.y2); - lv_area_move(&clear_area, -buf_area->x1, -buf_area->y1); - lv_draw_buf_clear(draw_buf, &clear_area); + /*Clear the right part*/ + lv_area_set(&clear_area, dsc->area.x2 + 1, dsc->area.y1, t->clip_area.x2, dsc->area.y2); + lv_area_move(&clear_area, -buf_area->x1, -buf_area->y1); + lv_draw_buf_clear(draw_buf, &clear_area); + } lv_draw_sw_mask_radius_param_t param; lv_draw_sw_mask_radius_init(¶m, &dsc->area, dsc->radius, false); diff --git a/src/draw/sw/lv_draw_sw_triangle.c b/src/draw/sw/lv_draw_sw_triangle.c index f935e19c3a..2adb4cb5e5 100644 --- a/src/draw/sw/lv_draw_sw_triangle.c +++ b/src/draw/sw/lv_draw_sw_triangle.c @@ -126,17 +126,17 @@ void lv_draw_sw_triangle(lv_draw_task_t * t, const lv_draw_triangle_dsc_t * dsc) lv_area_t blend_area = draw_area; blend_area.y2 = blend_area.y1; lv_draw_sw_blend_dsc_t blend_dsc; - blend_dsc.color = dsc->bg_color; - blend_dsc.opa = dsc->bg_opa; + blend_dsc.color = dsc->color; + blend_dsc.opa = dsc->opa; blend_dsc.mask_buf = mask_buf; blend_dsc.blend_area = &blend_area; blend_dsc.mask_area = &blend_area; blend_dsc.blend_mode = LV_BLEND_MODE_NORMAL; blend_dsc.src_buf = NULL; - lv_grad_dir_t grad_dir = dsc->bg_grad.dir; + lv_grad_dir_t grad_dir = dsc->grad.dir; - lv_draw_sw_grad_calc_t * grad = lv_draw_sw_grad_get(&dsc->bg_grad, lv_area_get_width(&tri_area), + lv_draw_sw_grad_calc_t * grad = lv_draw_sw_grad_get(&dsc->grad, lv_area_get_width(&tri_area), lv_area_get_height(&tri_area)); lv_opa_t * grad_opa_map = NULL; if(grad && grad_dir == LV_GRAD_DIR_HOR) { @@ -156,7 +156,7 @@ void lv_draw_sw_triangle(lv_draw_task_t * t, const lv_draw_triangle_dsc_t * dsc) LV_ASSERT_NULL(grad); blend_dsc.color = grad->color_map[y - tri_area.y1]; blend_dsc.opa = grad->opa_map[y - tri_area.y1]; - if(dsc->bg_opa < LV_OPA_MAX) blend_dsc.opa = LV_OPA_MIX2(blend_dsc.opa, dsc->bg_opa); + if(dsc->opa < LV_OPA_MAX) blend_dsc.opa = LV_OPA_MIX2(blend_dsc.opa, dsc->opa); } else if(grad_dir == LV_GRAD_DIR_HOR) { if(grad_opa_map) { diff --git a/src/draw/vg_lite/lv_draw_vg_lite_img.c b/src/draw/vg_lite/lv_draw_vg_lite_img.c index efed4e7931..26b4a282ad 100644 --- a/src/draw/vg_lite/lv_draw_vg_lite_img.c +++ b/src/draw/vg_lite/lv_draw_vg_lite_img.c @@ -131,7 +131,7 @@ void lv_draw_vg_lite_img(lv_draw_task_t * t, const lv_draw_image_dsc_t * dsc, lv_vg_lite_path_append_rect( path, 0, 0, - lv_area_get_width(coords), lv_area_get_height(coords), + lv_area_get_width(&dsc->image_area), lv_area_get_height(&dsc->image_area), dsc->clip_radius); lv_vg_lite_path_set_transform(path, NULL); } diff --git a/src/draw/vg_lite/lv_draw_vg_lite_triangle.c b/src/draw/vg_lite/lv_draw_vg_lite_triangle.c index 4683d6be65..01bb909de1 100644 --- a/src/draw/vg_lite/lv_draw_vg_lite_triangle.c +++ b/src/draw/vg_lite/lv_draw_vg_lite_triangle.c @@ -67,14 +67,14 @@ void lv_draw_vg_lite_triangle(lv_draw_task_t * t, const lv_draw_triangle_dsc_t * vg_lite_matrix_t matrix = u->global_matrix; - if(dsc->bg_grad.dir != LV_GRAD_DIR_NONE) { + if(dsc->grad.dir != LV_GRAD_DIR_NONE) { #if LV_USE_VECTOR_GRAPHIC lv_vg_lite_draw_grad_helper( u, &u->target_buffer, lv_vg_lite_path_get_path(path), &tri_area, - &dsc->bg_grad, + &dsc->grad, &matrix, VG_LITE_FILL_EVEN_ODD, VG_LITE_BLEND_SRC_OVER); @@ -89,7 +89,7 @@ void lv_draw_vg_lite_triangle(lv_draw_task_t * t, const lv_draw_triangle_dsc_t * VG_LITE_FILL_EVEN_ODD, &matrix, VG_LITE_BLEND_SRC_OVER, - lv_vg_lite_color(dsc->bg_color, dsc->bg_opa, true)); + lv_vg_lite_color(dsc->color, dsc->opa, true)); } lv_vg_lite_path_drop(u, path); diff --git a/src/misc/lv_event.h b/src/misc/lv_event.h index 11c6aecc85..ca52d18e45 100644 --- a/src/misc/lv_event.h +++ b/src/misc/lv_event.h @@ -70,7 +70,7 @@ typedef enum { LV_EVENT_DRAW_POST_BEGIN, /**< Starting the post draw phase (when all children are drawn)*/ LV_EVENT_DRAW_POST, /**< Perform the post draw phase (when all children are drawn)*/ LV_EVENT_DRAW_POST_END, /**< Finishing the post draw phase (when all children are drawn)*/ - LV_EVENT_DRAW_TASK_ADDED, /**< Adding a draw task */ + LV_EVENT_DRAW_TASK_ADDED, /**< Adding a draw task. The `LV_OBJ_FLAG_SEND_DRAW_TASK_EVENTS` flag needs to be set */ /** Special events */ LV_EVENT_VALUE_CHANGED, /**< Widget's value has changed (i.e. slider moved)*/ diff --git a/src/widgets/span/lv_span.c b/src/widgets/span/lv_span.c index 6e0b968f91..043aa96415 100644 --- a/src/widgets/span/lv_span.c +++ b/src/widgets/span/lv_span.c @@ -55,7 +55,6 @@ static const lv_font_t * lv_span_get_style_text_font(lv_obj_t * par, lv_span_t * static int32_t lv_span_get_style_text_letter_space(lv_obj_t * par, lv_span_t * span); static lv_color_t lv_span_get_style_text_color(lv_obj_t * par, lv_span_t * span); static lv_opa_t lv_span_get_style_text_opa(lv_obj_t * par, lv_span_t * span); -static lv_blend_mode_t lv_span_get_style_text_blend_mode(lv_obj_t * par, lv_span_t * span); static int32_t lv_span_get_style_text_decor(lv_obj_t * par, lv_span_t * span); static inline void span_text_check(const char ** text); @@ -880,20 +879,6 @@ static lv_opa_t lv_span_get_style_text_opa(lv_obj_t * par, lv_span_t * span) return opa; } -static lv_blend_mode_t lv_span_get_style_text_blend_mode(lv_obj_t * par, lv_span_t * span) -{ - lv_blend_mode_t mode; - lv_style_value_t value; - lv_style_res_t res = lv_style_get_prop(&span->style, LV_STYLE_BLEND_MODE, &value); - if(res != LV_STYLE_RES_FOUND) { - mode = (lv_blend_mode_t)lv_obj_get_style_blend_mode(par, LV_PART_MAIN); - } - else { - mode = (lv_blend_mode_t)value.num; - } - return mode; -} - static int32_t lv_span_get_style_text_decor(lv_obj_t * par, lv_span_t * span) { int32_t decor; @@ -1183,7 +1168,6 @@ static void lv_draw_span(lv_obj_t * obj, lv_layer_t * layer) label_draw_dsc.color = lv_span_get_style_text_color(obj, pinfo->span); label_draw_dsc.opa = lv_span_get_style_text_opa(obj, pinfo->span); label_draw_dsc.font = lv_span_get_style_text_font(obj, pinfo->span); - label_draw_dsc.blend_mode = lv_span_get_style_text_blend_mode(obj, pinfo->span); if(obj_opa < LV_OPA_MAX) { label_draw_dsc.opa = LV_OPA_MIX2(label_draw_dsc.opa, obj_opa); } diff --git a/tests/ref_imgs_vg_lite/draw/bg_image_1.png b/tests/ref_imgs_vg_lite/draw/bg_image_1.png index d2d980b1d5..edf6a8b333 100644 Binary files a/tests/ref_imgs_vg_lite/draw/bg_image_1.png and b/tests/ref_imgs_vg_lite/draw/bg_image_1.png differ diff --git a/tests/ref_imgs_vg_lite/draw/clip_corner_1.png b/tests/ref_imgs_vg_lite/draw/clip_corner_1.png index d9f73fa7ab..fd09fabeff 100644 Binary files a/tests/ref_imgs_vg_lite/draw/clip_corner_1.png and b/tests/ref_imgs_vg_lite/draw/clip_corner_1.png differ diff --git a/tests/ref_imgs_vg_lite/snapshot_2.png b/tests/ref_imgs_vg_lite/snapshot_2.png index 8ea559bd3f..06ef9a7468 100644 Binary files a/tests/ref_imgs_vg_lite/snapshot_2.png and b/tests/ref_imgs_vg_lite/snapshot_2.png differ diff --git a/tests/ref_imgs_vg_lite/widgets/obj_flag_overflow_visible_1_4.png b/tests/ref_imgs_vg_lite/widgets/obj_flag_overflow_visible_1_4.png index 5b1d60bb0e..df63a77669 100644 Binary files a/tests/ref_imgs_vg_lite/widgets/obj_flag_overflow_visible_1_4.png and b/tests/ref_imgs_vg_lite/widgets/obj_flag_overflow_visible_1_4.png differ