1 /**
2  * @file lv_cpicker.h
3  *
4  */
5 
6 #ifndef LV_CPICKER_H
7 #define LV_CPICKER_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_CPICKER != 0
19 
20 #include "../lv_core/lv_obj.h"
21 
22 /*********************
23  *      DEFINES
24  *********************/
25 
26 /**********************
27  *      TYPEDEFS
28  **********************/
29 
30 enum {
31     LV_CPICKER_TYPE_RECT,
32     LV_CPICKER_TYPE_DISC,
33 };
34 typedef uint8_t lv_cpicker_type_t;
35 
36 enum {
37     LV_CPICKER_COLOR_MODE_HUE,
38     LV_CPICKER_COLOR_MODE_SATURATION,
39     LV_CPICKER_COLOR_MODE_VALUE
40 };
41 typedef uint8_t lv_cpicker_color_mode_t;
42 
43 
44 
45 /*Data of colorpicker*/
46 typedef struct {
47     lv_color_hsv_t hsv;
48     struct {
49         lv_style_list_t style_list;
50         lv_point_t pos;
51         uint8_t colored     : 1;
52 
53     } knob;
54     uint32_t last_click_time;
55     uint32_t last_change_time;
56     lv_point_t last_press_point;
57     lv_cpicker_color_mode_t color_mode  : 2;
58     uint8_t color_mode_fixed            : 1;
59     lv_cpicker_type_t type              : 1;
60 } lv_cpicker_ext_t;
61 
62 /*Parts*/
63 enum {
64     LV_CPICKER_PART_MAIN = LV_OBJ_PART_MAIN,
65     LV_CPICKER_PART_KNOB = _LV_OBJ_PART_VIRTUAL_LAST,
66     _LV_CPICKER_PART_VIRTUAL_LAST,
67     _LV_CPICKER_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST,
68 };
69 
70 
71 /**********************
72  * GLOBAL PROTOTYPES
73  **********************/
74 
75 /**
76  * Create a colorpicker objects
77  * @param par pointer to an object, it will be the parent of the new colorpicker
78  * @param copy pointer to a colorpicker object, if not NULL then the new object will be copied from it
79  * @return pointer to the created colorpicker
80  */
81 lv_obj_t * lv_cpicker_create(lv_obj_t * par, const lv_obj_t * copy);
82 
83 /*=====================
84  * Setter functions
85  *====================*/
86 
87 /**
88  * Set a new type for a colorpicker
89  * @param cpicker pointer to a colorpicker object
90  * @param type new type of the colorpicker (from 'lv_cpicker_type_t' enum)
91  */
92 void lv_cpicker_set_type(lv_obj_t * cpicker, lv_cpicker_type_t type);
93 
94 /**
95  * Set the current hue of a colorpicker.
96  * @param cpicker pointer to colorpicker object
97  * @param hue current selected hue [0..360]
98  * @return true if changed, otherwise false
99  */
100 bool lv_cpicker_set_hue(lv_obj_t * cpicker, uint16_t hue);
101 
102 /**
103  * Set the current saturation of a colorpicker.
104  * @param cpicker pointer to colorpicker object
105  * @param saturation current selected saturation [0..100]
106  * @return true if changed, otherwise false
107  */
108 bool lv_cpicker_set_saturation(lv_obj_t * cpicker, uint8_t saturation);
109 
110 /**
111  * Set the current value of a colorpicker.
112  * @param cpicker pointer to colorpicker object
113  * @param val current selected value [0..100]
114  * @return true if changed, otherwise false
115  */
116 bool lv_cpicker_set_value(lv_obj_t * cpicker, uint8_t val);
117 
118 /**
119  * Set the current hsv of a colorpicker.
120  * @param cpicker pointer to colorpicker object
121  * @param hsv current selected hsv
122  * @return true if changed, otherwise false
123  */
124 bool lv_cpicker_set_hsv(lv_obj_t * cpicker, lv_color_hsv_t hsv);
125 
126 /**
127  * Set the current color of a colorpicker.
128  * @param cpicker pointer to colorpicker object
129  * @param color current selected color
130  * @return true if changed, otherwise false
131  */
132 bool lv_cpicker_set_color(lv_obj_t * cpicker, lv_color_t color);
133 
134 /**
135  * Set the current color mode.
136  * @param cpicker pointer to colorpicker object
137  * @param mode color mode (hue/sat/val)
138  */
139 void lv_cpicker_set_color_mode(lv_obj_t * cpicker, lv_cpicker_color_mode_t mode);
140 
141 /**
142  * Set if the color mode is changed on long press on center
143  * @param cpicker pointer to colorpicker object
144  * @param fixed color mode cannot be changed on long press
145  */
146 void lv_cpicker_set_color_mode_fixed(lv_obj_t * cpicker, bool fixed);
147 
148 /**
149  * Make the knob to be colored to the current color
150  * @param cpicker pointer to colorpicker object
151  * @param en true: color the knob; false: not color the knob
152  */
153 void lv_cpicker_set_knob_colored(lv_obj_t * cpicker, bool en);
154 
155 /*=====================
156  * Getter functions
157  *====================*/
158 
159 /**
160  * Get the current color mode.
161  * @param cpicker pointer to colorpicker object
162  * @return color mode (hue/sat/val)
163  */
164 lv_cpicker_color_mode_t lv_cpicker_get_color_mode(lv_obj_t * cpicker);
165 
166 /**
167  * Get if the color mode is changed on long press on center
168  * @param cpicker pointer to colorpicker object
169  * @return mode cannot be changed on long press
170  */
171 bool lv_cpicker_get_color_mode_fixed(lv_obj_t * cpicker);
172 
173 /**
174  * Get the current hue of a colorpicker.
175  * @param cpicker pointer to colorpicker object
176  * @return current selected hue
177  */
178 uint16_t lv_cpicker_get_hue(lv_obj_t * cpicker);
179 
180 /**
181  * Get the current saturation of a colorpicker.
182  * @param cpicker pointer to colorpicker object
183  * @return current selected saturation
184  */
185 uint8_t lv_cpicker_get_saturation(lv_obj_t * cpicker);
186 
187 /**
188  * Get the current hue of a colorpicker.
189  * @param cpicker pointer to colorpicker object
190  * @return current selected value
191  */
192 uint8_t lv_cpicker_get_value(lv_obj_t * cpicker);
193 
194 /**
195  * Get the current selected hsv of a colorpicker.
196  * @param cpicker pointer to colorpicker object
197  * @return current selected hsv
198  */
199 lv_color_hsv_t lv_cpicker_get_hsv(lv_obj_t * cpicker);
200 
201 /**
202  * Get the current selected color of a colorpicker.
203  * @param cpicker pointer to colorpicker object
204  * @return current selected color
205  */
206 lv_color_t lv_cpicker_get_color(lv_obj_t * cpicker);
207 
208 /**
209  * Whether the knob is colored to the current color or not
210  * @param cpicker pointer to color picker object
211  * @return true: color the knob; false: not color the knob
212  */
213 bool lv_cpicker_get_knob_colored(lv_obj_t * cpicker);
214 
215 /*=====================
216  * Other functions
217  *====================*/
218 
219 /**********************
220  *      MACROS
221  **********************/
222 
223 #endif  /*LV_USE_CPICKER*/
224 
225 #ifdef __cplusplus
226 } /* extern "C" */
227 #endif
228 
229 #endif  /*LV_CPICKER_H*/
230