1 #include "../lv_examples.h"
2 #if LV_BUILD_EXAMPLES
3 
4 #if LV_USE_DRAW_SW_COMPLEX_GRADIENTS
5 
6 /**
7  * Simulate metallic knob using conical gradient
8  * For best effect set LV_GRADIENT_MAX_STOPS to 8 or at least 3
9  */
lv_example_style_16(void)10 void lv_example_style_16(void)
11 {
12 #if LV_GRADIENT_MAX_STOPS >= 8
13     static const lv_color_t grad_colors[8] = {
14         LV_COLOR_MAKE(0xe8, 0xe8, 0xe8),
15         LV_COLOR_MAKE(0xff, 0xff, 0xff),
16         LV_COLOR_MAKE(0xfa, 0xfa, 0xfa),
17         LV_COLOR_MAKE(0x79, 0x79, 0x79),
18         LV_COLOR_MAKE(0x48, 0x48, 0x48),
19         LV_COLOR_MAKE(0x4b, 0x4b, 0x4b),
20         LV_COLOR_MAKE(0x70, 0x70, 0x70),
21         LV_COLOR_MAKE(0xe8, 0xe8, 0xe8),
22     };
23 #elif LV_GRADIENT_MAX_STOPS >= 3
24     static const lv_color_t grad_colors[3] = {
25         LV_COLOR_MAKE(0xe8, 0xe8, 0xe8),
26         LV_COLOR_MAKE(0xff, 0xff, 0xff),
27         LV_COLOR_MAKE(0x79, 0x79, 0x79),
28     };
29 #else
30     static const lv_color_t grad_colors[2] = {
31         LV_COLOR_MAKE(0xe8, 0xe8, 0xe8),
32         LV_COLOR_MAKE(0x79, 0x79, 0x79),
33     };
34 #endif
35 
36     /*Create a style with gradient background and shadow*/
37     static lv_style_t style;
38     lv_style_init(&style);
39     lv_style_set_radius(&style, 500);
40     lv_style_set_bg_opa(&style, LV_OPA_COVER);
41     lv_style_set_shadow_color(&style, lv_color_black());
42     lv_style_set_shadow_width(&style, 50);
43     lv_style_set_shadow_offset_x(&style, 20);
44     lv_style_set_shadow_offset_y(&style, 20);
45     lv_style_set_shadow_opa(&style, LV_OPA_50);
46 
47     /*First define a color gradient. In this example we use a gray color map with random values.*/
48     static lv_grad_dsc_t grad;
49 
50     lv_gradient_init_stops(&grad, grad_colors, NULL, NULL, sizeof(grad_colors) / sizeof(lv_color_t));
51 
52     /*Make a conical gradient with the center in the middle of the object*/
53 #if LV_GRADIENT_MAX_STOPS >= 8
54     lv_grad_conical_init(&grad, LV_GRAD_CENTER, LV_GRAD_CENTER, 0, 120, LV_GRAD_EXTEND_REFLECT);
55 #elif LV_GRADIENT_MAX_STOPS >= 3
56     lv_grad_conical_init(&grad, LV_GRAD_CENTER, LV_GRAD_CENTER, 45, 125, LV_GRAD_EXTEND_REFLECT);
57 #else
58     lv_grad_conical_init(&grad, LV_GRAD_CENTER, LV_GRAD_CENTER, 45, 110, LV_GRAD_EXTEND_REFLECT);
59 #endif
60 
61     /*Set gradient as background*/
62     lv_style_set_bg_grad(&style, &grad);
63 
64     /*Create an object with the new style*/
65     lv_obj_t * obj = lv_obj_create(lv_screen_active());
66     lv_obj_add_style(obj, &style, 0);
67     lv_obj_set_size(obj, 200, 200);
68     lv_obj_center(obj);
69 }
70 
71 #else
72 
lv_example_style_16(void)73 void lv_example_style_16(void)
74 {
75     lv_obj_t * label = lv_label_create(lv_screen_active());
76     lv_obj_set_width(label, LV_PCT(80));
77     lv_label_set_text(label, "LV_USE_DRAW_SW_COMPLEX_GRADIENTS is not enabled");
78     lv_label_set_long_mode(label, LV_LABEL_LONG_MODE_SCROLL_CIRCULAR);
79     lv_obj_center(label);
80 }
81 
82 #endif /*LV_USE_DRAW_SW_COMPLEX_GRADIENTS*/
83 
84 #endif /*LV_BUILD_EXAMPLES*/
85