Skip to content

Commit

Permalink
[Fix] Pattern tab: With smooth scrolling enabling, buttons were alway…
Browse files Browse the repository at this point in the history
…s drawn natively, even at 96 DPI, because we cannot obtain a window handle from an offscreen DC.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22740 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Jan 3, 2025
1 parent 1dabd7c commit 8659dd4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 44 deletions.
5 changes: 3 additions & 2 deletions mptrack/Ctrl_ins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ void CNoteMapWnd::OnPaint()
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))
Expand Down Expand Up @@ -215,7 +216,7 @@ void CNoteMapWnd::OnPaint()
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;
Expand Down Expand Up @@ -262,7 +263,7 @@ void CNoteMapWnd::OnPaint()
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);
Expand Down
40 changes: 21 additions & 19 deletions mptrack/Draw_pat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,18 +538,20 @@ void CViewPattern::OnDraw(CDC *pDC)
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)
Expand Down Expand Up @@ -593,7 +595,7 @@ void CViewPattern::OnDraw(CDC *pDC)
PATTERNINDEX nPrevPat = PATTERNINDEX_INVALID;

// Display previous pattern
if(TrackerSettings::Instance().patternSetup & PatternSetup::ShowPrevNextPattern)
if(patternSetup[PatternSetup::ShowPrevNextPattern])
{
if(m_nOrder > 0 && m_nOrder < ordCount)
{
Expand All @@ -614,7 +616,7 @@ void CViewPattern::OnDraw(CDC *pDC)
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
Expand All @@ -637,10 +639,10 @@ void CViewPattern::OnDraw(CDC *pDC)

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)
Expand All @@ -660,7 +662,7 @@ void CViewPattern::OnDraw(CDC *pDC)
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);
}
Expand All @@ -679,7 +681,7 @@ void CViewPattern::OnDraw(CDC *pDC)
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
}
Expand All @@ -698,8 +700,8 @@ void CViewPattern::OnDraw(CDC *pDC)
{
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);

Expand All @@ -721,9 +723,9 @@ void CViewPattern::OnDraw(CDC *pDC)
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)
Expand Down Expand Up @@ -767,7 +769,7 @@ void CViewPattern::OnDraw(CDC *pDC)
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);
}

Expand All @@ -786,8 +788,8 @@ void CViewPattern::OnDraw(CDC *pDC)
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;
Expand Down Expand Up @@ -819,7 +821,7 @@ static constexpr UINT EncodeRowColor(int rowBkCol, int rowCol, bool rowSelected)
}


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");
Expand Down Expand Up @@ -919,7 +921,7 @@ void CViewPattern::DrawPatternData(HDC hdc, PATTERNINDEX nPattern, bool selEnabl
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;
Expand Down
31 changes: 15 additions & 16 deletions mptrack/Mptrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2001,10 +2001,9 @@ int DrawTextT(HDC hdc, const char *lpchText, int cchText, LPRECT lprc, UINT form
}

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);
Expand All @@ -2023,45 +2022,45 @@ static void DrawButtonRectImpl(HDC hdc, HFONT font, CRect rect, const Tchar *lps
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);
}


Expand Down
8 changes: 4 additions & 4 deletions mptrack/Mptrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,10 @@ RGBQUAD rgb2quad(COLORREF c);
// 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);
Expand Down
2 changes: 1 addition & 1 deletion mptrack/View_pat.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class CViewPattern final : public CModScrollView
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)
Expand Down
5 changes: 3 additions & 2 deletions mptrack/tuningRatioMapWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void CTuningRatioMapWnd::OnPaint()
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)
{
Expand Down Expand Up @@ -88,7 +89,7 @@ void CTuningRatioMapWnd::OnPaint()

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);
Expand All @@ -114,7 +115,7 @@ void CTuningRatioMapWnd::OnPaint()

}
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);
Expand Down

0 comments on commit 8659dd4

Please sign in to comment.