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 "../lv_core/lv_obj.h"
21 
22 /*********************
23  *      DEFINES
24  *********************/
25 
26 /**********************
27  *      TYPEDEFS
28  **********************/
29 
30 enum {
31     LV_ARC_TYPE_NORMAL,
32     LV_ARC_TYPE_SYMMETRIC,
33     LV_ARC_TYPE_REVERSE
34 };
35 typedef uint8_t lv_arc_type_t;
36 
37 /*Data of arc*/
38 typedef struct {
39     /*New data for this type */
40     uint16_t rotation_angle;
41     uint16_t arc_angle_start;
42     uint16_t arc_angle_end;
43     uint16_t bg_angle_start;
44     uint16_t bg_angle_end;
45     lv_style_list_t style_arc;
46     lv_style_list_t style_knob; /* Style of the knob */
47 
48     int16_t cur_value; /*Current value of the arc*/
49     int16_t min_value; /*Minimum value of the arc*/
50     int16_t max_value; /*Maximum value of the arc*/
51     uint16_t dragging    : 1;
52     uint16_t type        : 2;
53     uint16_t adjustable  : 1;
54     uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/
55     uint32_t last_tick; /*Last dragging event timestamp of the arc*/
56     int16_t last_angle; /*Last dragging angle of the arc*/
57 } lv_arc_ext_t;
58 
59 /*Parts of the arc*/
60 enum {
61     LV_ARC_PART_BG = LV_OBJ_PART_MAIN,
62     LV_ARC_PART_INDIC,
63     LV_ARC_PART_KNOB,
64     _LV_ARC_PART_VIRTUAL_LAST,
65     _LV_ARC_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST,
66 };
67 typedef uint8_t lv_arc_part_t;
68 
69 /**********************
70  * GLOBAL PROTOTYPES
71  **********************/
72 
73 /**
74  * Create a arc objects
75  * @param par pointer to an object, it will be the parent of the new arc
76  * @param copy pointer to a arc object, if not NULL then the new object will be copied from it
77  * @return pointer to the created arc
78  */
79 lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy);
80 
81 /*======================
82  * Add/remove functions
83  *=====================*/
84 
85 /*=====================
86  * Setter functions
87  *====================*/
88 
89 /**
90  * Set the start angle of an arc. 0 deg: right, 90 bottom, etc.
91  * @param arc pointer to an arc object
92  * @param start the start angle
93  */
94 void lv_arc_set_start_angle(lv_obj_t * arc, uint16_t start);
95 
96 /**
97  * Set the start angle of an arc. 0 deg: right, 90 bottom, etc.
98  * @param arc pointer to an arc object
99  * @param end the end angle
100  */
101 void lv_arc_set_end_angle(lv_obj_t * arc, uint16_t end);
102 
103 /**
104  * Set the start and end angles
105  * @param arc pointer to an arc object
106  * @param start the start angle
107  * @param end the end angle
108  */
109 void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end);
110 
111 /**
112  * Set the start angle of an arc background. 0 deg: right, 90 bottom, etc.
113  * @param arc pointer to an arc object
114  * @param start the start angle
115  */
116 void lv_arc_set_bg_start_angle(lv_obj_t * arc, uint16_t start);
117 
118 /**
119  * Set the start angle of an arc background. 0 deg: right, 90 bottom etc.
120  * @param arc pointer to an arc object
121  * @param end the end angle
122  */
123 void lv_arc_set_bg_end_angle(lv_obj_t * arc, uint16_t end);
124 
125 /**
126  * Set the start and end angles of the arc background
127  * @param arc pointer to an arc object
128  * @param start the start angle
129  * @param end the end angle
130  */
131 void lv_arc_set_bg_angles(lv_obj_t * arc, uint16_t start, uint16_t end);
132 
133 /**
134  * Set the rotation for the whole arc
135  * @param arc pointer to an arc object
136  * @param rotation_angle rotation angle
137  */
138 void lv_arc_set_rotation(lv_obj_t * arc, uint16_t rotation_angle);
139 
140 
141 /**
142  * Set the type of arc.
143  * @param arc pointer to arc object
144  * @param type arc type
145  */
146 void lv_arc_set_type(lv_obj_t * arc, lv_arc_type_t type);
147 
148 /**
149  * Set a new value on the arc
150  * @param arc pointer to a arc object
151  * @param value new value
152  */
153 void lv_arc_set_value(lv_obj_t * arc, int16_t value);
154 
155 /**
156  * Set minimum and the maximum values of a arc
157  * @param arc pointer to the arc object
158  * @param min minimum value
159  * @param max maximum value
160  */
161 void lv_arc_set_range(lv_obj_t * arc, int16_t min, int16_t max);
162 
163 /**
164  * Set the threshold of arc knob increments
165  * position.
166  * @param arc pointer to a arc object
167  * @param threshold increment threshold
168  */
169 void lv_arc_set_chg_rate(lv_obj_t * arc, uint16_t threshold);
170 
171 /**
172  * Set whether the arc is adjustable.
173  * @param arc pointer to a arc object
174  * @param adjustable whether the arc has a knob that can be dragged
175  */
176 void lv_arc_set_adjustable(lv_obj_t * arc, bool adjustable);
177 
178 /*=====================
179  * Getter functions
180  *====================*/
181 
182 /**
183  * Get the start angle of an arc.
184  * @param arc pointer to an arc object
185  * @return the start angle [0..360]
186  */
187 uint16_t lv_arc_get_angle_start(lv_obj_t * arc);
188 
189 /**
190  * Get the end angle of an arc.
191  * @param arc pointer to an arc object
192  * @return the end angle [0..360]
193  */
194 uint16_t lv_arc_get_angle_end(lv_obj_t * arc);
195 
196 /**
197  * Get the start angle of an arc background.
198  * @param arc pointer to an arc object
199  * @return the start angle [0..360]
200  */
201 uint16_t lv_arc_get_bg_angle_start(lv_obj_t * arc);
202 
203 /**
204  * Get the end angle of an arc background.
205  * @param arc pointer to an arc object
206  * @return the end angle [0..360]
207  */
208 uint16_t lv_arc_get_bg_angle_end(lv_obj_t * arc);
209 
210 /**
211  * Get whether the arc is type or not.
212  * @param arc pointer to a arc object
213  * @return arc type
214  */
215 lv_arc_type_t lv_arc_get_type(const lv_obj_t * arc);
216 
217 /**
218  * Get the value of the of a arc
219  * @param arc pointer to a arc object
220  * @return the value of the of the arc
221  */
222 int16_t lv_arc_get_value(const lv_obj_t * arc);
223 
224 /**
225  * Get the minimum value of a arc
226  * @param arc pointer to a arc object
227  * @return the minimum value of the arc
228  */
229 int16_t lv_arc_get_min_value(const lv_obj_t * arc);
230 
231 /**
232  * Get the maximum value of a arc
233  * @param arc pointer to a arc object
234  * @return the maximum value of the arc
235  */
236 int16_t lv_arc_get_max_value(const lv_obj_t * arc);
237 
238 /**
239  * Give the arc is being dragged or not
240  * @param arc pointer to a arc object
241  * @return true: drag in progress false: not dragged
242  */
243 bool lv_arc_is_dragged(const lv_obj_t * arc);
244 
245 /**
246  * Get whether the arc is adjustable.
247  * @param arc pointer to a arc object
248  * @return whether the arc has a knob that can be dragged
249  */
250 bool lv_arc_get_adjustable(lv_obj_t * arc);
251 
252 /*=====================
253  * Other functions
254  *====================*/
255 
256 /**********************
257  *      MACROS
258  **********************/
259 
260 #endif /*LV_USE_ARC*/
261 
262 #ifdef __cplusplus
263 } /* extern "C" */
264 #endif
265 
266 #endif /*LV_ARC_H*/
267