diff --git a/MusicPlayer2/UIElement/ComboBox.cpp b/MusicPlayer2/UIElement/ComboBox.cpp index 604b7a9a..5f298a87 100644 --- a/MusicPlayer2/UIElement/ComboBox.cpp +++ b/MusicPlayer2/UIElement/ComboBox.cpp @@ -72,11 +72,6 @@ bool UiElement::ComboBox::LButtonUp(CPoint point) show_drop_list = !show_drop_list; return true; } - if (show_drop_list && rect_drop_list.PtInRect(point)) - { - drop_list->LButtonUp(point); - return true; - } return false; } @@ -121,8 +116,9 @@ bool UiElement::ComboBox::MouseLeave() return false; } -void UiElement::ComboBox::TopMostClicked(CPoint point) +bool UiElement::ComboBox::GlobalLButtonUp(CPoint point) { + bool rtn = false; if (!rect.PtInRect(point) && IsShown() && IsEnable()) { if (show_drop_list && rect_drop_list.PtInRect(point)) @@ -136,10 +132,21 @@ void UiElement::ComboBox::TopMostClicked(CPoint point) if (m_selection_changed_trigger) m_selection_changed_trigger(this); } + rtn = true; } show_drop_list = false; - } + return rtn; +} + +bool UiElement::ComboBox::GlobalLButtonDown(CPoint point) +{ + if (IsShown() && IsEnable() && show_drop_list && rect_drop_list.PtInRect(point)) + { + drop_list->LButtonDown(point); + return true; + } + return false; } void UiElement::ComboBox::AddString(const std::wstring& str) diff --git a/MusicPlayer2/UIElement/ComboBox.h b/MusicPlayer2/UIElement/ComboBox.h index c438cfd2..5599eab8 100644 --- a/MusicPlayer2/UIElement/ComboBox.h +++ b/MusicPlayer2/UIElement/ComboBox.h @@ -13,7 +13,8 @@ namespace UiElement virtual bool LButtonDown(CPoint point) override; virtual bool MouseMove(CPoint point) override; virtual bool MouseLeave() override; - virtual void TopMostClicked(CPoint point) override; + virtual bool GlobalLButtonUp(CPoint point) override; + virtual bool GlobalLButtonDown(CPoint point) override; void AddString(const std::wstring& str); void SetCurSel(int index); diff --git a/MusicPlayer2/UIElement/UIElement.cpp b/MusicPlayer2/UIElement/UIElement.cpp index 3e390eda..46610120 100644 --- a/MusicPlayer2/UIElement/UIElement.cpp +++ b/MusicPlayer2/UIElement/UIElement.cpp @@ -138,10 +138,24 @@ void UiElement::Element::ClearRect() //rect = CRect(); } -void UiElement::Element::TopMostClicked(CPoint point) +bool UiElement::Element::GlobalLButtonUp(CPoint point) { for (auto& child : childLst) - child->TopMostClicked(point); + { + if (child->GlobalLButtonUp(point)) + return true; + } + return false; +} + +bool UiElement::Element::GlobalLButtonDown(CPoint point) +{ + for (auto& child : childLst) + { + if (child->GlobalLButtonDown(point)) + return true; + } + return false; } UiElement::Element* UiElement::Element::RootElement() diff --git a/MusicPlayer2/UIElement/UIElement.h b/MusicPlayer2/UIElement/UIElement.h index 33b3ed0a..92fa2c06 100644 --- a/MusicPlayer2/UIElement/UIElement.h +++ b/MusicPlayer2/UIElement/UIElement.h @@ -68,7 +68,8 @@ namespace UiElement CRect GetRect() const; //获取此元素在界面中的矩形区域 void SetRect(CRect _rect); virtual void ClearRect(); - virtual void TopMostClicked(CPoint point); //鼠标左键点击时响应,用于隐藏元素顶层的显示 + virtual bool GlobalLButtonUp(CPoint point); //响应全局鼠标左键抬起事件 + virtual bool GlobalLButtonDown(CPoint point); //响应全局鼠标左键按下事件 //遍历所有界面元素 //visible_only为true时,遇到stackElement时,只遍历stackElement下面可见的子节点 diff --git a/MusicPlayer2/UIElement/Volume.cpp b/MusicPlayer2/UIElement/Volume.cpp index a9801a56..1e3d6dd8 100644 --- a/MusicPlayer2/UIElement/Volume.cpp +++ b/MusicPlayer2/UIElement/Volume.cpp @@ -212,8 +212,11 @@ bool UiElement::Volume::MouseWheel(int delta, CPoint point) return false; } -void UiElement::Volume::TopMostClicked(CPoint point) +bool UiElement::Volume::GlobalLButtonUp(CPoint point) { + bool rtn = false; + volumn_up_btn.pressed = false; + volumn_down_btn.pressed = false; if (!rect.PtInRect(point) && IsShown()) { //Èç¹ûÒѾ­ÏÔʾÁËÒôÁ¿µ÷Õû°´ť£¬Ôòµã»÷ÒôÁ¿µ÷Õûʱ±£³ÖÒôÁ¿µ÷Õû°´ťµÄÏÔʾ @@ -221,13 +224,13 @@ void UiElement::Volume::TopMostClicked(CPoint point) { if (volumn_up_btn.rect.PtInRect(point)) { - m_show_volume_adj = true; CPlayer::GetInstance().MusicControl(Command::VOLUME_ADJ, theApp.m_nc_setting_data.volum_step); + rtn = true; } else if (volumn_down_btn.rect.PtInRect(point)) { - m_show_volume_adj = true; CPlayer::GetInstance().MusicControl(Command::VOLUME_ADJ, -theApp.m_nc_setting_data.volum_step); + rtn = true; } else { @@ -235,6 +238,24 @@ void UiElement::Volume::TopMostClicked(CPoint point) } } } + return rtn; +} + +bool UiElement::Volume::GlobalLButtonDown(CPoint point) +{ + bool rtn = false; + if (IsShown() && IsEnable() && m_show_volume_adj) + { + if (volumn_up_btn.rect.PtInRect(point)) + { + volumn_up_btn.pressed = true; + } + else if (volumn_down_btn.rect.PtInRect(point)) + { + volumn_down_btn.pressed = true; + } + } + return false; } void UiElement::Volume::FromXmlNode(tinyxml2::XMLElement* xml_node) diff --git a/MusicPlayer2/UIElement/Volume.h b/MusicPlayer2/UIElement/Volume.h index 87eae90b..f94c3841 100644 --- a/MusicPlayer2/UIElement/Volume.h +++ b/MusicPlayer2/UIElement/Volume.h @@ -14,7 +14,8 @@ namespace UiElement virtual bool MouseMove(CPoint point) override; virtual bool MouseWheel(int delta, CPoint point) override; - virtual void TopMostClicked(CPoint point) override; + virtual bool GlobalLButtonUp(CPoint point) override; + virtual bool GlobalLButtonDown(CPoint point) override; virtual void FromXmlNode(tinyxml2::XMLElement* xml_node); protected: diff --git a/MusicPlayer2/UserUi.cpp b/MusicPlayer2/UserUi.cpp index 5155ba26..2ebfc49d 100644 --- a/MusicPlayer2/UserUi.cpp +++ b/MusicPlayer2/UserUi.cpp @@ -338,7 +338,8 @@ wstring CUserUi::GetUIName() bool CUserUi::LButtonUp(CPoint point) { auto root_element = GetMouseEventResponseElement(); - root_element->TopMostClicked(point); + if (root_element->GlobalLButtonUp(point)) + return true; if (!CPlayerUIBase::LButtonUp(point) && !CPlayerUIBase::PointInMenubarArea(point) && !CPlayerUIBase::PointInTitlebarArea(point)) { //显示了面板,且不是全屏面板的情况下,点击面板以外的地方关闭面板 @@ -360,12 +361,14 @@ bool CUserUi::LButtonUp(CPoint point) bool CUserUi::LButtonDown(CPoint point) { m_mouse_clicked_point = point; + auto root_element = GetMouseEventResponseElement(); + if (root_element->GlobalLButtonDown(point)) + return true; if (!CPlayerUIBase::LButtonDown(point)) { bool rtn = false; if (!CPlayerUIBase::PointInMenubarArea(point) && !CPlayerUIBase::PointInTitlebarArea(point)) { - auto root_element = GetMouseEventResponseElement(); rtn = root_element->LButtonDown(point); } return rtn; @@ -422,7 +425,7 @@ bool CUserUi::RButtonUp(CPoint point) { auto root_element = GetMouseEventResponseElement(); rtn = root_element->RButtonUp(point); - root_element->TopMostClicked(point); + root_element->GlobalLButtonUp(point); } if (!rtn) rtn = CPlayerUIBase::RButtonUp(point); diff --git a/MusicPlayer2/res/ui/test_panel.xml b/MusicPlayer2/res/ui/test_panel.xml index c41a8dff..525e9ec2 100644 --- a/MusicPlayer2/res/ui/test_panel.xml +++ b/MusicPlayer2/res/ui/test_panel.xml @@ -35,6 +35,7 @@ +