Skip to content

Commit 42abc23

Browse files
committed
Refactor FilepathEdit to draw hamburger menu with GDI+ lines instead of text
1 parent 34ebfc4 commit 42abc23

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

Src/FilepathEdit.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,20 +286,30 @@ void CFilepathEdit::OnNcPaint()
286286
dc.FillSolidRect(CRect(rect.left + margin, rect.bottom - margin, rect.right, rect.bottom), m_crBackGnd);
287287
}
288288

289+
static float PointToPixel(CDC& dc, float pt)
290+
{
291+
const int lpx = dc.GetDeviceCaps(LOGPIXELSX);
292+
return pt * lpx / 72.0f;
293+
}
294+
289295
void CFilepathEdit::OnPaint()
290296
{
291297
__super::OnPaint();
292298
if (!m_bInEditing)
293299
{
294300
CClientDC dc(this);
295-
CFont *pFontOld = dc.SelectObject(GetFont());
296-
int oldTextColor = dc.SetTextColor(m_crText);
297-
int oldBkMode = dc.SetBkMode(TRANSPARENT);
301+
Gdiplus::Graphics graphics(dc);
302+
graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
298303
CRect rc = GetMenuCharRect(&dc);
299-
dc.TextOutW(rc.left, 0, IsWin7_OrGreater() ? _T("\u2261") : _T("="));
300-
dc.SetBkMode(oldBkMode);
301-
dc.SetTextColor(oldTextColor);
302-
dc.SelectObject(pFontOld);
304+
Gdiplus::Pen pen(Gdiplus::Color(255, GetRValue(m_crText), GetGValue(m_crText), GetBValue(m_crText)), PointToPixel(dc, 0.75f));
305+
const int lineCount = 3;
306+
const float spacing = PointToPixel(dc, 2.25f);
307+
const int padding = static_cast<int>(PointToPixel(dc, 0.75f));
308+
for (int i = 0; i < lineCount; ++i)
309+
{
310+
float y = rc.top + (rc.Height() - (lineCount - 1) * spacing) / 2 + i * spacing;
311+
graphics.DrawLine(&pen, static_cast<float>(rc.left + padding), y, static_cast<float>(rc.right - padding), y);
312+
}
303313
}
304314
}
305315

@@ -321,8 +331,7 @@ CRect CFilepathEdit::GetMenuCharRect(CDC* pDC)
321331
{
322332
CRect rc;
323333
GetClientRect(rc);
324-
int charWidth;
325-
pDC->GetCharWidth('=', '=', &charWidth);
334+
int charWidth = static_cast<int>(PointToPixel(*pDC, 6.0f));
326335
rc.left = rc.right - charWidth;
327336
return rc;
328337
}

0 commit comments

Comments
 (0)