1 #include <stdio.h>
2 #include <lvgl/lvgl.h>
3
4 #include "furniture_control_ui.h"
5 #include "home_ui.h"
6 #include "icebox_ui.h"
7 #include "main.h"
8
9 ///////////////////// VARIABLES ////////////////////
10 extern uint32_t LV_EVENT_GET_COMP_CHILD;
11
12 static lv_obj_t * furniture_control_ui_Screen1 = NULL;
13 static lv_obj_t * furniture_control_ui_box = NULL;
14 static lv_obj_t * furniture_control_ui_icebox_box = NULL;
15 static lv_obj_t * furniture_control_ui_player_box = NULL;
16 static lv_obj_t * furniture_control_ui_coffee_box = NULL;
17 static lv_obj_t * furniture_control_ui_return;
18 static lv_obj_t * furniture_control_ui_Label2;
19 static lv_obj_t * furniture_control_ui_icebox;
20 static lv_obj_t * furniture_control_ui_player;
21 static lv_obj_t * furniture_control_ui_coffee_machine;
22 static lv_obj_t * furniture_control_ui_Label1;
23 static lv_obj_t * furniture_control_ui_Label4;
24 static lv_obj_t * furniture_control_ui_Label3;
25 static lv_obj_t * bg_pic;
26 static lv_obj_t * v_bg;
27 static lv_img_dsc_t * bg_snapshot;
28 ///////////////////// TEST LVGL SETTINGS ////////////////////
29
30 ///////////////////// ANIMATIONS ////////////////////
31
32 ///////////////////// FUNCTIONS ////////////////////
bg_pic_snapshot_blur(void)33 static void bg_pic_snapshot_blur(void)
34 {
35 lv_draw_rect_dsc_t dsc;
36
37 bg_snapshot = lv_snapshot_take(bg_pic, LV_IMG_CF_TRUE_COLOR);
38
39 lv_obj_t * canvas = lv_canvas_create(NULL);
40 lv_area_t area;
41 lv_canvas_set_buffer(canvas, bg_snapshot->data,
42 bg_snapshot->header.w,
43 bg_snapshot->header.h,
44 bg_snapshot->header.cf);
45 area.x1 = 0;
46 area.y1 = 0;
47 area.x2 = bg_snapshot->header.w - 1;
48 area.y2 = bg_snapshot->header.h - 1;
49 lv_canvas_blur_ver(canvas, &area, 100);
50 lv_canvas_blur_hor(canvas, &area, 100);
51 lv_draw_rect_dsc_init(&dsc);
52 dsc.bg_opa = 20;
53 dsc.bg_color = lv_color_black();
54 lv_canvas_draw_rect(canvas, 0, 0,
55 bg_snapshot->header.w,
56 bg_snapshot->header.h, &dsc);
57 lv_obj_del(canvas);
58 }
59
furniture_control_page_jump_home_callback(lv_event_t * event)60 void furniture_control_page_jump_home_callback(lv_event_t* event) {
61 printf("page_jump_return_home_callback is into \n");
62 home_ui_init();
63 lv_obj_del(furniture_control_ui_Screen1);
64 free(bg_snapshot);
65 bg_snapshot = NULL;
66 furniture_control_ui_Screen1 = NULL;
67 }
68
furniture_control_page_jump_icebox_callback(lv_event_t * event)69 void furniture_control_page_jump_icebox_callback(lv_event_t* event) {
70 printf("furniture_control_page_jump_icebox_callback is into \n");
71 icebox_ui_init();
72 lv_obj_del(furniture_control_ui_Screen1);
73 free(bg_snapshot);
74 bg_snapshot = NULL;
75 furniture_control_ui_Screen1 = NULL;
76 }
77
furniture_control_page_jump_coffee_machine_callback(lv_event_t * event)78 void furniture_control_page_jump_coffee_machine_callback(lv_event_t* event) {
79 printf("furniture_control_page_jump_coffee_machine_callback is into \n");
80 coffee_machine_ui_init();
81 lv_obj_del(furniture_control_ui_Screen1);
82 free(bg_snapshot);
83 bg_snapshot = NULL;
84 furniture_control_ui_Screen1 = NULL;
85 }
86
furniture_control_page_jump_player_callback(lv_event_t * event)87 void furniture_control_page_jump_player_callback(lv_event_t* event) {
88 printf("furniture_control_page_jump_player_callback is into \n");
89 player_ui_init();
90 lv_obj_del(furniture_control_ui_Screen1);
91 free(bg_snapshot);
92 bg_snapshot = NULL;
93 furniture_control_ui_Screen1 = NULL;
94 }
95
96
97 ///////////////////// SCREENS ////////////////////
98
ui_furniture_control_screen_init(void)99 void ui_furniture_control_screen_init(void)
100 {
101 int x, y;
102 int ofs;
103 furniture_control_ui_Screen1 = lv_obj_create(NULL);
104 lv_obj_clear_flag(furniture_control_ui_Screen1, LV_OBJ_FLAG_SCROLLABLE); /// Flags
105
106 bg_pic = lv_img_create(furniture_control_ui_Screen1);
107 lv_obj_set_pos(bg_pic, 0, 0);
108 lv_img_set_src(bg_pic, BG_PIC_0);
109 bg_pic_snapshot_blur();
110
111 furniture_control_ui_return = lv_img_create(furniture_control_ui_Screen1);
112 lv_img_set_src(furniture_control_ui_return, IMG_RETURN_BTN);
113 lv_obj_set_width(furniture_control_ui_return, LV_SIZE_CONTENT); /// 32
114 lv_obj_set_height(furniture_control_ui_return, LV_SIZE_CONTENT); /// 32
115 lv_obj_align(furniture_control_ui_return, LV_ALIGN_TOP_LEFT, 10, 10);
116 lv_obj_add_flag(furniture_control_ui_return, LV_OBJ_FLAG_ADV_HITTEST); /// Flags
117 lv_obj_clear_flag(furniture_control_ui_return, LV_OBJ_FLAG_SCROLLABLE); /// Flags
118 lv_obj_add_flag(furniture_control_ui_return, LV_OBJ_FLAG_CLICKABLE);
119 if (furniture_control_ui_return != NULL) {
120 lv_obj_add_event_cb(furniture_control_ui_return, furniture_control_page_jump_home_callback, LV_EVENT_CLICKED, NULL);
121 }
122
123 furniture_control_ui_Label2 = lv_label_create(furniture_control_ui_Screen1);
124 lv_obj_set_width(furniture_control_ui_Label2, 249);
125 lv_obj_set_height(furniture_control_ui_Label2, 26);
126 lv_obj_align(furniture_control_ui_Label2, LV_ALIGN_TOP_LEFT, 100, 20);
127 lv_obj_add_style(furniture_control_ui_Label2, &style_txt_m, LV_PART_MAIN);
128 lv_label_set_text(furniture_control_ui_Label2, "家电显控");
129
130 furniture_control_ui_box = lv_obj_create(furniture_control_ui_Screen1);
131 lv_obj_remove_style_all(furniture_control_ui_box);
132 lv_obj_set_width(furniture_control_ui_box, lv_pct(100));
133 lv_obj_set_height(furniture_control_ui_box, lv_pct(33));
134 lv_obj_align(furniture_control_ui_box, LV_ALIGN_TOP_LEFT, 0, lv_pct(33));
135 lv_obj_set_flex_flow(furniture_control_ui_box, LV_FLEX_FLOW_ROW);//行
136
137 v_bg = lv_img_create(furniture_control_ui_box);
138 lv_obj_set_width(v_bg, lv_pct(100));
139 lv_obj_set_height(v_bg, lv_pct(100));
140 lv_obj_refr_pos(v_bg);
141 x = lv_obj_get_x(v_bg) + lv_obj_get_x(furniture_control_ui_box);
142 y = lv_obj_get_y(v_bg) + lv_obj_get_y(furniture_control_ui_box);
143 ofs = (y * bg_snapshot->header.w + x) * lv_img_cf_get_px_size(bg_snapshot->header.cf) / 8;
144 bg_snapshot->data = bg_snapshot->data + ofs;
145 lv_img_set_src(v_bg, bg_snapshot);
146 lv_obj_set_flex_flow(v_bg, LV_FLEX_FLOW_ROW);//行
147 lv_obj_clear_flag(v_bg, LV_OBJ_FLAG_SCROLLABLE);
148
149 furniture_control_ui_icebox_box = lv_obj_create(v_bg);
150 lv_obj_remove_style_all(furniture_control_ui_icebox_box);
151 lv_obj_set_width(furniture_control_ui_icebox_box, lv_pct(33));
152 lv_obj_set_height(furniture_control_ui_icebox_box, lv_pct(100));
153 lv_obj_align(furniture_control_ui_icebox_box, LV_ALIGN_TOP_LEFT, 0, 0);
154
155 furniture_control_ui_icebox = lv_img_create(furniture_control_ui_icebox_box);
156 lv_img_set_src(furniture_control_ui_icebox, IMG_ICEBOX);
157 lv_obj_set_width(furniture_control_ui_icebox, LV_SIZE_CONTENT); /// 64
158 lv_obj_set_height(furniture_control_ui_icebox, LV_SIZE_CONTENT); /// 64
159 lv_obj_set_align(furniture_control_ui_icebox, LV_ALIGN_CENTER);
160 lv_obj_add_flag(furniture_control_ui_icebox, LV_OBJ_FLAG_ADV_HITTEST); /// Flags
161 lv_obj_clear_flag(furniture_control_ui_icebox, LV_OBJ_FLAG_SCROLLABLE); /// Flags
162 lv_obj_add_flag(furniture_control_ui_icebox, LV_OBJ_FLAG_CLICKABLE);
163 if (furniture_control_ui_icebox != NULL) {
164 lv_obj_add_event_cb(furniture_control_ui_icebox, furniture_control_page_jump_icebox_callback, LV_EVENT_CLICKED, NULL);
165 }
166
167 furniture_control_ui_Label1 = lv_label_create(furniture_control_ui_icebox_box);
168 lv_obj_set_width(furniture_control_ui_Label1, LV_SIZE_CONTENT); /// 1
169 lv_obj_set_height(furniture_control_ui_Label1, LV_SIZE_CONTENT); /// 1
170 lv_obj_align(furniture_control_ui_Label1, LV_ALIGN_CENTER, 0, 80);
171 lv_obj_add_style(furniture_control_ui_Label1, &style_txt_m, LV_PART_MAIN);
172 lv_label_set_text(furniture_control_ui_Label1, "每日菜谱");
173
174
175 furniture_control_ui_player_box = lv_obj_create(v_bg);
176 lv_obj_remove_style_all(furniture_control_ui_player_box);
177 lv_obj_set_width(furniture_control_ui_player_box, lv_pct(33));
178 lv_obj_set_height(furniture_control_ui_player_box, lv_pct(100));
179 lv_obj_align(furniture_control_ui_player_box, LV_ALIGN_TOP_LEFT, 0, 0);
180
181 furniture_control_ui_player = lv_img_create(furniture_control_ui_player_box);
182 lv_img_set_src(furniture_control_ui_player, IMG_PLAYER);
183 lv_obj_set_width(furniture_control_ui_player, LV_SIZE_CONTENT); /// 64
184 lv_obj_set_height(furniture_control_ui_player, LV_SIZE_CONTENT); /// 64
185 lv_obj_set_align(furniture_control_ui_player, LV_ALIGN_CENTER);
186 lv_obj_add_flag(furniture_control_ui_player, LV_OBJ_FLAG_ADV_HITTEST); /// Flags
187 lv_obj_clear_flag(furniture_control_ui_player, LV_OBJ_FLAG_SCROLLABLE); /// Flags
188 lv_obj_add_flag(furniture_control_ui_player, LV_OBJ_FLAG_CLICKABLE);
189 if (furniture_control_ui_player != NULL) {
190 lv_obj_add_event_cb(furniture_control_ui_player, furniture_control_page_jump_player_callback, LV_EVENT_CLICKED, NULL);
191 }
192
193 furniture_control_ui_Label4 = lv_label_create(furniture_control_ui_player_box);
194 lv_obj_set_width(furniture_control_ui_Label4, LV_SIZE_CONTENT); /// 1
195 lv_obj_set_height(furniture_control_ui_Label4, LV_SIZE_CONTENT); /// 1
196 lv_obj_align(furniture_control_ui_Label4, LV_ALIGN_CENTER, 0, 80);
197 lv_obj_add_style(furniture_control_ui_Label4, &style_txt_m, LV_PART_MAIN);
198 lv_label_set_text(furniture_control_ui_Label4, "宣传视频");
199
200 furniture_control_ui_coffee_box = lv_img_create(v_bg);
201 lv_obj_remove_style_all(furniture_control_ui_coffee_box);
202 lv_obj_set_width(furniture_control_ui_coffee_box, lv_pct(33));
203 lv_obj_set_height(furniture_control_ui_coffee_box, lv_pct(100));
204 lv_obj_align(furniture_control_ui_coffee_box, LV_ALIGN_TOP_LEFT, 0, 0);
205
206 furniture_control_ui_coffee_machine = lv_img_create(furniture_control_ui_coffee_box);
207 lv_img_set_src(furniture_control_ui_coffee_machine, IMG_COFFEE);
208 lv_obj_set_width(furniture_control_ui_coffee_machine, LV_SIZE_CONTENT); /// 64
209 lv_obj_set_height(furniture_control_ui_coffee_machine, LV_SIZE_CONTENT); /// 64
210 lv_obj_set_align(furniture_control_ui_coffee_machine, LV_ALIGN_CENTER);
211 lv_obj_add_flag(furniture_control_ui_coffee_machine, LV_OBJ_FLAG_ADV_HITTEST); /// Flags
212 lv_obj_clear_flag(furniture_control_ui_coffee_machine, LV_OBJ_FLAG_SCROLLABLE); /// Flags
213 lv_obj_add_flag(furniture_control_ui_coffee_machine, LV_OBJ_FLAG_CLICKABLE);
214 if (furniture_control_ui_coffee_machine != NULL) {
215 lv_obj_add_event_cb(furniture_control_ui_coffee_machine, furniture_control_page_jump_coffee_machine_callback, LV_EVENT_CLICKED, NULL);
216 }
217
218 furniture_control_ui_Label3 = lv_label_create(furniture_control_ui_coffee_box);
219 lv_obj_set_width(furniture_control_ui_Label3, LV_SIZE_CONTENT); /// 1
220 lv_obj_set_height(furniture_control_ui_Label3, LV_SIZE_CONTENT); /// 1
221 lv_obj_align(furniture_control_ui_Label3, LV_ALIGN_CENTER, 0, 80);
222 lv_obj_add_style(furniture_control_ui_Label3, &style_txt_m, LV_PART_MAIN);
223 lv_label_set_text(furniture_control_ui_Label3, "咖啡机");
224 }
225
furniture_control_ui_init(void)226 void furniture_control_ui_init(void)
227 {
228 if (!furniture_control_ui_Screen1)
229 ui_furniture_control_screen_init();
230 lv_disp_load_scr(furniture_control_ui_Screen1);
231 }
232
233