1 #include <stdio.h>
2 #include "main.h"
3 #include "coffee_machine.h"
4 #include "furniture_control_ui.h"
5
6 ///////////////////// VARIABLES ////////////////////
7 static lv_obj_t * coffee_machine_screen = NULL;
8 static lv_obj_t * coffee_machine_label1 = NULL;
9 static lv_obj_t * coffee_machine_box = NULL;
10 static lv_obj_t * coffee_machine_png_box = NULL;
11 static lv_obj_t * coffee_machine_box_name = NULL;
12 static lv_obj_t * coffee_machine_name = NULL;
13 static lv_obj_t * coffee_machine_button_box = NULL;
14 static lv_obj_t * coffee_machine_button = NULL;
15 static lv_obj_t * coffee_machine_button_label = NULL;
16 static lv_obj_t * bg_pic = NULL;
17 static lv_obj_t * ui_return;
18
19 static lv_obj_t * coffee_1;
20 static lv_obj_t * coffee_2;
21 static lv_obj_t * coffee_3;
22 static lv_obj_t * coffee_4;
23 static lv_obj_t * coffee_5;
24 static lv_obj_t * coffee_6;
25 static lv_obj_t * coffee_0;
26 static int scroll_value = 0;
27 ///////////////////// TEST LVGL SETTINGS ////////////////////
28
29 ///////////////////// ANIMATIONS ////////////////////
30
31 ///////////////////// FUNCTIONS ////////////////////
32
coffee_machine_page_jump_furniture_control_callback(lv_event_t * event)33 void coffee_machine_page_jump_furniture_control_callback(lv_event_t* event) {
34 printf("coffee_machine_page_jump_furniture_control_callback is into \n");
35 furniture_control_ui_init();
36 lv_obj_del(coffee_machine_screen);
37 coffee_machine_screen = NULL;
38 }
39
coffee_machine_png_box_scroll_callback(lv_event_t * event)40 void coffee_machine_png_box_scroll_callback(lv_event_t* event) {
41 lv_obj_t* screen = lv_event_get_target(event);
42 scroll_value = lv_obj_get_scroll_left(screen);
43 //printf("%d pixels are scrolled out on the left\n", scroll_value);
44 if (scroll_value > 0 && scroll_value < 250) {
45 lv_img_set_zoom(coffee_1, 256);
46 lv_img_set_zoom(coffee_2, 192);
47 lv_label_set_text(coffee_machine_name, "美式咖啡");
48 }
49 if (scroll_value > 250 && scroll_value < 650 ) {
50 lv_img_set_zoom(coffee_1, 192);
51 lv_img_set_zoom(coffee_2, 256);
52 lv_img_set_zoom(coffee_3, 192);
53 lv_label_set_text(coffee_machine_name, "意式咖啡");
54 }
55 if (scroll_value > 650 && scroll_value < 1050) {
56 lv_img_set_zoom(coffee_2, 192);
57 lv_img_set_zoom(coffee_3, 256);
58 lv_img_set_zoom(coffee_4, 192);
59 lv_label_set_text(coffee_machine_name, "美味拿铁");
60 }
61 if (scroll_value > 1050 && scroll_value < 1450) {
62 lv_img_set_zoom(coffee_3, 192);
63 lv_img_set_zoom(coffee_4, 256);
64 lv_img_set_zoom(coffee_5, 192);
65 lv_label_set_text(coffee_machine_name, "卡布奇诺");
66 }
67 if (scroll_value > 1450 && scroll_value < 1850) {
68 lv_img_set_zoom(coffee_4, 192);
69 lv_img_set_zoom(coffee_5, 256);
70 lv_label_set_text(coffee_machine_name, "RK咖啡");
71 }
72 }
73
74 ///////////////////// SCREENS ////////////////////
ui_coffee_machine_screen_init(void)75 void ui_coffee_machine_screen_init(void)
76 {
77 coffee_machine_screen = lv_obj_create(NULL);
78 lv_obj_clear_flag(coffee_machine_screen, LV_OBJ_FLAG_SCROLLABLE); /// Flags
79
80 bg_pic = lv_img_create(coffee_machine_screen);
81 lv_obj_set_pos(bg_pic, 0, 0);
82 lv_img_set_src(bg_pic, BG_PIC_4);
83
84 coffee_machine_label1 = lv_label_create(coffee_machine_screen);
85 lv_obj_set_width(coffee_machine_label1, 249);
86 lv_obj_set_height(coffee_machine_label1, 26);
87 lv_obj_align(coffee_machine_label1, LV_ALIGN_TOP_LEFT, 100, 20);
88 lv_obj_add_style(coffee_machine_label1, &style_txt_m, LV_PART_MAIN);
89 lv_label_set_text(coffee_machine_label1, "咖啡机");
90
91 ui_return = lv_img_create(coffee_machine_screen);
92 lv_img_set_src(ui_return, IMG_RETURN_BTN);
93 lv_obj_set_width(ui_return, LV_SIZE_CONTENT); /// 32
94 lv_obj_set_height(ui_return, LV_SIZE_CONTENT); /// 32
95 lv_obj_align(ui_return, LV_ALIGN_TOP_LEFT, 10, 10);
96 lv_obj_add_flag(ui_return, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_ADV_HITTEST); /// Flags
97 lv_obj_clear_flag(ui_return, LV_OBJ_FLAG_SCROLLABLE); /// Flags
98 if (ui_return != NULL) {
99 lv_obj_add_event_cb(ui_return, coffee_machine_page_jump_furniture_control_callback, LV_EVENT_CLICKED, NULL);
100 }
101
102 coffee_machine_box = lv_obj_create(coffee_machine_screen);
103 lv_obj_remove_style_all(coffee_machine_box);
104 lv_obj_set_width(coffee_machine_box, lv_pct(100));
105 lv_obj_set_height(coffee_machine_box, lv_pct(80));
106 lv_obj_align(coffee_machine_box, LV_ALIGN_TOP_LEFT, 0, lv_pct(10));
107 //lv_obj_set_flex_flow(coffee_machine_box, LV_FLEX_FLOW_COLUMN);//列
108
109 coffee_machine_png_box = lv_obj_create(coffee_machine_box);
110 lv_obj_remove_style_all(coffee_machine_png_box);
111 lv_obj_set_width(coffee_machine_png_box, lv_pct(100));
112 lv_obj_set_height(coffee_machine_png_box, 400);
113 lv_obj_align(coffee_machine_png_box, LV_ALIGN_TOP_LEFT, 0, 250);
114 if (coffee_machine_png_box != NULL) {
115 lv_obj_add_event_cb(coffee_machine_png_box, coffee_machine_png_box_scroll_callback, LV_EVENT_SCROLL, NULL);
116 }
117 //lv_obj_set_style_radius(coffee_machine_png_box, LV_RADIUS_CIRCLE, 0);
118 //lv_obj_set_style_clip_corner(coffee_machine_png_box, true, 0);
119
120 //图片缩放 lv_img_set_zoom
121 //设置咖啡图片
122 coffee_0 = lv_img_create(coffee_machine_png_box);
123 lv_obj_set_width(coffee_0, 300);
124 lv_obj_set_height(coffee_0, 300);
125 lv_obj_align(coffee_0, LV_ALIGN_CENTER, -400, 10);
126
127 coffee_1 = lv_img_create(coffee_machine_png_box);
128 lv_obj_set_width(coffee_1, 300);
129 lv_obj_set_height(coffee_1, 300);
130 lv_obj_align(coffee_1, LV_ALIGN_CENTER, 0, 10);
131 lv_img_set_src(coffee_1, COFFEE_1);
132 coffee_2 = lv_img_create(coffee_machine_png_box);
133 lv_obj_set_width(coffee_2, 300);
134 lv_obj_set_height(coffee_2, 300);
135 lv_obj_align(coffee_2, LV_ALIGN_CENTER, 400, 10);
136 lv_img_set_src(coffee_2, COFFEE_2);
137 lv_img_set_zoom(coffee_2, 192);
138 coffee_3 = lv_img_create(coffee_machine_png_box);
139 lv_obj_set_width(coffee_3, 300);
140 lv_obj_set_height(coffee_3, 300);
141 lv_obj_align(coffee_3, LV_ALIGN_CENTER, 800, 10);
142 lv_img_set_src(coffee_3, COFFEE_3);
143 lv_img_set_zoom(coffee_3, 192);
144 coffee_4 = lv_img_create(coffee_machine_png_box);
145 lv_obj_set_width(coffee_4, 300);
146 lv_obj_set_height(coffee_4, 300);
147 lv_obj_align(coffee_4, LV_ALIGN_CENTER, 1200, 10);
148 lv_img_set_src(coffee_4, COFFEE_4);
149 lv_img_set_zoom(coffee_4, 192);
150 coffee_5 = lv_img_create(coffee_machine_png_box);
151 lv_obj_set_width(coffee_5, 300);
152 lv_obj_set_height(coffee_5, 300);
153 lv_obj_align(coffee_5, LV_ALIGN_CENTER, 1600, 10);
154 lv_img_set_src(coffee_5, COFFEE_5);
155 lv_img_set_zoom(coffee_5, 192);
156
157 coffee_6 = lv_img_create(coffee_machine_png_box);
158 lv_obj_set_width(coffee_6, 300);
159 lv_obj_set_height(coffee_6, 300);
160 lv_obj_align(coffee_6, LV_ALIGN_CENTER, 2000, 10);
161 //设置咖啡图片
162
163 coffee_machine_box_name = lv_obj_create(coffee_machine_box);
164 lv_obj_remove_style_all(coffee_machine_box_name);
165 lv_obj_set_width(coffee_machine_box_name, lv_pct(100));
166 lv_obj_set_height(coffee_machine_box_name, lv_pct(20));
167 lv_obj_align(coffee_machine_box_name, LV_ALIGN_TOP_LEFT, 0, lv_pct(55));
168
169 coffee_machine_name = lv_label_create(coffee_machine_box_name);
170 lv_obj_add_style(coffee_machine_name, &style_txt_m, LV_PART_MAIN);
171 lv_label_set_text(coffee_machine_name, "美式咖啡");
172 lv_obj_set_style_text_color(coffee_machine_name, lv_color_white(), LV_PART_MAIN);
173 lv_obj_align(coffee_machine_name, LV_ALIGN_CENTER, 0, 0);
174
175 coffee_machine_button_box = lv_obj_create(coffee_machine_box);
176 lv_obj_remove_style_all(coffee_machine_button_box);
177 lv_obj_set_width(coffee_machine_button_box, lv_pct(100));
178 lv_obj_set_height(coffee_machine_button_box, lv_pct(20));
179 lv_obj_align(coffee_machine_button_box, LV_ALIGN_TOP_LEFT, 0, lv_pct(75));
180
181 coffee_machine_button = lv_btn_create(coffee_machine_button_box);
182 lv_obj_set_width(coffee_machine_button, lv_pct(40));
183 lv_obj_set_height(coffee_machine_button, lv_pct(100));
184 lv_obj_set_style_bg_color(coffee_machine_button, lv_color_hex(0xDED6D6), LV_PART_MAIN);
185 lv_obj_align(coffee_machine_button, LV_ALIGN_CENTER, 0, 0);
186 lv_obj_set_style_radius(coffee_machine_button, LV_RADIUS_CIRCLE, 0);
187
188 coffee_machine_button_label = lv_label_create(coffee_machine_button);
189 lv_obj_add_style(coffee_machine_button_label, &style_txt_m, LV_PART_MAIN);
190 lv_obj_align(coffee_machine_button_label, LV_ALIGN_CENTER, 0, 0);
191 lv_label_set_text(coffee_machine_button_label, "开始制作");
192
193 }
194
coffee_machine_ui_init(void)195 void coffee_machine_ui_init(void)
196 {
197 if (!coffee_machine_screen)
198 ui_coffee_machine_screen_init();
199 lv_disp_load_scr(coffee_machine_screen);
200 }
201