exmample(label): fix gradient label

This commit is contained in:
Gabor Kiss-Vamosi
2023-03-08 11:26:22 +01:00
parent 73b446015a
commit 8b39ec0ed5

View File

@@ -32,11 +32,11 @@ static void add_mask_event_cb(lv_event_t * e)
void lv_example_label_4(void) void lv_example_label_4(void)
{ {
/* Create the mask of a text by drawing it to a canvas*/ /* Create the mask of a text by drawing it to a canvas*/
static lv_opa_t mask_map[MASK_WIDTH * MASK_HEIGHT]; static lv_color_t mask_map[MASK_WIDTH * MASK_HEIGHT];
/*Create a "8 bit alpha" canvas and clear it*/ /*Create a "8 bit alpha" canvas and clear it*/
lv_obj_t * canvas = lv_canvas_create(lv_scr_act()); lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
lv_canvas_set_buffer(canvas, mask_map, MASK_WIDTH, MASK_HEIGHT, LV_COLOR_FORMAT_L8); lv_canvas_set_buffer(canvas, mask_map, MASK_WIDTH, MASK_HEIGHT, LV_COLOR_FORMAT_NATIVE);
lv_canvas_fill_bg(canvas, lv_color_black(), LV_OPA_TRANSP); lv_canvas_fill_bg(canvas, lv_color_black(), LV_OPA_TRANSP);
/*Draw a label to the canvas. The result "image" will be used as mask*/ /*Draw a label to the canvas. The result "image" will be used as mask*/
@@ -49,6 +49,14 @@ void lv_example_label_4(void)
/*The mask is reads the canvas is not required anymore*/ /*The mask is reads the canvas is not required anymore*/
lv_obj_del(canvas); lv_obj_del(canvas);
/*Convert the mask to A8*/
uint32_t i;
uint8_t * mask8 = (uint8_t *) mask_map;
lv_color_t * mask_c = mask_map;
for(i = 0; i < MASK_WIDTH * MASK_HEIGHT; i++) {
mask8[i] = lv_color_brightness(mask_c[i]);
}
/* Create an object from where the text will be masked out. /* Create an object from where the text will be masked out.
* Now it's a rectangle with a gradient but it could be an image too*/ * Now it's a rectangle with a gradient but it could be an image too*/
lv_obj_t * grad = lv_obj_create(lv_scr_act()); lv_obj_t * grad = lv_obj_create(lv_scr_act());