1 /**
2  * @file lv_obj_draw.h
3  *
4  */
5 
6 #ifndef LV_OBJ_DRAW_H
7 #define LV_OBJ_DRAW_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../draw/lv_draw.h"
17 
18 /*********************
19  *      DEFINES
20  *********************/
21 
22 /**********************
23  *      TYPEDEFS
24  **********************/
25 
26 struct _lv_obj_t;
27 struct _lv_obj_class_t;
28 
29 /** Cover check results.*/
30 typedef enum {
31     LV_COVER_RES_COVER      = 0,
32     LV_COVER_RES_NOT_COVER  = 1,
33     LV_COVER_RES_MASKED     = 2,
34 } lv_cover_res_t;
35 
36 typedef struct {
37     lv_draw_ctx_t * draw_ctx;           /**< Draw context*/
38     const struct _lv_obj_class_t * class_p;     /**< The class that sent the event */
39     uint32_t type;                      /**< The type if part being draw. Element of `lv_<name>_draw_part_type_t` */
40     lv_area_t * draw_area;              /**< The area of the part being drawn*/
41     lv_draw_rect_dsc_t *
42     rect_dsc;      /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for rectangle-like parts*/
43     lv_draw_label_dsc_t *
44     label_dsc;    /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for text-like parts*/
45     lv_draw_line_dsc_t *
46     line_dsc;      /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for line-like parts*/
47     lv_draw_img_dsc_t  *
48     img_dsc;       /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for image-like parts*/
49     lv_draw_arc_dsc_t  *
50     arc_dsc;       /**< A draw descriptor that can be modified to changed what LVGL will draw. Set only for arc-like parts*/
51     const lv_point_t *
52     p1;              /**< A point calculated during drawing. E.g. a point of chart or the center of an arc.*/
53     const lv_point_t * p2;              /**< A point calculated during drawing. E.g. a point of chart.*/
54     char * text;                  /**< A text calculated during drawing. Can be modified. E.g. tick labels on a chart axis.*/
55     uint32_t text_length;               /**< Size of the text buffer containing null-terminated text string calculated during drawing.*/
56     uint32_t part;                      /**< The current part for which the event is sent*/
57     uint32_t id;                        /**< The index of the part. E.g. a button's index on button matrix or table cell index.*/
58     lv_coord_t radius;                  /**< E.g. the radius of an arc (not the corner radius).*/
59     int32_t value;                      /**< A value calculated during drawing. E.g. Chart's tick line value.*/
60     const void * sub_part_ptr;          /**< A pointer the identifies something in the part. E.g. chart series. */
61 } lv_obj_draw_part_dsc_t;
62 
63 /**********************
64  * GLOBAL PROTOTYPES
65  **********************/
66 
67 /**
68  * Initialize a rectangle draw descriptor from an object's styles in its current state
69  * @param obj pointer to an object
70  * @param part part of the object. E.g.  `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc
71  * @param draw_dsc the descriptor to initialize.
72  *                 If an `..._opa` field is set to `LV_OPA_TRANSP` the related properties won't be initialized.
73  *                 Should be initialized with `lv_draw_rect_dsc_init(draw_dsc)`.
74  * @note Only the relevant fields will be set.
75  *       E.g. if `border width == 0` the other border properties won't be evaluated.
76  */
77 void lv_obj_init_draw_rect_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_rect_dsc_t * draw_dsc);
78 
79 /**
80  * Initialize a label draw descriptor from an object's styles in its current state
81  * @param obj pointer to an object
82  * @param part part of the object. E.g.  `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc
83  * @param draw_dsc the descriptor to initialize.
84  *                 If the `opa` field is set to or the property is equal to `LV_OPA_TRANSP` the rest won't be initialized.
85  *                 Should be initialized with `lv_draw_label_dsc_init(draw_dsc)`.
86  */
87 void lv_obj_init_draw_label_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_label_dsc_t * draw_dsc);
88 
89 /**
90  * Initialize an image draw descriptor from an object's styles in its current state
91  * @param obj pointer to an object
92  * @param part part of the object. E.g.  `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc
93  * @param draw_dsc the descriptor to initialize.
94  *                 Should be initialized with `lv_draw_image_dsc_init(draw_dsc)`.
95  */
96 void lv_obj_init_draw_img_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_img_dsc_t * draw_dsc);
97 
98 
99 /**
100  * Initialize a line draw descriptor from an object's styles in its current state
101  * @param obj pointer to an object
102  * @param part part of the object. E.g.  `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc
103  * @param draw_dsc the descriptor to initialize.
104  *                 Should be initialized with `lv_draw_line_dsc_init(draw_dsc)`.
105  */
106 void lv_obj_init_draw_line_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_line_dsc_t * draw_dsc);
107 
108 /**
109  * Initialize an arc draw descriptor from an object's styles in its current state
110  * @param obj pointer to an object
111  * @param part part of the object. E.g.  `LV_PART_MAIN`, `LV_PART_SCROLLBAR`, `LV_PART_KNOB`, etc
112  * @param draw_dsc the descriptor to initialize.
113  *                 Should be initialized with `lv_draw_arc_dsc_init(draw_dsc)`.
114  */
115 void lv_obj_init_draw_arc_dsc(struct _lv_obj_t * obj, uint32_t part, lv_draw_arc_dsc_t * draw_dsc);
116 
117 /**
118  * Get the required extra size (around the object's part) to draw shadow, outline, value etc.
119  * @param obj pointer to an object
120  * @param part part of the object
121  * @return the extra size required around the object
122  */
123 lv_coord_t lv_obj_calculate_ext_draw_size(struct _lv_obj_t * obj, uint32_t part);
124 
125 /**
126  * Initialize a draw descriptor used in events.
127  * @param dsc pointer to a descriptor. Later it should be passed as parameter to an `LV_EEVNT_DRAW_PART_BEGIN/END` event.
128  * @param draw the current draw context. (usually returned by `lv_event_get_draw_ctx(e)`)
129  */
130 void lv_obj_draw_dsc_init(lv_obj_draw_part_dsc_t * dsc, lv_draw_ctx_t * draw_ctx);
131 
132 /**
133  * Check the type obj a part draw descriptor
134  * @param dsc       the descriptor (normally the event parameter)
135  * @param class_p   pointer to class to which `type` is related
136  * @param type      element of `lv_<name>_draw_part_type_t`
137  * @return          true if ::dsc is related to ::class_p and ::type
138  */
139 bool lv_obj_draw_part_check_type(lv_obj_draw_part_dsc_t * dsc, const struct _lv_obj_class_t * class_p, uint32_t type);
140 
141 /**
142  * Send a 'LV_EVENT_REFR_EXT_DRAW_SIZE' Call the ancestor's event handler to the object to refresh the value of the extended draw size.
143  * The result will be saved in `obj`.
144  * @param obj pointer to an object
145  */
146 void lv_obj_refresh_ext_draw_size(struct _lv_obj_t * obj);
147 
148 /**
149  * Get the extended draw area of an object.
150  * @param obj pointer to an object
151  * @return the size extended draw area around the real coordinates
152  */
153 lv_coord_t _lv_obj_get_ext_draw_size(const struct _lv_obj_t * obj);
154 
155 /**********************
156  *      MACROS
157  **********************/
158 
159 #ifdef __cplusplus
160 } /*extern "C"*/
161 #endif
162 
163 #endif /*LV_OBJ_DRAW_H*/
164