1 #include "stdafx.h"
2 #include "MiniModeUserUi.h"
3 #include "MiniModeDlg.h"
4
CMiniModeUserUi(CWnd * pMainWnd,const std::wstring & xml_path)5 CMiniModeUserUi::CMiniModeUserUi(CWnd* pMainWnd, const std::wstring& xml_path)
6 : CUserUi(pMainWnd, xml_path)
7 {
8 InitUiPlaylist();
9 }
10
CMiniModeUserUi(CWnd * pMainWnd,UINT id)11 CMiniModeUserUi::CMiniModeUserUi(CWnd* pMainWnd, UINT id)
12 : CUserUi(pMainWnd, id)
13 {
14 InitUiPlaylist();
15 }
16
~CMiniModeUserUi()17 CMiniModeUserUi::~CMiniModeUserUi()
18 {
19 }
20
InitUiPlaylist()21 void CMiniModeUserUi::InitUiPlaylist()
22 {
23 //保存原来的UI
24 m_ui_element = m_root_default;
25 CMiniModeDlg* pMinimodeDlg = dynamic_cast<CMiniModeDlg*>(m_pMainWnd);
26 if (pMinimodeDlg != nullptr)
27 {
28 //如果使用UI播放列表,则向UI中添加一个播放列表元素
29 if (pMinimodeDlg->IsUseUiPlaylist())
30 {
31 CElementFactory factory;
32 //新的UI
33 std::shared_ptr<UiElement::Element> ui_new = factory.CreateElement("element", this);
34 //创建一个垂直布局
35 std::shared_ptr<UiElement::Element> vertical_layout = factory.CreateElement("verticalLayout", this);
36 //垂直布局添加到新的UI中
37 ui_new->AddChild(vertical_layout);
38 //原来的UI添加到垂直布局中
39 vertical_layout->AddChild(m_ui_element);
40 //添加一个搜索框
41 std::shared_ptr<UiElement::Element> search_box = factory.CreateElement("searchBox", this);
42 search_box->height.FromString("26");
43 vertical_layout->AddChild(search_box);
44 //添加一个播放列表
45 m_playlist_emelment = factory.CreateElement("playlist", this);
46 vertical_layout->AddChild(m_playlist_emelment);
47 //使用新的UI
48 m_root_default = ui_new;
49 }
50 }
51 }
52
GetUiSize(int & width,int & height,int & height_with_playlist)53 bool CMiniModeUserUi::GetUiSize(int& width, int& height, int& height_with_playlist)
54 {
55 if (m_ui_element != nullptr)
56 {
57 //设置绘图区域
58 width = m_ui_element->width.GetValue(CRect());
59 height = m_ui_element->height.GetValue(CRect());
60 height_with_playlist = height + theApp.DPI(292);
61 return true;
62 }
63 return false;
64 }
65
GetPlaylist() const66 std::shared_ptr<UiElement::Playlist> CMiniModeUserUi::GetPlaylist() const
67 {
68 return std::dynamic_pointer_cast<UiElement::Playlist>(m_playlist_emelment);
69 }
70
_DrawInfo(CRect draw_rect,bool reset)71 void CMiniModeUserUi::_DrawInfo(CRect draw_rect, bool reset /*= false*/)
72 {
73 if (m_root_default != nullptr)
74 {
75 m_root_default->SetRect(draw_rect);
76 m_root_default->Draw();
77 //绘制音量调整按钮
78 DrawVolumnAdjBtn();
79 }
80 }
81
PreDrawInfo()82 void CMiniModeUserUi::PreDrawInfo()
83 {
84 //设置颜色
85 m_colors = CPlayerUIHelper::GetUIColors(theApp.m_app_setting_data.theme_color, theApp.m_app_setting_data.dark_mode, IsDrawBackgroundAlpha());
86
87 //设置绘图区域
88 int width{}, height{}, height_width_playlist;
89 GetUiSize(width, height, height_width_playlist);
90 CSize window_size;
91 if (IsShowUiPlaylist())
92 window_size = CSize(width, height_width_playlist);
93 else
94 window_size = CSize(width, height);
95
96 m_draw_rect = CRect(CPoint(0, 0), window_size);
97 }
98
LButtonUp(CPoint point)99 bool CMiniModeUserUi::LButtonUp(CPoint point)
100 {
101 for (auto& btn : m_buttons)
102 {
103 if (btn.second.rect.PtInRect(point))
104 {
105 switch (btn.first)
106 {
107 case BTN_MINI:
108 btn.second.hover = false;
109 btn.second.pressed = false;
110 m_pMainWnd->SendMessage(WM_COMMAND, IDOK);
111 return true;
112 case BTN_CLOSE:
113 if (theApp.m_general_setting_data.minimize_to_notify_icon)
114 m_pMainWnd->ShowWindow(HIDE_WINDOW);
115 else
116 m_pMainWnd->SendMessage(WM_COMMAND, ID_MINI_MODE_EXIT);
117 return true;
118 case BTN_SHOW_PLAYLIST:
119 btn.second.hover = false;
120 btn.second.pressed = false;
121 m_pMainWnd->SendMessage(WM_COMMAND, ID_SHOW_PLAY_LIST);
122 return true;
123 case BTN_SKIN:
124 {
125 btn.second.hover = false;
126 btn.second.pressed = false;
127 CPoint point1;
128 GetCursorPos(&point1);
129 CMenu* pMenu = theApp.m_menu_mgr.GetMenu(MenuMgr::MiniModeSwitchUiMenu);
130 ASSERT(pMenu != nullptr);
131 if (pMenu != nullptr)
132 pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point1.x, point1.y, m_pMainWnd);
133 return true;
134 }
135 }
136
137 }
138 }
139
140 return CUserUi::LButtonUp(point);
141 }
142
PointInControlArea(CPoint point) const143 bool CMiniModeUserUi::PointInControlArea(CPoint point) const
144 {
145 if (!__super::PointInControlArea(point))
146 {
147 bool rtn = false;
148 m_root_default->IterateAllElements([&](UiElement::Element* ele) -> bool {
149 UiElement::Button* button = dynamic_cast<UiElement::Button*>(ele);
150 if (button != nullptr && button->GetRect().PtInRect(point))
151 {
152 rtn = true;
153 return true;
154 }
155
156 UiElement::StackElement* stack_element = dynamic_cast<UiElement::StackElement*>(ele);
157 if (stack_element != nullptr && stack_element->indicator.rect.PtInRect(point))
158 {
159 rtn = true;
160 return true;
161 }
162
163 UiElement::ListElement* list_emement = dynamic_cast<UiElement::ListElement*>(ele);
164 if (list_emement != nullptr && list_emement->GetRect().PtInRect(point))
165 {
166 rtn = true;
167 return true;
168 }
169
170 UiElement::SearchBox* search_box = dynamic_cast<UiElement::SearchBox*>(ele);
171 if (search_box != nullptr && search_box->GetRect().PtInRect(point))
172 {
173 rtn = true;
174 return true;
175 }
176 return false;
177 });
178
179 return rtn;
180 }
181 else
182 {
183 return true;
184 }
185 }
186
GetStackElements() const187 const std::vector<std::shared_ptr<UiElement::Element>>& CMiniModeUserUi::GetStackElements() const
188 {
189 //由于迷你模式只会有一个UI,因此这里直接返回m_stack_elements中的第一个
190 if (!m_stack_elements.empty())
191 return m_stack_elements.begin()->second;
192 static std::vector<std::shared_ptr<UiElement::Element>> vec_empty;
193 return vec_empty;
194 }
195
IsShowUiPlaylist() const196 bool CMiniModeUserUi::IsShowUiPlaylist() const
197 {
198 CMiniModeDlg* pMinimodeDlg = dynamic_cast<CMiniModeDlg*>(m_pMainWnd);
199 if (pMinimodeDlg != nullptr)
200 {
201 return pMinimodeDlg->IsUseUiPlaylist() && pMinimodeDlg->IsShowPlaylist();
202 }
203 return false;
204 }
205