Skip to content

Commit

Permalink
[Imp] Comments tab: Sample / instrument names are now drawn using the…
Browse files Browse the repository at this point in the history
… Comments font, which is typically a fixed-width font (https://bugs.openmpt.org/view.php?id=1758).

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@20545 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Apr 9, 2024
1 parent 03bb135 commit 79782c1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 17 deletions.
78 changes: 61 additions & 17 deletions mptrack/view_com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,24 @@ enum

static constexpr CListCtrlEx::Header SampleHeaders[SMPLIST_COLUMNS] =
{
{ _T("Sample Name"), 192, LVCFMT_LEFT },
{ _T("Num"), 45, LVCFMT_RIGHT },
{ _T("Size"), 72, LVCFMT_RIGHT },
{ _T("Type"), 80, LVCFMT_RIGHT },
{ _T("C-5 Freq"), 80, LVCFMT_RIGHT },
{ _T("Instr"), 64, LVCFMT_RIGHT },
{ _T("File Name"), 128, LVCFMT_RIGHT },
{ _T("Path"), 256, LVCFMT_LEFT },
{ _T("Sample Name"), 208, LVCFMT_LEFT },
{ _T("Num"), 45, LVCFMT_RIGHT },
{ _T("Size"), 72, LVCFMT_RIGHT },
{ _T("Type"), 80, LVCFMT_RIGHT },
{ _T("C-5 Freq"), 80, LVCFMT_RIGHT },
{ _T("Instr"), 64, LVCFMT_RIGHT },
{ _T("File Name"), 128, LVCFMT_RIGHT },
{ _T("Path"), 256, LVCFMT_LEFT },
};

static constexpr CListCtrlEx::Header InstrumentHeaders[INSLIST_COLUMNS] =
{
{ _T("Instrument Name"), 192, LVCFMT_LEFT },
{ _T("Num"), 45, LVCFMT_RIGHT },
{ _T("Samples"), 64, LVCFMT_RIGHT },
{ _T("Envelopes"), 128, LVCFMT_RIGHT },
{ _T("File Name"), 128, LVCFMT_RIGHT },
{ _T("Plugin"), 128, LVCFMT_RIGHT },
{ _T("Instrument Name"), 208, LVCFMT_LEFT },
{ _T("Num"), 45, LVCFMT_RIGHT },
{ _T("Samples"), 64, LVCFMT_RIGHT },
{ _T("Envelopes"), 128, LVCFMT_RIGHT },
{ _T("File Name"), 128, LVCFMT_RIGHT },
{ _T("Plugin"), 128, LVCFMT_RIGHT },
};


Expand All @@ -95,6 +95,7 @@ BEGIN_MESSAGE_MAP(CViewComments, CModScrollView)
ON_NOTIFY(LVN_BEGINLABELEDIT, IDC_LIST_DETAILS, &CViewComments::OnBeginLabelEdit)
ON_NOTIFY(NM_DBLCLK, IDC_LIST_DETAILS, &CViewComments::OnDblClickListItem)
ON_NOTIFY(NM_RCLICK, IDC_LIST_DETAILS, &CViewComments::OnRClickListItem)
ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST_DETAILS, &CViewComments::OnCustomDrawList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

Expand Down Expand Up @@ -130,13 +131,14 @@ void CViewComments::OnInitialUpdate()
m_ToolBar.Init(CMainFrame::GetMainFrame()->m_MiscIcons, CMainFrame::GetMainFrame()->m_MiscIconsDisabled);
m_ItemList.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL | LVS_EDITLABELS | LVS_NOSORTHEADER, rect, this, IDC_LIST_DETAILS);
m_ItemList.ModifyStyleEx(0, WS_EX_STATICEDGE);

// Add ToolBar Buttons
m_ToolBar.AddButton(IDC_LIST_SAMPLES, IMAGE_SAMPLES);
m_ToolBar.AddButton(IDC_LIST_INSTRUMENTS, IMAGE_INSTRUMENTS);
//m_ToolBar.AddButton(IDC_LIST_PATTERNS, TIMAGE_TAB_PATTERNS);
m_ToolBar.SetIndent(4);
UpdateButtonState();
UpdateView(UpdateHint().ModType());
UpdateView(UpdateHint().ModType().MPTOptions());
}


Expand All @@ -153,6 +155,7 @@ void CViewComments::OnDestroy()
commentState.initialized = true;
commentState.nId = m_nListId;
}
m_fixedFont.DeleteObject();
CModScrollView::OnDestroy();
}

Expand Down Expand Up @@ -293,6 +296,16 @@ void CViewComments::UpdateView(UpdateHint hint, CObject *)
if (hintType[HINT_MPTOPTIONS])
{
m_ToolBar.UpdateStyle();

// Font for sample / instrument names
CFont *font = m_ItemList.GetFont();
LOGFONT lf;
font->GetLogFont(&lf);
mpt::WriteWinBuf(lf.lfFaceName) = mpt::ToWin(TrackerSettings::Instance().commentsFont.Get().name);
m_fixedFont.DeleteObject();
m_fixedFont.CreateFontIndirect(&lf);

m_ItemList.Invalidate(FALSE);
}
const SampleHint sampleHint = hint.ToType<SampleHint>();
const InstrumentHint instrHint = hint.ToType<InstrumentHint>();
Expand Down Expand Up @@ -555,8 +568,8 @@ void CViewComments::OnBeginLabelEdit(LPNMHDR, LRESULT *)
void CViewComments::OnEndLabelEdit(LPNMHDR pnmhdr, LRESULT *)
{
CMainFrame::GetInputHandler()->Bypass(false);
LV_DISPINFO *plvDispInfo = (LV_DISPINFO *)pnmhdr;
LV_ITEM &lvItem = plvDispInfo->item;
LV_DISPINFO &lvDispInfo = *reinterpret_cast<LV_DISPINFO *>(pnmhdr);
LV_ITEM &lvItem = lvDispInfo.item;
CModDoc *pModDoc = GetDocument();

if(lvItem.pszText != nullptr && !lvItem.iSubItem && pModDoc)
Expand Down Expand Up @@ -672,6 +685,37 @@ void CViewComments::OnRClickListItem(NMHDR *, LRESULT *)
}


void CViewComments::OnCustomDrawList(NMHDR *pNMHDR, LRESULT *pResult)
{
const auto &lvcd = *reinterpret_cast<NMLVCUSTOMDRAW *>(pNMHDR);
*pResult = CDRF_DODEFAULT;

switch(lvcd.nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
*pResult = CDRF_NOTIFYSUBITEMDRAW;
break;
case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
if(lvcd.iSubItem == 0)
{
m_oldFont = SelectFont(lvcd.nmcd.hdc, m_fixedFont);
*pResult = CDRF_NEWFONT | CDRF_NOTIFYPOSTPAINT;
}
break;
case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
if(lvcd.iSubItem == 0)
{
SelectFont(lvcd.nmcd.hdc, m_oldFont);
*pResult = CDRF_NEWFONT;
}
break;
}
}


void CViewComments::OnCopyNames()
{
std::wstring names;
Expand Down
3 changes: 3 additions & 0 deletions mptrack/view_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class CViewComments: public CModScrollView
protected:
CModControlBar m_ToolBar;
CListCtrlEx m_ItemList;
CFont m_fixedFont;
HFONT m_oldFont = nullptr;
int m_nCurrentListId = 0, m_nListId = 0;
ModCommand::NOTE m_lastNote = NOTE_NONE;
CHANNELINDEX m_noteChannel = CHANNELINDEX_INVALID;
Expand Down Expand Up @@ -59,6 +61,7 @@ class CViewComments: public CModScrollView
afx_msg void OnBeginLabelEdit(LPNMHDR pnmhdr, LRESULT *pLResult);
afx_msg void OnDblClickListItem(NMHDR *, LRESULT *);
afx_msg void OnRClickListItem(NMHDR *, LRESULT *);
afx_msg void OnCustomDrawList(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnCopyNames();
afx_msg LRESULT OnMidiMsg(WPARAM midiData, LPARAM);
afx_msg LRESULT OnCustomKeyMsg(WPARAM, LPARAM);
Expand Down

0 comments on commit 79782c1

Please sign in to comment.