1 /**
2 * @file lv_demo_render.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_demo_render.h"
10
11 #if LV_USE_DEMO_RENDER
12
13 #include "../../lvgl_private.h"
14
15 /*********************
16 * DEFINES
17 *********************/
18
19 #define COL_CNT 8
20 #define ROW_CNT 8
21 #define DEF_WIDTH 55
22 #define DEF_HEIGHT 30
23
24 /**********************
25 * TYPEDEFS
26 **********************/
27 typedef struct {
28 const char * name;
29 void (*create_cb)(lv_obj_t * parent);
30 } scene_dsc_t;
31
32 /**********************
33 * STATIC PROTOTYPES
34 **********************/
35 static lv_opa_t opa_saved;
36 static void add_to_cell(lv_obj_t * obj, int32_t col, int32_t row);
37
fill_obj_create(lv_obj_t * parent,int32_t col,int32_t row)38 static lv_obj_t * fill_obj_create(lv_obj_t * parent, int32_t col, int32_t row)
39 {
40 lv_color_t colors[] = {lv_color_hex3(0x000),
41 lv_color_hex3(0xfff),
42 lv_color_hex3(0xf00),
43 lv_color_hex3(0x0f0),
44 lv_color_hex3(0x00f),
45 lv_color_hex3(0xff0),
46 lv_color_hex3(0x0ff),
47 lv_color_hex3(0xf0f),
48 };
49
50 lv_obj_t * obj = lv_obj_create(parent);
51 lv_obj_remove_style_all(obj);
52 lv_obj_set_style_opa(obj, opa_saved, 0);
53 lv_obj_set_style_bg_opa(obj, LV_OPA_COVER, 0);
54 lv_obj_set_style_bg_color(obj, colors[col], 0);
55 lv_obj_set_size(obj, DEF_WIDTH, DEF_HEIGHT);
56 add_to_cell(obj, col, row);
57
58 return obj;
59
60 }
61
fill_cb(lv_obj_t * parent)62 static void fill_cb(lv_obj_t * parent)
63 {
64
65 uint32_t i;
66 for(i = 0; i < COL_CNT; i++) {
67 fill_obj_create(parent, i, 0);
68 }
69
70 for(i = 0; i < COL_CNT; i++) {
71 lv_obj_t * obj = fill_obj_create(parent, i, 1);
72 lv_obj_set_style_radius(obj, 10, 0);
73 }
74
75 for(i = 0; i < COL_CNT; i++) {
76 lv_obj_t * obj = fill_obj_create(parent, i, 2);
77 lv_obj_set_style_radius(obj, 100, 0);
78 }
79
80 for(i = 0; i < COL_CNT; i++) {
81 lv_obj_t * obj = fill_obj_create(parent, i, 3);
82 lv_obj_set_style_radius(obj, 10, 0);
83 lv_obj_set_style_bg_grad_dir(obj, LV_GRAD_DIR_HOR, 0);
84 lv_obj_set_style_bg_grad_color(obj, lv_color_hex3(0x888), 0);
85 lv_obj_set_style_bg_grad_stop(obj, 200, 0);
86 }
87
88 for(i = 0; i < COL_CNT; i++) {
89 lv_obj_t * obj = fill_obj_create(parent, i, 4);
90 lv_obj_set_style_radius(obj, 10, 0);
91 lv_obj_set_style_bg_grad_dir(obj, LV_GRAD_DIR_VER, 0);
92 lv_obj_set_style_bg_grad_color(obj, lv_color_hex3(0x888), 0);
93 lv_obj_set_style_bg_grad_stop(obj, 200, 0);
94 }
95
96 for(i = 0; i < COL_CNT; i++) {
97
98 lv_obj_t * obj = fill_obj_create(parent, i, 5);
99 lv_obj_set_style_radius(obj, 10, 0);
100 lv_obj_set_style_bg_grad_dir(obj, LV_GRAD_DIR_HOR, 0);
101 lv_obj_set_style_bg_grad_color(obj, lv_color_hex3(0x888), 0);
102 lv_obj_set_style_bg_grad_opa(obj, LV_OPA_TRANSP, 0);
103 lv_obj_set_style_bg_grad_stop(obj, 200, 0);
104 }
105
106 for(i = 0; i < COL_CNT; i++) {
107 lv_obj_t * obj = fill_obj_create(parent, i, 6);
108 lv_obj_set_style_radius(obj, 10, 0);
109 lv_obj_set_style_bg_grad_dir(obj, LV_GRAD_DIR_VER, 0);
110 lv_obj_set_style_bg_grad_color(obj, lv_color_hex3(0x888), 0);
111 lv_obj_set_style_bg_grad_opa(obj, LV_OPA_TRANSP, 0);
112 lv_obj_set_style_bg_grad_stop(obj, 200, 0);
113 }
114 }
115
border_obj_create(lv_obj_t * parent,int32_t col,int32_t row)116 static lv_obj_t * border_obj_create(lv_obj_t * parent, int32_t col, int32_t row)
117 {
118 lv_obj_t * obj = lv_obj_create(parent);
119 lv_obj_remove_style_all(obj);
120 lv_obj_set_style_border_color(obj, lv_color_hex3(0x000), 0);
121 lv_obj_set_style_border_width(obj, 3, 0);
122 lv_obj_set_style_opa(obj, opa_saved, 0);
123 lv_obj_set_size(obj, DEF_WIDTH, DEF_HEIGHT);
124 add_to_cell(obj, col, row);
125
126 return obj;
127
128 }
129
border_cb(lv_obj_t * parent)130 static void border_cb(lv_obj_t * parent)
131 {
132 lv_border_side_t sides[] = {
133 LV_BORDER_SIDE_NONE,
134 LV_BORDER_SIDE_FULL,
135 LV_BORDER_SIDE_LEFT,
136 LV_BORDER_SIDE_RIGHT,
137 LV_BORDER_SIDE_TOP,
138 LV_BORDER_SIDE_BOTTOM,
139 LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_RIGHT,
140 LV_BORDER_SIDE_RIGHT | LV_BORDER_SIDE_BOTTOM,
141 LV_BORDER_SIDE_LEFT | LV_BORDER_SIDE_BOTTOM,
142 LV_BORDER_SIDE_LEFT | LV_BORDER_SIDE_TOP,
143 LV_BORDER_SIDE_LEFT | LV_BORDER_SIDE_RIGHT,
144 LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM,
145 LV_BORDER_SIDE_LEFT | LV_BORDER_SIDE_RIGHT | LV_BORDER_SIDE_BOTTOM,
146 LV_BORDER_SIDE_LEFT | LV_BORDER_SIDE_BOTTOM | LV_BORDER_SIDE_TOP,
147 LV_BORDER_SIDE_LEFT | LV_BORDER_SIDE_RIGHT | LV_BORDER_SIDE_TOP,
148 LV_BORDER_SIDE_BOTTOM | LV_BORDER_SIDE_RIGHT | LV_BORDER_SIDE_TOP,
149 };
150
151 uint32_t i;
152 for(i = 0; i < COL_CNT; i++) {
153 lv_obj_t * obj = border_obj_create(parent, i, 0);
154 lv_obj_set_style_radius(obj, 0, 0);
155 lv_obj_set_style_border_side(obj, sides[i], 0);
156 lv_obj_set_style_border_color(obj, lv_color_hex3(0xf00), 0);
157 }
158
159 for(i = 0; i < COL_CNT; i++) {
160 lv_obj_t * obj = border_obj_create(parent, i, 1);
161 lv_obj_set_style_radius(obj, 0, 0);
162 lv_obj_set_style_border_side(obj, sides[i + 8], 0);
163 lv_obj_set_style_border_color(obj, lv_color_hex3(0xf00), 0);
164 }
165
166 for(i = 0; i < COL_CNT; i++) {
167 lv_obj_t * obj = border_obj_create(parent, i, 2);
168 lv_obj_set_style_radius(obj, 10, 0);
169 lv_obj_set_style_border_side(obj, sides[i], 0);
170 lv_obj_set_style_border_color(obj, lv_color_hex3(0x0f0), 0);
171 }
172
173 for(i = 0; i < COL_CNT; i++) {
174 lv_obj_t * obj = border_obj_create(parent, i, 3);
175 lv_obj_set_style_radius(obj, 10, 0);
176 lv_obj_set_style_border_side(obj, sides[i + 8], 0);
177 lv_obj_set_style_border_color(obj, lv_color_hex3(0x0f0), 0);
178 }
179
180 for(i = 0; i < COL_CNT; i++) {
181 lv_obj_t * obj = border_obj_create(parent, i, 4);
182 lv_obj_set_style_radius(obj, 100, 0);
183 lv_obj_set_style_border_side(obj, sides[i], 0);
184 lv_obj_set_style_border_color(obj, lv_color_hex3(0x00f), 0);
185 }
186
187 for(i = 0; i < COL_CNT; i++) {
188 lv_obj_t * obj = border_obj_create(parent, i, 5);
189 lv_obj_set_style_radius(obj, 100, 0);
190 lv_obj_set_style_border_side(obj, sides[i + 8], 0);
191 lv_obj_set_style_border_color(obj, lv_color_hex3(0x00f), 0);
192 }
193
194 for(i = 0; i < COL_CNT; i++) {
195 lv_obj_t * obj = border_obj_create(parent, i, 6);
196 lv_obj_set_style_radius(obj, 100, 0);
197 lv_obj_set_style_border_side(obj, sides[i], 0);
198 lv_obj_set_style_border_color(obj, lv_color_hex3(0x888), 0);
199 lv_obj_set_style_border_width(obj, 10, 0);
200 }
201
202 for(i = 0; i < COL_CNT; i++) {
203 lv_obj_t * obj = border_obj_create(parent, i, 7);
204 lv_obj_set_style_radius(obj, 100, 0);
205 lv_obj_set_style_border_side(obj, sides[i + 8], 0);
206 lv_obj_set_style_border_color(obj, lv_color_hex3(0x888), 0);
207 lv_obj_set_style_border_width(obj, 10, 0);
208 }
209 }
210
box_shadow_obj_create(lv_obj_t * parent,int32_t col,int32_t row)211 static lv_obj_t * box_shadow_obj_create(lv_obj_t * parent, int32_t col, int32_t row)
212 {
213 lv_obj_t * obj = lv_obj_create(parent);
214 lv_obj_remove_style_all(obj);
215 lv_obj_set_style_bg_opa(obj, LV_OPA_20, 0);
216 lv_obj_set_style_bg_color(obj, lv_color_black(), 0);
217 lv_obj_set_style_shadow_color(obj, lv_color_hex3(0xf00), 0);
218 lv_obj_set_style_opa(obj, opa_saved, 0);
219 lv_obj_set_size(obj, DEF_WIDTH - 20, DEF_HEIGHT - 5);
220 add_to_cell(obj, col, row);
221
222 return obj;
223 }
224
box_shadow_cb(lv_obj_t * parent)225 static void box_shadow_cb(lv_obj_t * parent)
226 {
227
228 static const int32_t grid_rows[] = {45, 45, 45, 45, 45, 45, LV_GRID_TEMPLATE_LAST};
229 static const int32_t grid_cols[] = {68, 68, 68, 68, 68, 68, 68, LV_GRID_TEMPLATE_LAST};
230 lv_obj_set_grid_dsc_array(parent, grid_cols, grid_rows);
231
232 lv_point_t ofs[] = {
233 {0, 0},
234 {5, 5},
235 {5, -5},
236 {-5, 5},
237 {-5, -5},
238 {10, 0},
239 {0, 10},
240 };
241
242 uint32_t i;
243 for(i = 0; i < 7; i++) {
244 lv_obj_t * obj = box_shadow_obj_create(parent, i, 0);
245 lv_obj_set_style_radius(obj, 0, 0);
246 lv_obj_set_style_shadow_width(obj, 10, 0);
247 lv_obj_set_style_shadow_offset_x(obj, ofs[i].x, 0);
248 lv_obj_set_style_shadow_offset_y(obj, ofs[i].y, 0);
249 }
250
251 for(i = 0; i < 7; i++) {
252 lv_obj_t * obj = box_shadow_obj_create(parent, i, 1);
253 lv_obj_set_style_radius(obj, 5, 0);
254 lv_obj_set_style_shadow_width(obj, 10, 0);
255 lv_obj_set_style_shadow_offset_x(obj, ofs[i].x, 0);
256 lv_obj_set_style_shadow_offset_y(obj, ofs[i].y, 0);
257 }
258
259 for(i = 0; i < 7; i++) {
260 lv_obj_t * obj = box_shadow_obj_create(parent, i, 2);
261 lv_obj_set_style_radius(obj, 100, 0);
262 lv_obj_set_style_shadow_width(obj, 10, 0);
263 lv_obj_set_style_shadow_offset_x(obj, ofs[i].x, 0);
264 lv_obj_set_style_shadow_offset_y(obj, ofs[i].y, 0);
265 }
266
267 for(i = 0; i < 7; i++) {
268 lv_obj_t * obj = box_shadow_obj_create(parent, i, 3);
269 lv_obj_set_style_radius(obj, 5, 0);
270 lv_obj_set_style_shadow_width(obj, 10, 0);
271 lv_obj_set_style_shadow_spread(obj, 3, 0);
272 lv_obj_set_style_shadow_offset_x(obj, ofs[i].x, 0);
273 lv_obj_set_style_shadow_offset_y(obj, ofs[i].y, 0);
274 }
275 }
276
text_obj_create(lv_obj_t * parent,int32_t col,int32_t row)277 static lv_obj_t * text_obj_create(lv_obj_t * parent, int32_t col, int32_t row)
278 {
279
280 lv_obj_t * obj = lv_label_create(parent);
281 lv_obj_remove_style_all(obj);
282 lv_label_set_text(obj, "Hello LVGL! It should be a placeholder: ű. Looks good?");
283 lv_obj_set_style_opa(obj, opa_saved, 0);
284 add_to_cell(obj, col, row);
285
286 return obj;
287
288 }
289
text_cb(lv_obj_t * parent)290 static void text_cb(lv_obj_t * parent)
291 {
292 lv_obj_t * obj;
293
294 obj = text_obj_create(parent, 3, 0);
295
296 obj = text_obj_create(parent, 3, 1);
297 lv_obj_set_style_text_color(obj, lv_color_hex3(0xff0), 0);
298
299 obj = text_obj_create(parent, 3, 2);
300 lv_label_set_text_selection_start(obj, 12);
301 lv_label_set_text_selection_end(obj, 21);
302 lv_obj_set_style_bg_color(obj, lv_color_hex3(0x0ff), LV_PART_SELECTED);
303
304 obj = text_obj_create(parent, 3, 3);
305 lv_obj_set_style_text_decor(obj, LV_TEXT_DECOR_UNDERLINE, 0);
306
307 obj = text_obj_create(parent, 3, 4);
308 lv_obj_set_style_text_decor(obj, LV_TEXT_DECOR_STRIKETHROUGH, 0);
309
310 obj = text_obj_create(parent, 3, 5);
311 lv_obj_set_style_text_decor(obj, LV_TEXT_DECOR_UNDERLINE | LV_TEXT_DECOR_STRIKETHROUGH, 0);
312
313 }
314
image_obj_create(lv_obj_t * parent,int32_t col,int32_t row,bool recolor)315 static lv_obj_t * image_obj_create(lv_obj_t * parent, int32_t col, int32_t row, bool recolor)
316 {
317 lv_obj_t * obj = lv_image_create(parent);
318 lv_obj_remove_style_all(obj);
319 if(recolor) {
320 lv_obj_set_style_image_recolor_opa(obj, LV_OPA_50, 0);
321 lv_obj_set_style_image_recolor(obj, lv_color_hex3(0x0f0), 0);
322 }
323
324 lv_obj_set_style_opa(obj, opa_saved, 0);
325 add_to_cell(obj, col, row);
326
327 return obj;
328
329 }
330
image_core_cb(lv_obj_t * parent,bool recolor,uint32_t startAt)331 static void image_core_cb(lv_obj_t * parent, bool recolor, uint32_t startAt)
332 {
333 LV_IMAGE_DECLARE(img_render_lvgl_logo_xrgb8888);
334 LV_IMAGE_DECLARE(img_render_lvgl_logo_rgb888);
335 LV_IMAGE_DECLARE(img_render_lvgl_logo_rgb565);
336 LV_IMAGE_DECLARE(img_render_lvgl_logo_rgb565a8);
337 LV_IMAGE_DECLARE(img_render_lvgl_logo_argb8888);
338 LV_IMAGE_DECLARE(img_render_lvgl_logo_l8);
339 LV_IMAGE_DECLARE(img_render_lvgl_logo_i1);
340
341 const void * srcs[] = {
342 &img_render_lvgl_logo_argb8888,
343 &img_render_lvgl_logo_xrgb8888,
344 &img_render_lvgl_logo_rgb888,
345 &img_render_lvgl_logo_rgb565,
346 &img_render_lvgl_logo_rgb565a8,
347 &img_render_lvgl_logo_l8,
348 &img_render_lvgl_logo_i1,
349 };
350
351 const void * names[] = {
352 "ARGB\n8888",
353 "XRGB\n8888",
354 "RGB\n888",
355 "RGB\n565",
356 "RGB\n565A8",
357 "L8",
358 "I1",
359 };
360
361 uint32_t stopAt = startAt + LV_MIN(sizeof(srcs) / sizeof(void *) - startAt, 4);
362 uint32_t i;
363 for(i = startAt; i < stopAt; i++) {
364 lv_obj_t * obj;
365 uint32_t row = i - startAt;
366
367 obj = lv_label_create(parent);
368 lv_label_set_text(obj, names[i]);
369 add_to_cell(obj, 0, row * 2);
370
371 obj = image_obj_create(parent, 1, row * 2, recolor);
372 lv_image_set_src(obj, srcs[i]);
373
374 obj = image_obj_create(parent, 2, row * 2, recolor);
375 lv_image_set_src(obj, srcs[i]);
376 lv_image_set_rotation(obj, 300);
377 lv_image_set_pivot(obj, 0, 0);
378
379 obj = image_obj_create(parent, 3, row * 2, recolor);
380 lv_image_set_src(obj, srcs[i]);
381 lv_image_set_scale(obj, 400);
382 lv_image_set_pivot(obj, 0, 0);
383
384 obj = image_obj_create(parent, 4, row * 2, recolor);
385 lv_image_set_src(obj, srcs[i]);
386 lv_image_set_scale_x(obj, 400);
387 lv_image_set_pivot(obj, 0, 0);
388
389 obj = image_obj_create(parent, 5, row * 2, recolor);
390 lv_image_set_src(obj, srcs[i]);
391 lv_image_set_scale_y(obj, 400);
392 lv_image_set_pivot(obj, 0, 0);
393
394 obj = image_obj_create(parent, 6, row * 2, recolor);
395 lv_image_set_src(obj, srcs[i]);
396 lv_image_set_rotation(obj, 300);
397 lv_image_set_scale(obj, 400);
398 lv_image_set_pivot(obj, 0, 0);
399
400 obj = image_obj_create(parent, 7, row * 2, recolor);
401 lv_image_set_src(obj, srcs[i]);
402 lv_image_set_scale_y(obj, 400);
403 lv_image_set_rotation(obj, 300);
404 lv_image_set_pivot(obj, 0, 0);
405 }
406 }
407
image_normal_1_cb(lv_obj_t * parent)408 static void image_normal_1_cb(lv_obj_t * parent)
409 {
410 image_core_cb(parent, false, 0);
411 }
412
image_recolored_1_cb(lv_obj_t * parent)413 static void image_recolored_1_cb(lv_obj_t * parent)
414 {
415 image_core_cb(parent, true, 0);
416 }
417
image_normal_2_cb(lv_obj_t * parent)418 static void image_normal_2_cb(lv_obj_t * parent)
419 {
420 image_core_cb(parent, false, 4);
421 }
422
image_recolored_2_cb(lv_obj_t * parent)423 static void image_recolored_2_cb(lv_obj_t * parent)
424 {
425 image_core_cb(parent, true, 4);
426 }
427
line_obj_create(lv_obj_t * parent,int32_t col,int32_t row,lv_point_precise_t p[])428 static lv_obj_t * line_obj_create(lv_obj_t * parent, int32_t col, int32_t row, lv_point_precise_t p[])
429 {
430 lv_obj_t * obj = lv_line_create(parent);
431 lv_obj_remove_style_all(obj);
432 lv_line_set_points(obj, p, 2);
433 lv_obj_set_size(obj, DEF_WIDTH, DEF_HEIGHT);
434 lv_obj_set_style_line_color(obj, lv_color_hex3(0xff0), 0);
435 lv_obj_set_style_opa(obj, opa_saved, 0);
436 add_to_cell(obj, col, row);
437
438 return obj;
439 }
440
line_cb(lv_obj_t * parent)441 static void line_cb(lv_obj_t * parent)
442 {
443
444 static lv_point_precise_t points[][2] = {
445 {{5, DEF_HEIGHT / 2}, {DEF_WIDTH - 5, DEF_HEIGHT / 2}}, /* - */
446 {{5, DEF_HEIGHT / 2}, {DEF_WIDTH - 5, DEF_HEIGHT / 2 + 1}}, /* - */
447 {{5, DEF_HEIGHT / 2}, {DEF_WIDTH - 5, DEF_HEIGHT / 2 - 1}}, /* - */
448 {{DEF_WIDTH / 2, 5}, {DEF_WIDTH / 2, DEF_HEIGHT - 5}}, /* | */
449 {{DEF_WIDTH / 2, 5}, {DEF_WIDTH / 2 + 1, DEF_HEIGHT - 5}}, /* | */
450 {{DEF_WIDTH / 2, 5}, {DEF_WIDTH / 2 - 1, DEF_HEIGHT - 5}}, /* | */
451 {{5, 5}, {DEF_WIDTH - 5, DEF_HEIGHT - 5}}, /* \ */
452 {{DEF_WIDTH - 5, 5}, {5, DEF_HEIGHT - 5}}, /* / */
453 };
454
455 int32_t widths[] = {1, 3, 5, 10};
456
457 uint32_t r;
458 for(r = 0; r < 2; r++) {
459 uint32_t w;
460 for(w = 0; w < 4; w++) {
461 uint32_t i;
462 for(i = 0; i < COL_CNT; i++) {
463 lv_obj_t * obj = line_obj_create(parent, i, w + 4 * r, points[i]);
464 lv_obj_set_style_line_width(obj, widths[w], 0);
465 lv_obj_set_style_line_rounded(obj, r, 0);
466 }
467 }
468 }
469 }
470
arc_obj_create(lv_obj_t * parent,int32_t col,int32_t row,int32_t w,lv_value_precise_t start,lv_value_precise_t end)471 static lv_obj_t * arc_obj_create(lv_obj_t * parent, int32_t col, int32_t row, int32_t w,
472 lv_value_precise_t start, lv_value_precise_t end)
473 {
474 lv_obj_t * obj = lv_arc_create(parent);
475 lv_obj_remove_style_all(obj);
476 lv_obj_set_style_arc_width(obj, w, 0);
477 lv_obj_set_style_arc_color(obj, lv_color_white(), 0);
478 lv_obj_set_style_opa(obj, opa_saved, 0);
479 lv_arc_set_bg_angles(obj, start, end);
480 lv_obj_set_size(obj, DEF_HEIGHT, DEF_HEIGHT);
481 lv_obj_set_style_line_color(obj, lv_color_hex3(0xff0), 0);
482 add_to_cell(obj, col, row);
483
484 return obj;
485 }
486
arc_core_cb(lv_obj_t * parent,const void * img_src)487 static void arc_core_cb(lv_obj_t * parent, const void * img_src)
488 {
489 static lv_value_precise_t angles[][2] = {
490 {355, 5},
491 {85, 95},
492 {175, 185},
493 {265, 275},
494 {30, 330},
495 {120, 60},
496 {0, 180},
497 {0, 360},
498 };
499
500 int32_t widths[] = {1, 5, 10, 100};
501
502 uint32_t r;
503 for(r = 0; r < 2; r++) {
504 uint32_t w;
505 for(w = 0; w < 4; w++) {
506 uint32_t i;
507 for(i = 0; i < COL_CNT; i++) {
508 lv_obj_t * obj = arc_obj_create(parent, i, w + 4 * r, widths[w], angles[i][0], angles[i][1]);
509 lv_obj_set_style_arc_rounded(obj, r, 0);
510 lv_obj_set_style_arc_image_src(obj, img_src, 0);
511 }
512 }
513 }
514 }
515
arc_normal_cb(lv_obj_t * parent)516 static void arc_normal_cb(lv_obj_t * parent)
517 {
518 arc_core_cb(parent, NULL);
519 }
520
arc_image_cb(lv_obj_t * parent)521 static void arc_image_cb(lv_obj_t * parent)
522 {
523 LV_IMAGE_DECLARE(img_render_arc_bg);
524 arc_core_cb(parent, &img_render_arc_bg);
525 }
526
triangle_draw_event_cb(lv_event_t * e)527 static void triangle_draw_event_cb(lv_event_t * e)
528 {
529 lv_draw_triangle_dsc_t dsc;
530 lv_draw_triangle_dsc_init(&dsc);
531
532 lv_obj_t * obj = lv_event_get_target(e);
533
534 lv_point_t * p_rel = lv_event_get_user_data(e);
535
536 lv_area_t coords;
537 lv_obj_get_coords(obj, &coords);
538 dsc.p[0].x = p_rel[0].x + coords.x1 + 8;
539 dsc.p[0].y = p_rel[0].y + coords.y1 + 2;
540 dsc.p[1].x = p_rel[1].x + coords.x1 + 8;
541 dsc.p[1].y = p_rel[1].y + coords.y1 + 2;
542 dsc.p[2].x = p_rel[2].x + coords.x1 + 8;
543 dsc.p[2].y = p_rel[2].y + coords.y1 + 2;
544
545 lv_opa_t opa = lv_obj_get_style_opa(obj, 0);
546 dsc.bg_grad.dir = lv_obj_get_style_bg_grad_dir(obj, 0);
547 dsc.bg_grad.stops[0].color = lv_obj_get_style_bg_color(obj, 0);
548 dsc.bg_grad.stops[0].frac = lv_obj_get_style_bg_main_stop(obj, 0);
549 dsc.bg_grad.stops[0].opa = LV_OPA_MIX2(lv_obj_get_style_bg_main_opa(obj, 0), opa);
550 dsc.bg_grad.stops[1].color = lv_obj_get_style_bg_grad_color(obj, 0);
551 dsc.bg_grad.stops[1].frac = lv_obj_get_style_bg_grad_stop(obj, 0);
552 dsc.bg_grad.stops[1].opa = LV_OPA_MIX2(lv_obj_get_style_bg_grad_opa(obj, 0), opa);
553 dsc.bg_grad.stops_count = 2;
554
555 dsc.bg_color = dsc.bg_grad.stops[0].color;
556 dsc.bg_opa = dsc.bg_grad.stops[0].opa;
557
558 lv_draw_triangle(lv_event_get_layer(e), &dsc);
559 }
560
triangle_obj_create(lv_obj_t * parent,int32_t col,int32_t row,lv_point_t p[])561 static lv_obj_t * triangle_obj_create(lv_obj_t * parent, int32_t col, int32_t row, lv_point_t p[])
562 {
563 lv_obj_t * obj = lv_arc_create(parent);
564 lv_obj_remove_style_all(obj);
565 lv_obj_set_size(obj, DEF_WIDTH, DEF_HEIGHT);
566 lv_obj_set_style_bg_color(obj, lv_color_hex3(0xff0), 0);
567 lv_obj_set_style_opa(obj, opa_saved, 0);
568 lv_obj_add_event_cb(obj, triangle_draw_event_cb, LV_EVENT_DRAW_MAIN, p);
569 add_to_cell(obj, col, row);
570
571 return obj;
572 }
573
triangle_cb(lv_obj_t * parent)574 static void triangle_cb(lv_obj_t * parent)
575 {
576 static lv_point_t points[16][3] = {
577
578 /*Right angle triangles*/
579 {{0, 0}, {0, 26}, {26, 26}}, /* |\ */
580 {{0, 26}, {26, 0}, {26, 26}}, /* /| */
581 {{0, 0}, {26, 0}, {26, 26}}, /* \| */
582 {{0, 0}, {0, 26}, {26, 0}}, /* |/ */
583
584 /*One side vertical or horizontal triangles*/
585 {{0, 0}, {26, 0}, {13, 26}}, /* \/ */
586 {{0, 26}, {26, 26}, {13, 0 }}, /* /\ */
587 {{0, 0}, {0, 26}, {26, 13}}, /* > */
588 {{0, 13}, {26, 0}, {26, 26}}, /* < */
589
590 /*Thin triangles*/
591 {{0, 0}, {26, 26}, {13, 18}}, /* \ */
592 {{0, 0}, {26, 26}, {13, 8}}, /* \ */
593 {{26, 0}, {0, 26}, {13, 18}}, /* / */
594 {{26, 0}, {0, 26}, {13, 8}}, /* / */
595
596 /*General triangles with various point orders*/
597 {{0, 1}, {26, 6}, {13, 26}}, /*ABC*/
598 {{0, 1}, {13, 26}, {26, 6}}, /*ACB*/
599 {{26, 6}, {0, 1}, {13, 26}}, /*BAC*/
600 {{13, 26}, {26, 6}, {0, 1}}, /*CBA*/
601 };
602
603 uint32_t i;
604 for(i = 0; i < 16; i++) {
605 triangle_obj_create(parent, i % 8, i / 8, points[i]);
606 }
607
608 for(i = 0; i < 16; i++) {
609 lv_obj_t * obj = triangle_obj_create(parent, i % 8, 2 + i / 8, points[i]);
610 lv_obj_set_style_bg_grad_color(obj, lv_color_hex3(0xf00), 0);
611 lv_obj_set_style_bg_grad_dir(obj, LV_GRAD_DIR_VER, 0);
612 }
613
614 for(i = 0; i < 16; i++) {
615 lv_obj_t * obj = triangle_obj_create(parent, i % 8, 4 + i / 8, points[i]);
616 lv_obj_set_style_bg_grad_color(obj, lv_color_hex3(0xf00), 0);
617 lv_obj_set_style_bg_grad_dir(obj, LV_GRAD_DIR_HOR, 0);
618 }
619
620 for(i = 0; i < 8; i++) {
621 lv_obj_t * obj = triangle_obj_create(parent, i % 8, 6 + i / 8, points[i]);
622 lv_obj_set_style_bg_grad_color(obj, lv_color_hex3(0xf00), 0);
623 lv_obj_set_style_bg_grad_dir(obj, LV_GRAD_DIR_VER, 0);
624 lv_obj_set_style_bg_grad_opa(obj, LV_OPA_TRANSP, 0);
625 }
626
627 for(i = 0; i < 8; i++) {
628 lv_obj_t * obj = triangle_obj_create(parent, i % 8, 7 + i / 8, points[i]);
629 lv_obj_set_style_bg_grad_color(obj, lv_color_hex3(0xf00), 0);
630 lv_obj_set_style_bg_grad_dir(obj, LV_GRAD_DIR_HOR, 0);
631 lv_obj_set_style_bg_grad_opa(obj, LV_OPA_TRANSP, 0);
632 }
633 }
634
layer_obj_create(lv_obj_t * parent,int32_t col,int32_t row,lv_blend_mode_t blend_mode)635 static lv_obj_t * layer_obj_create(lv_obj_t * parent, int32_t col, int32_t row, lv_blend_mode_t blend_mode)
636 {
637 lv_obj_t * obj = lv_obj_create(parent);
638 lv_obj_remove_style_all(obj);
639 lv_obj_set_size(obj, DEF_WIDTH - 10, DEF_HEIGHT);
640 lv_obj_set_style_bg_opa(obj, LV_OPA_COVER, 0);
641 lv_obj_set_style_bg_color(obj, lv_color_hex3(0xff0), 0);
642 lv_obj_set_style_bg_grad_color(obj, lv_color_hex3(0xf00), 0);
643 lv_obj_set_style_bg_grad_dir(obj, LV_GRAD_DIR_VER, 0);
644 lv_obj_set_style_border_width(obj, 3, 0);
645 lv_obj_set_style_border_color(obj, lv_color_hex3(0x000), 0);
646 lv_obj_set_style_transform_pivot_x(obj, 0, 0);
647 lv_obj_set_style_transform_pivot_y(obj, 0, 0);
648 lv_obj_set_style_blend_mode(obj, blend_mode, 0);
649 lv_obj_set_style_opa(obj, opa_saved, 0);
650 add_to_cell(obj, col, row);
651
652 lv_obj_t * label = lv_label_create(obj);
653 lv_label_set_text(label, "ABC");
654 lv_obj_center(label);
655
656 return obj;
657 }
658
layer_core_cb(lv_obj_t * parent,lv_blend_mode_t blend_mode)659 static void layer_core_cb(lv_obj_t * parent, lv_blend_mode_t blend_mode)
660 {
661
662 uint32_t i;
663 for(i = 0; i < 2; i++) {
664 int32_t row = 4 * i;
665 lv_obj_t * obj;
666
667 obj = layer_obj_create(parent, 0, row, blend_mode);
668 lv_obj_set_style_radius(obj, 8 * i, 0);
669
670 obj = layer_obj_create(parent, 1, row, blend_mode);
671 lv_obj_set_style_transform_rotation(obj, 300, 0);
672 lv_obj_set_style_translate_x(obj, 10, 0);
673 lv_obj_set_style_radius(obj, 8 * i, 0);
674
675 obj = layer_obj_create(parent, 2, row, blend_mode);
676 lv_obj_set_style_transform_scale(obj, 400, 0);
677 lv_obj_set_style_radius(obj, 8 * i, 0);
678
679 obj = layer_obj_create(parent, 4, row, blend_mode);
680 lv_obj_set_style_transform_rotation(obj, 300, 0);
681 lv_obj_set_style_transform_scale(obj, 400, 0);
682 lv_obj_set_style_radius(obj, 8 * i, 0);
683
684 obj = layer_obj_create(parent, 5, row, blend_mode);
685 lv_obj_set_style_transform_scale_x(obj, 400, 0);
686 lv_obj_set_style_radius(obj, 8 * i, 0);
687
688 obj = layer_obj_create(parent, 7, row, blend_mode);
689 lv_obj_set_style_transform_scale_y(obj, 400, 0);
690 lv_obj_set_style_radius(obj, 8 * i, 0);
691
692 obj = layer_obj_create(parent, 0, row + 2, blend_mode);
693 lv_obj_set_style_transform_rotation(obj, 300, 0);
694 lv_obj_set_style_transform_scale_x(obj, 400, 0);
695 lv_obj_set_style_translate_x(obj, 10, 0);
696 lv_obj_set_style_radius(obj, 8 * i, 0);
697
698 obj = layer_obj_create(parent, 2, row + 2, blend_mode);
699 lv_obj_set_style_transform_rotation(obj, 300, 0);
700 lv_obj_set_style_transform_scale_y(obj, 400, 0);
701 lv_obj_set_style_radius(obj, 8 * i, 0);
702
703 obj = layer_obj_create(parent, 5, row + 2, blend_mode);
704 lv_obj_set_style_opa_layered(obj, LV_OPA_50, 0);
705 lv_obj_set_style_translate_y(obj, 10, 0);
706 lv_obj_set_style_radius(obj, 8 * i, 0);
707
708 obj = layer_obj_create(parent, 7, row + 2, blend_mode);
709 lv_obj_set_style_opa_layered(obj, LV_OPA_50, 0);
710 lv_obj_set_style_transform_rotation(obj, 300, 0);
711 lv_obj_set_style_translate_y(obj, 10, 0);
712 lv_obj_set_style_radius(obj, 8 * i, 0);
713 }
714 }
715
layer_normal_cb(lv_obj_t * parent)716 static void layer_normal_cb(lv_obj_t * parent)
717 {
718 layer_core_cb(parent, LV_BLEND_MODE_NORMAL);
719 }
720
create_blend_mode_image_buffer(lv_obj_t * canvas)721 static void create_blend_mode_image_buffer(lv_obj_t * canvas)
722 {
723 lv_canvas_fill_bg(canvas, lv_color_hex3(0x844), LV_OPA_COVER);
724
725 lv_layer_t layer;
726 lv_canvas_init_layer(canvas, &layer);
727
728 lv_draw_label_dsc_t dsc;
729 lv_draw_label_dsc_init(&dsc);
730 dsc.color = lv_color_hex(0xff0000);
731 dsc.text = "R";
732
733 lv_area_t coords = {0, 0, 100, 60};
734
735 lv_draw_label(&layer, &dsc, &coords);
736 dsc.color = lv_color_hex(0x00ff00);
737 dsc.text = "G";
738 coords.x1 = 11;
739 lv_draw_label(&layer, &dsc, &coords);
740
741 dsc.color = lv_color_hex(0x0000ff);
742 dsc.text = "B";
743 coords.x1 = 23;
744 lv_draw_label(&layer, &dsc, &coords);
745
746 dsc.color = lv_color_hex(0xffffff);
747 dsc.text = "W";
748 coords.y1 = 14;
749 coords.x1 = 4;
750 lv_draw_label(&layer, &dsc, &coords);
751
752 dsc.color = lv_color_hex(0x000000);
753 dsc.text = "K";
754 coords.x1 = 20;
755 lv_draw_label(&layer, &dsc, &coords);
756
757 lv_canvas_finish_layer(canvas, &layer);
758 }
759
create_blend_mode_obj(lv_obj_t * parent,int32_t col,int32_t row,const void * src,lv_blend_mode_t blend_mode)760 static lv_obj_t * create_blend_mode_obj(lv_obj_t * parent, int32_t col, int32_t row, const void * src,
761 lv_blend_mode_t blend_mode)
762 {
763 lv_obj_t * obj = lv_image_create(parent);
764 lv_image_set_src(obj, src);
765 lv_image_set_blend_mode(obj, blend_mode);
766 lv_obj_set_style_image_opa(obj, opa_saved, 0);
767 lv_obj_set_style_image_recolor(obj, lv_color_hex(0x00ff00), 0);
768
769 add_to_cell(obj, col, row);
770
771 return obj;
772 }
773
canvas_draw_buf_reshape(lv_draw_buf_t * draw_buf)774 static void canvas_draw_buf_reshape(lv_draw_buf_t * draw_buf)
775 {
776 #if LV_USE_DRAW_VG_LITE
777 /* VG-Lite requires automatic stride calculation */
778 lv_draw_buf_t * buf = lv_draw_buf_reshape(draw_buf,
779 draw_buf->header.cf,
780 draw_buf->header.w,
781 draw_buf->header.h,
782 LV_STRIDE_AUTO);
783 LV_ASSERT_MSG(buf == draw_buf, "Reshape failed");
784 #else
785 LV_UNUSED(draw_buf);
786 #endif
787 }
788
blend_mode_cb(lv_obj_t * parent)789 static void blend_mode_cb(lv_obj_t * parent)
790 {
791
792 static const int32_t grid_cols[] = {53, 53, 53, 53, 53, 53, 53, 53, 53, LV_GRID_TEMPLATE_LAST};
793 static const int32_t grid_rows[] = {32, 40, 40, 40, 40, 40, 40, LV_GRID_TEMPLATE_LAST};
794 lv_obj_set_grid_dsc_array(parent, grid_cols, grid_rows);
795
796 /*Make the parent darker for additive blending*/
797 lv_obj_set_style_bg_color(parent, lv_color_hex(0x808080), 0);
798
799 LV_DRAW_BUF_DEFINE_STATIC(buf_rgb565, 36, 30, LV_COLOR_FORMAT_RGB565);
800 LV_DRAW_BUF_DEFINE_STATIC(buf_rgb888, 36, 30, LV_COLOR_FORMAT_RGB888);
801 LV_DRAW_BUF_DEFINE_STATIC(buf_xrgb8888, 36, 30, LV_COLOR_FORMAT_XRGB8888);
802 LV_DRAW_BUF_DEFINE_STATIC(buf_argb8888, 36, 30, LV_COLOR_FORMAT_ARGB8888);
803
804 /*The canvas will stay in the top left corner to show the original image*/
805 lv_obj_t * canvas = lv_canvas_create(lv_screen_active());
806
807 const char * cf_txt[] = {"RGB565", "RGB888.", "XRGB8888", "ARGB8888"};
808 lv_draw_buf_t * cf_bufs[] = {&buf_rgb565, &buf_rgb888, &buf_xrgb8888, &buf_argb8888};
809 static lv_draw_buf_t image_dscs[4];
810
811 const char * mode_txt[] = {"Add.", "Sub.", "Mul."};
812 lv_blend_mode_t mode_values[] = {LV_BLEND_MODE_ADDITIVE, LV_BLEND_MODE_SUBTRACTIVE, LV_BLEND_MODE_MULTIPLY};
813
814 uint32_t m;
815 for(m = 0; m < 3; m++) {
816 lv_obj_t * mode_label = lv_label_create(parent);
817 lv_label_set_text(mode_label, mode_txt[m]);
818 lv_obj_set_grid_cell(mode_label, LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 1 + m * 2, 2);
819 }
820
821 uint32_t cf;
822 for(cf = 0; cf < 4; cf++) {
823 lv_obj_t * cf_label = lv_label_create(parent);
824 lv_label_set_text(cf_label, cf_txt[cf]);
825 lv_obj_set_grid_cell(cf_label, LV_GRID_ALIGN_CENTER, 1 + cf * 2, 2, LV_GRID_ALIGN_CENTER, 0, 1);
826
827 canvas_draw_buf_reshape(cf_bufs[cf]);
828 lv_canvas_set_draw_buf(canvas, cf_bufs[cf]);
829 create_blend_mode_image_buffer(canvas);
830 lv_draw_buf_t * img_src = lv_canvas_get_draw_buf(canvas);
831 image_dscs[cf] = *img_src;
832
833 for(m = 0; m < 3; m++) {
834 lv_obj_t * img;
835 img = create_blend_mode_obj(parent, 1 + cf * 2, 1 + m * 2, &image_dscs[cf], mode_values[m]);
836
837 img = create_blend_mode_obj(parent, 2 + cf * 2, 1 + m * 2, &image_dscs[cf], mode_values[m]);
838 lv_image_set_rotation(img, 200);
839
840 img = create_blend_mode_obj(parent, 1 + cf * 2, 2 + m * 2, &image_dscs[cf], mode_values[m]);
841 lv_obj_set_style_image_recolor_opa(img, LV_OPA_50, 0);
842
843 img = create_blend_mode_obj(parent, 2 + cf * 2, 2 + m * 2, &image_dscs[cf], mode_values[m]);
844 lv_image_set_rotation(img, 200);
845 lv_obj_set_style_image_recolor_opa(img, LV_OPA_50, 0);
846 }
847 }
848
849 /*Show the recolored image to show the original image*/
850 lv_obj_t * img_recolored = lv_image_create(parent);
851 lv_image_set_src(img_recolored, lv_canvas_get_image(canvas));
852 lv_obj_set_style_image_recolor(img_recolored, lv_color_hex(0x00ff00), 0);
853 lv_obj_set_style_image_recolor_opa(img_recolored, LV_OPA_50, 0);
854 lv_obj_set_y(img_recolored, 30);
855 lv_obj_add_flag(img_recolored, LV_OBJ_FLAG_IGNORE_LAYOUT);
856
857 }
858
859 #if LV_USE_DRAW_SW_COMPLEX_GRADIENTS
860
create_linear_gradient_obj(lv_obj_t * parent,int32_t col,int32_t row,lv_grad_dsc_t * grad,int32_t x1,int32_t y1,lv_grad_extend_t extend,bool use_opa_map,int32_t radius)861 static lv_obj_t * create_linear_gradient_obj(lv_obj_t * parent, int32_t col, int32_t row, lv_grad_dsc_t * grad,
862 int32_t x1, int32_t y1, lv_grad_extend_t extend, bool use_opa_map, int32_t radius)
863 {
864 const lv_color_t grad_color[2] = {
865 LV_COLOR_MAKE(0xd5, 0x03, 0x47),
866 LV_COLOR_MAKE(0x00, 0x00, 0x00),
867 };
868
869 const lv_opa_t grad_opa[2] = {
870 LV_OPA_100, LV_OPA_0,
871 };
872
873 /*init gradient color map*/
874 lv_gradient_init_stops(grad, grad_color, use_opa_map ? grad_opa : NULL, NULL, sizeof(grad_color) / sizeof(lv_color_t));
875
876 /*init gradient parameters*/
877 grad->dir = LV_GRAD_DIR_LINEAR;
878 grad->params.linear.start.x = 0; /*vector start x position*/
879 grad->params.linear.start.y = 0; /*vector start y position*/
880 grad->params.linear.end.x = x1; /*vector end x position*/
881 grad->params.linear.end.y = y1; /*vector end y position*/
882 grad->extend = extend; /*color pattern outside the vector*/
883
884 /*create rectangle*/
885 lv_obj_t * obj = lv_obj_create(parent);
886 lv_obj_remove_style_all(obj);
887 lv_obj_set_size(obj, 70, 50);
888 lv_obj_set_style_radius(obj, radius, 0);
889 lv_obj_set_style_bg_opa(obj, LV_OPA_COVER, 0);
890 lv_obj_set_style_opa(obj, opa_saved, 0);
891
892 /*set gradient as background*/
893 lv_obj_set_style_bg_grad(obj, grad, 0);
894
895 add_to_cell(obj, col, row);
896
897 return obj;
898 }
899
linear_gradient_cb(lv_obj_t * parent)900 static void linear_gradient_cb(lv_obj_t * parent)
901 {
902 static const int32_t grid_cols[] = { 53, 53, 53, 53, 53, 53, 53, 53, 53, LV_GRID_TEMPLATE_LAST };
903 static const int32_t grid_rows[] = { 32, 40, 40, 40, 40, 40, 40, LV_GRID_TEMPLATE_LAST };
904 lv_obj_set_grid_dsc_array(parent, grid_cols, grid_rows);
905
906 const char * opa_txt[] = { "no opa", "no opa round", "stop opa", "stop opa round" };
907 int32_t radius_values[] = { 0, 20, 0, 20 };
908 bool opa_map_values[] = { false, false, true, true };
909
910 const char * offs_txt[] = { "pad", "repeat", "reflect" };
911 int32_t x1_values[] = { lv_pct(100), lv_pct(15), lv_pct(30)};
912 int32_t y1_values[] = { lv_pct(100), lv_pct(30), lv_pct(15) };
913 lv_grad_extend_t extend_values[] = { LV_GRAD_EXTEND_PAD, LV_GRAD_EXTEND_REPEAT, LV_GRAD_EXTEND_REFLECT };
914
915 static lv_grad_dsc_t grad_values[3][4];
916
917 uint32_t y;
918 for(y = 0; y < 3; y++) {
919 lv_obj_t * offs_label = lv_label_create(parent);
920 lv_label_set_text(offs_label, offs_txt[y]);
921 lv_obj_set_grid_cell(offs_label, LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 1 + y * 2, 2);
922 }
923
924 uint32_t x;
925 for(x = 0; x < 4; x++) {
926 lv_obj_t * op_label = lv_label_create(parent);
927 lv_label_set_text(op_label, opa_txt[x]);
928 lv_obj_set_grid_cell(op_label, LV_GRID_ALIGN_CENTER, 1 + x * 2, 2, LV_GRID_ALIGN_CENTER, 0, 1);
929
930 for(y = 0; y < 3; y++) {
931 create_linear_gradient_obj(parent, 1 + x * 2, 1 + y * 2, &grad_values[y][x], x1_values[y], y1_values[y],
932 extend_values[y], opa_map_values[x], radius_values[x]);
933 }
934 }
935 }
936
create_radial_gradient_obj(lv_obj_t * parent,int32_t col,int32_t row,lv_grad_dsc_t * grad,int32_t offs,int32_t r0,lv_grad_extend_t extend,bool use_opa_map,int32_t radius)937 static lv_obj_t * create_radial_gradient_obj(lv_obj_t * parent, int32_t col, int32_t row, lv_grad_dsc_t * grad,
938 int32_t offs, int32_t r0, lv_grad_extend_t extend, bool use_opa_map, int32_t radius)
939 {
940 const lv_color_t grad_color[2] = {
941 LV_COLOR_MAKE(0xd5, 0x03, 0x47),
942 LV_COLOR_MAKE(0x00, 0x00, 0x00),
943 };
944
945 const lv_opa_t grad_opa[2] = {
946 LV_OPA_100, LV_OPA_0,
947 };
948
949 /*init gradient color map*/
950 lv_gradient_init_stops(grad, grad_color, use_opa_map ? grad_opa : NULL, NULL, sizeof(grad_color) / sizeof(lv_color_t));
951
952 /*init gradient parameters*/
953 grad->dir = LV_GRAD_DIR_RADIAL;
954 grad->params.radial.focal.x = lv_pct(50); /*start circle center x position*/
955 grad->params.radial.focal.y = lv_pct(50); /*start circle center y position*/
956 grad->params.radial.focal_extent.x = grad->params.radial.focal.x + r0; /*start circle point x coordinate*/
957 grad->params.radial.focal_extent.y = grad->params.radial.focal.y; /*start circle point y coordinate*/
958 grad->params.radial.end.x = grad->params.radial.focal.x + offs; /*end circle center x position*/
959 grad->params.radial.end.y = grad->params.radial.focal.y + offs; /*end circle center y position*/
960 grad->params.radial.end_extent.x = grad->params.radial.end.x; /*end circle point x coordinate*/
961 grad->params.radial.end_extent.y = lv_pct(85); /*end circle point y coordinate*/
962 grad->extend = extend; /*color pattern outside the border circles*/
963
964 /*create rectangle*/
965 lv_obj_t * obj = lv_obj_create(parent);
966 lv_obj_remove_style_all(obj);
967 lv_obj_set_size(obj, 70, 50);
968 lv_obj_set_style_radius(obj, radius, 0);
969 lv_obj_set_style_bg_opa(obj, LV_OPA_COVER, 0);
970 lv_obj_set_style_opa(obj, opa_saved, 0);
971
972 /*set gradient as background*/
973 lv_obj_set_style_bg_grad(obj, grad, 0);
974
975 add_to_cell(obj, col, row);
976
977 return obj;
978 }
979
radial_gradient_cb(lv_obj_t * parent)980 static void radial_gradient_cb(lv_obj_t * parent)
981 {
982 static const int32_t grid_cols[] = { 53, 53, 53, 53, 53, 53, 53, 53, 53, LV_GRID_TEMPLATE_LAST };
983 static const int32_t grid_rows[] = { 32, 40, 40, 40, 40, 40, 40, LV_GRID_TEMPLATE_LAST };
984 lv_obj_set_grid_dsc_array(parent, grid_cols, grid_rows);
985
986 const char * opa_txt[] = { "no opa", "no opa round", "stop opa", "stop opa round" };
987 int32_t radius_values[] = { 0, 20, 0, 20 };
988 bool opa_map_values[] = { false, false, true, true };
989
990 const char * offs_txt[] = { "pad", "repeat", "reflect" };
991 lv_grad_extend_t extend_values[] = { LV_GRAD_EXTEND_PAD, LV_GRAD_EXTEND_REPEAT, LV_GRAD_EXTEND_REFLECT};
992
993 static lv_grad_dsc_t grad_values[3][4];
994
995 uint32_t y;
996 for(y = 0; y < 3; y++) {
997 lv_obj_t * offs_label = lv_label_create(parent);
998 lv_label_set_text(offs_label, offs_txt[y]);
999 lv_obj_set_grid_cell(offs_label, LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 1 + y * 2, 2);
1000 }
1001
1002 uint32_t x;
1003 for(x = 0; x < 4; x++) {
1004 lv_obj_t * op_label = lv_label_create(parent);
1005 lv_label_set_text(op_label, opa_txt[x]);
1006 lv_obj_set_grid_cell(op_label, LV_GRID_ALIGN_CENTER, 1 + x * 2, 2, LV_GRID_ALIGN_CENTER, 0, 1);
1007
1008 for(y = 0; y < 3; y++) {
1009 create_radial_gradient_obj(parent, 1 + x * 2, 1 + y * 2, &grad_values[y][x], y * 5, 0, extend_values[y],
1010 opa_map_values[x], radius_values[x]);
1011 }
1012 }
1013 }
1014
create_conical_gradient_obj(lv_obj_t * parent,int32_t col,int32_t row,lv_grad_dsc_t * grad,int32_t a0,int32_t a1,lv_grad_extend_t extend,bool use_opa_map,int32_t radius)1015 static lv_obj_t * create_conical_gradient_obj(lv_obj_t * parent, int32_t col, int32_t row, lv_grad_dsc_t * grad,
1016 int32_t a0, int32_t a1, lv_grad_extend_t extend, bool use_opa_map, int32_t radius)
1017 {
1018 const lv_color_t grad_color[2] = {
1019 LV_COLOR_MAKE(0xd5, 0x03, 0x47),
1020 LV_COLOR_MAKE(0x00, 0x00, 0x00),
1021 };
1022
1023 const lv_opa_t grad_opa[2] = {
1024 LV_OPA_100, LV_OPA_0,
1025 };
1026
1027 /*init gradient color map*/
1028 lv_gradient_init_stops(grad, grad_color, use_opa_map ? grad_opa : NULL, NULL, sizeof(grad_color) / sizeof(lv_color_t));
1029
1030 /*init gradient parameters*/
1031 grad->dir = LV_GRAD_DIR_CONICAL;
1032 grad->params.conical.center.x = lv_pct(50); /*center x position*/
1033 grad->params.conical.center.y = lv_pct(50); /*center y position*/
1034 grad->params.conical.start_angle = a0; /*start angle*/
1035 grad->params.conical.end_angle = a1; /*end angle*/
1036 grad->extend = extend; /*color pattern outside the vector*/
1037
1038 /*create rectangle*/
1039 lv_obj_t * obj = lv_obj_create(parent);
1040 lv_obj_remove_style_all(obj);
1041 lv_obj_set_size(obj, 70, 50);
1042 lv_obj_set_style_radius(obj, radius, 0);
1043 lv_obj_set_style_bg_opa(obj, LV_OPA_COVER, 0);
1044 lv_obj_set_style_opa(obj, opa_saved, 0);
1045
1046 /*set gradient as background*/
1047 lv_obj_set_style_bg_grad(obj, grad, 0);
1048
1049 add_to_cell(obj, col, row);
1050
1051 return obj;
1052 }
1053
conical_gradient_cb(lv_obj_t * parent)1054 static void conical_gradient_cb(lv_obj_t * parent)
1055 {
1056 static const int32_t grid_cols[] = { 53, 53, 53, 53, 53, 53, 53, 53, 53, LV_GRID_TEMPLATE_LAST };
1057 static const int32_t grid_rows[] = { 32, 40, 40, 40, 40, 40, 40, LV_GRID_TEMPLATE_LAST };
1058 lv_obj_set_grid_dsc_array(parent, grid_cols, grid_rows);
1059
1060 const char * opa_txt[] = { "no opa", "no opa round", "stop opa", "stop opa round" };
1061 int32_t radius_values[] = { 0, 20, 0, 20 };
1062 bool opa_map_values[] = { false, false, true, true };
1063
1064 const char * offs_txt[] = { "pad", "repeat", "reflect" };
1065 lv_grad_extend_t extend_values[] = { LV_GRAD_EXTEND_PAD, LV_GRAD_EXTEND_REPEAT, LV_GRAD_EXTEND_REFLECT };
1066
1067 static lv_grad_dsc_t grad_values[3][4];
1068
1069 uint32_t y;
1070 for(y = 0; y < 3; y++) {
1071 lv_obj_t * offs_label = lv_label_create(parent);
1072 lv_label_set_text(offs_label, offs_txt[y]);
1073 lv_obj_set_grid_cell(offs_label, LV_GRID_ALIGN_CENTER, 0, 1, LV_GRID_ALIGN_CENTER, 1 + y * 2, 2);
1074 }
1075
1076 uint32_t x;
1077 for(x = 0; x < 4; x++) {
1078 lv_obj_t * op_label = lv_label_create(parent);
1079 lv_label_set_text(op_label, opa_txt[x]);
1080 lv_obj_set_grid_cell(op_label, LV_GRID_ALIGN_CENTER, 1 + x * 2, 2, LV_GRID_ALIGN_CENTER, 0, 1);
1081
1082 for(y = 0; y < 3; y++) {
1083 create_conical_gradient_obj(parent, 1 + x * 2, 1 + y * 2, &grad_values[y][x], 10, 100, extend_values[y],
1084 opa_map_values[x], radius_values[x]);
1085 }
1086 }
1087 }
1088
1089 #endif
1090
1091 /**********************
1092 * STATIC VARIABLES
1093 **********************/
1094
1095 static scene_dsc_t scenes[] = {
1096 {.name = "fill", .create_cb = fill_cb},
1097 {.name = "border", .create_cb = border_cb},
1098 {.name = "box_shadow", .create_cb = box_shadow_cb},
1099 {.name = "text", .create_cb = text_cb},
1100 {.name = "image_normal_1", .create_cb = image_normal_1_cb},
1101 {.name = "image_recolor_1", .create_cb = image_recolored_1_cb},
1102 {.name = "image_normal_2", .create_cb = image_normal_2_cb},
1103 {.name = "image_recolor_2", .create_cb = image_recolored_2_cb},
1104 {.name = "line", .create_cb = line_cb},
1105 {.name = "arc_normal", .create_cb = arc_normal_cb},
1106 {.name = "arc_image", .create_cb = arc_image_cb},
1107 {.name = "triangle", .create_cb = triangle_cb},
1108 {.name = "layer_normal", .create_cb = layer_normal_cb},
1109 {.name = "blend_mode", .create_cb = blend_mode_cb},
1110
1111 #if LV_USE_DRAW_SW_COMPLEX_GRADIENTS
1112 {.name = "linear_gradient", .create_cb = linear_gradient_cb},
1113 {.name = "radial_gradient", .create_cb = radial_gradient_cb},
1114 {.name = "conical_gradient", .create_cb = conical_gradient_cb},
1115 #endif
1116
1117 {.name = "", .create_cb = NULL}
1118 };
1119
1120 /**********************
1121 * MACROS
1122 **********************/
1123
1124 /**********************
1125 * GLOBAL FUNCTIONS
1126 **********************/
1127
lv_demo_render(lv_demo_render_scene_t id,lv_opa_t opa)1128 void lv_demo_render(lv_demo_render_scene_t id, lv_opa_t opa)
1129 {
1130 lv_obj_t * scr = lv_screen_active();
1131 lv_obj_clean(scr);
1132 lv_obj_remove_style_all(scr);
1133 lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, 0);
1134 lv_obj_set_style_text_color(scr, lv_color_black(), 0);
1135 lv_obj_set_style_bg_color(scr, lv_color_white(), 0);
1136
1137 lv_obj_t * main_parent = lv_obj_create(scr);
1138 lv_obj_remove_style_all(main_parent);
1139 lv_obj_set_style_bg_opa(main_parent, LV_OPA_COVER, 0);
1140 lv_obj_set_style_bg_color(main_parent, lv_color_hex3(0xaaf), 0);
1141 lv_obj_set_size(main_parent, 480, 272);
1142
1143 static const int32_t grid_cols[] = {60, 60, 60, 60, 60, 60, 60, 60, LV_GRID_TEMPLATE_LAST};
1144 static const int32_t grid_rows[] = {34, 34, 34, 34, 34, 34, 34, 34, LV_GRID_TEMPLATE_LAST};
1145 lv_obj_set_grid_dsc_array(main_parent, grid_cols, grid_rows);
1146
1147 opa_saved = opa;
1148
1149 if(scenes[id].create_cb) scenes[id].create_cb(main_parent);
1150 }
1151
lv_demo_render_get_scene_name(lv_demo_render_scene_t id)1152 const char * lv_demo_render_get_scene_name(lv_demo_render_scene_t id)
1153 {
1154 if(id > LV_DEMO_RENDER_SCENE_NUM) return NULL;
1155 return scenes[id].name;
1156 }
1157
1158 /**********************
1159 * STATIC FUNCTIONS
1160 **********************/
1161
add_to_cell(lv_obj_t * obj,int32_t col,int32_t row)1162 static void add_to_cell(lv_obj_t * obj, int32_t col, int32_t row)
1163 {
1164 lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_CENTER, col, 1, LV_GRID_ALIGN_CENTER, row, 1);
1165 }
1166
1167 #endif
1168