def draw_event_cb(e): obj = e.get_target() cont_a = lv.area_t() obj.get_coords(cont_a) #Add the faded area before the lines are drawn dsc = e.get_draw_part_dsc() if dsc.part == lv.PART.ITEMS: if not dsc.p1 or not dsc.p2: return # Add a line mask that keeps the area below the line line_mask_param = lv.draw_mask_line_param_t() line_mask_param.points_init(dsc.p1.x, dsc.p1.y, dsc.p2.x, dsc.p2.y, lv.DRAW_MASK_LINE_SIDE.BOTTOM) line_mask_id = lv.draw_mask_add(line_mask_param, None) #Draw a rectangle that will be affected by the mask draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() draw_rect_dsc.bg_opa = lv.OPA.COVER draw_rect_dsc.bg_color = dsc.line_dsc.color a = lv.area_t() a.x1 = dsc.p1.x a.x2 = dsc.p2.x a.y1 = min(dsc.p1.y, dsc.p2.y) a.y2 = cont_a.y2 - 13 # -13 cuts off where the rectangle draws over the chart margin. Without this an area of 0 doesn't look like 0 dsc.draw_ctx.rect(draw_rect_dsc, a) # Remove the mask lv.draw_mask_free_param(line_mask_param) lv.draw_mask_remove_id(line_mask_id)
def draw_event_cb(e): obj = lv.obj.__cast__(e.get_target()) # Add the faded area before the lines are drawn dsc = lv.obj_draw_part_dsc_t.cast(e.get_param()) if dsc.part != lv.PART.ITEMS: return if not dsc.p1 or not dsc.p2: return # Add a line mask that keeps the area below the line line_mask_param = lv.draw_mask_line_param_t() line_mask_param.points_init(dsc.p1.x, dsc.p1.y, dsc.p2.x, dsc.p2.y, lv.DRAW_MASK_LINE_SIDE.BOTTOM) # line_mask_id = line_mask_param.draw_mask_add(None) line_mask_id = lv.draw_mask_add(line_mask_param, None) # Add a fade effect: transparent bottom covering top h = obj.get_height() fade_mask_param = lv.draw_mask_fade_param_t() coords = lv.area_t() obj.get_coords(coords) fade_mask_param.init(coords, lv.OPA.COVER, coords.y1 + h // 8, lv.OPA.TRANSP, coords.y2) fade_mask_id = lv.draw_mask_add(fade_mask_param, None) # Draw a rectangle that will be affected by the mask draw_rect_dsc = lv.draw_rect_dsc_t() draw_rect_dsc.init() draw_rect_dsc.bg_opa = lv.OPA._20 draw_rect_dsc.bg_color = dsc.line_dsc.color a = lv.area_t() a.x1 = dsc.p1.x a.x2 = dsc.p2.x - 1 a.y1 = min(dsc.p1.y, dsc.p2.y) coords = lv.area_t() obj.get_coords(coords) a.y2 = coords.y2 lv.draw_rect(a, dsc.clip_area, draw_rect_dsc) # Remove the masks lv.draw_mask_remove_id(line_mask_id) lv.draw_mask_remove_id(fade_mask_id)
while lv.tick_elaps(t) < 1000: pass a.x1 = 100 a.y1 = 100 a.x2 = 150 a.y2 = 150 r1.init(a, lv.RADIUS.CIRCLE, True) om.add_mask(r1) lv.refr_now(None) t = lv.tick_get() while lv.tick_elaps(t) < 1000: pass l1 = lv.draw_mask_line_param_t() l1.points_init(0, 0, 100, 200, lv.DRAW_MASK_LINE_SIDE.TOP) om.add_mask(l1) lv.refr_now(None) t = lv.tick_get() while lv.tick_elaps(t) < 1000: pass f1 = lv.draw_mask_fade_param_t() a.x1 = 100 a.y1 = 0 a.x2 = 200 a.y2 = 200 f1.init(a, lv.OPA.TRANSP, 0, lv.OPA.COVER, 150) om.add_mask(f1)