Skip to content

Commit

Permalink
全屏模式下同步放大UI搜索框中的图标和字体
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyang219 committed Aug 31, 2024
1 parent eb2c79c commit db7d7dd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
10 changes: 8 additions & 2 deletions MusicPlayer2/SearchEditCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ void CSearchEditCtrl::OnDrawBrowseButton(CDC * pDC, CRect rect, BOOL bIsButtonPr
IconMgr::IconType icon_type = IconMgr::IconType::IT_Find;
if (m_draw_clear_btn) // 文本框为空时显示搜索图标,否则显示关闭图标
icon_type = IconMgr::IconType::IT_Cancel;
HICON hIcon = theApp.m_icon_mgr.GetHICON(icon_type, IconMgr::IconStyle::IS_OutlinedDark, IconMgr::IconSize::IS_DPI_16);
CSize icon_size = IconMgr::GetIconSize(IconMgr::IconSize::IS_DPI_16);
IconMgr::IconSize size_type = m_big_icon ? IconMgr::IconSize::IS_DPI_16_Full_Screen : IconMgr::IconSize::IS_DPI_16;
HICON hIcon = theApp.m_icon_mgr.GetHICON(icon_type, IconMgr::IconStyle::IS_OutlinedDark, size_type);
CSize icon_size = IconMgr::GetIconSize(size_type);
CPoint icon_top_left;
icon_top_left.x = rc_draw.left + (rc_draw.Width() - icon_size.cx) / 2;
icon_top_left.y = rc_draw.top + (rc_draw.Height() - icon_size.cy) / 2;
Expand Down Expand Up @@ -122,6 +123,11 @@ void CSearchEditCtrl::OnChangeLayout()

}

void CSearchEditCtrl::SetBigIcon(bool big_icon)
{
m_big_icon = big_icon;
}

void CSearchEditCtrl::UpdateToolTipPosition()
{
CRect rc_client;
Expand Down
2 changes: 2 additions & 0 deletions MusicPlayer2/SearchEditCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CSearchEditCtrl : public CMFCEditBrowseCtrl
virtual void OnBrowse() override;
virtual void OnDrawBrowseButton(CDC* pDC, CRect rect, BOOL bIsButtonPressed, BOOL bIsButtonHot) override;
virtual void OnChangeLayout()override;
void SetBigIcon(bool big_icon);

protected:
void UpdateToolTipPosition(); //更新鼠标提示的位置
Expand All @@ -26,6 +27,7 @@ class CSearchEditCtrl : public CMFCEditBrowseCtrl
ColorTable& m_theme_color;
CToolTipCtrl m_tool_tip;
bool m_draw_clear_btn{}; //如果为true,则显示“清除搜索结果”按钮,否则,显示“搜索”按钮
bool m_big_icon{};

private:
virtual void PreSubclassWindow();
Expand Down
7 changes: 6 additions & 1 deletion MusicPlayer2/UIElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3403,10 +3403,15 @@ void UiElement::SearchBox::LButtonUp(CPoint point)
clear_btn.pressed = false;
//点击清除按钮时清除搜索结果
if (icon_rect.PtInRect(point))
{
search_box_ctrl->Clear();
}
//点击搜索框区域时显示搜索框控件
else if (search_box_ctrl != nullptr && rect.PtInRect(point))
search_box_ctrl->Show(this);
{
bool big_font{ ui->m_ui_data.full_screen && ui->IsDrawLargeIcon() };
search_box_ctrl->Show(this, big_font);
}
}

void UiElement::SearchBox::LButtonDown(CPoint point)
Expand Down
6 changes: 5 additions & 1 deletion MusicPlayer2/UiSearchBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ CUiSearchBox::~CUiSearchBox()
{
}

void CUiSearchBox::Show(UiElement::SearchBox* ui_search_box)
void CUiSearchBox::Show(UiElement::SearchBox* ui_search_box, bool big_icon)
{
m_ui_search_box = ui_search_box;
ASSERT(m_pParentWnd != nullptr);
if (m_pParentWnd != nullptr)
{
CFont& font{ theApp.m_font_set.dlg.GetFont(big_icon) };
CCommon::SetDialogFont(this, &font);
ShowWindow(SW_SHOW);
CRect rect = ui_search_box->GetRect();
m_pParentWnd->ClientToScreen(&rect);
MoveWindow(rect);
m_search_box.OnChangeLayout();
m_search_box.SetBigIcon(big_icon);
}
}

Expand Down
2 changes: 1 addition & 1 deletion MusicPlayer2/UiSearchBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CUiSearchBox : public CDialog
CUiSearchBox(CWnd* pParent); // 标准构造函数
void Create();
virtual ~CUiSearchBox();
void Show(UiElement::SearchBox* ui_search_box); //显示搜索框。ui_search_box:对应的UI中的搜索框
void Show(UiElement::SearchBox* ui_search_box, bool big_icon); //显示搜索框。ui_search_box:对应的UI中的搜索框
void Clear(); //清除搜索状态
void UpdatePos(); //当父窗口大小或位置变化时调用此函数以同步搜索框的位置(暂时未使用)

Expand Down

0 comments on commit db7d7dd

Please sign in to comment.