From: <sv...@op...> - 2024-11-10 21:18:30
|
Author: sagamusix Date: Sun Nov 10 22:18:18 2024 New Revision: 22150 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22150 Log: [Fix] Tuning ratio map note index text and main tool bar text was not drawn at correct DPI if the tuning window was on a different screen than the main window. Modified: trunk/OpenMPT/mptrack/ChannelManagerDlg.cpp trunk/OpenMPT/mptrack/HighDPISupport.cpp trunk/OpenMPT/mptrack/HighDPISupport.h trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainbar.cpp trunk/OpenMPT/mptrack/Mainbar.h trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/mptrack/tuningRatioMapWnd.cpp Modified: trunk/OpenMPT/mptrack/ChannelManagerDlg.cpp ============================================================================== --- trunk/OpenMPT/mptrack/ChannelManagerDlg.cpp Sun Nov 10 21:48:42 2024 (r22149) +++ trunk/OpenMPT/mptrack/ChannelManagerDlg.cpp Sun Nov 10 22:18:18 2024 (r22150) @@ -513,10 +513,7 @@ if(!m_font.m_hObject) { - NONCLIENTMETRICS metrics; - metrics.cbSize = sizeof(metrics); - HighDPISupport::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(metrics), &metrics, 0, m_hWnd); - m_font.CreateFontIndirect(&metrics.lfMessageFont); + HighDPISupport::CreateGUIFont(m_font, m_hWnd); } PAINTSTRUCT pDC; Modified: trunk/OpenMPT/mptrack/HighDPISupport.cpp ============================================================================== --- trunk/OpenMPT/mptrack/HighDPISupport.cpp Sun Nov 10 21:48:42 2024 (r22149) +++ trunk/OpenMPT/mptrack/HighDPISupport.cpp Sun Nov 10 22:18:18 2024 (r22150) @@ -148,4 +148,13 @@ } +void HighDPISupport::CreateGUIFont(CFont &font, HWND hwnd) +{ + NONCLIENTMETRICS metrics; + metrics.cbSize = sizeof(metrics); + HighDPISupport::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(metrics), &metrics, 0, hwnd); + font.CreateFontIndirect(&metrics.lfMessageFont); +} + + OPENMPT_NAMESPACE_END Modified: trunk/OpenMPT/mptrack/HighDPISupport.h ============================================================================== --- trunk/OpenMPT/mptrack/HighDPISupport.h Sun Nov 10 21:48:42 2024 (r22149) +++ trunk/OpenMPT/mptrack/HighDPISupport.h Sun Nov 10 22:18:18 2024 (r22150) @@ -41,6 +41,8 @@ BOOL SystemParametersInfo(UINT uiAction, UINT uiParam, void *pvParam, UINT fWinIni, uint32 dpi); BOOL SystemParametersInfo(UINT uiAction, UINT uiParam, void *pvParam, UINT fWinIni, HWND hwnd); + void CreateGUIFont(CFont &font, HWND hwnd); + // Applies DPI scaling factor to some given size MPT_FORCEINLINE int ScalePixels(int pixels, HWND hwnd) { Modified: trunk/OpenMPT/mptrack/MainFrm.cpp ============================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp Sun Nov 10 21:48:42 2024 (r22149) +++ trunk/OpenMPT/mptrack/MainFrm.cpp Sun Nov 10 22:18:18 2024 (r22150) @@ -160,7 +160,7 @@ // GDI HICON CMainFrame::m_hIcon = nullptr; -HFONT CMainFrame::m_hGUIFont = nullptr; +CFont CMainFrame::m_hGUIFont; HFONT CMainFrame::m_hFixedFont = nullptr; HPEN CMainFrame::penDarkGray = nullptr; HPEN CMainFrame::penGray99 = nullptr; @@ -349,10 +349,7 @@ m_SampleIcons.Create(IDB_SMPTOOLBAR, 20, 18, SAMPLEIMG_NUMIMAGES, 1, dc, scaling, false); ReleaseDC(dc); - NONCLIENTMETRICS metrics; - metrics.cbSize = sizeof(metrics); - HighDPISupport::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(metrics), &metrics, 0, m_hWnd); - m_hGUIFont = CreateFontIndirect(&metrics.lfMessageFont); + HighDPISupport::CreateGUIFont(m_hGUIFont, m_hWnd); penDarkGray = ::CreatePen(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW)); penGray99 = ::CreatePen(PS_SOLID, 0, RGB(0x99, 0x99, 0x99)); @@ -404,9 +401,9 @@ PatternFont::DeleteFontData(); // Kill GDI Objects + m_hGUIFont.DeleteObject(); #define DeleteGDIObject(h) ::DeleteObject(h); h = NULL; DeleteGDIObject(penDarkGray); - DeleteGDIObject(m_hGUIFont); DeleteGDIObject(m_hFixedFont); DeleteGDIObject(penGray99); #undef DeleteGDIObject Modified: trunk/OpenMPT/mptrack/Mainbar.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Mainbar.cpp Sun Nov 10 21:48:42 2024 (r22149) +++ trunk/OpenMPT/mptrack/Mainbar.cpp Sun Nov 10 22:18:18 2024 (r22150) @@ -308,6 +308,7 @@ LRESULT CMainToolBar::OnDPIChangedAfterParent(WPARAM, LPARAM) { auto result = Default(); + m_font.DeleteObject(); UpdateSizes(); RefreshToolbar(); return result; @@ -327,7 +328,9 @@ void CMainToolBar::UpdateSizes() { CDC *dc = GetDC(); - const auto hFont = reinterpret_cast<WPARAM>(CMainFrame::GetGUIFont()); + if(!m_font.m_hObject) + HighDPISupport::CreateGUIFont(m_font, m_hWnd); + const auto hFont = reinterpret_cast<WPARAM>(m_font.m_hObject); const double scaling = HighDPISupport::GetDpiForWindow(m_hWnd) / 96.0; const int imgSize = HighDPISupport::ScalePixels(16, m_hWnd), btnSizeX = HighDPISupport::ScalePixels(23, m_hWnd), btnSizeY = HighDPISupport::ScalePixels(22, m_hWnd); m_ImageList.Create(IDB_MAINBAR, 16, 16, IMGLIST_NUMIMAGES, 1, dc, scaling, false); @@ -352,7 +355,7 @@ {m_EditGlobalVolume, _T("999"), EDITGLOBALVOL_INDEX, IDC_EDIT_GLOBALVOL }, }; - auto oldFont = dc->SelectObject(CMainFrame::GetGUIFont()); + auto oldFont = dc->SelectObject(m_font); const int textPaddingX = HighDPISupport::ScalePixels(10, m_hWnd), textPaddingY = HighDPISupport::ScalePixels(4, m_hWnd), textMinHeight = HighDPISupport::ScalePixels(20, m_hWnd); for(auto &info : TextWnds) { Modified: trunk/OpenMPT/mptrack/Mainbar.h ============================================================================== --- trunk/OpenMPT/mptrack/Mainbar.h Sun Nov 10 21:48:42 2024 (r22149) +++ trunk/OpenMPT/mptrack/Mainbar.h Sun Nov 10 22:18:18 2024 (r22150) @@ -84,6 +84,7 @@ protected: UpdateToolTip m_tooltip; CImageListEx m_ImageList, m_ImageListDisabled; + CFont m_font; CNumberEdit m_EditTempo; CEdit m_EditSpeed, m_EditOctave, m_EditRowsPerBeat, m_EditGlobalVolume; CStatic m_StaticTempo, m_StaticSpeed, m_StaticRowsPerBeat, m_StaticGlobalVolume; Modified: trunk/OpenMPT/mptrack/Mainfrm.h ============================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h Sun Nov 10 21:48:42 2024 (r22149) +++ trunk/OpenMPT/mptrack/Mainfrm.h Sun Nov 10 22:18:18 2024 (r22150) @@ -148,7 +148,8 @@ // GDI static HICON m_hIcon; - static HFONT m_hGUIFont, m_hFixedFont; + static CFont m_hGUIFont; + static HFONT m_hFixedFont; static HPEN penDarkGray, penHalfDarkGray, penGray99; static HCURSOR curDragging, curNoDrop, curArrow, curNoDrop2, curVSplit; static MODPLUGDIB *bmpNotes; @@ -262,7 +263,6 @@ static HFONT GetGUIFont() { return m_hGUIFont; } static HFONT &GetCommentsFont() { return m_hFixedFont; } static void UpdateAllViews(UpdateHint hint, CObject *pHint=NULL); - static LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK FocusChangeProc(int code, WPARAM wParam, LPARAM lParam); static CInputHandler *m_InputHandler; Modified: trunk/OpenMPT/mptrack/Mptrack.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp Sun Nov 10 21:48:42 2024 (r22149) +++ trunk/OpenMPT/mptrack/Mptrack.cpp Sun Nov 10 22:18:18 2024 (r22150) @@ -1952,7 +1952,7 @@ } template<typename Tchar> -static void DrawButtonRectImpl(HDC hdc, CRect rect, const Tchar *lpszText, bool disabled, bool pushed, DWORD textFlags, uint32 topMargin) +static void DrawButtonRectImpl(HDC hdc, HFONT font, CRect rect, const Tchar *lpszText, bool disabled, bool pushed, DWORD textFlags, uint32 topMargin) { int width = HighDPISupport::ScalePixels(1, WindowFromDC(hdc)); if(width != 1) @@ -1985,25 +1985,36 @@ ::SetTextColor(hdc, GetSysColor(disabled ? COLOR_GRAYTEXT : COLOR_BTNTEXT)); ::SetBkMode(hdc, TRANSPARENT); rect.top += topMargin; - auto oldfont = SelectFont(hdc, CMainFrame::GetGUIFont()); + auto oldFont = SelectFont(hdc, font); DrawTextT(hdc, lpszText, -1, &rect, textFlags | DT_SINGLELINE | DT_NOPREFIX); - SelectFont(hdc, oldfont); + SelectFont(hdc, oldFont); } } void DrawButtonRect(HDC hdc, const RECT *lpRect, LPCSTR lpszText, BOOL bDisabled, BOOL bPushed, DWORD dwFlags, uint32 topMargin) { - DrawButtonRectImpl(hdc, *lpRect, lpszText, bDisabled, bPushed, dwFlags, topMargin); + DrawButtonRectImpl(hdc, CMainFrame::GetGUIFont(), *lpRect, lpszText, bDisabled, bPushed, dwFlags, topMargin); } void DrawButtonRect(HDC hdc, const RECT *lpRect, LPCWSTR lpszText, BOOL bDisabled, BOOL bPushed, DWORD dwFlags, uint32 topMargin) { - DrawButtonRectImpl(hdc, *lpRect, lpszText, bDisabled, bPushed, dwFlags, topMargin); + DrawButtonRectImpl(hdc, CMainFrame::GetGUIFont(), *lpRect, lpszText, bDisabled, bPushed, dwFlags, topMargin); } +void DrawButtonRect(HDC hdc, HFONT font, const RECT *lpRect, LPCSTR lpszText, bool bDisabled, bool bPushed, DWORD dwFlags, uint32 topMargin) +{ + DrawButtonRectImpl(hdc, font, *lpRect, lpszText, bDisabled, bPushed, dwFlags, topMargin); +} + + +void DrawButtonRect(HDC hdc, HFONT font, const RECT *lpRect, LPCWSTR lpszText, bool bDisabled, bool bPushed, DWORD dwFlags, uint32 topMargin) +{ + DrawButtonRectImpl(hdc, font, *lpRect, lpszText, bDisabled, bPushed, dwFlags, topMargin); +} + ////////////////////////////////////////////////////////////////////////////////// // Misc functions Modified: trunk/OpenMPT/mptrack/Mptrack.h ============================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h Sun Nov 10 21:48:42 2024 (r22149) +++ trunk/OpenMPT/mptrack/Mptrack.h Sun Nov 10 22:18:18 2024 (r22150) @@ -416,6 +416,8 @@ int DrawTextT(HDC hdc, const char *lpchText, int cchText, LPRECT lprc, UINT format); void DrawButtonRect(HDC hdc, const RECT *lpRect, LPCSTR lpszText = nullptr, BOOL bDisabled = FALSE, BOOL bPushed = FALSE, DWORD dwFlags = (DT_CENTER | DT_VCENTER), uint32 topMargin = 0); void DrawButtonRect(HDC hdc, const RECT *lpRect, LPCWSTR lpszText = nullptr, BOOL bDisabled = FALSE, BOOL bPushed = FALSE, DWORD dwFlags = (DT_CENTER | DT_VCENTER), uint32 topMargin = 0); +void DrawButtonRect(HDC hdc, HFONT font, const RECT *lpRect, LPCSTR lpszText = nullptr, bool bDisabled = false, bool bPushed = false, DWORD dwFlags = (DT_CENTER | DT_VCENTER), uint32 topMargin = 0); +void DrawButtonRect(HDC hdc, HFONT font, const RECT *lpRect, LPCWSTR lpszText = nullptr, bool bDisabled = false, bool bPushed = false, DWORD dwFlags = (DT_CENTER | DT_VCENTER), uint32 topMargin = 0); // Misc functions void ErrorBox(UINT nStringID, CWnd *p = nullptr); Modified: trunk/OpenMPT/mptrack/tuningRatioMapWnd.cpp ============================================================================== --- trunk/OpenMPT/mptrack/tuningRatioMapWnd.cpp Sun Nov 10 21:48:42 2024 (r22149) +++ trunk/OpenMPT/mptrack/tuningRatioMapWnd.cpp Sun Nov 10 22:18:18 2024 (r22150) @@ -56,10 +56,7 @@ } if(!m_font.m_hObject) { - NONCLIENTMETRICS metrics; - metrics.cbSize = sizeof(metrics); - HighDPISupport::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(metrics), &metrics, 0, m_hWnd); - m_font.CreateFontIndirect(&metrics.lfMessageFont); + HighDPISupport::CreateGUIFont(m_font, m_hWnd); m_cxFont = m_cyFont = 0; } @@ -91,7 +88,7 @@ rect.SetRect(0, ypaint, m_cxFont, ypaint + m_cyFont); const auto noteStr = isValidNote ? mpt::tfmt::val(noteToDraw) : mpt::tstring(_T("...")); - DrawButtonRect(dc, &rect, noteStr.c_str(), FALSE, FALSE); + DrawButtonRect(dc, m_font, &rect, noteStr.c_str(), false, false); // Mapped Note const bool highLight = focus && (nPos == (int)m_nNote); @@ -117,7 +114,7 @@ } rect.SetRect(rcClient.left + m_cxFont * 4 - 1, rcClient.top, rcClient.left + m_cxFont * 4 + 3, ypaint); - DrawButtonRect(dc, &rect, _T("")); + DrawButtonRect(dc, m_font, &rect, _T("")); if (ypaint < rcClient.bottom) { rect.SetRect(rcClient.left, ypaint, rcClient.right, rcClient.bottom); |