Răsfoiți Sursa

- Handle windows text scaling better to 125%, 150% and 175%
- improve snap to windows edges

Scott Brogden 9 ani în urmă
părinte
comite
e8b2ac0031
7 a modificat fișierele cu 134 adăugiri și 56 ștergeri
  1. 17 17
      DittoWindow.cpp
  2. 11 0
      GdiImageDrawer.cpp
  3. 1 0
      GdiImageDrawer.h
  4. 0 38
      QPasteWnd.cpp
  5. 0 1
      QPasteWnd.h
  6. 102 0
      WndEx.cpp
  7. 3 0
      WndEx.h

+ 17 - 17
DittoWindow.cpp

@@ -277,13 +277,13 @@ void CDittoWindow::DoNcPaint(CWnd *pWnd)
 	BOOL bVertical = FALSE;
 	if(m_lRightBorder == m_captionBorderWidth)
 	{
-		rightRect.SetRect(rcBorder.right - m_captionBorderWidth + border, rcBorder.top, rcBorder.right, rcBorder.top + IndexToPos(index, false));
-		leftRect.SetRect(rcBorder.right - m_captionBorderWidth + border, rcBorder.top + IndexToPos(index, false), rcBorder.right, rcBorder.bottom);
+		rightRect.SetRect(rcBorder.right - (m_captionBorderWidth - border), rcBorder.top, rcBorder.right, rcBorder.top + IndexToPos(index, false));
+		leftRect.SetRect(rcBorder.right - (m_captionBorderWidth - border), rcBorder.top + IndexToPos(index, false), rcBorder.right, rcBorder.bottom);
 		
 		textRect.SetRect(rcBorder.right, rightRect.bottom + theApp.m_metrics.ScaleX(10), rcBorder.right - m_captionBorderWidth, rcBorder.bottom - theApp.m_metrics.ScaleX(50));
 
-		int left = (rcBorder.right - m_captionBorderWidth + border) + theApp.m_metrics.ScaleX((m_captionBorderWidth / 2) - (theApp.m_metrics.ScaleX(16) / 2));
-		int right = left + theApp.m_metrics.ScaleX(16);
+		int left = rightRect.left;
+		int right = rightRect.right;
 
 		int top = IndexToPos(closeIndex, false);
 		m_crCloseBT.SetRect(left, top, right, top+ widthHeight);
@@ -309,8 +309,8 @@ void CDittoWindow::DoNcPaint(CWnd *pWnd)
 
 		textRect.SetRect(rcBorder.left + m_captionBorderWidth - theApp.m_metrics.ScaleX(0), rightRect.bottom + theApp.m_metrics.ScaleX(10), rcBorder.left - theApp.m_metrics.ScaleX(5), rcBorder.bottom - theApp.m_metrics.ScaleX(50));
 
-		int left = theApp.m_metrics.ScaleX((m_captionBorderWidth / 2) - (theApp.m_metrics.ScaleX(16) / 2));
-		int right = left + theApp.m_metrics.ScaleX(16);
+		int left = rightRect.left;
+		int right = rightRect.right;
 
 		int top = IndexToPos(closeIndex, false);
 		m_crCloseBT.SetRect(left, top, right, top + widthHeight);
@@ -335,8 +335,8 @@ void CDittoWindow::DoNcPaint(CWnd *pWnd)
 
 		textRect.SetRect(leftRect.right, leftRect.top, leftRect.right, leftRect.bottom);
 
-		int top = theApp.m_metrics.ScaleX((m_captionBorderWidth/2) - (theApp.m_metrics.ScaleX(16)/2));
-		int bottom = top + theApp.m_metrics.ScaleX(16);
+		int top = rightRect.top;
+		int bottom = rightRect.bottom;
 
 		int left = rcBorder.right - IndexToPos(closeIndex, true);
 		m_crCloseBT.SetRect(left, top, left + widthHeight, bottom);
@@ -356,13 +356,13 @@ void CDittoWindow::DoNcPaint(CWnd *pWnd)
 	}
 	else if(m_lBottomBorder == m_captionBorderWidth)
 	{
-		leftRect.SetRect(rcBorder.left, rcBorder.bottom- m_captionBorderWidth + border, rcBorder.right - IndexToPos(index - 1, true) - theApp.m_metrics.ScaleX(8), rcBorder.bottom);
-		rightRect.SetRect(leftRect.right, rcBorder.bottom - m_captionBorderWidth + border, rcBorder.right, rcBorder.bottom);
+		leftRect.SetRect(rcBorder.left, rcBorder.bottom- m_captionBorderWidth - border, rcBorder.right - IndexToPos(index - 1, true) - theApp.m_metrics.ScaleX(8), rcBorder.bottom);
+		rightRect.SetRect(leftRect.right, rcBorder.bottom - m_captionBorderWidth - border, rcBorder.right, rcBorder.bottom);
 
 		textRect.SetRect(leftRect.right, leftRect.top, leftRect.right, leftRect.bottom);
 
-		int top = leftRect.top + theApp.m_metrics.ScaleX((m_captionBorderWidth / 2) - (theApp.m_metrics.ScaleX(16) / 2));
-		int bottom = top + theApp.m_metrics.ScaleX(16);
+		int top = rightRect.top;
+		int bottom = rightRect.bottom;
 
 		int left = rcBorder.right - IndexToPos(closeIndex, true);
 		m_crCloseBT.SetRect(left, top, left + widthHeight, bottom);
@@ -517,11 +517,11 @@ void CDittoWindow::DrawChevronBtn(CWindowDC &dc, CWnd *pWnd)
 		
 	if(this->m_bMinimized)
 	{
-		m_chevronLeftButton.Draw(&dc, pWnd, m_crChevronBT.left, m_crChevronBT.top, m_bMouseOverChevron, m_bMouseDownOnChevron);
+		m_chevronLeftButton.Draw(&dc, pWnd, m_crChevronBT, m_bMouseOverChevron, m_bMouseDownOnChevron);
 	}
 	else
 	{
-		m_chevronRightButton.Draw(&dc, pWnd, m_crChevronBT.left, m_crChevronBT.top, m_bMouseOverChevron, m_bMouseDownOnChevron);
+		m_chevronRightButton.Draw(&dc, pWnd, m_crChevronBT, m_bMouseOverChevron, m_bMouseDownOnChevron);
 	}
 }
 
@@ -537,7 +537,7 @@ void CDittoWindow::DrawCloseBtn(CWindowDC &dc, CWnd *pWnd)
 		return;
 	}
 	
-	m_closeButton.Draw(&dc, pWnd, m_crCloseBT.left, m_crCloseBT.top, m_bMouseOverClose, m_bMouseDownOnClose);
+	m_closeButton.Draw(&dc, pWnd, m_crCloseBT, m_bMouseOverClose, m_bMouseDownOnClose);
 }
 
 void CDittoWindow::DrawMinimizeBtn(CWindowDC &dc, CWnd *pWnd)
@@ -547,7 +547,7 @@ void CDittoWindow::DrawMinimizeBtn(CWindowDC &dc, CWnd *pWnd)
 		return;
 	}
 
-	m_minimizeButton.Draw(&dc, pWnd, m_crMinimizeBT.left, m_crMinimizeBT.top, m_bMouseOverClose, m_bMouseDownOnClose);
+	m_minimizeButton.Draw(&dc, pWnd, m_crMinimizeBT, m_bMouseOverClose, m_bMouseDownOnClose);
 }
 
 void CDittoWindow::DrawMaximizeBtn(CWindowDC &dc, CWnd *pWnd)
@@ -557,7 +557,7 @@ void CDittoWindow::DrawMaximizeBtn(CWindowDC &dc, CWnd *pWnd)
 		return;
 	}
 
-	m_maximizeButton.Draw(&dc, pWnd, m_crMaximizeBT.left, m_crMaximizeBT.top, m_bMouseOverMaximize, m_bMouseDownOnMaximize);
+	m_maximizeButton.Draw(&dc, pWnd, m_crMaximizeBT, m_bMouseOverMaximize, m_bMouseDownOnMaximize);
 }
 
 void CDittoWindow::DoNcLButtonDown(CWnd *pWnd, UINT nHitTest, CPoint point) 

+ 11 - 0
GdiImageDrawer.cpp

@@ -53,6 +53,17 @@ BOOL CGdiImageDrawer::LoadStdImageDPI(UINT id96, UINT id120, UINT id144, UINT id
 	return ret;
 }
 
+void CGdiImageDrawer::Draw(CDC* pScreenDC, CWnd *pWnd, CRect rc, bool mouseHover, bool mouseDown)
+{
+	int width = m_pStdImage->m_pBitmap->GetWidth();
+	int height = m_pStdImage->m_pBitmap->GetHeight();
+
+	int x = rc.left + (rc.Width() / 2) - (width / 2);
+	int y = rc.top + (rc.Height() / 2) - (height / 2);
+
+	Draw(pScreenDC, pWnd, x, y, mouseHover, mouseDown);
+}
+
 void CGdiImageDrawer::Draw(CDC* pScreenDC, CWnd *pWnd, int posX, int posY, bool mouseHover, bool mouseDown, int forceWidth, int forceHeight)
 {
 	int width = m_pStdImage->m_pBitmap->GetWidth();

+ 1 - 0
GdiImageDrawer.h

@@ -11,6 +11,7 @@ public:
 	BOOL LoadStdImage(UINT id, LPCTSTR pType);
 	BOOL LoadStdImageDPI(UINT id96, UINT id120, UINT id144, UINT id168, UINT id192, LPCTSTR pType);
 	void Draw(CDC* pScreenDC, CWnd *pWnd, int posX, int posY, bool mouseHover, bool mouseDown, int forceWidth = INT_MAX, int forceHeight = INT_MAX);
+	void Draw(CDC* pScreenDC, CWnd *pWnd, CRect rc, bool mouseHover, bool mouseDown);
 	BOOL LoadRaw(unsigned char* bitmapData, int imageSize);
 
 	UINT ImageWidth() { return m_pStdImage->m_pBitmap->GetWidth(); }

+ 0 - 38
QPasteWnd.cpp

@@ -4807,44 +4807,6 @@ void CQPasteWnd::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
     CWndEx::OnNcLButtonDblClk(nHitTest, point);
 }
 
-#define WNDSNAP_ALLOWANCE 12
-
-void CQPasteWnd::OnWindowPosChanging(WINDOWPOS *lpwndpos)
-{
-    CWndEx::OnWindowPosChanging(lpwndpos);
-	
-    CRect rcScreen;
-
-    CRect cr(lpwndpos->x, lpwndpos->y, lpwndpos->x + lpwndpos->cx, lpwndpos->y + lpwndpos->cy);
-    int nMonitor = GetMonitorFromRect(&cr);
-    GetMonitorRect(nMonitor, &rcScreen);
-
-    // Snap X axis to left
-    if(abs(lpwndpos->x - rcScreen.left) <= WNDSNAP_ALLOWANCE)
-    {
-        lpwndpos->x = rcScreen.left;
-    }
-
-    // Snap X axis to right
-    if(abs(lpwndpos->x + lpwndpos->cx - rcScreen.right) <= WNDSNAP_ALLOWANCE)
-    {
-        lpwndpos->x = rcScreen.right - lpwndpos->cx;
-    }
-
-    // Snap Y axis to top
-    if(abs(lpwndpos->y - rcScreen.top) <= WNDSNAP_ALLOWANCE)
-    {
-        // Assign new cordinate
-        lpwndpos->y = rcScreen.top;
-    }
-
-    // Snap Y axis to bottom
-    if(abs(lpwndpos->y + lpwndpos->cy - rcScreen.bottom) <= WNDSNAP_ALLOWANCE)
-    {
-        lpwndpos->y = rcScreen.bottom - lpwndpos->cy;
-    }
-}
-
 void CQPasteWnd::OnShowGroupsTop()
 {
 	m_lstHeader.HidePopup();

+ 0 - 1
QPasteWnd.h

@@ -382,7 +382,6 @@ protected:
 	afx_msg LRESULT OnSetListCount(WPARAM wParam, LPARAM lParam);
     afx_msg HBRUSH CtlColor(CDC *pDC, UINT nCtlColor);
     afx_msg void OnNcLButtonDblClk(UINT nHitTest, CPoint point);
-    afx_msg void OnWindowPosChanging(WINDOWPOS *lpwndpos);
     afx_msg void OnViewcaptionbaronRight();
     afx_msg void OnViewcaptionbaronBottom();
     afx_msg void OnViewcaptionbaronLeft();

+ 102 - 0
WndEx.cpp

@@ -25,6 +25,7 @@ CWndEx::CWndEx()
 	SetCaptionColorActive(false, TRUE);
 	m_crFullSizeWindow.SetRectEmpty();
 	m_lDelayMaxSeconds = 2;
+	m_lButtonDownOnCaption = false;
 }
 
 CWndEx::~CWndEx()
@@ -167,6 +168,15 @@ void CWndEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
 {
 	m_DittoWindow.DoNcLButtonDown(this, nHitTest, point);
 
+	switch (nHitTest)
+	{
+	case HTCAPTION:
+		m_lButtonDownOnCaption = true;
+		break;
+	default:
+		m_lButtonDownOnCaption = false;
+	}
+
 	CWnd::OnNcLButtonDown(nHitTest, point);
 }
 
@@ -363,6 +373,96 @@ void CWndEx::OnTimer(UINT_PTR nIDEvent)
 	CWnd::OnTimer(nIDEvent);
 }
 
+void CWndEx::SnapToEdge(WINDOWPOS* lpwndpos)
+{
+	if (lpwndpos->cx == 0 &&
+		lpwndpos->cy == 0)
+	{
+		return;
+	}
+
+	const char threshold = 12;
+	RECT rect = { 0 };
+	HMONITOR hMonitor;
+	MONITORINFO mi;
+	
+	// Grab information about our monitors
+	// For multi-monitor support, we use this instead of SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
+	hMonitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
+	mi.cbSize = sizeof(mi);
+	GetMonitorInfo(hMonitor, &mi);
+	rect = mi.rcWork;
+
+	bool edgeMove = true;
+	bool captionMove = false;
+
+	if (m_lButtonDownOnCaption)
+	{
+		edgeMove = false;
+		captionMove = true;
+	}
+
+	// Snap to left
+	if (lpwndpos->x >= (rect.left - threshold) &&
+		lpwndpos->x <= (rect.left + threshold))
+	{
+		if (edgeMove)
+		{
+			int diff = lpwndpos->x - rect.left;
+			lpwndpos->cx += diff;
+		}
+		if (edgeMove || captionMove)
+		{
+			lpwndpos->x = rect.left;
+		}
+	}
+
+	// Snap to right
+	if ((lpwndpos->x + lpwndpos->cx) >= (rect.right - threshold) &&
+		(lpwndpos->x + lpwndpos->cx) <= (rect.right + threshold))
+	{
+		if (edgeMove)
+		{
+			int diff = rect.right - (lpwndpos->x + lpwndpos->cx);
+			lpwndpos->cx += diff;
+		}
+		if (captionMove)
+		{
+			lpwndpos->x = (rect.right - lpwndpos->cx);
+		}
+	}
+
+	// Snap to top
+	if (lpwndpos->y >= (rect.top - threshold) &&
+		lpwndpos->y <= (rect.top + threshold))
+	{
+		if (edgeMove)
+		{
+			int diff = lpwndpos->y - rect.top;
+			lpwndpos->cy += diff;
+		}
+		if (edgeMove || captionMove)
+		{
+			lpwndpos->y = rect.top;
+		}
+	}
+
+	// Snap to bottom
+	if ((lpwndpos->y + lpwndpos->cy) >= (rect.bottom - threshold) &&
+		(lpwndpos->y + lpwndpos->cy) <= (rect.bottom + threshold))
+	{
+		if (edgeMove)
+		{
+			int diff = rect.bottom - (lpwndpos->y + lpwndpos->cy);
+			lpwndpos->cy += diff;
+		}
+		if (captionMove)
+		{
+			lpwndpos->y = (rect.bottom - lpwndpos->cy);
+		}
+	}
+}
+
 void CWndEx::OnWindowPosChanging(WINDOWPOS* lpwndpos)
 {
 	CWnd::OnWindowPosChanging(lpwndpos);
@@ -372,6 +472,8 @@ void CWndEx::OnWindowPosChanging(WINDOWPOS* lpwndpos)
 		KillTimer(TIMER_AUTO_MAX);
 		m_bMaxSetTimer = false;
 	}
+
+	SnapToEdge(lpwndpos);
 }
 
 void CWndEx::OnSize(UINT nType, int cx, int cy)

+ 3 - 0
WndEx.h

@@ -57,6 +57,9 @@ protected:
 	COleDateTime m_TimeMaximized;
 	int m_lDelayMaxSeconds;
 	CToolTipCtrl m_toolTip;
+	bool m_lButtonDownOnCaption;
+
+	void SnapToEdge(WINDOWPOS* lpwndpos);
 
 // Implementation
 public: