1 #pragma once 2 #include "LyricsWindow.h" 3 #include "CommonData.h" 4 #include "IniHelper.h" 5 #include "IconMgr.h" 6 7 struct LyricStyle 8 { 9 COLORREF color1 = 0; 10 COLORREF color2 = 0; 11 int gradient_mode = 0; 12 }; 13 14 struct LyricStyleDefaultData //桌面歌词预设数据 15 { 16 LyricStyle normal_style; 17 LyricStyle highlight_style; 18 }; 19 const int LYRIC_DEFAULT_STYLE_NUM = 3; 20 21 class CDesktopLyric : public CLyricsWindow 22 { 23 public: 24 struct UIButton //界面中绘制的按钮 25 { 26 CRect rect; //按钮的矩形区域 27 bool hover{ false }; //鼠标是否指向按钮 28 bool pressed{ false }; //按钮是否按下 29 bool enable{ true }; //按钮是否启用 30 }; 31 32 enum BtnKey //标识按钮的类型 33 { 34 BTN_APP, 35 BTN_STOP, //停止 36 BTN_PREVIOUS, //上一曲 37 BTN_PLAY_PAUSE, //播放/暂停 38 BTN_NEXT, //下一曲 39 BTN_LOCK, 40 BTN_DOUBLE_LINE, 41 BTN_BACKGROUND_PENETRATE, 42 BTN_SETTING, 43 BTN_LYRIC_DELAY, 44 BTN_LYRIC_FORWARD, 45 BTN_DEFAULT_STYLE, 46 BTN_CLOSE, 47 MAX //用于指示枚举的最大个数 48 }; 49 50 public: 51 CDesktopLyric(); 52 ~CDesktopLyric(); 53 54 void Create(); 55 // 由ui线程调用,刷新一次桌面歌词显示 56 void ShowLyric(); 57 // 从播放实例获取歌词信息,由PreDrawLyric调用 58 void UpdateLyric(Gdiplus::Graphics* pGraphics, Gdiplus::Font* pFont); 59 void ClearLyric(); 60 void ApplySettings(const DesktopLyricSettingData& data); 61 void SetLyricWindowVisible(bool visible); 62 void SetLyricWindowLock(bool locked); 63 void SetLyricOpacity(int opacity); 64 void SetLyricBackgroundPenetrate(bool penetrate); 65 LyricStyleDefaultData GetDefaultStyle(int index) const; 66 void SetDefaultStyle(const LyricStyleDefaultData& style_data, int index); 67 void RestoreDefaultStyle(); 68 69 static void LyricStyleDefaultDataToLyricSettingData(const LyricStyleDefaultData& style_data, DesktopLyricSettingData& setting_data); 70 static void LyricSettingDatatOLyricStyleDefaultData(const DesktopLyricSettingData& setting_data, LyricStyleDefaultData& style_data); 71 72 void LoadDefaultStyle(CIniHelper& ini); 73 void SaveDefaultStyle(CIniHelper& ini) const; 74 75 void UpdateMouseToolTip(BtnKey btn, LPCTSTR str); 76 void UpdateToolTipPosition(); 77 78 protected: 79 //添加鼠标提示 80 void AddToolTips(); 81 //为一个按钮添加鼠标提示 82 void AddMouseToolTip(BtnKey btn, LPCTSTR str); 83 //绘制工具条 84 void DrawToolbar(Gdiplus::Graphics* pGraphics); 85 //绘制工具条上的图标 86 void DrawToolIcon(Gdiplus::Graphics* pGraphics, IconMgr::IconType icon_type, CRect rect, BtnKey btn, bool checked = false); 87 88 virtual void PreDrawLyric(Gdiplus::Graphics* pGraphics, Gdiplus::Font* pFont) override; 89 virtual void AfterDrawLyric(Gdiplus::Graphics* pGraphics) override; 90 91 private: 92 void SetWindowStyle(); 93 94 private: 95 //CLyricsWindow m_lyric_window; 96 LyricStyleDefaultData m_default_style[LYRIC_DEFAULT_STYLE_NUM]; 97 98 CToolTipCtrl m_tool_tip; 99 std::map<BtnKey, UIButton> m_buttons; 100 bool m_first_draw = true; //第一次绘制工具条时,则为true 101 bool m_bHover = false; //鼠标是否在指向窗口 102 bool m_bMouseInWindowRect = false; //鼠标是否在当前窗口区域内 103 bool m_bMenuPopedUp = false; 104 bool m_bLocked = false; //是否锁定歌词窗口 105 bool m_lyricBackgroundPenetrate = false; 106 107 public: 108 afx_msg void OnLButtonDown(UINT nFlags, CPoint point); 109 afx_msg void OnLButtonUp(UINT nFlags, CPoint point); 110 afx_msg void OnMouseMove(UINT nFlags, CPoint point); 111 afx_msg void OnMouseHover(UINT nFlags, CPoint point); 112 afx_msg void OnMouseLeave(); 113 afx_msg void OnSizing(UINT fwSide, LPRECT pRect); 114 afx_msg void OnRButtonUp(UINT nFlags, CPoint point); 115 virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); 116 afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI); 117 protected: 118 // afx_msg LRESULT OnInitmenu(WPARAM wParam, LPARAM lParam); 119 public: 120 virtual BOOL PreTranslateMessage(MSG* pMsg); 121 afx_msg void OnTimer(UINT_PTR nIDEvent); 122 123 DECLARE_MESSAGE_MAP() 124 afx_msg void OnLyricDefaultStyle1(); 125 afx_msg void OnLyricDefaultStyle2(); 126 afx_msg void OnLyricDefaultStyle3(); 127 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); 128 afx_msg void OnInitMenu(CMenu* pMenu); 129 }; 130