From: <sv...@op...> - 2025-01-03 15:41:03
|
Author: sagamusix Date: Fri Jan 3 16:40:39 2025 New Revision: 22740 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22740 Log: [Fix] Pattern tab: With smooth scrolling enabling, buttons were always drawn natively, even at 96 DPI, because we cannot obtain a window handle from an offscreen DC. Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/Draw_pat.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/mptrack/View_pat.h trunk/OpenMPT/mptrack/tuningRatioMapWnd.cpp Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp Fri Jan 3 11:47:43 2025 (r22739) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp Fri Jan 3 16:40:39 2025 (r22740) @@ -173,6 +173,7 @@ const auto highlightBrush = GetSysColorBrush(COLOR_HIGHLIGHT), windowBrush = GetSysColorBrush(COLOR_WINDOW); const auto colorText = GetSysColor(COLOR_WINDOWTEXT); const auto colorTextSel = GetSysColor(COLOR_HIGHLIGHTTEXT); + const int lineWidth = HighDPISupport::ScalePixels(1, *this); auto oldFont = dc.SelectObject(CMainFrame::GetGUIFont()); dc.SetBkMode(TRANSPARENT); if ((m_cxFont <= 0) || (m_cyFont <= 0)) @@ -215,7 +216,7 @@ s.clear(); } rect.SetRect(0, ypaint, m_cxFont, ypaint+m_cyFont); - DrawButtonRect(dc, &rect, s.c_str(), FALSE, FALSE); + DrawButtonRect(dc, lineWidth, &rect, s.c_str(), false, false); // Mapped Note bool highlight = ((focus) && (nPos == (int)m_nNote)); rect.left = rect.right; @@ -262,7 +263,7 @@ dc.DrawText(s.c_str(), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX); } rect.SetRect(rcClient.left + m_cxFont * 2 - 1, rcClient.top, rcClient.left + m_cxFont * 2 + 3, ypaint); - DrawButtonRect(dc, &rect, _T(""), FALSE, FALSE); + DrawButtonRect(dc, lineWidth, &rect, _T(""), false, false); if (ypaint < rcClient.bottom) { rect.SetRect(rcClient.left, ypaint, rcClient.right, rcClient.bottom); Modified: trunk/OpenMPT/mptrack/Draw_pat.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Draw_pat.cpp Fri Jan 3 11:47:43 2025 (r22739) +++ trunk/OpenMPT/mptrack/Draw_pat.cpp Fri Jan 3 16:40:39 2025 (r22740) @@ -538,18 +538,20 @@ if ((pModDoc = GetDocument()) == nullptr) return; m_chnState.resize(pModDoc->GetNumChannels()); - + + FlagSet<PatternSetup> patternSetup = TrackerSettings::Instance().patternSetup; const int vuHeight = MulDiv(VUMETERS_HEIGHT, m_dpi, 96); const int colHeight = MulDiv(COLHDR_HEIGHT, m_dpi, 96); const int chanColorHeight = MulDiv(4, m_dpi, 96); const int chanColorOffset = MulDiv(2, m_dpi, 96); const int recordInsX = MulDiv(3, m_dpi, 96); - const bool doSmoothScroll = (TrackerSettings::Instance().patternSetup & PatternSetup::SmoothScrolling); + const bool doSmoothScroll = patternSetup[PatternSetup::SmoothScrolling]; + const int lineWidth = HighDPISupport::ScalePixels(1, *this); GetClientRect(&rcClient); HDC hdc; - HBITMAP oldBitmap = NULL; + HBITMAP oldBitmap = nullptr; if(doSmoothScroll) { if(rcClient != m_oldClient) @@ -593,7 +595,7 @@ PATTERNINDEX nPrevPat = PATTERNINDEX_INVALID; // Display previous pattern - if(TrackerSettings::Instance().patternSetup & PatternSetup::ShowPrevNextPattern) + if(patternSetup[PatternSetup::ShowPrevNextPattern]) { if(m_nOrder > 0 && m_nOrder < ordCount) { @@ -614,7 +616,7 @@ ypaint += (nSkip - n) * m_szCell.cy; rect.SetRect(0, m_szHeader.cy, nColumnWidth * ncols + m_szHeader.cx, ypaint - 1); m_Dib.SetBlendMode(true); - DrawPatternData(hdc, nPrevPat, false, false, + DrawPatternData(hdc, lineWidth, nPrevPat, false, false, nPrevRows - n, nPrevRows, xofs, rcClient, &ypaint); m_Dib.SetBlendMode(false); } else @@ -637,10 +639,10 @@ UINT nrows = sndFile.Patterns.IsValidPat(m_nPattern) ? sndFile.Patterns[m_nPattern].GetNumRows() : 0; int ypatternend = ypaint + (nrows-yofs)*m_szCell.cy; - DrawPatternData(hdc, m_nPattern, true, (pMainFrm->GetModPlaying() == pModDoc), + DrawPatternData(hdc, lineWidth, m_nPattern, true, (pMainFrm->GetModPlaying() == pModDoc), yofs, nrows, xofs, rcClient, &ypaint); // Display next pattern - if((TrackerSettings::Instance().patternSetup & PatternSetup::ShowPrevNextPattern) && (ypaint < rcClient.bottom) && (ypaint == ypatternend)) + if(patternSetup[PatternSetup::ShowPrevNextPattern] && (ypaint < rcClient.bottom) && (ypaint == ypatternend)) { int nVisRows = (rcClient.bottom - ypaint + m_szCell.cy - 1) / m_szCell.cy; if(nVisRows > 0) @@ -660,7 +662,7 @@ ROWINDEX n = std::min(static_cast<ROWINDEX>(nVisRows), nNextRows); m_Dib.SetBlendMode(true); - DrawPatternData(hdc, nNextPat, false, false, + DrawPatternData(hdc, lineWidth, nNextPat, false, false, 0, n, xofs, rcClient, &ypaint); m_Dib.SetBlendMode(false); } @@ -679,7 +681,7 @@ int width = HighDPISupport::ScalePixels(1, m_hWnd); rc.SetRect(0, ypaint, rcClient.right + 1, rcClient.bottom + 1); if(width == 1) - DrawButtonRect(hdc, &rc, _T("")); + DrawButtonRect(hdc, lineWidth, &rc, _T("")); else DrawEdge(hdc, rc, EDGE_RAISED, BF_TOPLEFT | BF_MIDDLE); // Prevent lower edge from being drawn } @@ -698,8 +700,8 @@ { sprintf(s, "#%u", m_nPattern); rect.right = m_szHeader.cx; - DrawButtonRect(hdc, &rect, s, FALSE, - (m_bInItemRect && m_nDragItem.Type() == DragItem::PatternHeader) ? TRUE : FALSE); + DrawButtonRect(hdc, lineWidth, &rect, s, false, + m_bInItemRect && m_nDragItem.Type() == DragItem::PatternHeader); const int dropWidth = HighDPISupport::ScalePixels(2, m_hWnd); @@ -721,9 +723,9 @@ else if(numVisibleColums < 5) pszfmt = sndFile.m_bChannelMuteTogglePending[ncolhdr] ? "[Chn %u]" : "Chn %u"; sprintf(s, pszfmt, ncolhdr + 1, channel.szName.buf); - DrawButtonRect(hdc, &rect, s, - channel.dwFlags[CHN_MUTE] ? TRUE : FALSE, - (m_bInItemRect && m_nDragItem.Type() == DragItem::ChannelHeader && m_nDragItem.Value() == ncolhdr) ? TRUE : FALSE, + DrawButtonRect(hdc, lineWidth, &rect, s, + channel.dwFlags[CHN_MUTE], + m_bInItemRect && m_nDragItem.Type() == DragItem::ChannelHeader && m_nDragItem.Value() == ncolhdr, recordGroup != RecordGroup::NoGroup ? DT_RIGHT : DT_CENTER, chanColorHeight); if(channel.color != ModChannelSettings::INVALID_COLOR) @@ -767,7 +769,7 @@ InvertRect(hdc, &rect); s[0] = (recordGroup == RecordGroup::Group1) ? '1' : '2'; s[1] = '\0'; - DrawButtonRect(hdc, &insRect, s, FALSE, FALSE, DT_CENTER); + DrawButtonRect(hdc, lineWidth, &insRect, s, false, false, DT_CENTER); FrameRect(hdc, &insRect, blackBrush); } @@ -786,8 +788,8 @@ sprintf(s, "%u: %s", mixPlug, (sndFile.m_MixPlugins[mixPlug - 1]).pMixPlugin ? sndFile.m_MixPlugins[mixPlug - 1].GetNameLocale() : "[empty]"); else sprintf(s, "---"); - DrawButtonRect(hdc, &rect, s, channel.dwFlags[CHN_NOFX] ? TRUE : FALSE, - ((m_bInItemRect) && (m_nDragItem.Type() == DragItem::PluginName) && (m_nDragItem.Value() == ncolhdr)) ? TRUE : FALSE, DT_CENTER); + DrawButtonRect(hdc, lineWidth, &rect, s, channel.dwFlags[CHN_NOFX], + m_bInItemRect && (m_nDragItem.Type() == DragItem::PluginName) && (m_nDragItem.Value() == ncolhdr), DT_CENTER); } } else break; @@ -819,7 +821,7 @@ } -void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnable, +void CViewPattern::DrawPatternData(HDC hdc, const int lineWidth, PATTERNINDEX nPattern, bool selEnable, bool isPlaying, ROWINDEX startRow, ROWINDEX numRows, CHANNELINDEX startChan, CRect &rcClient, int *pypaint) { static_assert(1 << PatternCursor::lastColumn <= Util::MaxValueOfType(ChannelState{}.selectedCols), "Columns are used as bitmasks"); @@ -919,7 +921,7 @@ else wsprintf(s, _T("%d"), compRow); - DrawButtonRect(hdc, &rect, s, !selEnable || rowDisabled); + DrawButtonRect(hdc, lineWidth, &rect, s, !selEnable || rowDisabled); oldrowcolor = EncodeRowColor(row_bkcol, row_col, bRowSel); bRowSel = (m_Selection.ContainsVertical(PatternCursor(row))); row_col = MODCOLOR_TEXTNORMAL; Modified: trunk/OpenMPT/mptrack/Mptrack.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp Fri Jan 3 11:47:43 2025 (r22739) +++ trunk/OpenMPT/mptrack/Mptrack.cpp Fri Jan 3 16:40:39 2025 (r22740) @@ -2001,10 +2001,9 @@ } template<typename Tchar> -static void DrawButtonRectImpl(HDC hdc, HFONT font, CRect rect, const Tchar *lpszText, bool disabled, bool pushed, DWORD textFlags, uint32 topMargin) +static void DrawButtonRectImpl(HDC hdc, int lineWidth, HFONT font, CRect rect, const Tchar *text, bool disabled, bool pushed, DWORD textFlags, uint32 topMargin) { - int width = HighDPISupport::ScalePixels(1, WindowFromDC(hdc)); - if(width != 1) + if(lineWidth != 1) { // Draw "real" buttons in Hi-DPI mode DrawFrameControl(hdc, rect, DFC_BUTTON, pushed ? (DFCS_PUSHED | DFCS_BUTTONPUSH) : DFCS_BUTTONPUSH); @@ -2023,45 +2022,45 @@ SelectPen(hdc, oldpen); } - if(lpszText && lpszText[0]) + if(text && text[0]) { - rect.DeflateRect(width, width); + rect.DeflateRect(lineWidth, lineWidth); if(pushed) { - rect.top += width; - rect.left += width; + rect.top += lineWidth; + rect.left += lineWidth; } ::SetTextColor(hdc, GetSysColor(disabled ? COLOR_GRAYTEXT : COLOR_BTNTEXT)); ::SetBkMode(hdc, TRANSPARENT); rect.top += topMargin; auto oldFont = SelectFont(hdc, font); - DrawTextT(hdc, lpszText, -1, &rect, textFlags | DT_SINGLELINE | DT_NOPREFIX); + DrawTextT(hdc, text, -1, &rect, textFlags | DT_SINGLELINE | DT_NOPREFIX); SelectFont(hdc, oldFont); } } -void DrawButtonRect(HDC hdc, const RECT *lpRect, LPCSTR lpszText, BOOL bDisabled, BOOL bPushed, DWORD dwFlags, uint32 topMargin) +void DrawButtonRect(HDC hdc, int lineWidth, const RECT *lpRect, const char *text, bool disabled, bool pushed, DWORD dwFlags, uint32 topMargin) { - DrawButtonRectImpl(hdc, CMainFrame::GetGUIFont(), *lpRect, lpszText, bDisabled, bPushed, dwFlags, topMargin); + DrawButtonRectImpl(hdc, lineWidth, CMainFrame::GetGUIFont(), *lpRect, text, disabled, pushed, dwFlags, topMargin); } -void DrawButtonRect(HDC hdc, const RECT *lpRect, LPCWSTR lpszText, BOOL bDisabled, BOOL bPushed, DWORD dwFlags, uint32 topMargin) +void DrawButtonRect(HDC hdc, int lineWidth, const RECT *lpRect, const wchar_t * text, bool disabled, bool pushed, DWORD dwFlags, uint32 topMargin) { - DrawButtonRectImpl(hdc, CMainFrame::GetGUIFont(), *lpRect, lpszText, bDisabled, bPushed, dwFlags, topMargin); + DrawButtonRectImpl(hdc, lineWidth, CMainFrame::GetGUIFont(), *lpRect, text, disabled, pushed, dwFlags, topMargin); } -void DrawButtonRect(HDC hdc, HFONT font, const RECT *lpRect, LPCSTR lpszText, bool bDisabled, bool bPushed, DWORD dwFlags, uint32 topMargin) +void DrawButtonRect(HDC hdc, int lineWidth, HFONT font, const RECT *lpRect, const char * text, bool disabled, bool pushed, DWORD dwFlags, uint32 topMargin) { - DrawButtonRectImpl(hdc, font, *lpRect, lpszText, bDisabled, bPushed, dwFlags, topMargin); + DrawButtonRectImpl(hdc, lineWidth, font, *lpRect, text, disabled, pushed, dwFlags, topMargin); } -void DrawButtonRect(HDC hdc, HFONT font, const RECT *lpRect, LPCWSTR lpszText, bool bDisabled, bool bPushed, DWORD dwFlags, uint32 topMargin) +void DrawButtonRect(HDC hdc, int lineWidth, HFONT font, const RECT *lpRect, const wchar_t * text, bool disabled, bool pushed, DWORD dwFlags, uint32 topMargin) { - DrawButtonRectImpl(hdc, font, *lpRect, lpszText, bDisabled, bPushed, dwFlags, topMargin); + DrawButtonRectImpl(hdc, lineWidth, font, *lpRect, text, disabled, pushed, dwFlags, topMargin); } Modified: trunk/OpenMPT/mptrack/Mptrack.h ============================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h Fri Jan 3 11:47:43 2025 (r22739) +++ trunk/OpenMPT/mptrack/Mptrack.h Fri Jan 3 16:40:39 2025 (r22740) @@ -419,10 +419,10 @@ // Other bitmap functions int DrawTextT(HDC hdc, const wchar_t *lpchText, int cchText, LPRECT lprc, UINT format); 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); +void DrawButtonRect(HDC hdc, int lineWidth, const RECT *lpRect, const char *text = nullptr, bool disabled = false, bool pushed = false, DWORD dwFlags = (DT_CENTER | DT_VCENTER), uint32 topMargin = 0); +void DrawButtonRect(HDC hdc, int lineWidth, const RECT *lpRect, const wchar_t *text = nullptr, bool disabled = false, bool pushed = false, DWORD dwFlags = (DT_CENTER | DT_VCENTER), uint32 topMargin = 0); +void DrawButtonRect(HDC hdc, int lineWidth, HFONT font, const RECT *lpRect, const char *text = nullptr, bool disabled = false, bool pushed = false, DWORD dwFlags = (DT_CENTER | DT_VCENTER), uint32 topMargin = 0); +void DrawButtonRect(HDC hdc, int lineWidth, HFONT font, const RECT *lpRect, const wchar_t *text = nullptr, bool disabled = false, bool pushed = false, DWORD dwFlags = (DT_CENTER | DT_VCENTER), uint32 topMargin = 0); // Misc functions void ErrorBox(UINT nStringID, CWnd *p = nullptr); Modified: trunk/OpenMPT/mptrack/View_pat.h ============================================================================== --- trunk/OpenMPT/mptrack/View_pat.h Fri Jan 3 11:47:43 2025 (r22739) +++ trunk/OpenMPT/mptrack/View_pat.h Fri Jan 3 16:40:39 2025 (r22740) @@ -289,7 +289,7 @@ void OnDropSelection(); public: - void DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnable, bool isPlaying, ROWINDEX startRow, ROWINDEX numRows, CHANNELINDEX startChan, CRect &rcClient, int *pypaint); + void DrawPatternData(HDC hdc, const int lineWidth, PATTERNINDEX nPattern, bool selEnable, bool isPlaying, ROWINDEX startRow, ROWINDEX numRows, CHANNELINDEX startChan, CRect &rcClient, int *pypaint); void DrawLetter(int x, int y, char letter, int sizex = 10, int ofsx = 0); void DrawLetter(int x, int y, wchar_t letter, int sizex = 10, int ofsx = 0); #if MPT_CXX_AT_LEAST(20) Modified: trunk/OpenMPT/mptrack/tuningRatioMapWnd.cpp ============================================================================== --- trunk/OpenMPT/mptrack/tuningRatioMapWnd.cpp Fri Jan 3 11:47:43 2025 (r22739) +++ trunk/OpenMPT/mptrack/tuningRatioMapWnd.cpp Fri Jan 3 16:40:39 2025 (r22740) @@ -48,6 +48,7 @@ const auto colorText = GetSysColor(COLOR_WINDOWTEXT); const auto colorTextSel = GetSysColor(COLOR_HIGHLIGHTTEXT); const auto highlightBrush = GetSysColorBrush(COLOR_HIGHLIGHT), windowBrush = GetSysColorBrush(COLOR_WINDOW); + const int lineWidth = HighDPISupport::ScalePixels(1, *this); if(int dpi = HighDPISupport::GetDpiForWindow(m_hWnd); m_dpi != dpi) { @@ -88,7 +89,7 @@ rect.SetRect(0, ypaint, m_cxFont, ypaint + m_cyFont); const auto noteStr = isValidNote ? mpt::tfmt::val(noteToDraw) : mpt::tstring(_T("...")); - DrawButtonRect(dc, m_font, &rect, noteStr.c_str(), false, false); + DrawButtonRect(dc, lineWidth, m_font, &rect, noteStr.c_str(), false, false); // Mapped Note const bool highLight = focus && (nPos == (int)m_nNote); @@ -114,7 +115,7 @@ } rect.SetRect(rcClient.left + m_cxFont * 4 - 1, rcClient.top, rcClient.left + m_cxFont * 4 + 3, ypaint); - DrawButtonRect(dc, m_font, &rect, _T("")); + DrawButtonRect(dc, lineWidth, m_font, &rect, _T("")); if (ypaint < rcClient.bottom) { rect.SetRect(rcClient.left, ypaint, rcClient.right, rcClient.bottom); |