Important: unclear posts may not receive useful answers.
Before posting
- Get familiar with Markdown to format and structure your post
- Be sure to update lvgl from the latest version from the
master
branch.- Be sure you have checked the FAQ and read the relevant part of the documentation.
- If applicable use the Simulator to eliminate hardware related issues.
Delete this section if you read and applied the mentioned points.
Description
What MCU/Processor/Board and compiler are you using?
Simulator
What LVGL version are you using?
What do you want to achieve?
I’m tryng to create some rectanglular outlines (with shifted perspective) that fill with color to indicate things. I have the shapes working but not sure how to update the canvas after an event.
The plan is to fill these outlines with canvas polygons but I can’t get these to draw based on an event and also not sure how to remove them just leaving the outlines aswell.
I also can’t work out how to get click events via mouse detected using a simulator, using WSL2 on windows 11
What have you tried so far?
Code to reproduce
Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.
lv_obj_t * layer_shape(lv_obj_t * parent){
lv_draw_rect_dsc_t rect_dsc;
lv_draw_rect_dsc_init(&rect_dsc);
rect_dsc.bg_opa = LV_OPA_60;
rect_dsc.bg_color = lv_color_black();//lv_palette_lighten(LV_PALETTE_RED, 4);
rect_dsc.blend_mode = LV_BLEND_MODE_ADDITIVE;
lv_draw_line_dsc_t draw_dsc_main, draw_dsc_outer, draw_dsc_inner;
lv_draw_line_dsc_init(&draw_dsc_main);
lv_draw_line_dsc_init(&draw_dsc_outer);
lv_draw_line_dsc_init(&draw_dsc_inner);
set_main_draw_line_style(&draw_dsc_main);
set_offset_draw_line_style(&draw_dsc_outer);
set_offset_draw_line_style(&draw_dsc_inner);
static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, LAYER_SHAPE_HEIGHT + 5)];
lv_obj_t * canvas = lv_canvas_create(parent);
lv_obj_add_flag(canvas, LV_OBJ_FLAG_CLICKABLE);
//lv_obj_set_click(canvas, true);
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH ,LAYER_SHAPE_HEIGHT + 5, LV_IMG_CF_TRUE_COLOR_ALPHA);
lv_canvas_fill_bg(canvas, lv_palette_darken(LV_PALETTE_GREY, 1), LV_OPA_TRANSP);
//lv_obj_add_style(canvas, &main_draw_line_style, 0);
//lv_obj_align(canvas, LV_ALIGN_RIGHT_MID,0 ,0);
// lv_canvas_draw_rect(canvas, 10, 10, 20, 20, &rect_dsc);
lv_point_t left = {5, (LAYER_SHAPE_HEIGHT / 2)+ 2.5};
lv_point_t top = {(LAYER_SHAPE_WIDTH / 2 ) + 5,2.5};
lv_point_t right = {LAYER_SHAPE_WIDTH + 5,(LAYER_SHAPE_HEIGHT / 2)+ 2.5};
lv_point_t bottom = {(LAYER_SHAPE_WIDTH / 2 ) + 5,LAYER_SHAPE_HEIGHT + 2.5};
const lv_point_t points[4] = {left, top, right,
bottom};
lv_canvas_draw_polygon(canvas, points, 4,&rect_dsc);
const lv_point_t main_line_points[5] = {left,top,right,bottom,left};
const lv_point_t outer_line_points[5] = {{left.x - LINE_OFFSET, left.y }, translate_point(top, 0, -LINE_OFFSET),translate_point(right,LINE_OFFSET, 0),
translate_point(bottom,0,LINE_OFFSET) , {left.x - LINE_OFFSET, left.y }};
const lv_point_t inner_line_points[5] = {translate_point(left,LINE_OFFSET,0), translate_point(top, 0, LINE_OFFSET),translate_point(right,-LINE_OFFSET, 0),
translate_point(bottom,0,-LINE_OFFSET) , translate_point(left,LINE_OFFSET,0)};
lv_canvas_draw_line(canvas, outer_line_points,5, &draw_dsc_outer);
lv_canvas_draw_line(canvas, inner_line_points,5, &draw_dsc_inner);
lv_canvas_draw_line(canvas, main_line_points, 5, &draw_dsc_main);
lv_area_t blur_area = {
4, 1, LAYER_SHAPE_WIDTH + 6, LAYER_SHAPE_HEIGHT + 4
};
lv_canvas_blur_hor(canvas, &blur_area, 1.5);
lv_canvas_blur_ver(canvas, &blur_area, 1.5)
lv_obj_add_flag(canvas, LV_OBJ_FLAG_EVENT_BUBBLE);
return canvas;
}
lv_obj_t * layer_indicators(lv_obj_t * parent){
static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
lv_obj_t * canvas = lv_canvas_create(parent);
lv_obj_add_flag(canvas, LV_OBJ_FLAG_CLICKABLE);
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH ,CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED);
lv_canvas_fill_bg(canvas, lv_color_black(), LV_OPA_100);
lv_obj_align(canvas, LV_ALIGN_TOP_LEFT,4 ,4);
lv_img_dsc_t * img ;
img = lv_canvas_get_img(layer_shape(canvas));
for(int i = 0;i < 5; i++){
lv_canvas_transform(canvas, img,0,256, 0,(4 * 10) - ( i * 10),0 ,0, false);
}
static lv_color_t cbuf_tmp[CANVAS_WIDTH * CANVAS_HEIGHT];
memcpy(cbuf_tmp, cbuf, sizeof(cbuf_tmp));
img->data = (void *)cbuf_tmp;
lv_obj_add_event_cb(canvas, layer_change_cb,LV_EVENT_PRESSED, NULL );
lv_obj_add_event_cb(canvas, layer_change_cb,LV_EVENT_CLICKED, NULL );
return canvas;
}