1 #include "../../lv_examples.h"
2 #if LV_USE_IMG && LV_USE_SLIDER && LV_BUILD_EXAMPLES
3
4 static lv_obj_t * create_slider(lv_color_t color);
5 static void slider_event_cb(lv_event_t * e);
6
7 static lv_obj_t * red_slider, * green_slider, * blue_slider, * intense_slider;
8 static lv_obj_t * img1;
9
10 /**
11 * Demonstrate runtime image re-coloring
12 */
lv_example_img_2(void)13 void lv_example_img_2(void)
14 {
15 /*Create 4 sliders to adjust RGB color and re-color intensity*/
16 red_slider = create_slider(lv_palette_main(LV_PALETTE_RED));
17 green_slider = create_slider(lv_palette_main(LV_PALETTE_GREEN));
18 blue_slider = create_slider(lv_palette_main(LV_PALETTE_BLUE));
19 intense_slider = create_slider(lv_palette_main(LV_PALETTE_GREY));
20
21 lv_slider_set_value(red_slider, LV_OPA_20, LV_ANIM_OFF);
22 lv_slider_set_value(green_slider, LV_OPA_90, LV_ANIM_OFF);
23 lv_slider_set_value(blue_slider, LV_OPA_60, LV_ANIM_OFF);
24 lv_slider_set_value(intense_slider, LV_OPA_50, LV_ANIM_OFF);
25
26 lv_obj_align(red_slider, LV_ALIGN_LEFT_MID, 25, 0);
27 lv_obj_align_to(green_slider, red_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0);
28 lv_obj_align_to(blue_slider, green_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0);
29 lv_obj_align_to(intense_slider, blue_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0);
30
31 /*Now create the actual image*/
32 LV_IMG_DECLARE(img_cogwheel_argb)
33 img1 = lv_img_create(lv_scr_act());
34 lv_img_set_src(img1, &img_cogwheel_argb);
35 lv_obj_align(img1, LV_ALIGN_RIGHT_MID, -20, 0);
36
37 lv_event_send(intense_slider, LV_EVENT_VALUE_CHANGED, NULL);
38 }
39
slider_event_cb(lv_event_t * e)40 static void slider_event_cb(lv_event_t * e)
41 {
42 LV_UNUSED(e);
43
44 /*Recolor the image based on the sliders' values*/
45 lv_color_t color = lv_color_make(lv_slider_get_value(red_slider), lv_slider_get_value(green_slider),
46 lv_slider_get_value(blue_slider));
47 lv_opa_t intense = lv_slider_get_value(intense_slider);
48 lv_obj_set_style_img_recolor_opa(img1, intense, 0);
49 lv_obj_set_style_img_recolor(img1, color, 0);
50 }
51
create_slider(lv_color_t color)52 static lv_obj_t * create_slider(lv_color_t color)
53 {
54 lv_obj_t * slider = lv_slider_create(lv_scr_act());
55 lv_slider_set_range(slider, 0, 255);
56 lv_obj_set_size(slider, 10, 200);
57 lv_obj_set_style_bg_color(slider, color, LV_PART_KNOB);
58 lv_obj_set_style_bg_color(slider, lv_color_darken(color, LV_OPA_40), LV_PART_INDICATOR);
59 lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
60 return slider;
61 }
62
63 #endif
64