xref: /OK3568_Linux_fs/app/lvgl_demo/rk_demo/smart_home/info_ui.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <time.h>
5 #include <unistd.h>
6 
7 #include <lvgl/lvgl.h>
8 
9 #include "main.h"
10 #include "smart_home_ui.h"
11 #include "ui_resource.h"
12 
13 static lv_obj_t * bg;
14 
15 static lv_img_dsc_t * bg_snapshot;
16 
17 static lv_obj_t * area_date;
18 static lv_obj_t * area_weather;
19 static lv_obj_t * area_scene;
20 
21 static lv_img_dsc_t * bg_img_date;
22 static lv_img_dsc_t * bg_img_weather;
23 static lv_img_dsc_t * bg_img_scene;
24 
menu_info_init(lv_obj_t * parent)25 lv_obj_t * menu_info_init(lv_obj_t * parent)
26 {
27     lv_obj_t * obj;
28     lv_obj_t * label;
29     int x, y;
30     int ofs;
31 
32     bg = lv_obj_create(parent);
33     lv_obj_remove_style_all(bg);
34     lv_obj_set_size(bg, lv_pct(100), lv_pct(90));
35     lv_obj_clear_flag(bg, LV_OBJ_FLAG_SCROLLABLE);
36     lv_obj_center(bg);
37     lv_obj_refr_size(bg);
38     lv_obj_refr_pos(bg);
39 
40     bg_snapshot = smart_home_ui_bg_blur();
41     bg_img_date = malloc(sizeof(*bg_img_date));
42     bg_img_weather = malloc(sizeof(*bg_img_weather));
43     bg_img_scene = malloc(sizeof(*bg_img_scene));
44 
45     memcpy(bg_img_date, bg_snapshot, sizeof(*bg_img_date));
46     memcpy(bg_img_weather, bg_snapshot, sizeof(*bg_img_weather));
47     memcpy(bg_img_scene, bg_snapshot, sizeof(*bg_img_scene));
48 
49     area_date = lv_img_create(bg);
50     lv_obj_set_size(area_date, 300, 300);
51     lv_obj_align(area_date, LV_ALIGN_CENTER, -160, -160);
52     lv_obj_refr_size(area_date);
53     lv_obj_refr_pos(area_date);
54     x = lv_obj_get_x(area_date) + lv_obj_get_x(bg);
55     y = lv_obj_get_y(area_date) + lv_obj_get_y(bg);
56     ofs = (y * bg_img_date->header.w + x)
57           * lv_img_cf_get_px_size(bg_img_date->header.cf) / 8;
58     bg_img_date->data = bg_snapshot->data + ofs;
59     lv_img_set_src(area_date, bg_img_date);
60 
61     obj = lv_label_create(area_date);
62     lv_label_set_text(obj, "10:32");
63     lv_obj_add_style(obj, &style_txt_l, LV_PART_MAIN);
64     lv_obj_set_style_text_color(obj, lv_color_white(), LV_PART_MAIN);
65     lv_obj_align(obj, LV_ALIGN_CENTER, 0, -50);
66     label = lv_label_create(area_date);
67     lv_label_set_text(label, "7月13日 周四");
68     lv_obj_add_style(label, &style_txt_m, LV_PART_MAIN);
69     lv_obj_set_style_text_color(label, lv_color_white(), LV_PART_MAIN);
70     lv_obj_align_to(label, obj, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
71 
72     area_weather = lv_img_create(bg);
73     lv_obj_set_size(area_weather, 300, 300);
74     lv_obj_align(area_weather, LV_ALIGN_CENTER, 160, -160);
75     lv_obj_refr_size(area_weather);
76     lv_obj_refr_pos(area_weather);
77     x = lv_obj_get_x(area_weather) + lv_obj_get_x(bg);
78     y = lv_obj_get_y(area_weather) + lv_obj_get_y(bg);
79     ofs = (y * bg_img_weather->header.w + x)
80           * lv_img_cf_get_px_size(bg_img_weather->header.cf) / 8;
81     bg_img_weather->data = bg_snapshot->data + ofs;
82     lv_img_set_src(area_weather, bg_img_weather);
83 
84     obj = lv_label_create(area_weather);
85     lv_label_set_text(obj, "32℃");
86     lv_obj_add_style(obj, &style_txt_l, LV_PART_MAIN);
87     lv_obj_set_style_text_color(obj, lv_color_white(), LV_PART_MAIN);
88     lv_obj_align(obj, LV_ALIGN_CENTER, 0, -50);
89     label = lv_label_create(area_weather);
90     lv_label_set_text(label, "福州   晴");
91     lv_obj_add_style(label, &style_txt_m, LV_PART_MAIN);
92     lv_obj_set_style_text_color(label, lv_color_white(), LV_PART_MAIN);
93     lv_obj_align_to(label, obj, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
94 
95     area_scene = lv_img_create(bg);
96     lv_obj_set_size(area_scene, 620, 300);
97     lv_obj_clear_flag(area_scene, LV_OBJ_FLAG_SCROLLABLE);
98     lv_obj_align(area_scene, LV_ALIGN_CENTER, 0, 160);
99     lv_obj_refr_size(area_scene);
100     lv_obj_refr_pos(area_scene);
101     x = lv_obj_get_x(area_scene) + lv_obj_get_x(bg);
102     y = lv_obj_get_y(area_scene) + lv_obj_get_y(bg);
103     ofs = (y * bg_img_scene->header.w + x)
104           * lv_img_cf_get_px_size(bg_img_scene->header.cf) / 8;
105     bg_img_scene->data = bg_snapshot->data + ofs;
106     lv_img_set_src(area_scene, bg_img_scene);
107 
108     obj = lv_btn_create(area_scene);
109     lv_obj_align(obj, LV_ALIGN_CENTER, -150, 0);
110     lv_obj_set_size(obj, 150, 150);
111     lv_obj_set_style_radius(obj, 75, LV_PART_MAIN);
112     obj = lv_label_create(obj);
113     lv_label_set_text(obj, "回家");
114     lv_obj_add_style(obj, &style_txt_s, LV_PART_MAIN);
115     lv_obj_set_style_text_color(obj, lv_color_white(), LV_PART_MAIN);
116     lv_obj_center(obj);
117 
118     obj = lv_btn_create(area_scene);
119     lv_obj_align(obj, LV_ALIGN_CENTER, 150, 0);
120     lv_obj_set_size(obj, 150, 150);
121     lv_obj_set_style_radius(obj, 75, LV_PART_MAIN);
122     obj = lv_label_create(obj);
123     lv_label_set_text(obj, "外出");
124     lv_obj_add_style(obj, &style_txt_s, LV_PART_MAIN);
125     lv_obj_set_style_text_color(obj, lv_color_white(), LV_PART_MAIN);
126     lv_obj_center(obj);
127 
128     return bg;
129 }
130 
menu_info_deinit(void)131 void menu_info_deinit(void)
132 {
133     lv_obj_del(bg);
134     bg = NULL;
135 
136     free(bg_img_date);
137     free(bg_img_weather);
138     free(bg_img_scene);
139 }
140 
141