xref: /OK3568_Linux_fs/app/lvgl_demo/rk_demo/smart_home/music_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 "ui_resource.h"
11 #include "smart_home_ui.h"
12 
13 static lv_obj_t * bg;
14 
15 static lv_img_dsc_t * bg_snapshot;
16 
17 static lv_img_dsc_t * bg_img;
18 
19 static lv_obj_t * area_player;
20 static lv_obj_t * area_label;
21 static lv_obj_t * slider;
22 static lv_obj_t * area_btn;
23 static lv_obj_t * box_btn;
24 static lv_obj_t * label_singer;
25 static lv_obj_t * label_song;
26 static char * btn_img[] = {
27     IMG_SKIP_BACK,
28     IMG_PLAY,
29     IMG_SKIP_FORWARD,
30     IMG_VOL_DOWN,
31     IMG_VOL_UP,
32     IMG_VOL_MUTE,
33 };
34 
menu_music_init(lv_obj_t * parent)35 lv_obj_t * menu_music_init(lv_obj_t * parent)
36 {
37     lv_obj_t * obj;
38     int x, y;
39     int ofs;
40 
41     bg = lv_img_create(parent);
42     lv_obj_remove_style_all(bg);
43     lv_obj_set_size(bg, lv_pct(90), lv_pct(30));
44     lv_obj_clear_flag(bg, LV_OBJ_FLAG_SCROLLABLE);
45     lv_obj_clear_flag(bg, LV_OBJ_FLAG_ADV_HITTEST);
46     lv_obj_center(bg);
47     lv_obj_refr_size(bg);
48     lv_obj_refr_pos(bg);
49 
50     bg_snapshot = smart_home_ui_bg_blur();
51     bg_img = malloc(sizeof(*bg_img));
52     memcpy(bg_img, bg_snapshot, sizeof(*bg_img));
53 
54     x = lv_obj_get_x(bg);
55     y = lv_obj_get_y(bg);
56     ofs = (y * bg_img->header.w + x)
57           * lv_img_cf_get_px_size(bg_img->header.cf) / 8;
58     bg_img->data = bg_snapshot->data + ofs;
59     lv_img_set_src(bg, bg_img);
60 
61     obj = lv_label_create(bg);
62     lv_label_set_text(obj, "蓝牙音乐");
63     lv_obj_add_style(obj, &style_txt_s, LV_PART_MAIN);
64     lv_obj_set_style_text_color(obj, lv_color_white(), LV_PART_MAIN);
65     lv_obj_align(obj, LV_ALIGN_TOP_LEFT, 0, 0);
66 
67     area_player = lv_obj_create(bg);
68     lv_obj_remove_style_all(area_player);
69     lv_obj_set_size(area_player, lv_pct(80), lv_pct(90));
70     lv_obj_align(area_player, LV_ALIGN_BOTTOM_MID, 0, 0);
71     lv_obj_set_style_pad_left(area_player, 10, LV_PART_MAIN);
72     lv_obj_set_style_pad_right(area_player, 10, LV_PART_MAIN);
73     lv_obj_clear_flag(area_player, LV_OBJ_FLAG_SCROLLABLE);
74 
75     area_label = lv_slider_create(area_player);
76     lv_obj_remove_style_all(area_label);
77     lv_obj_set_size(area_label, lv_pct(100), LV_SIZE_CONTENT);
78     lv_obj_set_flex_flow(area_label, LV_FLEX_FLOW_COLUMN);
79     lv_obj_set_style_pad_row(area_label, 10, 0);
80     lv_obj_align(area_label, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
81 
82     label_singer = lv_label_create(area_label);
83     lv_label_set_text(label_singer, "歌曲名");
84     lv_obj_add_style(label_singer, &style_txt_m, LV_PART_MAIN);
85     lv_obj_set_style_text_color(label_singer, lv_color_white(), LV_PART_MAIN);
86 
87     label_song = lv_label_create(area_label);
88     lv_label_set_text(label_song, "歌手名");
89     lv_obj_add_style(label_song, &style_txt_m, LV_PART_MAIN);
90     lv_obj_set_style_text_color(label_song, lv_color_white(), LV_PART_MAIN);
91 
92     slider = lv_slider_create(area_player);
93     lv_obj_set_width(slider, lv_pct(100));
94     lv_obj_align(slider, LV_ALIGN_CENTER, 0, 0);
95 
96     area_btn = lv_obj_create(area_player);
97     lv_obj_remove_style_all(area_btn);
98     lv_obj_set_size(area_btn, lv_pct(100), LV_SIZE_CONTENT);
99     lv_obj_align_to(area_btn, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 20);
100     lv_obj_set_style_pad_column(area_btn, 30, LV_PART_MAIN);
101     lv_obj_set_flex_align(area_btn, LV_FLEX_ALIGN_CENTER,
102                           LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
103 
104     for (int i = 0; i < 6; i++)
105     {
106         obj = lv_img_create(area_btn);
107         lv_img_set_src(obj, btn_img[i]);
108     }
109 
110     return bg;
111 }
112 
menu_music_deinit(void)113 void menu_music_deinit(void)
114 {
115     lv_obj_del(bg);
116     bg = NULL;
117 
118     free(bg_img);
119 }
120 
121