1 /**
2  * @file lv_arc.h
3  *
4  */
5 
6 #ifndef LV_ARC_H
7 #define LV_ARC_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../lv_conf_internal.h"
17 
18 #if LV_USE_ARC != 0
19 
20 #include "../core/lv_obj.h"
21 
22 /*********************
23  *      DEFINES
24  *********************/
25 
26 /**********************
27  *      TYPEDEFS
28  **********************/
29 
30 enum {
31     LV_ARC_MODE_NORMAL,
32     LV_ARC_MODE_SYMMETRICAL,
33     LV_ARC_MODE_REVERSE
34 };
35 typedef uint8_t lv_arc_mode_t;
36 
37 typedef struct {
38     lv_obj_t obj;
39     uint16_t rotation;
40     uint16_t indic_angle_start;
41     uint16_t indic_angle_end;
42     uint16_t bg_angle_start;
43     uint16_t bg_angle_end;
44     int16_t value;              /*Current value of the arc*/
45     int16_t min_value;          /*Minimum value of the arc*/
46     int16_t max_value;          /*Maximum value of the arc*/
47     uint32_t dragging    : 1;
48     uint32_t type        : 2;
49     uint32_t min_close   : 1;   /*1: the last pressed angle was closer to minimum end*/
50     uint32_t in_out      : 1;   /* 1: The click was within the background arc angles. 0: Click outside */
51     uint32_t chg_rate;          /*Drag angle rate of change of the arc (degrees/sec)*/
52     uint32_t last_tick;         /*Last dragging event timestamp of the arc*/
53     int16_t last_angle;         /*Last dragging angle of the arc*/
54 } lv_arc_t;
55 
56 extern const lv_obj_class_t lv_arc_class;
57 
58 /**
59  * `type` field in `lv_obj_draw_part_dsc_t` if `class_p = lv_arc_class`
60  * Used in `LV_EVENT_DRAW_PART_BEGIN` and `LV_EVENT_DRAW_PART_END`
61  */
62 typedef enum {
63     LV_ARC_DRAW_PART_BACKGROUND,    /**< The background arc*/
64     LV_ARC_DRAW_PART_FOREGROUND,    /**< The foreground arc*/
65     LV_ARC_DRAW_PART_KNOB,          /**< The knob*/
66 } lv_arc_draw_part_type_t;
67 
68 /**********************
69  * GLOBAL PROTOTYPES
70  **********************/
71 
72 /**
73  * Create an arc object
74  * @param parent pointer to an object, it will be the parent of the new arc
75  * @return pointer to the created arc
76  */
77 lv_obj_t * lv_arc_create(lv_obj_t * parent);
78 
79 /*======================
80  * Add/remove functions
81  *=====================*/
82 
83 /*=====================
84  * Setter functions
85  *====================*/
86 
87 /**
88  * Set the start angle of an arc. 0 deg: right, 90 bottom, etc.
89  * @param obj   pointer to an arc object
90  * @param start the start angle
91  */
92 void lv_arc_set_start_angle(lv_obj_t * obj, uint16_t start);
93 
94 /**
95  * Set the end angle of an arc. 0 deg: right, 90 bottom, etc.
96  * @param obj   pointer to an arc object
97  * @param end   the end angle
98  */
99 void lv_arc_set_end_angle(lv_obj_t * obj, uint16_t end);
100 
101 /**
102  * Set the start and end angles
103  * @param obj   pointer to an arc object
104  * @param start the start angle
105  * @param end   the end angle
106  */
107 void lv_arc_set_angles(lv_obj_t * obj, uint16_t start, uint16_t end);
108 
109 /**
110  * Set the start angle of an arc background. 0 deg: right, 90 bottom, etc.
111  * @param obj   pointer to an arc object
112  * @param start the start angle
113  */
114 void lv_arc_set_bg_start_angle(lv_obj_t * obj, uint16_t start);
115 
116 /**
117  * Set the start angle of an arc background. 0 deg: right, 90 bottom etc.
118  * @param obj   pointer to an arc object
119  * @param end   the end angle
120  */
121 void lv_arc_set_bg_end_angle(lv_obj_t * obj, uint16_t end);
122 
123 /**
124  * Set the start and end angles of the arc background
125  * @param obj   pointer to an arc object
126  * @param start the start angle
127  * @param end   the end angle
128  */
129 void lv_arc_set_bg_angles(lv_obj_t * obj, uint16_t start, uint16_t end);
130 
131 /**
132  * Set the rotation for the whole arc
133  * @param obj       pointer to an arc object
134  * @param rotation  rotation angle
135  */
136 void lv_arc_set_rotation(lv_obj_t * obj, uint16_t rotation);
137 
138 /**
139  * Set the type of arc.
140  * @param obj   pointer to arc object
141  * @param mode  arc's mode
142  */
143 void lv_arc_set_mode(lv_obj_t * obj, lv_arc_mode_t type);
144 
145 /**
146  * Set a new value on the arc
147  * @param obj   pointer to an arc object
148  * @param value new value
149  */
150 void lv_arc_set_value(lv_obj_t * obj, int16_t value);
151 
152 /**
153  * Set minimum and the maximum values of an arc
154  * @param obj   pointer to the arc object
155  * @param min   minimum value
156  * @param max   maximum value
157  */
158 void lv_arc_set_range(lv_obj_t * obj, int16_t min, int16_t max);
159 
160 /**
161  * Set a change rate to limit the speed how fast the arc should reach the pressed point.
162  * @param obj       pointer to an arc object
163  * @param rate      the change rate
164  */
165 void lv_arc_set_change_rate(lv_obj_t * obj, uint16_t rate);
166 
167 /*=====================
168  * Getter functions
169  *====================*/
170 
171 /**
172  * Get the start angle of an arc.
173  * @param obj   pointer to an arc object
174  * @return      the start angle [0..360]
175  */
176 uint16_t lv_arc_get_angle_start(lv_obj_t * obj);
177 
178 /**
179  * Get the end angle of an arc.
180  * @param obj   pointer to an arc object
181  * @return      the end angle [0..360]
182  */
183 uint16_t lv_arc_get_angle_end(lv_obj_t * obj);
184 
185 /**
186  * Get the start angle of an arc background.
187  * @param obj   pointer to an arc object
188  * @return      the  start angle [0..360]
189  */
190 uint16_t lv_arc_get_bg_angle_start(lv_obj_t * obj);
191 
192 /**
193  * Get the end angle of an arc background.
194  * @param obj   pointer to an arc object
195  * @return      the end angle [0..360]
196  */
197 uint16_t lv_arc_get_bg_angle_end(lv_obj_t * obj);
198 
199 /**
200  * Get the value of an arc
201  * @param obj       pointer to an arc object
202  * @return          the value of the arc
203  */
204 int16_t lv_arc_get_value(const lv_obj_t * obj);
205 
206 /**
207  * Get the minimum value of an arc
208  * @param obj   pointer to an arc object
209  * @return      the minimum value of the arc
210  */
211 int16_t lv_arc_get_min_value(const lv_obj_t * obj);
212 
213 /**
214  * Get the maximum value of an arc
215  * @param obj   pointer to an arc object
216  * @return      the maximum value of the arc
217  */
218 int16_t lv_arc_get_max_value(const lv_obj_t * obj);
219 
220 /**
221  * Get whether the arc is type or not.
222  * @param obj       pointer to an arc object
223  * @return          arc's mode
224  */
225 lv_arc_mode_t lv_arc_get_mode(const lv_obj_t * obj);
226 
227 /*=====================
228  * Other functions
229  *====================*/
230 
231 /**
232  * Align an object to the current position of the arc (knob)
233  * @param obj           pointer to an arc object
234  * @param obj_to_align  pointer to an object to align
235  * @param r_offset      consider the radius larger with this value (< 0: for smaller radius)
236  */
237 void lv_arc_align_obj_to_angle(const lv_obj_t * obj, lv_obj_t * obj_to_align, lv_coord_t r_offset);
238 
239 /**
240  * Rotate an object to the current position of the arc (knob)
241  * @param obj           pointer to an arc object
242  * @param obj_to_align  pointer to an object to rotate
243  * @param r_offset      consider the radius larger with this value (< 0: for smaller radius)
244  */
245 void lv_arc_rotate_obj_to_angle(const lv_obj_t * obj, lv_obj_t * obj_to_rotate, lv_coord_t r_offset);
246 
247 /**********************
248  *      MACROS
249  **********************/
250 
251 #endif /*LV_USE_ARC*/
252 
253 #ifdef __cplusplus
254 } /*extern "C"*/
255 #endif
256 
257 #endif /*LV_ARC_H*/
258