mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-26 02:37:01 +08:00
feat(draw): add comments and unify struct names (#7878)
This commit is contained in:
committed by
GitHub
parent
5f9dd14da0
commit
e819dd72b7
@@ -52,14 +52,20 @@ Draw a vector graphic to the canvas
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_8
|
||||
:language: c
|
||||
|
||||
Draw Fancy Letter Effects
|
||||
-------------------------
|
||||
Draw a triangle to the canvas
|
||||
-----------------------------
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_9
|
||||
:language: c
|
||||
|
||||
Draw Fancy Letter Effects 2
|
||||
---------------------------
|
||||
Draw Fancy Letter Effects
|
||||
-------------------------
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_10
|
||||
:language: c
|
||||
:language: c
|
||||
|
||||
|
||||
Draw Fancy Letter Effects 2
|
||||
---------------------------
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_11
|
||||
:language: c
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
static void timer_cb(lv_timer_t * timer)
|
||||
{
|
||||
static int16_t counter = 0;
|
||||
const char * string = "windstorrrrrrrrrrrrrrrrm~>>>";
|
||||
const int16_t string_len = (int16_t)lv_strlen(string);
|
||||
const char * string = "lol~ I'm wavvvvvvving~>>>";
|
||||
const int16_t string_len = lv_strlen(string);
|
||||
|
||||
lv_obj_t * canvas = (lv_obj_t *)lv_timer_get_user_data(timer);
|
||||
lv_layer_t layer;
|
||||
@@ -22,15 +22,15 @@ static void timer_cb(lv_timer_t * timer)
|
||||
letter_dsc.font = lv_font_get_default();
|
||||
|
||||
{
|
||||
#define CURVE2_X(t) ((t) * 2 + lv_trigo_cos((t) * 5) * 40 / 32767 - 10)
|
||||
#define CURVE2_Y(t, T) ((t) * lv_trigo_sin(((t) + (T)) * 5) * 40 / 32767 / 80 + CANVAS_HEIGHT / 2)
|
||||
#define CURVE2_X(t) (t * 2 + 10)
|
||||
#define CURVE2_Y(t) (lv_trigo_sin((t) * 5) * 40 / 32767 + CANVAS_HEIGHT / 2)
|
||||
|
||||
int32_t pre_x = CURVE2_X(-1);
|
||||
int32_t pre_y = CURVE2_Y(-1, 0);
|
||||
int32_t pre_y = CURVE2_Y(-1);
|
||||
for(int16_t i = 0; i < string_len; i++) {
|
||||
const int16_t angle = (int16_t)(i * 5);
|
||||
const int32_t x = CURVE2_X(angle);
|
||||
const int32_t y = CURVE2_Y(angle + 30, counter / 2);
|
||||
const int32_t y = CURVE2_Y(angle + counter / 2);
|
||||
const lv_point_t point = { .x = x, .y = y };
|
||||
|
||||
letter_dsc.unicode = (uint32_t)string[i % string_len];
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS && LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 300
|
||||
#define CANVAS_HEIGHT 200
|
||||
|
||||
static void timer_cb(lv_timer_t * timer)
|
||||
{
|
||||
static int32_t counter = 0;
|
||||
const char * string = "windstorrrrrrrrrrrrrrrrm~>>>";
|
||||
const int16_t string_len = lv_strlen(string);
|
||||
|
||||
lv_obj_t * canvas = (lv_obj_t *) lv_timer_get_user_data(timer);
|
||||
lv_layer_t layer;
|
||||
lv_canvas_init_layer(canvas, &layer);
|
||||
|
||||
lv_canvas_fill_bg(canvas, lv_color_white(), LV_OPA_COVER);
|
||||
|
||||
lv_draw_letter_dsc_t letter_dsc;
|
||||
lv_draw_letter_dsc_init(&letter_dsc);
|
||||
letter_dsc.color = lv_color_hex(0xff0000);
|
||||
letter_dsc.font = lv_font_get_default();
|
||||
|
||||
{
|
||||
#define CURVE2_X(t) ((t) * 2 + lv_trigo_cos((t) * 5) * 40 / 32767 - 10)
|
||||
#define CURVE2_Y(t, T) ((t) * lv_trigo_sin(((t) + (T)) * 5) * 40 / 32767 / 80 + CANVAS_HEIGHT / 2)
|
||||
|
||||
int32_t pre_x = CURVE2_X(-1);
|
||||
int32_t pre_y = CURVE2_Y(-1, 0);
|
||||
for(int16_t i = 0; i < string_len; i++) {
|
||||
const int32_t angle = i * 5;
|
||||
const int32_t x = CURVE2_X(angle);
|
||||
const int32_t y = CURVE2_Y(angle + 30, counter / 2);
|
||||
|
||||
letter_dsc.unicode = (uint32_t)string[i % string_len];
|
||||
letter_dsc.rotation = lv_atan2(y - pre_y, x - pre_x) * 10;
|
||||
letter_dsc.color = lv_color_hsv_to_rgb(i * 10, 100, 100);
|
||||
lv_draw_letter(&layer, &letter_dsc, &(lv_point_t) {
|
||||
.x = x, .y = y
|
||||
});
|
||||
|
||||
pre_x = x;
|
||||
pre_y = y;
|
||||
}
|
||||
}
|
||||
|
||||
lv_canvas_finish_layer(canvas, &layer);
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
void lv_example_canvas_11(void)
|
||||
{
|
||||
/*Create a buffer for the canvas*/
|
||||
LV_DRAW_BUF_DEFINE_STATIC(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888);
|
||||
LV_DRAW_BUF_INIT_STATIC(draw_buf);
|
||||
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_screen_active());
|
||||
lv_obj_set_size(canvas, CANVAS_WIDTH, CANVAS_HEIGHT);
|
||||
|
||||
lv_obj_center(canvas);
|
||||
|
||||
lv_canvas_set_draw_buf(canvas, &draw_buf);
|
||||
|
||||
lv_timer_create(timer_cb, 16, canvas);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,67 +1,51 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS && LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 300
|
||||
#define CANVAS_HEIGHT 200
|
||||
|
||||
static void timer_cb(lv_timer_t * timer)
|
||||
{
|
||||
static int16_t counter = 0;
|
||||
const char * string = "lol~ I'm wavvvvvvving~>>>";
|
||||
const int16_t string_len = (int16_t)lv_strlen(string);
|
||||
|
||||
lv_obj_t * canvas = (lv_obj_t *)lv_timer_get_user_data(timer);
|
||||
lv_layer_t layer;
|
||||
lv_canvas_init_layer(canvas, &layer);
|
||||
|
||||
lv_canvas_fill_bg(canvas, lv_color_white(), LV_OPA_COVER);
|
||||
|
||||
lv_draw_letter_dsc_t letter_dsc;
|
||||
lv_draw_letter_dsc_init(&letter_dsc);
|
||||
letter_dsc.color = lv_color_hex(0xff0000);
|
||||
letter_dsc.font = lv_font_get_default();
|
||||
|
||||
{
|
||||
#define CURVE2_X(t) (t * 2 + 10)
|
||||
#define CURVE2_Y(t) (lv_trigo_sin((t) * 5) * 40 / 32767 + CANVAS_HEIGHT / 2)
|
||||
|
||||
int32_t pre_x = CURVE2_X(-1);
|
||||
int32_t pre_y = CURVE2_Y(-1);
|
||||
for(int16_t i = 0; i < string_len; i++) {
|
||||
const int16_t angle = (int16_t)(i * 5);
|
||||
const int32_t x = CURVE2_X(angle);
|
||||
const int32_t y = CURVE2_Y(angle + counter / 2);
|
||||
const lv_point_t point = { .x = x, .y = y };
|
||||
|
||||
letter_dsc.unicode = (uint32_t)string[i % string_len];
|
||||
letter_dsc.rotation = lv_atan2(y - pre_y, x - pre_x) * 10;
|
||||
letter_dsc.color = lv_color_hsv_to_rgb(i * 10, 100, 100);
|
||||
lv_draw_letter(&layer, &letter_dsc, &point);
|
||||
|
||||
pre_x = x;
|
||||
pre_y = y;
|
||||
}
|
||||
}
|
||||
|
||||
lv_canvas_finish_layer(canvas, &layer);
|
||||
|
||||
counter++;
|
||||
}
|
||||
#define CANVAS_WIDTH 150
|
||||
#define CANVAS_HEIGHT 150
|
||||
|
||||
/**
|
||||
* Draw a triangle to the canvas
|
||||
*/
|
||||
void lv_example_canvas_9(void)
|
||||
{
|
||||
/*Create a buffer for the canvas*/
|
||||
LV_DRAW_BUF_DEFINE_STATIC(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888);
|
||||
LV_DRAW_BUF_INIT_STATIC(draw_buf);
|
||||
|
||||
/*Create a canvas and initialize its palette*/
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_screen_active());
|
||||
lv_obj_set_size(canvas, CANVAS_WIDTH, CANVAS_HEIGHT);
|
||||
|
||||
lv_canvas_set_draw_buf(canvas, &draw_buf);
|
||||
lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
|
||||
lv_obj_center(canvas);
|
||||
|
||||
lv_canvas_set_draw_buf(canvas, &draw_buf);
|
||||
lv_layer_t layer;
|
||||
lv_canvas_init_layer(canvas, &layer);
|
||||
|
||||
lv_timer_create(timer_cb, 16, canvas);
|
||||
lv_draw_triangle_dsc_t tri_dsc;
|
||||
lv_draw_triangle_dsc_init(&tri_dsc);
|
||||
tri_dsc.p[0].x = 10;
|
||||
tri_dsc.p[0].y = 10;
|
||||
tri_dsc.p[1].x = 100;
|
||||
tri_dsc.p[1].y = 30;
|
||||
tri_dsc.p[2].x = 50;
|
||||
tri_dsc.p[2].y = 100;
|
||||
|
||||
tri_dsc.grad.stops_count = 2;
|
||||
tri_dsc.grad.dir = LV_GRAD_DIR_VER;
|
||||
tri_dsc.grad.stops[0].color = lv_color_hex(0xff0000);
|
||||
tri_dsc.grad.stops[0].frac = 64; /*Start at 25%*/
|
||||
tri_dsc.grad.stops[0].opa = LV_OPA_COVER;
|
||||
tri_dsc.grad.stops[1].color = lv_color_hex(0x0000ff);
|
||||
tri_dsc.grad.stops[1].opa = LV_OPA_TRANSP;
|
||||
tri_dsc.grad.stops[1].frac = 3 * 64; /*End at 75%*/
|
||||
|
||||
tri_dsc.opa = 128; /*Set the overall opacity to 50%*/
|
||||
|
||||
lv_draw_triangle(&layer, &tri_dsc);
|
||||
|
||||
lv_canvas_finish_layer(canvas, &layer);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -71,17 +71,18 @@ static void add_faded_area(lv_event_t * e)
|
||||
tri_dsc.p[1].y = draw_line_dsc->p2.y;
|
||||
tri_dsc.p[2].x = draw_line_dsc->p1.y < draw_line_dsc->p2.y ? draw_line_dsc->p1.x : draw_line_dsc->p2.x;
|
||||
tri_dsc.p[2].y = LV_MAX(draw_line_dsc->p1.y, draw_line_dsc->p2.y);
|
||||
tri_dsc.bg_grad.dir = LV_GRAD_DIR_VER;
|
||||
tri_dsc.grad.dir = LV_GRAD_DIR_VER;
|
||||
|
||||
int32_t full_h = lv_obj_get_height(obj);
|
||||
int32_t fract_uppter = (int32_t)(LV_MIN(draw_line_dsc->p1.y, draw_line_dsc->p2.y) - coords.y1) * 255 / full_h;
|
||||
int32_t fract_lower = (int32_t)(LV_MAX(draw_line_dsc->p1.y, draw_line_dsc->p2.y) - coords.y1) * 255 / full_h;
|
||||
tri_dsc.bg_grad.stops[0].color = ser_color;
|
||||
tri_dsc.bg_grad.stops[0].opa = (lv_opa_t)(255 - fract_uppter);
|
||||
tri_dsc.bg_grad.stops[0].frac = 0;
|
||||
tri_dsc.bg_grad.stops[1].color = ser_color;
|
||||
tri_dsc.bg_grad.stops[1].opa = (lv_opa_t)(255 - fract_lower);
|
||||
tri_dsc.bg_grad.stops[1].frac = 255;
|
||||
tri_dsc.grad.stops[0].color = ser_color;
|
||||
tri_dsc.grad.stops[0].opa = (lv_opa_t)(255 - fract_uppter);
|
||||
tri_dsc.grad.stops[0].opa = 255 - fract_uppter;
|
||||
tri_dsc.grad.stops[0].frac = 0;
|
||||
tri_dsc.grad.stops[1].color = ser_color;
|
||||
tri_dsc.grad.stops[1].opa = (lv_opa_t)(255 - fract_lower);
|
||||
tri_dsc.grad.stops[1].frac = 255;
|
||||
|
||||
lv_draw_triangle(base_dsc->layer, &tri_dsc);
|
||||
|
||||
|
||||
@@ -32,4 +32,5 @@ void lv_example_dropdown_1(void)
|
||||
lv_obj_add_event_cb(dd, event_handler, LV_EVENT_ALL, NULL);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -59,6 +59,7 @@ void lv_example_canvas_7(void);
|
||||
void lv_example_canvas_8(void);
|
||||
void lv_example_canvas_9(void);
|
||||
void lv_example_canvas_10(void);
|
||||
void lv_example_canvas_11(void);
|
||||
|
||||
void lv_example_chart_1(void);
|
||||
void lv_example_chart_2(void);
|
||||
|
||||
Reference in New Issue
Block a user