数据定型定义
/* A struct is used to keep track of the series list because later we need to draw to the series in the reverse order to which they were initialised. */
typedef struct {
lv_obj_t* obj;
lv_chart_series_t* series_list[3];
} stacked_area_chart_t;
定义变量
static stacked_area_chart_t stacked_area_chart;
事件处理函数
/**
* Callback which draws the blocks of colour under the lines
**/
static void draw_event_cb(lv_event_t* e)
{
lv_obj_t* obj = lv_event_get_target(e); // 获取产生事件的对象
/*Add the faded area before the lines are drawn*/
lv_obj_draw_part_dsc_t* dsc = lv_event_get_draw_part_dsc(e); //获取事件绘制描述符
if (dsc->part == LV_PART_ITEMS) { //仅对LV_PART_ITEMS处理
if (!dsc->p1 || !dsc->p2) //空指针不处理
return;
/*Add a line mask that keeps the area below the line*/
lv_draw_mask_line_param_t line_mask_param;
lv_draw_mask_line_points_init(&line_mask_param, dsc->p1->x, dsc->p1->y, dsc->p2->x, dsc->p2->y,
LV_DRAW_MASK_LINE_SIDE_BOTTOM); // 初时化线条mask参数
int16_t line_mask_id = lv_draw_mask_add(&line_mask_param, NULL); //添加mask
/*Draw a rectangle that will be affected by the mask*/
lv_draw_rect_dsc_t draw_rect_dsc;
lv_draw_rect_dsc_init(&draw_rect_dsc);
draw_rect_dsc.bg_opa = LV_OPA_COVER; //透明度为覆盖
draw_rect_dsc.bg_color = dsc->line_dsc->color; //背景色和线条同色
lv_area_t a;
a.x1 = dsc->p1->x;
a.x2 = dsc->p2->x;
a.y1 = LV_MIN(dsc->p1->y, dsc->p2->y); //取最小值
a.y2 = obj->coords.y2 -13; /* -13 cuts off where the rectangle draws over the chart margin.Without this an area of 0 doesn't look like 0 */
lv_draw_rect(dsc->draw_ctx, &draw_rect_dsc, &a); //绘制矩形区域
/*Remove the mask*/
lv_draw_mask_free_param(&line_mask_param); //移除mask param
lv_draw_mask_remove_id(line_mask_id); //移除mask id
}
}
四舍五入处理
/**
* Helper function to round a fixed point number
**/
static int32_t round_fixed_point(int32_t n, int8_t shift)
{
/* Create a bitmask to isolates the decimal part of the fixed point number */
int32_t mask = 1;
for (int32_t bit_pos = 0; bit_pos
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?