mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-21 06:53:01 +08:00
cbfbcb47f9
Use function instead of color macros
54 lines
1.8 KiB
C
54 lines
1.8 KiB
C
#include "../../../lvgl.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_color = lv_color_red();
|
|
rect_dsc.bg_grad_color = lv_color_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_color_yellow();
|
|
|
|
static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
|
|
|
lv_obj_t * canvas = lv_canvas_create(lv_scr_act(), NULL);
|
|
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
|
lv_obj_align(canvas, NULL, LV_ALIGN_CENTER, 0, 0);
|
|
lv_canvas_fill_bg(canvas, lv_color_grey_lighten_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 an other buffer where the orignal image is stored.
|
|
* So copy the current image to buffer and rotate it to the canvas */
|
|
static lv_color_t cbuf_tmp[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_color_grey_lighten_3(), LV_OPA_COVER);
|
|
lv_canvas_transform(canvas, &img, 30, LV_IMG_ZOOM_NONE, 0, 0, CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2, true);
|
|
}
|
|
|
|
#endif
|