Hello guys, I am getting better at lvgl, but still some challenges come around, now I cannot get to really understand the palette of the canvas.
I am initially loading an image to the screen which is being loaded correctly with this code:
void drawButtonnsLV(){
lv_obj_t * img1 = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img1, &btns_menuv2);
lv_obj_align(img1, NULL, LV_ALIGN_CENTER, 0, 0);
}
Then, I am trying to place a canvas on top to draw on it and be displayed like part the of the first image I loaded, however this code, creates a red canvas with a hole, but I cannot get to really be transparent and only the “hole” be in the color of my choice, I guess part of the fault is the palette but that’s the part I dont understand
void lv_ex_canvas_2(void)
{
/*Create a button to better see the transparency*/
//lv_btn_create(lv_scr_act(), NULL);
/*Create a buffer for the canvas*/
static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT)];
/*Create a canvas and initialize its the palette*/
lv_obj_t * canvas = lv_canvas_create(lv_scr_act(), NULL);
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_INDEXED_1BIT);
lv_canvas_set_palette(canvas, 0, LV_COLOR_TRANSP);
lv_canvas_set_palette(canvas, 1, LV_COLOR_RED);
/*Create colors with the indices of the palette*/
lv_color_t c0;
lv_color_t c1;
c0.full = 0;
c1.full = 1;
// /*Transparent background*/
lv_canvas_fill_bg(canvas, c1, LV_OPA_TRANSP);
// /*Create hole on the canvas*/
uint32_t x;
uint32_t y;
for( y = 10; y < 30; y++) {
for( x = 5; x < 20; x++) {
lv_canvas_set_px(canvas, x, y, c0);
}
}
}
My goal in hierarchy should be something like this:
±–background-image
±–transparent-canvas
±–draw rectangles