Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
47
sdk/lib/lvgl/examples/widgets/canvas/index.rst
Normal file
47
sdk/lib/lvgl/examples/widgets/canvas/index.rst
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
Drawing on the Canvas and rotate
|
||||
""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_1
|
||||
:language: c
|
||||
|
||||
Transparent Canvas with chroma keying
|
||||
""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_2
|
||||
:language: c
|
||||
|
||||
|
||||
Draw a rectangle to the canvas
|
||||
""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_3
|
||||
:language: c
|
||||
|
||||
|
||||
Draw a label to the canvas
|
||||
""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_4
|
||||
:language: c
|
||||
|
||||
|
||||
Draw an arc to the canvas
|
||||
""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_5
|
||||
:language: c
|
||||
|
||||
|
||||
Draw an image to the canvas
|
||||
""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_6
|
||||
:language: c
|
||||
|
||||
|
||||
Draw a line to the canvas
|
||||
""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_7
|
||||
:language: c
|
||||
53
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_1.c
Normal file
53
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_1.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS && LV_BUILD_EXAMPLES
|
||||
|
||||
|
||||
#define CANVAS_WIDTH 200
|
||||
#define CANVAS_HEIGHT 150
|
||||
|
||||
void lv_example_canvas_1(void)
|
||||
{
|
||||
lv_draw_rect_dsc_t rect_dsc;
|
||||
lv_draw_rect_dsc_init(&rect_dsc);
|
||||
rect_dsc.radius = 10;
|
||||
rect_dsc.bg_opa = LV_OPA_COVER;
|
||||
rect_dsc.bg_grad.dir = LV_GRAD_DIR_HOR;
|
||||
rect_dsc.bg_grad.stops[0].color = lv_palette_main(LV_PALETTE_RED);
|
||||
rect_dsc.bg_grad.stops[1].color = lv_palette_main(LV_PALETTE_BLUE);
|
||||
rect_dsc.border_width = 2;
|
||||
rect_dsc.border_opa = LV_OPA_90;
|
||||
rect_dsc.border_color = lv_color_white();
|
||||
rect_dsc.shadow_width = 5;
|
||||
rect_dsc.shadow_ofs_x = 5;
|
||||
rect_dsc.shadow_ofs_y = 5;
|
||||
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
label_dsc.color = lv_palette_main(LV_PALETTE_ORANGE);
|
||||
|
||||
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_obj_center(canvas);
|
||||
lv_canvas_fill_bg(canvas, lv_palette_lighten(LV_PALETTE_GREY, 3), LV_OPA_COVER);
|
||||
|
||||
lv_canvas_draw_rect(canvas, 70, 60, 100, 70, &rect_dsc);
|
||||
|
||||
lv_canvas_draw_text(canvas, 40, 20, 100, &label_dsc, "Some text on text canvas");
|
||||
|
||||
/*Test the rotation. It requires another buffer where the original image is stored.
|
||||
*So copy the current image to buffer and rotate it to the canvas*/
|
||||
static uint8_t cbuf_tmp[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
memcpy(cbuf_tmp, cbuf, sizeof(cbuf_tmp));
|
||||
lv_img_dsc_t img;
|
||||
img.data = (void *)cbuf_tmp;
|
||||
img.header.cf = LV_IMG_CF_TRUE_COLOR;
|
||||
img.header.w = CANVAS_WIDTH;
|
||||
img.header.h = CANVAS_HEIGHT;
|
||||
|
||||
lv_canvas_fill_bg(canvas, lv_palette_lighten(LV_PALETTE_GREY, 3), LV_OPA_COVER);
|
||||
lv_canvas_transform(canvas, &img, 120, LV_IMG_ZOOM_NONE, 0, 0, CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2, true);
|
||||
}
|
||||
|
||||
#endif
|
||||
43
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_1.py
Normal file
43
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_1.py
Normal file
@@ -0,0 +1,43 @@
|
||||
_CANVAS_WIDTH = 200
|
||||
_CANVAS_HEIGHT = 150
|
||||
LV_IMG_ZOOM_NONE = 256
|
||||
|
||||
rect_dsc = lv.draw_rect_dsc_t()
|
||||
rect_dsc.init()
|
||||
rect_dsc.radius = 10
|
||||
rect_dsc.bg_opa = lv.OPA.COVER
|
||||
rect_dsc.bg_grad.dir = lv.GRAD_DIR.HOR
|
||||
rect_dsc.bg_grad.stops[0].color = lv.palette_main(lv.PALETTE.RED)
|
||||
rect_dsc.bg_grad.stops[1].color = lv.palette_main(lv.PALETTE.BLUE)
|
||||
rect_dsc.border_width = 2
|
||||
rect_dsc.border_opa = lv.OPA._90
|
||||
rect_dsc.border_color = lv.color_white()
|
||||
rect_dsc.shadow_width = 5
|
||||
rect_dsc.shadow_ofs_x = 5
|
||||
rect_dsc.shadow_ofs_y = 5
|
||||
|
||||
label_dsc = lv.draw_label_dsc_t()
|
||||
label_dsc.init()
|
||||
label_dsc.color = lv.palette_main(lv.PALETTE.YELLOW)
|
||||
|
||||
cbuf = bytearray(_CANVAS_WIDTH * _CANVAS_HEIGHT * 4)
|
||||
|
||||
canvas = lv.canvas(lv.scr_act())
|
||||
canvas.set_buffer(cbuf, _CANVAS_WIDTH, _CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR)
|
||||
canvas.center()
|
||||
canvas.fill_bg(lv.palette_lighten(lv.PALETTE.GREY, 3), lv.OPA.COVER)
|
||||
|
||||
canvas.draw_rect(70, 60, 100, 70, rect_dsc)
|
||||
canvas.draw_text(40, 20, 100, label_dsc, "Some text on text canvas")
|
||||
|
||||
# Test the rotation. It requires another buffer where the original image is stored.
|
||||
# So copy the current image to buffer and rotate it to the canvas
|
||||
|
||||
img = lv.img_dsc_t()
|
||||
img.data = cbuf[:]
|
||||
img.header.cf = lv.img.CF.TRUE_COLOR
|
||||
img.header.w = _CANVAS_WIDTH
|
||||
img.header.h = _CANVAS_HEIGHT
|
||||
|
||||
canvas.fill_bg(lv.palette_lighten(lv.PALETTE.GREY, 3), lv.OPA.COVER)
|
||||
canvas.transform(img, 30, LV_IMG_ZOOM_NONE, 0, 0, _CANVAS_WIDTH // 2, _CANVAS_HEIGHT // 2, True)
|
||||
43
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_2.c
Normal file
43
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_2.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS && LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 50
|
||||
#define CANVAS_HEIGHT 50
|
||||
|
||||
/**
|
||||
* Create a transparent canvas with Chroma keying and indexed color format (palette).
|
||||
*/
|
||||
void lv_example_canvas_2(void)
|
||||
{
|
||||
/*Create a button to better see the transparency*/
|
||||
lv_btn_create(lv_scr_act());
|
||||
|
||||
/*Create a buffer for the canvas*/
|
||||
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
/*Create a canvas and initialize its palette*/
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_INDEXED_1BIT);
|
||||
lv_canvas_set_palette(canvas, 0, LV_COLOR_CHROMA_KEY);
|
||||
lv_canvas_set_palette(canvas, 1, lv_palette_main(LV_PALETTE_RED));
|
||||
|
||||
/*Create colors with the indices of the palette*/
|
||||
lv_color_t c0;
|
||||
lv_color_t c1;
|
||||
|
||||
c0.full = 0;
|
||||
c1.full = 1;
|
||||
|
||||
/*Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored)*/
|
||||
lv_canvas_fill_bg(canvas, c1, LV_OPA_COVER);
|
||||
|
||||
/*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_color(canvas, x, y, c0);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
45
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_2.py
Normal file
45
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_2.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import math
|
||||
|
||||
CANVAS_WIDTH = 50
|
||||
CANVAS_HEIGHT = 50
|
||||
LV_COLOR_CHROMA_KEY = lv.color_hex(0x00ff00)
|
||||
|
||||
def LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h):
|
||||
return int(math.floor((w + 7) / 8 ) * h)
|
||||
|
||||
def LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h):
|
||||
return LV_IMG_BUF_SIZE_ALPHA_1BIT(w, h) + 4 * 2
|
||||
|
||||
def LV_CANVAS_BUF_SIZE_INDEXED_1BIT(w, h):
|
||||
return LV_IMG_BUF_SIZE_INDEXED_1BIT(w, h)
|
||||
|
||||
#
|
||||
# Create a transparent canvas with Chroma keying and indexed color format (palette).
|
||||
#
|
||||
|
||||
# Create a button to better see the transparency
|
||||
btn=lv.btn(lv.scr_act())
|
||||
|
||||
# Create a buffer for the canvas
|
||||
cbuf= bytearray(LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT))
|
||||
|
||||
# Create a canvas and initialize its palette
|
||||
canvas = lv.canvas(lv.scr_act())
|
||||
canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.INDEXED_1BIT)
|
||||
canvas.set_palette(0, LV_COLOR_CHROMA_KEY)
|
||||
canvas.set_palette(1, lv.palette_main(lv.PALETTE.RED))
|
||||
|
||||
# Create colors with the indices of the palette
|
||||
c0 = lv.color_t()
|
||||
c1 = lv.color_t()
|
||||
|
||||
c0.full = 0
|
||||
c1.full = 1
|
||||
|
||||
# Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored)
|
||||
canvas.fill_bg(c1, lv.OPA.COVER)
|
||||
|
||||
# Create hole on the canvas
|
||||
for y in range(10,30):
|
||||
for x in range(5,20):
|
||||
canvas.set_px(x, y, c0)
|
||||
36
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_3.c
Normal file
36
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_3.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS && LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 50
|
||||
#define CANVAS_HEIGHT 50
|
||||
|
||||
/**
|
||||
* Draw a rectangle to the canvas
|
||||
*/
|
||||
void lv_example_canvas_3(void)
|
||||
{
|
||||
/*Create a buffer for the canvas*/
|
||||
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
/*Create a canvas and initialize its palette*/
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
|
||||
lv_obj_center(canvas);
|
||||
|
||||
lv_draw_rect_dsc_t dsc;
|
||||
lv_draw_rect_dsc_init(&dsc);
|
||||
dsc.bg_color = lv_palette_main(LV_PALETTE_RED);
|
||||
dsc.border_color = lv_palette_main(LV_PALETTE_BLUE);
|
||||
dsc.border_width = 3;
|
||||
dsc.outline_color = lv_palette_main(LV_PALETTE_GREEN);
|
||||
dsc.outline_width = 2;
|
||||
dsc.outline_pad = 2;
|
||||
dsc.outline_opa = LV_OPA_50;
|
||||
dsc.radius = 5;
|
||||
dsc.border_width = 3;
|
||||
lv_canvas_draw_rect(canvas, 10, 10, 30, 20, &dsc);
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
31
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_3.py
Normal file
31
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_3.py
Normal file
@@ -0,0 +1,31 @@
|
||||
CANVAS_WIDTH = 50
|
||||
CANVAS_HEIGHT = 50
|
||||
|
||||
LV_COLOR_SIZE = 32
|
||||
#
|
||||
# Draw a rectangle to the canvas
|
||||
#
|
||||
# Create a buffer for the canvas
|
||||
cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT)
|
||||
|
||||
# Create a canvas and initialize its palette*/
|
||||
canvas = lv.canvas(lv.scr_act())
|
||||
canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR)
|
||||
|
||||
canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER)
|
||||
canvas.center()
|
||||
|
||||
dsc = lv.draw_rect_dsc_t()
|
||||
dsc.init()
|
||||
|
||||
dsc.bg_color = lv.palette_main(lv.PALETTE.RED)
|
||||
dsc.border_color = lv.palette_main(lv.PALETTE.BLUE)
|
||||
dsc.border_width = 3
|
||||
dsc.outline_color = lv.palette_main(lv.PALETTE.GREEN)
|
||||
dsc.outline_width = 2
|
||||
dsc.outline_pad = 2
|
||||
dsc.outline_opa = lv.OPA._50
|
||||
dsc.radius = 5
|
||||
dsc.border_width = 3
|
||||
canvas.draw_rect(10, 10, 30, 20, dsc)
|
||||
|
||||
29
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_4.c
Normal file
29
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_4.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS && LV_FONT_MONTSERRAT_18 && LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 50
|
||||
#define CANVAS_HEIGHT 50
|
||||
|
||||
/**
|
||||
* Draw a text to the canvas
|
||||
*/
|
||||
void lv_example_canvas_4(void)
|
||||
{
|
||||
/*Create a buffer for the canvas*/
|
||||
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
/*Create a canvas and initialize its palette*/
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
|
||||
lv_obj_center(canvas);
|
||||
|
||||
lv_draw_label_dsc_t dsc;
|
||||
lv_draw_label_dsc_init(&dsc);
|
||||
dsc.color = lv_palette_main(LV_PALETTE_RED);
|
||||
dsc.font = &lv_font_montserrat_18;
|
||||
dsc.decor = LV_TEXT_DECOR_UNDERLINE;
|
||||
|
||||
lv_canvas_draw_text(canvas, 10, 10, 30, &dsc, "Hello");
|
||||
}
|
||||
#endif
|
||||
44
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_4.py
Normal file
44
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_4.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import fs_driver
|
||||
|
||||
CANVAS_WIDTH = 50
|
||||
CANVAS_HEIGHT = 50
|
||||
|
||||
LV_COLOR_SIZE = 32
|
||||
|
||||
#
|
||||
# Draw a text to the canvas
|
||||
#
|
||||
|
||||
# Create a buffer for the canvas
|
||||
cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT)
|
||||
|
||||
# Create a canvas and initialize its palette
|
||||
canvas = lv.canvas(lv.scr_act())
|
||||
canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR)
|
||||
canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER)
|
||||
canvas.center()
|
||||
|
||||
dsc = lv.draw_label_dsc_t()
|
||||
dsc.init()
|
||||
|
||||
dsc.color = lv.palette_main(lv.PALETTE.RED)
|
||||
|
||||
try:
|
||||
dsc.font = lv_font_montserrat_18
|
||||
except:
|
||||
# needed for dynamic font loading
|
||||
fs_drv = lv.fs_drv_t()
|
||||
fs_driver.fs_register(fs_drv, 'S')
|
||||
|
||||
print("Loading font montserrat_18")
|
||||
font_montserrat_18 = lv.font_load("S:../../assets/font/montserrat-18.fnt")
|
||||
if not font_montserrat_18:
|
||||
print("Font loading failed")
|
||||
else:
|
||||
dsc.font = font_montserrat_18
|
||||
|
||||
dsc.decor = lv.TEXT_DECOR.UNDERLINE
|
||||
print('Printing "Hello"')
|
||||
canvas.draw_text(10, 10, 30, dsc, "Hello")
|
||||
|
||||
|
||||
28
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_5.c
Normal file
28
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_5.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS && LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 50
|
||||
#define CANVAS_HEIGHT 50
|
||||
|
||||
/**
|
||||
* Draw an arc to the canvas
|
||||
*/
|
||||
void lv_example_canvas_5(void)
|
||||
{
|
||||
/*Create a buffer for the canvas*/
|
||||
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
/*Create a canvas and initialize its palette*/
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
|
||||
lv_obj_center(canvas);
|
||||
|
||||
lv_draw_arc_dsc_t dsc;
|
||||
lv_draw_arc_dsc_init(&dsc);
|
||||
dsc.color = lv_palette_main(LV_PALETTE_RED);
|
||||
dsc.width = 5;
|
||||
|
||||
lv_canvas_draw_arc(canvas, 25, 25, 15, 0, 220, &dsc);
|
||||
}
|
||||
#endif
|
||||
32
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_5.py
Normal file
32
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_5.py
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/opt/bin/lv_micropython -i
|
||||
# Initialize
|
||||
|
||||
import lvgl as lv
|
||||
import display_driver
|
||||
import fs_driver
|
||||
|
||||
CANVAS_WIDTH = 50
|
||||
CANVAS_HEIGHT = 50
|
||||
|
||||
LV_COLOR_SIZE = 32
|
||||
|
||||
#
|
||||
# Draw an arc to the canvas
|
||||
#
|
||||
|
||||
# Create a buffer for the canvas
|
||||
cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT)
|
||||
|
||||
# Create a canvas and initialize its palette
|
||||
canvas = lv.canvas(lv.scr_act())
|
||||
canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR)
|
||||
canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER)
|
||||
canvas.center()
|
||||
|
||||
dsc = lv.draw_arc_dsc_t()
|
||||
dsc.init()
|
||||
dsc.color = lv.palette_main(lv.PALETTE.RED)
|
||||
dsc.width = 5
|
||||
|
||||
canvas.draw_arc(25, 25, 15, 0, 220, dsc)
|
||||
|
||||
27
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_6.c
Normal file
27
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_6.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS && LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 50
|
||||
#define CANVAS_HEIGHT 50
|
||||
|
||||
/**
|
||||
* Draw an image to the canvas
|
||||
*/
|
||||
void lv_example_canvas_6(void)
|
||||
{
|
||||
/*Create a buffer for the canvas*/
|
||||
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
/*Create a canvas and initialize its palette*/
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
|
||||
lv_obj_center(canvas);
|
||||
|
||||
lv_draw_img_dsc_t dsc;
|
||||
lv_draw_img_dsc_init(&dsc);
|
||||
|
||||
LV_IMG_DECLARE(img_star);
|
||||
lv_canvas_draw_img(canvas, 5, 5, &img_star, &dsc);
|
||||
}
|
||||
#endif
|
||||
36
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_6.py
Normal file
36
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_6.py
Normal file
@@ -0,0 +1,36 @@
|
||||
CANVAS_WIDTH = 50
|
||||
CANVAS_HEIGHT = 50
|
||||
|
||||
LV_COLOR_SIZE = 32
|
||||
|
||||
# Create an image from the png file
|
||||
try:
|
||||
with open('../../assets/img_star.png','rb') as f:
|
||||
png_data = f.read()
|
||||
except:
|
||||
print("Could not find star.png")
|
||||
sys.exit()
|
||||
|
||||
img_star_argb = lv.img_dsc_t({
|
||||
'data_size': len(png_data),
|
||||
'data': png_data
|
||||
})
|
||||
|
||||
#
|
||||
# Draw an image to the canvas
|
||||
#
|
||||
|
||||
# Create a buffer for the canvas
|
||||
cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT)
|
||||
|
||||
# Create a canvas and initialize its palette
|
||||
canvas = lv.canvas(lv.scr_act())
|
||||
canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR)
|
||||
canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER)
|
||||
canvas.center()
|
||||
|
||||
dsc = lv.draw_img_dsc_t()
|
||||
dsc.init()
|
||||
|
||||
canvas.draw_img(5, 5, img_star_argb, dsc)
|
||||
|
||||
31
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_7.c
Normal file
31
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_7.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS&& LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 50
|
||||
#define CANVAS_HEIGHT 50
|
||||
|
||||
/**
|
||||
* Draw a line to the canvas
|
||||
*/
|
||||
void lv_example_canvas_7(void)
|
||||
{
|
||||
/*Create a buffer for the canvas*/
|
||||
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
/*Create a canvas and initialize its palette*/
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
|
||||
lv_obj_center(canvas);
|
||||
|
||||
lv_draw_line_dsc_t dsc;
|
||||
lv_draw_line_dsc_init(&dsc);
|
||||
dsc.color = lv_palette_main(LV_PALETTE_RED);
|
||||
dsc.width = 4;
|
||||
dsc.round_end = 1;
|
||||
dsc.round_start = 1;
|
||||
|
||||
lv_point_t p[] = {{15, 15}, {35, 10}, {10, 40}};
|
||||
lv_canvas_draw_line(canvas, p, 3, &dsc);
|
||||
}
|
||||
#endif
|
||||
33
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_7.py
Normal file
33
sdk/lib/lvgl/examples/widgets/canvas/lv_example_canvas_7.py
Normal file
@@ -0,0 +1,33 @@
|
||||
CANVAS_WIDTH = 50
|
||||
CANVAS_HEIGHT = 50
|
||||
|
||||
LV_COLOR_SIZE = 32
|
||||
|
||||
#
|
||||
# Draw a line to the canvas
|
||||
#
|
||||
|
||||
# Create a buffer for the canvas
|
||||
cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT)
|
||||
|
||||
# Create a canvas and initialize its palette
|
||||
canvas = lv.canvas(lv.scr_act())
|
||||
canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR)
|
||||
canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER)
|
||||
canvas.center()
|
||||
|
||||
dsc = lv.draw_line_dsc_t()
|
||||
dsc.init()
|
||||
|
||||
dsc.color = lv.palette_main(lv.PALETTE.RED)
|
||||
dsc.width = 4
|
||||
dsc.round_end = 1
|
||||
dsc.round_start = 1
|
||||
|
||||
p = [ {"x":15,"y":15},
|
||||
{"x":35,"y":10},
|
||||
{"x":10,"y":40} ]
|
||||
|
||||
canvas.draw_line(p, 3, dsc)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user