Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Sep 28, 2024
1 parent cd1259a commit d50e145
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Src/Common/MDITabBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ CSize CMDITabBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)

LRESULT CMDITabBar::OnNcHitTest(CPoint point)
{
return m_titleBar.HitTest(point);
return m_titleBar.OnNcHitTest(point);
}

void CMDITabBar::OnNcMouseMove(UINT nHitTest, CPoint point)
Expand Down
80 changes: 39 additions & 41 deletions Src/TitleBarHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,41 @@ void CTitleBarHelper::OnSize(bool maximized, int cx, int cy)
m_pWnd->GetWindowRect(&m_rc);
}

LRESULT CTitleBarHelper::OnNcHitTest(CPoint pt)
{
if (!m_pWnd)
return HTNOWHERE;
CClientDC dc(m_pWnd);
const int leftMargin = PointToPixel(m_leftMargin);
const int rightMargin = PointToPixel(m_rightMargin);
const int borderWidth = PointToPixel(6);
CRect rc;
m_pWnd->GetWindowRect(&rc);
if (pt.y < rc.top + borderWidth)
{
if (pt.x < rc.left + borderWidth)
return HTTOPLEFT;
else if (rc.right - borderWidth <= pt.x)
return HTTOPRIGHT;
return HTTOP;
}
if (pt.x < rc.left + borderWidth)
return HTLEFT;
if (rc.right - borderWidth <= pt.x)
return HTRIGHT;
if (pt.x < rc.left + leftMargin)
return HTSYSMENU;
for (int i = 0; i < 3; i++)
{
static const int htbuttons[]{ HTMINBUTTON, HTMAXBUTTON, HTCLOSE };
CRect rcButton = GetButtonRect(i);
m_pWnd->ClientToScreen(&rcButton);
if (PtInRect(&rcButton, pt))
return htbuttons[i];
}
return HTCAPTION;
}

void CTitleBarHelper::OnNcMouseMove(UINT nHitTest, CPoint point)
{
if (!m_bMouseTracking)
Expand All @@ -148,15 +183,13 @@ void CTitleBarHelper::OnNcMouseMove(UINT nHitTest, CPoint point)
TrackMouseEvent(&tme);
m_bMouseTracking = true;
}
int i = HitTest(point);
if (i == HTMINBUTTON)
int i = -1;
if (nHitTest == HTMINBUTTON)
i = 0;
else if (i == HTMAXBUTTON)
else if (nHitTest == HTMAXBUTTON)
i = 1;
else if (i == HTCLOSE)
else if (nHitTest == HTCLOSE)
i = 2;
else
i = -1;
for (int button : {i, m_nTrackingButton})
{
if (button != -1)
Expand Down Expand Up @@ -232,41 +265,6 @@ void CTitleBarHelper::ShowSysMenu(CPoint point)
AfxGetMainWnd()->PostMessage(WM_SYSCOMMAND, cmd, 0);
}

int CTitleBarHelper::HitTest(CPoint pt)
{
if (!m_pWnd)
return HTNOWHERE;
CClientDC dc(m_pWnd);
const int leftMargin = PointToPixel(m_leftMargin);
const int rightMargin = PointToPixel(m_rightMargin);
const int borderWidth = PointToPixel(6);
CRect rc;
m_pWnd->GetWindowRect(&rc);
if (pt.y < rc.top + borderWidth)
{
if (pt.x < rc.left + borderWidth)
return HTTOPLEFT;
else if (rc.right - borderWidth <= pt.x)
return HTTOPRIGHT;
return HTTOP;
}
if (pt.x < rc.left + borderWidth)
return HTLEFT;
if (rc.right - borderWidth <= pt.x)
return HTRIGHT;
if (pt.x < rc.left + leftMargin)
return HTSYSMENU;
for (int i = 0; i < 3; i++)
{
static const int htbuttons[]{ HTMINBUTTON, HTMAXBUTTON, HTCLOSE };
CRect rcButton = GetButtonRect(i);
m_pWnd->ClientToScreen(&rcButton);
if (PtInRect(&rcButton, pt))
return htbuttons[i];
}
return HTCAPTION;
}

COLORREF CTitleBarHelper::GetIntermediateColor(COLORREF a, COLORREF b, float ratio)
{
const uint8_t R = static_cast<int8_t>((GetRValue(a) - GetRValue(b)) * ratio) + GetRValue(b);
Expand Down
2 changes: 1 addition & 1 deletion Src/TitleBarHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class CTitleBarHelper {
int GetRightMargin() const { return PointToPixel(m_rightMargin); }
CRect GetButtonRect(int button) const;
void OnSize(bool maximized, int cx, int cy);
LRESULT OnNcHitTest(CPoint pt);
void OnNcMouseMove(UINT nHitTest, CPoint point);
void OnNcMouseLeave();
void OnNcLButtonDblClk(UINT nHitTest, CPoint point);
void OnNcLButtonDown(UINT nHitTest, CPoint point);
void OnNcLButtonUp(UINT nHitTest, CPoint point);
void OnNcRButtonDown(UINT nHitTest, CPoint point);
void OnNcRButtonUp(UINT nHitTest, CPoint point);
int HitTest(CPoint pt);

private:
float PointToPixelF(float point) const { return point * m_dpi / 72.f; }
Expand Down

0 comments on commit d50e145

Please sign in to comment.