xref: /OK3568_Linux_fs/app/lvgl_demo/rk_demo/furniture_control/player_ui.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 #define MAX_FILE_COUNT 10
2 #define PATH_VIDEO "/oem/"
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <dirent.h>
6 #include "main.h"
7 #include "player_ui.h"
8 #include "furniture_control_ui.h"
9 
10 ///////////////////// VARIABLES ////////////////////
11 static lv_obj_t * ui_player_screen = NULL;
12 static lv_obj_t * player_label;
13 static lv_obj_t * ui_return;
14 static lv_obj_t * player_box = NULL;
15 static lv_obj_t * player_box_canvas = NULL;
16 static lv_obj_t * player_box_button = NULL;
17 static lv_obj_t * player_start_button = NULL;
18 static lv_obj_t * player_stop_button = NULL;
19 static lv_obj_t * player_list_button = NULL;
20 static lv_obj_t * video_label = NULL;
21 static lv_obj_t * video_list_box = NULL;
22 static lv_obj_t * video_list = NULL;
23 static lv_obj_t * bg_pic = NULL;
24 
25 
26 static lv_style_t style_txt;
27 static lv_style_t style_list;
28 //static lv_img_dsc_t * bg_snapshot;
29 ///////////////////// TEST LVGL SETTINGS ////////////////////
30 
31 ///////////////////// ANIMATIONS ////////////////////
32 
33 ///////////////////// FUNCTIONS ////////////////////
34 // static void bg_pic_snapshot_blur(void)
35 // {
36 //     lv_draw_rect_dsc_t dsc;
37 
38 //     bg_snapshot = lv_snapshot_take(bg_pic, LV_IMG_CF_TRUE_COLOR);
39 
40 //     lv_obj_t * canvas = lv_canvas_create(NULL);
41 //     lv_area_t area;
42 //     lv_canvas_set_buffer(canvas, bg_snapshot->data,
43 //                          bg_snapshot->header.w,
44 //                          bg_snapshot->header.h,
45 //                          bg_snapshot->header.cf);
46 //     area.x1 = 0;
47 //     area.y1 = 0;
48 //     area.x2 = bg_snapshot->header.w - 1;
49 //     area.y2 = bg_snapshot->header.h - 1;
50 //     lv_canvas_blur_ver(canvas, &area, 100);
51 //     lv_canvas_blur_hor(canvas, &area, 100);
52 //     lv_draw_rect_dsc_init(&dsc);
53 //     dsc.bg_opa = 70;
54 //     dsc.bg_color = lv_color_black();
55 //     lv_canvas_draw_rect(canvas, 0, 0,
56 //                         bg_snapshot->header.w,
57 //                         bg_snapshot->header.h, &dsc);
58 //     lv_obj_del(canvas);
59 // }
60 
style_init(void)61 static void style_init(void)
62 {
63     lv_style_init(&style_txt);
64     lv_style_set_text_font(&style_txt, ttf_main_s.font);
65     lv_style_set_text_color(&style_txt, lv_color_make(0xff, 0x23, 0x23));
66 
67     lv_style_init(&style_list);
68     lv_style_set_text_font(&style_list, ttf_main_m.font);
69     lv_style_set_text_color(&style_list, lv_color_black());
70 }
71 
player_page_jump_furniture_control_callback(lv_event_t * event)72 void player_page_jump_furniture_control_callback(lv_event_t* event) {
73     printf("player_page_jump_furniture_control_callback is into \n");
74     furniture_control_ui_init();
75     lv_obj_del(ui_player_screen);
76     //free(bg_snapshot);
77     ui_player_screen = NULL;
78     video_list_box = NULL;
79 }
80 
video_name_callback(lv_event_t * event)81 void video_name_callback(lv_event_t* event) {
82     char * file_name = lv_event_get_user_data(event);
83     printf("video_name select file %s\n", file_name);
84     lv_label_set_text(video_label, file_name);
85     lv_obj_del(video_list_box);
86     video_list_box = NULL;
87 }
88 
player_list_button_callback(lv_event_t * event)89 void player_list_button_callback(lv_event_t* event) {
90     printf("player_list_button_callback is into \n");
91     DIR *dir;
92     struct dirent *entry;
93     int file_count = 0;
94     if (video_list_box == NULL) {
95         video_list_box = lv_obj_create(player_box);
96         //lv_obj_remove_style_all(video_list_box);
97         lv_obj_set_width(video_list_box, lv_pct(50));
98         lv_obj_set_height(video_list_box, lv_pct(40));
99         lv_obj_align(video_list_box, LV_ALIGN_TOP_LEFT, 0, lv_pct(40));
100 
101         video_list = lv_list_create(video_list_box);
102         lv_obj_set_size(video_list, lv_pct(100), lv_pct(100));
103         lv_obj_center(video_list);
104         lv_obj_add_style(video_list, &style_list, LV_PART_MAIN);
105         lv_obj_set_style_pad_column(video_list, 10, LV_PART_MAIN);
106 
107         dir = opendir(PATH_VIDEO);
108         if (dir == NULL) {
109             printf("Error opening directory /oem\n");
110             return;
111         }
112         while ((entry = readdir(dir)) != NULL) {
113             if (entry->d_type == DT_REG) {
114                 //add_file_to_list(entry->d_name);
115                 lv_obj_t *obj_text = lv_list_add_btn(video_list, NULL, entry->d_name);
116                 lv_obj_add_flag(obj_text, LV_OBJ_FLAG_CLICKABLE);
117                 lv_obj_add_event_cb(obj_text, video_name_callback, LV_EVENT_CLICKED, entry->d_name);
118                 file_count++;
119                 if (file_count >= MAX_FILE_COUNT) {
120                     break;
121                 }
122             }
123         }
124     } else {
125         lv_obj_del(video_list_box);
126         video_list_box = NULL;
127     }
128 }
129 ///////////////////// SCREENS ////////////////////
ui_player_screen_init(void)130 void ui_player_screen_init(void)
131 {
132     style_init();
133 
134     ui_player_screen = lv_obj_create(NULL);
135     lv_obj_clear_flag(ui_player_screen, LV_OBJ_FLAG_SCROLLABLE);      /// Flags
136 
137     bg_pic = lv_img_create(ui_player_screen);
138     lv_obj_set_pos(bg_pic, 0, 0);
139     lv_img_set_src(bg_pic, BG_PIC_1);
140     //bg_pic_snapshot_blur();
141 
142     ui_return = lv_img_create(ui_player_screen);
143     lv_img_set_src(ui_return, IMG_RETURN_BTN);
144     lv_obj_set_width(ui_return, LV_SIZE_CONTENT);   /// 32
145     lv_obj_set_height(ui_return, LV_SIZE_CONTENT);    /// 32
146     lv_obj_align(ui_return, LV_ALIGN_TOP_LEFT, 10, 10);
147     lv_obj_add_flag(ui_return, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_ADV_HITTEST);     /// Flags
148     lv_obj_clear_flag(ui_return, LV_OBJ_FLAG_SCROLLABLE);      /// Flags
149     if (ui_return != NULL) {
150         lv_obj_add_event_cb(ui_return, player_page_jump_furniture_control_callback, LV_EVENT_CLICKED, NULL);
151     }
152 
153     player_label = lv_label_create(ui_player_screen);
154     lv_obj_set_width(player_label, 249);
155     lv_obj_set_height(player_label, 26);
156     lv_obj_align(player_label, LV_ALIGN_TOP_LEFT, 100, 20);
157     lv_obj_add_style(player_label, &style_txt_m, LV_PART_MAIN);
158     lv_label_set_text(player_label, "宣传视频");
159 
160     player_box = lv_obj_create(ui_player_screen);
161     lv_obj_remove_style_all(player_box);
162     lv_obj_set_width(player_box, lv_pct(100));
163     lv_obj_set_height(player_box, lv_pct(80));
164     lv_obj_align(player_box, LV_ALIGN_TOP_LEFT, 0, lv_pct(10));
165 
166     player_box_canvas = lv_obj_create(player_box);
167     lv_obj_remove_style_all(player_box_canvas);
168     lv_obj_set_width(player_box_canvas, lv_pct(100));
169     lv_obj_set_height(player_box_canvas, lv_pct(70));
170 
171     player_box_button = lv_obj_create(player_box);
172     lv_obj_remove_style_all(player_box_button);
173     lv_obj_set_width(player_box_button, lv_pct(100));
174     lv_obj_set_height(player_box_button, lv_pct(30));
175     lv_obj_align(player_box_button, LV_ALIGN_TOP_LEFT, 0, lv_pct(70));
176 
177     player_start_button = lv_img_create(player_box_button);
178     lv_img_set_src(player_start_button, IMG_PLAYER_START);
179     lv_obj_set_width(player_start_button, 128);   /// 64
180     lv_obj_set_height(player_start_button, 128);    /// 64
181     lv_obj_set_align(player_start_button, LV_ALIGN_CENTER);
182     lv_obj_add_flag(player_start_button, LV_OBJ_FLAG_CLICKABLE);
183 
184     player_stop_button = lv_img_create(player_box_button);
185     lv_img_set_src(player_stop_button, IMG_PLAYER_STOP);
186     lv_obj_set_width(player_stop_button, 128);   /// 64
187     lv_obj_set_height(player_stop_button, 128);    /// 64
188     lv_obj_align(player_stop_button, LV_ALIGN_CENTER, 250, 0);
189     lv_obj_add_flag(player_stop_button, LV_OBJ_FLAG_CLICKABLE);
190 
191     player_list_button = lv_img_create(player_box_button);
192     lv_img_set_src(player_list_button, IMG_PLAYER_LIST);
193     lv_obj_set_width(player_list_button, 128);   /// 64
194     lv_obj_set_height(player_list_button, 128);    /// 64
195     lv_obj_align(player_list_button, LV_ALIGN_CENTER, -250, 0);
196     lv_obj_add_flag(player_list_button, LV_OBJ_FLAG_ADV_HITTEST);     /// Flags
197     lv_obj_clear_flag(player_list_button, LV_OBJ_FLAG_SCROLLABLE);      /// Flags
198     lv_obj_add_flag(player_list_button, LV_OBJ_FLAG_CLICKABLE);
199     if (player_list_button != NULL) {
200         lv_obj_add_event_cb(player_list_button, player_list_button_callback, LV_EVENT_CLICKED, NULL);
201     }
202 
203     video_label = lv_label_create(player_box_button);
204     lv_obj_set_width(video_label, LV_SIZE_CONTENT);   /// 1
205     lv_obj_set_height(video_label, LV_SIZE_CONTENT);    /// 1
206     lv_obj_align(video_label, LV_ALIGN_CENTER, 0, 100);
207     lv_obj_add_style(video_label, &style_txt_m, LV_PART_MAIN);
208     lv_label_set_text(video_label, "");
209 
210 }
211 
player_ui_init(void)212 void player_ui_init(void)
213 {
214     if (!ui_player_screen)
215         ui_player_screen_init();
216     lv_disp_load_scr(ui_player_screen);
217 }
218