2021-04-08 13:07:48 +02:00
|
|
|
#include "../../lv_examples.h"
|
2023-07-15 20:59:41 +02:00
|
|
|
#if LV_USE_CANVAS && LV_BUILD_EXAMPLES
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2023-07-15 20:59:41 +02:00
|
|
|
#define CANVAS_WIDTH 80
|
|
|
|
#define CANVAS_HEIGHT 40
|
2021-02-08 09:53:03 +01:00
|
|
|
|
|
|
|
/**
|
2023-07-15 20:59:41 +02:00
|
|
|
* Create a transparent canvas with transparency
|
2021-02-08 09:53:03 +01:00
|
|
|
*/
|
|
|
|
void lv_example_canvas_2(void)
|
|
|
|
{
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_set_style_bg_color(lv_screen_active(), lv_palette_lighten(LV_PALETTE_RED, 5), 0);
|
2021-02-08 09:53:03 +01:00
|
|
|
|
|
|
|
/*Create a buffer for the canvas*/
|
2023-07-15 20:59:41 +02:00
|
|
|
static uint8_t cbuf[CANVAS_WIDTH * CANVAS_HEIGHT * 4];
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-08-27 12:15:39 +02:00
|
|
|
/*Create a canvas and initialize its palette*/
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_t * canvas = lv_canvas_create(lv_screen_active());
|
2023-07-15 20:59:41 +02:00
|
|
|
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888);
|
|
|
|
lv_obj_center(canvas);
|
2021-02-08 09:53:03 +01:00
|
|
|
|
|
|
|
/*Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored)*/
|
2023-07-15 20:59:41 +02:00
|
|
|
lv_canvas_fill_bg(canvas, lv_palette_main(LV_PALETTE_BLUE), LV_OPA_COVER);
|
2021-02-08 09:53:03 +01:00
|
|
|
|
|
|
|
/*Create hole on the canvas*/
|
|
|
|
uint32_t x;
|
|
|
|
uint32_t y;
|
2023-07-15 20:59:41 +02:00
|
|
|
for(y = 10; y < 20; y++) {
|
|
|
|
for(x = 5; x < 75; x++) {
|
|
|
|
lv_canvas_set_px(canvas, x, y, lv_palette_main(LV_PALETTE_BLUE), LV_OPA_50);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(y = 20; y < 30; y++) {
|
|
|
|
for(x = 5; x < 75; x++) {
|
|
|
|
lv_canvas_set_px(canvas, x, y, lv_palette_main(LV_PALETTE_BLUE), LV_OPA_20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(y = 30; y < 40; y++) {
|
|
|
|
for(x = 5; x < 75; x++) {
|
|
|
|
lv_canvas_set_px(canvas, x, y, lv_palette_main(LV_PALETTE_BLUE), LV_OPA_0);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|