Browse Source

added force close command, defaults esc - esc, more improvments to zooming on image

scott brogden 6 years ago
parent
commit
e25bd1e76e
8 changed files with 102 additions and 28 deletions
  1. 7 1
      Accels.cpp
  2. 10 3
      ActionEnums.cpp
  3. 1 0
      ActionEnums.h
  4. 42 19
      ImageViewer.cpp
  5. 30 0
      QPasteWnd.cpp
  6. 2 0
      QPasteWnd.h
  7. 8 4
      ScrollHelper.cpp
  8. 2 1
      ScrollHelper.h

+ 7 - 1
Accels.cpp

@@ -124,7 +124,8 @@ bool CAccels::OnMsg(MSG *pMsg, CAccel &a)
 			if (it2->second.Key2 == 0)
 			{
 				a = (*it2).second;
-				return true;				
+				//return now as a another command could have a second key defined
+				//if they don't press the second key this will be handled by a timer on the outside				
 			}
 			else
 			{
@@ -133,6 +134,11 @@ bool CAccels::OnMsg(MSG *pMsg, CAccel &a)
 				break;
 			}
 		}
+
+		if (a.Cmd > 0 && m_activeFirstKey == 0)
+		{
+			return true;
+		}
 	}
 
     return false;

+ 10 - 3
ActionEnums.cpp

@@ -368,6 +368,9 @@ CString ActionEnums::EnumDescription(ActionEnumValues value)
 	case COPY_SELECTION:
 		val = "Copy Selection";
 		break;
+	case FORCE_CLOSE_WINDOW:
+		val = "Force Close Window";
+		break;
 	}
 
 	CString translatedValue = theApp.m_Language.GetQuickPasteKeyboardString(value, val);
@@ -439,6 +442,8 @@ int ActionEnums::GetDefaultShortCutKeyA(ActionEnumValues value, int pos)
 			return ACCEL_MAKEKEY('0', HOTKEYF_CONTROL);
 		case CLOSEWINDOW:
 			return VK_ESCAPE;
+		case FORCE_CLOSE_WINDOW:
+			return VK_ESCAPE;
 		case TOGGLE_DESCRIPTION_WORD_WRAP:
 			return 'W';
 		case COPY_SELECTION:
@@ -482,9 +487,11 @@ int ActionEnums::GetDefaultShortCutKeyB(ActionEnumValues value, int pos)
 	switch (pos)
 	{
 	case 0:
-		//switch (value)
-		//{
-		//}
+		switch (value)
+		{
+		case FORCE_CLOSE_WINDOW:
+			return VK_ESCAPE;
+		}
 		break;
 	}
 

+ 1 - 0
ActionEnums.h

@@ -124,6 +124,7 @@ public:
 		SLUGIFY,
 		INVERT_CASE,
 		COPY_SELECTION,
+		FORCE_CLOSE_WINDOW,
 
 		LAST_ACTION
 	};

+ 42 - 19
ImageViewer.cpp

@@ -83,14 +83,14 @@ void CImageViewer::UpdateBitmapSize()
 			CRect rect;
 			GetClientRect(rect);
 
-			m_scrollHelper.SetDisplaySize(0, 0);
+			m_scrollHelper.SetDisplaySize(0, 0, 1);
 			m_scrollHelper.DetachWnd();
 			
 		}
 		else
 		{
 			m_scrollHelper.AttachWnd(this);
-			m_scrollHelper.SetDisplaySize(m_pGdiplusBitmap->GetWidth() * m_scale, m_pGdiplusBitmap->GetHeight() * m_scale);
+			m_scrollHelper.SetDisplaySize(m_pGdiplusBitmap->GetWidth(), m_pGdiplusBitmap->GetHeight(), m_scale);
 		}
 	}
 }
@@ -154,19 +154,26 @@ void CImageViewer::OnPaint()
 		else
 		{
 
+			Gdiplus::ImageAttributes attrs;
 			CSize s = m_scrollHelper.GetScrollPos();
+
 			Gdiplus::Graphics graphics(memDC);
 
 			graphics.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
 
 			graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf);
 			//graphics.ScaleTransform(m_scale, m_scale);
-			double x = m_scale;
-			if (x != 1)
-			{
-				x = 1.0 + (1.0 - m_scale);
-			}
-			graphics.DrawImage(m_pGdiplusBitmap, rect.left, rect.top, s.cx, s.cy, width * (x), height * (x), Gdiplus::UnitPixel);
+			//double x = m_scale;
+			//if (x != 1)
+			//{
+			//	x = 1.0 + (1.0 - m_scale);
+			//}
+
+			Gdiplus::Rect dest((int)0, (int)0, (int)rect.Width(), (int)rect.Height());
+
+			graphics.DrawImage(m_pGdiplusBitmap, dest, s.cx, s.cy, rect.Width() * (1/m_scale), rect.Height() * (1/m_scale), Gdiplus::UnitPixel, &attrs);
+
+			OutputDebugString(_T("OnPaint\r\n"));
 		}
 		
 		rect.top += height;
@@ -199,49 +206,64 @@ BOOL CImageViewer::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
 
 		int upDown = 1;
 
+		double oldScale = m_scale;
+
 
 		m_scrollHelper.GetScrollPos();
 
 		if (zDelta > 0)
 		{
-			m_scale -= .1;
-			upDown = -1;
+			m_scale += .1;
+			
 
 		}
 		else
 		{
-			m_scale += .1;
+			upDown = -1;
+			m_scale -= .1;
 		}		
 		
 		/*int n = (m_pGdiplusBitmap->GetWidth() - m_scrollHelper.GetPageSize().cx) * m_scale;
 		int n2 = (m_pGdiplusBitmap->GetHeight() - m_scrollHelper.GetPageSize().cy) * m_scale;
 		int d = n - o;
 		int d2 = n2 - o2;*/
-
+				
 		
 
 		POINT pointInImage;
 		pointInImage.x = pt.x;
 		pointInImage.y = pt.y;
+		
 
 		::ScreenToClient(m_hWnd, &pointInImage);
 
 		pointInImage.x += m_scrollHelper.GetScrollPos().cx;
 		pointInImage.y += m_scrollHelper.GetScrollPos().cy;
 
+		POINT b;
+		b.x = pointInImage.x;
+		b.y = pointInImage.y;
+
+		pointInImage.x = pointInImage.x * oldScale;
+		pointInImage.y = pointInImage.y * oldScale;
+
+		b.x = b.x * m_scale;
+		b.y = b.y * m_scale;
+		
+
 		UpdateBitmapSize();
 
-		POINT b;
-		b.x = pointInImage.x + (pointInImage.x * .1);
-		b.y = pointInImage.y + (pointInImage.y * .1);
+		//POINT b;
+		//b.x = pointInImage.x + (pointInImage.x * .1);
+		//b.y = pointInImage.y + (pointInImage.y * .1);
 
 		delta.x = (b.x - pointInImage.x) * upDown;
 		delta.y = (b.y - pointInImage.y) * upDown;
 
-		CString cs;
-		cs.Format(_T("pos in image: x: %d, y: %d, new x: %d, y: %d, diff: x: %d, y: %d\r\n"), pointInImage.x, pointInImage.y, b.x, b.y, delta.x, delta.y);
-		OutputDebugString(cs);
-		m_scrollHelper.Update(delta);
+		//CString cs;
+		//cs.Format(_T("pos in image: x: %d, y: %d, new x: %d, y: %d, diff: x: %d, y: %d\r\n"), pointInImage.x, pointInImage.y, b.x, b.y, delta.x, delta.y);
+		//OutputDebugString(cs);
+		//m_scrollHelper.Update(delta);
 
 		Invalidate();
 
@@ -304,6 +326,7 @@ void CImageViewer::OnLButtonUp(UINT nFlags, CPoint point)
 	{
 		CGetSetOptions::SetScaleImagesToDescWindow(!CGetSetOptions::GetScaleImagesToDescWindow());
 		this->UpdateBitmapSize();
+		m_scale = 1;
 		Invalidate();
 		return;
 	}

+ 30 - 0
QPasteWnd.cpp

@@ -57,6 +57,7 @@
 #define TIMER_PASTE_FROM_MODIFER	3
 #define TIMER_ERROR_MSG			4
 #define TIMER_DRAG_HIDE_WINDOW	6
+#define TIMER_DO_ACTION	7
 
 #define THREAD_DO_QUERY				0
 #define THREAD_EXIT_THREAD			1
@@ -2845,8 +2846,14 @@ bool CQPasteWnd::CheckActions(MSG * pMsg)
 	{
 		if (m_actions.OnMsg(pMsg, a))
 		{
+			KillTimer(TIMER_DO_ACTION);
 			ret = DoAction(a);
 		}
+		else if (a.Cmd > 0)
+		{
+			m_timerAction = a;
+			SetTimer(TIMER_DO_ACTION, 500, NULL);
+		}
 	}
 
 	return ret;
@@ -2891,6 +2898,9 @@ bool CQPasteWnd::DoAction(CAccel a)
 	case ActionEnums::CLOSEWINDOW:
 		ret = DoActionCloseWindow();
 		break;
+	case ActionEnums::FORCE_CLOSE_WINDOW:
+		ret = DoActionForceCloseWindow();
+		break;
 	case ActionEnums::NEXTTABCONTROL:
 		ret = DoActionNextTabControl();
 		break;
@@ -3463,6 +3473,14 @@ bool CQPasteWnd::DoActionToggleOutputDebugString()
 	return true;
 }
 
+bool CQPasteWnd::DoActionForceCloseWindow()
+{
+	Log(_T("Force closing window from hot keys"));
+	HideQPasteWindow(true);
+
+	return true;
+}
+
 bool CQPasteWnd::DoActionCloseWindow()
 {
 	bool ret = false;
@@ -5968,6 +5986,18 @@ void CQPasteWnd::OnTimer(UINT_PTR nIDEvent)
 			KillTimer(TIMER_DRAG_HIDE_WINDOW);
 		}
 	}
+	else if (nIDEvent == TIMER_DO_ACTION)
+	{
+		KillTimer(TIMER_DO_ACTION);
+
+		OutputDebugString(StrF(_T("DoActionTimer, cmd: %d"), m_timerAction.Cmd));
+
+		if (m_timerAction.Cmd > 0)
+		{
+			DoAction(m_timerAction);
+		}
+		m_timerAction = CAccel();		
+	}
 
     CWndEx::OnTimer(nIDEvent);
 }

+ 2 - 0
QPasteWnd.h

@@ -172,6 +172,7 @@ public:
 	CPopup m_popupMsg;
 	CCustomFriendsHelper m_customFriendsHelper;
 	bool m_noSearchResults;
+	CAccel m_timerAction;
 
     void RefreshNc();
     void UpdateStatus(bool bRepaintImmediately = false); // regenerates the status (caption) text
@@ -232,6 +233,7 @@ public:
 	bool DoActionToggleFileLogging();
 	bool DoActionToggleOutputDebugString();
 	bool DoActionCloseWindow();
+	bool DoActionForceCloseWindow();
 	bool DoActionNextTabControl();
 	bool DoActionPrevTabControl();
 	bool DoActionShowGroups();

+ 8 - 4
ScrollHelper.cpp

@@ -40,6 +40,7 @@ CScrollHelper::CScrollHelper()
     m_pageSize    = CSize(0,0);
     m_displaySize = CSize(0,0);
     m_scrollPos   = CSize(0,0);
+	m_zoomScale = 1;
 }
 
 CScrollHelper::~CScrollHelper()
@@ -57,16 +58,17 @@ void CScrollHelper::DetachWnd()
     m_attachWnd = NULL;
 }
 
-void CScrollHelper::SetDisplaySize(int displayWidth, int displayHeight)
+void CScrollHelper::SetDisplaySize(int displayWidth, int displayHeight, double zoomScale)
 {
+	m_zoomScale = zoomScale;
 	int cxSB = ::GetSystemMetrics(SM_CXVSCROLL);
 	int cySB = ::GetSystemMetrics(SM_CYHSCROLL);	
 
 	CString msg;
-	msg.Format(_T("width: %d, height: %d"), displayWidth, displayHeight);
+	msg.Format(_T("width: %d, height: %d, scale: %f"), displayWidth, displayHeight, m_zoomScale);
 	OutputDebugString(msg);
 
-    m_displaySize = CSize(displayWidth + cxSB, displayHeight + cySB);
+    m_displaySize = CSize((displayWidth) + cxSB, (displayHeight) + cySB);
 
     if ( m_attachWnd != NULL && ::IsWindow(m_attachWnd->m_hWnd) )
         UpdateScrollInfo();
@@ -182,6 +184,7 @@ void CScrollHelper::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
         m_scrollPos.cx += deltaPos;
         m_attachWnd->SetScrollPos(SB_HORZ, m_scrollPos.cx, TRUE);
         m_attachWnd->ScrollWindow(-deltaPos, 0);
+		m_attachWnd->Invalidate();
     }
 }
 
@@ -252,6 +255,7 @@ void CScrollHelper::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
         m_scrollPos.cy += deltaPos;
         m_attachWnd->SetScrollPos(SB_VERT, m_scrollPos.cy, TRUE);
         m_attachWnd->ScrollWindow(0, -deltaPos);
+		m_attachWnd->Invalidate();
     }
 }
 
@@ -436,7 +440,7 @@ void CScrollHelper::UpdateScrollInfo()
     // expect.
     CRect rect;
     GetClientRectSB(m_attachWnd, rect);
-    CSize windowSize(rect.Width(), rect.Height());
+    CSize windowSize(rect.Width() * (1/m_zoomScale), rect.Height() * (1/m_zoomScale));
 
     // Update horizontal scrollbar.
     CSize deltaPos(0,0);

+ 2 - 1
ScrollHelper.h

@@ -23,7 +23,7 @@ public:
     // scrollbars will appear. Set either the display width or display
     // height to zero if you don't want to enable the scrollbar in the
     // corresponding direction.
-    void   SetDisplaySize(int displayWidth, int displayHeight);
+    void   SetDisplaySize(int displayWidth, int displayHeight, double zoomScale);
     const CSize& GetDisplaySize() const;
 
     // Get current scroll position. This is needed if you are scrolling
@@ -55,6 +55,7 @@ private:
     CSize  m_pageSize;
     CSize  m_displaySize;
     CSize  m_scrollPos;
+	double m_zoomScale;
 };
 
 #endif // SCROLL_HELPER_INCLUDED