Skip to content

Commit

Permalink
添加IconMgr类重构HICON缓存 part05
Browse files Browse the repository at this point in the history
  • Loading branch information
lrisora committed Jun 19, 2024
1 parent d0f6637 commit ccb67e1
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 390 deletions.
43 changes: 12 additions & 31 deletions MusicPlayer2/CMediaLibDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ BOOL CMediaLibDlg::OnInitDialog()
SetButtonIcon(IDC_STATISTICS_INFO_BUTTON, IconMgr::IconType::IT_Info);
SetButtonIcon(IDC_PLAY_SELECTED, IconMgr::IconType::IT_Play);

//为每个标签添加图标
CImageList ImageList;
ImageList.Create(theApp.DPI(16), theApp.DPI(16), ILC_COLOR32 | ILC_MASK, 2, 2);

// 创建子对话框,因为CMediaLibDlg不会及时析构为避免持续占用大量内存不再使用成员变量存储子窗口窗口类
m_path_dlg = new CSetPathDlg();
m_playlist_dlg = new CSelectPlaylistDlg();
Expand All @@ -114,91 +110,76 @@ BOOL CMediaLibDlg::OnInitDialog()
m_folder_explore_dlg = new CFolderExploreDlg();
//文件夹
m_path_dlg->Create(IDD_SET_PATH_DIALOG);
ImageList.Add(theApp.m_icon_set.select_folder.GetIcon(true));
m_tab_ctrl.AddWindow(m_path_dlg, theApp.m_str_table.LoadText(L"TXT_FOLDER").c_str());
m_tab_ctrl.AddWindow(m_path_dlg, theApp.m_str_table.LoadText(L"TXT_FOLDER").c_str(), IconMgr::IconType::IT_Folder);

//播放列表
m_playlist_dlg->Create(IDD_SELECT_PLAYLIST_DIALOG);
ImageList.Add(theApp.m_icon_set.show_playlist.GetIcon(true));
m_tab_ctrl.AddWindow(m_playlist_dlg, theApp.m_str_table.LoadText(L"TXT_PLAYLIST").c_str());
m_tab_ctrl.AddWindow(m_playlist_dlg, theApp.m_str_table.LoadText(L"TXT_PLAYLIST").c_str(), IconMgr::IconType::IT_Playlist);

//艺术家
if ((theApp.m_media_lib_setting_data.display_item & MLDI_ARTIST) || (m_tab_show_force & MLDI_ARTIST))
{
m_artist_dlg->Create(IDD_MEDIA_CLASSIFY_DIALOG);
ImageList.Add(theApp.m_icon_set.artist.GetIcon(true));
m_tab_ctrl.AddWindow(m_artist_dlg, theApp.m_str_table.LoadText(L"TXT_ARTIST").c_str());
m_tab_ctrl.AddWindow(m_artist_dlg, theApp.m_str_table.LoadText(L"TXT_ARTIST").c_str(), IconMgr::IconType::IT_Artist);
}
//唱片集
if ((theApp.m_media_lib_setting_data.display_item & MLDI_ALBUM) || (m_tab_show_force & MLDI_ALBUM))
{
m_album_dlg->Create(IDD_MEDIA_CLASSIFY_DIALOG);
ImageList.Add(theApp.m_icon_set.album.GetIcon(true));
m_tab_ctrl.AddWindow(m_album_dlg, theApp.m_str_table.LoadText(L"TXT_ALBUM").c_str());
m_tab_ctrl.AddWindow(m_album_dlg, theApp.m_str_table.LoadText(L"TXT_ALBUM").c_str(), IconMgr::IconType::IT_Album);
}
//流派
if (theApp.m_media_lib_setting_data.display_item & MLDI_GENRE)
{
m_genre_dlg->Create(IDD_MEDIA_CLASSIFY_DIALOG);
ImageList.Add(theApp.m_icon_set.genre.GetIcon(true));
m_tab_ctrl.AddWindow(m_genre_dlg, theApp.m_str_table.LoadText(L"TXT_GENRE").c_str());
m_tab_ctrl.AddWindow(m_genre_dlg, theApp.m_str_table.LoadText(L"TXT_GENRE").c_str(), IconMgr::IconType::IT_Genre);
}
//年份
if (theApp.m_media_lib_setting_data.display_item & MLDI_YEAR)
{
m_year_dlg->Create(IDD_MEDIA_CLASSIFY_DIALOG);
ImageList.Add(theApp.m_icon_set.year.GetIcon(true));
m_tab_ctrl.AddWindow(m_year_dlg, theApp.m_str_table.LoadText(L"TXT_YEAR").c_str());
m_tab_ctrl.AddWindow(m_year_dlg, theApp.m_str_table.LoadText(L"TXT_YEAR").c_str(), IconMgr::IconType::IT_Year);
}
//类型
if (theApp.m_media_lib_setting_data.display_item & MLDI_TYPE)
{
m_type_dlg->Create(IDD_MEDIA_CLASSIFY_DIALOG);
ImageList.Add(theApp.m_icon_set.file_relate);
m_tab_ctrl.AddWindow(m_type_dlg, theApp.m_str_table.LoadText(L"TXT_FILE_TYPE").c_str());
m_tab_ctrl.AddWindow(m_type_dlg, theApp.m_str_table.LoadText(L"TXT_FILE_TYPE").c_str(), IconMgr::IconType::IT_File_Relate);
}
//比特率
if (theApp.m_media_lib_setting_data.display_item & MLDI_BITRATE)
{
m_bitrate_dlg->Create(IDD_MEDIA_CLASSIFY_DIALOG);
ImageList.Add(theApp.m_icon_set.bitrate);
m_tab_ctrl.AddWindow(m_bitrate_dlg, theApp.m_str_table.LoadText(L"TXT_BITRATE").c_str());
m_tab_ctrl.AddWindow(m_bitrate_dlg, theApp.m_str_table.LoadText(L"TXT_BITRATE").c_str(), IconMgr::IconType::IT_Bitrate);
}
//分级
if (theApp.m_media_lib_setting_data.display_item & MLDI_RATING)
{
m_rating_dlg->Create(IDD_MEDIA_CLASSIFY_DIALOG);
ImageList.Add(theApp.m_icon_set.star);
m_tab_ctrl.AddWindow(m_rating_dlg, theApp.m_str_table.LoadText(L"TXT_RATING").c_str());
m_tab_ctrl.AddWindow(m_rating_dlg, theApp.m_str_table.LoadText(L"TXT_RATING").c_str(), IconMgr::IconType::IT_Star);
}
//所有曲目
if (theApp.m_media_lib_setting_data.display_item & MLDI_ALL)
{
m_all_media_dlg->Create(IDD_ALL_MEDIA_DIALOG);
ImageList.Add(theApp.m_icon_set.media_lib.GetIcon(true));
m_tab_ctrl.AddWindow(m_all_media_dlg, theApp.m_str_table.LoadText(L"TXT_ALL_TRACKS").c_str());
m_tab_ctrl.AddWindow(m_all_media_dlg, theApp.m_str_table.LoadText(L"TXT_ALL_TRACKS").c_str(), IconMgr::IconType::IT_Media_Lib);
}
//最近播放
if (theApp.m_media_lib_setting_data.display_item & MLDI_RECENT)
{
m_recent_media_dlg->Create(IDD_ALL_MEDIA_DIALOG);
ImageList.Add(theApp.m_icon_set.recent_songs.GetIcon(true));
m_tab_ctrl.AddWindow(m_recent_media_dlg, theApp.m_str_table.LoadText(L"TXT_RECENT_PLAYED").c_str());
m_tab_ctrl.AddWindow(m_recent_media_dlg, theApp.m_str_table.LoadText(L"TXT_RECENT_PLAYED").c_str(), IconMgr::IconType::IT_History);
}
//文件夹浏览
if (theApp.m_media_lib_setting_data.display_item & MLDI_FOLDER_EXPLORE)
{
m_folder_explore_dlg->Create(IDD_FOLDER_EXPLORE_DIALOG);
ImageList.Add(theApp.m_icon_set.folder_explore.GetIcon(true));
m_tab_ctrl.AddWindow(m_folder_explore_dlg, theApp.m_str_table.LoadText(L"TXT_FOLDER_EXPLORE").c_str());
m_tab_ctrl.AddWindow(m_folder_explore_dlg, theApp.m_str_table.LoadText(L"TXT_FOLDER_EXPLORE").c_str(), IconMgr::IconType::IT_Folder_Explore);
}

m_tab_ctrl.SetItemSize(CSize(theApp.DPI(60), theApp.DPI(24)));
m_tab_ctrl.AdjustTabWindowSize();

m_tab_ctrl.SetImageList(&ImageList);
ImageList.Detach();

m_tab_ctrl.SetCurTab(m_init_tab);

OnPlaySelectedBtnEnable(0, 0);
Expand Down
16 changes: 15 additions & 1 deletion MusicPlayer2/CTabCtrlEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CTabCtrlEx::~CTabCtrlEx()
{
}

void CTabCtrlEx::AddWindow(CWnd* pWnd, LPCTSTR lable_text)
void CTabCtrlEx::AddWindow(CWnd* pWnd, LPCTSTR lable_text, IconMgr::IconType icon_type)
{
if (pWnd == nullptr || pWnd->GetSafeHwnd() == NULL)
return;
Expand All @@ -31,6 +31,8 @@ void CTabCtrlEx::AddWindow(CWnd* pWnd, LPCTSTR lable_text)
pWnd->MoveWindow(m_tab_rect);

m_tab_list.push_back(pWnd);
if (icon_type != IconMgr::IconType::IT_NO_ICON)
m_icon_list.push_back(icon_type);
}

void CTabCtrlEx::SetCurTab(int index)
Expand Down Expand Up @@ -75,6 +77,18 @@ void CTabCtrlEx::AdjustTabWindowSize()
{
m_tab_list[i]->MoveWindow(m_tab_rect);
}
//为每个标签添加图标
if (m_icon_list.empty())
return;
CImageList ImageList;
ImageList.Create(theApp.DPI(16), theApp.DPI(16), ILC_COLOR32 | ILC_MASK, 2, 2);
for (auto icon_type : m_icon_list)
{
HICON hIcon = theApp.m_icon_mgr.GetHICON(icon_type, IconMgr::IconStyle::IS_OutlinedDark, IconMgr::IconSize::IS_DPI_16);
ImageList.Add(hIcon);
}
SetImageList(&ImageList);
ImageList.Detach();
}

void CTabCtrlEx::CalSubWindowSize()
Expand Down
6 changes: 4 additions & 2 deletions MusicPlayer2/CTabCtrlEx.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once

#include "IconMgr.h"

// CTabCtrlEx

Expand All @@ -11,9 +11,10 @@ class CTabCtrlEx : public CTabCtrl
CTabCtrlEx();
virtual ~CTabCtrlEx();

void AddWindow(CWnd* pWnd, LPCTSTR lable_text); //向当前tab控件添加一个子窗口
void AddWindow(CWnd* pWnd, LPCTSTR lable_text, IconMgr::IconType icon_type); //向当前tab控件添加一个子窗口
void SetCurTab(int index);
CWnd* GetCurrentTab();
// 调整所有标签页大小兼执行设置图标
void AdjustTabWindowSize();

protected:
Expand All @@ -23,6 +24,7 @@ class CTabCtrlEx : public CTabCtrl

protected:
vector<CWnd*> m_tab_list; //保存tab控件每个子窗口的指针
vector<IconMgr::IconType> m_icon_list;
public:
afx_msg void OnTcnSelchange(NMHDR *pNMHDR, LRESULT *pResult);
virtual void PreSubclassWindow();
Expand Down
177 changes: 0 additions & 177 deletions MusicPlayer2/CommonData.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,183 +415,6 @@ struct NonCategorizedSettingData
int debug_log{ 0 }; //是否写入日志信息
};

struct IconRes
{
private:
HICON hIcon{};
HICON hIconDark{};
HICON hIconLarge{};
HICON hIconDarkLarge{};
CSize iconSize{};
CSize iconSizeLarge{};

public:
const HICON& GetIcon(bool dark = false, bool large = false) const
{
if (large)
return (dark && hIconDarkLarge != NULL ? hIconDarkLarge : hIconLarge);
else
return (dark && hIconDark != NULL ? hIconDark : hIcon);
}

void Load(UINT id, UINT id_dark, int size)
{
int size_large = static_cast<int>(size * CONSTVAL::FULL_SCREEN_ZOOM_FACTOR);

if (size < 32)
size = CCommon::IconSizeNormalize(size);
if (size_large < 32)
size_large = CCommon::IconSizeNormalize(size_large);

if (id != 0)
{
hIcon = CDrawCommon::LoadIconResource(id, size, size);
hIconLarge = CDrawCommon::LoadIconResource(id, size_large, size_large);
}
if (id_dark != 0)
{
hIconDark = CDrawCommon::LoadIconResource(id_dark, size, size);
hIconDarkLarge = CDrawCommon::LoadIconResource(id_dark, size_large, size_large);
}
iconSize.cx = iconSize.cy = size;
iconSizeLarge.cx = iconSizeLarge.cy = size_large;
}

const CSize& GetSize(bool large = false) const
{
return (large ? iconSizeLarge : iconSize);
}
};

struct IconSet
{
//界面图标
IconRes app;
HICON default_cover;
HICON default_cover_small;
HICON default_cover_not_played;
HICON default_cover_small_not_played;
IconRes default_cover_toolbar;
IconRes default_cover_toolbar_not_played;
IconRes skin;
IconRes eq;
IconRes setting;
IconRes mini;
IconRes play_oder;
IconRes play_shuffle;
IconRes play_random;
IconRes loop_playlist;
IconRes loop_track;
IconRes play_track;
IconRes previous;
IconRes play;
IconRes pause;
IconRes next;
IconRes stop;
IconRes info;
IconRes select_folder;
IconRes media_lib;
IconRes show_playlist;
IconRes find_songs;
IconRes full_screen;
IconRes full_screen1;
IconRes menu;
IconRes favourite;
IconRes heart;
IconRes double_line;
IconRes lock;
IconRes close;
IconRes edit;
IconRes add;
IconRes artist;
IconRes album;
IconRes genre;
IconRes year;
IconRes folder_explore;
IconRes lyric_forward;
IconRes lyric_delay;
IconRes recent_songs;
IconRes volume1;
IconRes volume2;
IconRes volume3;
IconRes volume0;

IconRes stop_l;
IconRes previous_l;
IconRes play_l;
IconRes pause_l;
IconRes next_l;

IconRes play_new;
IconRes pause_new;
IconRes previous_new;
IconRes next_new;

IconRes app_close;
IconRes maximize;
IconRes minimize;
IconRes restore;
IconRes sort;
IconRes display_mode;
IconRes link;
IconRes unlink;
IconRes switch_display;
IconRes lyric;
IconRes playlist_dock;
IconRes help;
IconRes dark_mode;
IconRes mini_restore;

//菜单图标(仅16x16)
HICON stop_new;
HICON save_new;
HICON save_as;
HICON music;
HICON file_relate;
HICON online;
HICON play_pause;
HICON convert;
HICON download;
HICON download1;
HICON ff_new;
HICON rew_new;
HICON playlist_float;
HICON statistics;
HICON pin;
HICON exit;
HICON album_cover;
HICON rename;
HICON tag;
HICON star;
HICON internal_lyric;
HICON speed_up;
HICON slow_down;
HICON shortcut;
HICON play_as_next;
HICON play_in_playlist;
HICON copy;
HICON play_in_folder;
HICON bitrate;
HICON reverb;
HICON hot_key;
HICON fix;
HICON up;

// 歌词编辑窗口的菜单图标(仅16x16)
HICON le_add_tag;
HICON le_replace_tag;
HICON le_delete_tag;
HICON le_find;
HICON le_replace;

HICON ok;
IconRes locate;
IconRes expand;

//通知区图标
HICON notify_icons[MAX_NOTIFY_ICON];
};


//界面相关的一些选项
struct UIData
Expand Down
12 changes: 12 additions & 0 deletions MusicPlayer2/IconMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ std::tuple<UINT, UINT, UINT, UINT> IconMgr::GetIconID(IconType type)
return { IDI_ARTIST_D, NULL, NULL, NULL };
case IconMgr::IconType::IT_Album:
return { IDI_ALBUM_D, NULL, NULL, NULL };
case IconMgr::IconType::IT_Genre:
return { IDI_GENRE_D, NULL, NULL, NULL };
case IconMgr::IconType::IT_Year:
return { IDI_YEAR_D, NULL, NULL, NULL };
case IconMgr::IconType::IT_Bitrate:
return { IDI_BITRATE, NULL, NULL, NULL };
case IconMgr::IconType::IT_History:
return { IDI_RECENT_SONG_D, NULL, NULL, NULL };
case IconMgr::IconType::IT_Key_Board:
return { IDI_HOT_KEY, NULL, NULL, NULL };
case IconMgr::IconType::IT_Reverb:
return { IDI_REVERB, NULL, NULL, NULL };
case IconMgr::IconType::IT_Double_Line:
return { IDI_DOUBLE_LINE_D, NULL, NULL, NULL };
case IconMgr::IconType::IT_Lock:
Expand Down
6 changes: 6 additions & 0 deletions MusicPlayer2/IconMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class IconMgr
IT_Star, // 星星/分级
IT_Artist, // 艺术家
IT_Album, // 专辑
IT_Genre, // 流派
IT_Year, // 年份
IT_Bitrate, // 比特率
IT_History, // 最近播放
IT_Key_Board, // 快捷键
IT_Reverb, // 混响
IT_Double_Line, // 双行
IT_Lock, // 锁/桌面歌词锁定
IT_Play_As_Next, // 下一首播放
Expand Down
Loading

0 comments on commit ccb67e1

Please sign in to comment.