您当前的位置: 首页 >  ar

仙剑情缘

暂无认证

  • 2浏览

    0关注

    333博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

LVGL 8.2.0 Stacked area chart

仙剑情缘 发布时间:2022-06-05 11:57:30 ,浏览量:2

数据定型定义
/* 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             
关注
打赏
1658017818
查看更多评论
0.0491s