1 /**
2 * @file lv_draw_line.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_draw_private.h"
10 #include "../core/lv_refr.h"
11 #include "../misc/lv_math.h"
12 #include "../misc/lv_types.h"
13 #include "../stdlib/lv_string.h"
14
15 /*********************
16 * DEFINES
17 *********************/
18
19 /**********************
20 * TYPEDEFS
21 **********************/
22
23 /**********************
24 * STATIC PROTOTYPES
25 **********************/
26
27 /**********************
28 * STATIC VARIABLES
29 **********************/
30
31 /**********************
32 * MACROS
33 **********************/
34
35 /**********************
36 * GLOBAL FUNCTIONS
37 **********************/
38
lv_draw_line_dsc_init(lv_draw_line_dsc_t * dsc)39 void LV_ATTRIBUTE_FAST_MEM lv_draw_line_dsc_init(lv_draw_line_dsc_t * dsc)
40 {
41 lv_memzero(dsc, sizeof(lv_draw_line_dsc_t));
42 dsc->width = 1;
43 dsc->opa = LV_OPA_COVER;
44 dsc->color = lv_color_black();
45 dsc->base.dsc_size = sizeof(lv_draw_line_dsc_t);
46 }
47
lv_draw_task_get_line_dsc(lv_draw_task_t * task)48 lv_draw_line_dsc_t * lv_draw_task_get_line_dsc(lv_draw_task_t * task)
49 {
50 return task->type == LV_DRAW_TASK_TYPE_LINE ? (lv_draw_line_dsc_t *)task->draw_dsc : NULL;
51 }
52
lv_draw_line(lv_layer_t * layer,const lv_draw_line_dsc_t * dsc)53 void LV_ATTRIBUTE_FAST_MEM lv_draw_line(lv_layer_t * layer, const lv_draw_line_dsc_t * dsc)
54 {
55 if(dsc->width == 0) return;
56 if(dsc->opa <= LV_OPA_MIN) return;
57
58 LV_PROFILER_DRAW_BEGIN;
59
60 lv_area_t a;
61 a.x1 = (int32_t)LV_MIN(dsc->p1.x, dsc->p2.x) - dsc->width;
62 a.x2 = (int32_t)LV_MAX(dsc->p1.x, dsc->p2.x) + dsc->width;
63 a.y1 = (int32_t)LV_MIN(dsc->p1.y, dsc->p2.y) - dsc->width;
64 a.y2 = (int32_t)LV_MAX(dsc->p1.y, dsc->p2.y) + dsc->width;
65
66 lv_draw_task_t * t = lv_draw_add_task(layer, &a);
67
68 t->draw_dsc = lv_malloc(sizeof(*dsc));
69 LV_ASSERT_MALLOC(t->draw_dsc);
70 lv_memcpy(t->draw_dsc, dsc, sizeof(*dsc));
71 t->type = LV_DRAW_TASK_TYPE_LINE;
72
73 lv_draw_finalize_task_creation(layer, t);
74 LV_PROFILER_DRAW_END;
75 }
76
77 /**********************
78 * STATIC FUNCTIONS
79 **********************/
80