acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
lv_example_img_2.c (2451B)
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 /** 12 * Demonstrate runtime image re-coloring 13 */ 14 void lv_example_img_2(void) 15 { 16 /*Create 4 sliders to adjust RGB color and re-color intensity*/ 17 red_slider = create_slider(lv_palette_main(LV_PALETTE_RED)); 18 green_slider = create_slider(lv_palette_main(LV_PALETTE_GREEN)); 19 blue_slider = create_slider(lv_palette_main(LV_PALETTE_BLUE)); 20 intense_slider = create_slider(lv_palette_main(LV_PALETTE_GREY)); 21 22 lv_slider_set_value(red_slider, LV_OPA_20, LV_ANIM_OFF); 23 lv_slider_set_value(green_slider, LV_OPA_90, LV_ANIM_OFF); 24 lv_slider_set_value(blue_slider, LV_OPA_60, LV_ANIM_OFF); 25 lv_slider_set_value(intense_slider, LV_OPA_50, LV_ANIM_OFF); 26 27 lv_obj_align(red_slider, LV_ALIGN_LEFT_MID, 25, 0); 28 lv_obj_align_to(green_slider, red_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0); 29 lv_obj_align_to(blue_slider, green_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0); 30 lv_obj_align_to(intense_slider, blue_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0); 31 32 /*Now create the actual image*/ 33 LV_IMG_DECLARE(img_cogwheel_argb) 34 img1 = lv_img_create(lv_scr_act()); 35 lv_img_set_src(img1, &img_cogwheel_argb); 36 lv_obj_align(img1, LV_ALIGN_RIGHT_MID, -20, 0); 37 38 lv_event_send(intense_slider, LV_EVENT_VALUE_CHANGED, NULL); 39 } 40 41 static void slider_event_cb(lv_event_t * e) 42 { 43 LV_UNUSED(e); 44 45 /*Recolor the image based on the sliders' values*/ 46 lv_color_t color = lv_color_make(lv_slider_get_value(red_slider), lv_slider_get_value(green_slider), 47 lv_slider_get_value(blue_slider)); 48 lv_opa_t intense = lv_slider_get_value(intense_slider); 49 lv_obj_set_style_img_recolor_opa(img1, intense, 0); 50 lv_obj_set_style_img_recolor(img1, color, 0); 51 } 52 53 static lv_obj_t * create_slider(lv_color_t color) 54 { 55 lv_obj_t * slider = lv_slider_create(lv_scr_act()); 56 lv_slider_set_range(slider, 0, 255); 57 lv_obj_set_size(slider, 10, 200); 58 lv_obj_set_style_bg_color(slider, color, LV_PART_KNOB); 59 lv_obj_set_style_bg_color(slider, lv_color_darken(color, LV_OPA_40), LV_PART_INDICATOR); 60 lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL); 61 return slider; 62 } 63 64 #endif