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