diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index b89e68251..22b718fd3 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -274,7 +274,8 @@ namespace Greenshot.Forms { // Make sure the mouse coordinates are fixed, when pressing shift cursorPos = FixMouseCoordinates(cursorPos); // As the cursorPos is not in Bitmap coordinates, we need to correct. - cursorPos.Offset(-capture.ScreenBounds.Location.X, -capture.ScreenBounds.Location.Y); + Point bitmapPos = new Point(cursorPos.X, cursorPos.Y); + bitmapPos.Offset(-capture.ScreenBounds.Location.X, -capture.ScreenBounds.Location.Y); Rectangle lastCaptureRect = new Rectangle(captureRect.Location, captureRect.Size); WindowDetails lastWindow = selectedCaptureWindow; bool horizontalMove = false; @@ -283,6 +284,7 @@ namespace Greenshot.Forms { // Change the zoom location if (zoomForm != null) { zoomForm.MouseLocation = cursorPos; + zoomForm.ZoomLocation = bitmapPos; } if (lastPos.X != cursorPos.X) { @@ -293,7 +295,7 @@ namespace Greenshot.Forms { } if (captureMode == CaptureMode.Region && mouseDown) { - captureRect = GuiRectangle.GetGuiRectangle(cursorPos.X, cursorPos.Y, mX - cursorPos.X, mY - cursorPos.Y); + captureRect = GuiRectangle.GetGuiRectangle(bitmapPos.X, bitmapPos.Y, mX - bitmapPos.X, mY - bitmapPos.Y); } // Iterate over the found windows and check if the current location is inside a window @@ -327,10 +329,10 @@ namespace Greenshot.Forms { int x2 = Math.Max(mX, lastPos.X); int y1 = Math.Min(mY, lastPos.Y); int y2 = Math.Max(mY, lastPos.Y); - x1= Math.Min(x1, cursorPos.X); - x2= Math.Max(x2, cursorPos.X); - y1= Math.Min(y1, cursorPos.Y); - y2= Math.Max(y2, cursorPos.Y); + x1= Math.Min(x1, bitmapPos.X); + x2= Math.Max(x2, bitmapPos.X); + y1= Math.Min(y1, bitmapPos.Y); + y2= Math.Max(y2, bitmapPos.Y); // Safety correction x2 += 2; @@ -339,8 +341,8 @@ namespace Greenshot.Forms { // Here we correct for text-size // Calculate the size - int textForWidth = Math.Max(Math.Abs(mX - cursorPos.X), Math.Abs(mX - lastPos.X)); - int textForHeight = Math.Max(Math.Abs(mY - cursorPos.Y), Math.Abs(mY - lastPos.Y)); + int textForWidth = Math.Max(Math.Abs(mX - bitmapPos.X), Math.Abs(mX - lastPos.X)); + int textForHeight = Math.Max(Math.Abs(mY - bitmapPos.Y), Math.Abs(mY - lastPos.Y)); using (Font rulerFont = new Font(FontFamily.GenericSansSerif, 8)) { Size measureWidth = TextRenderer.MeasureText(textForWidth.ToString(), rulerFont); @@ -373,13 +375,13 @@ namespace Greenshot.Forms { if (!conf.OptimizeForRDP) { if (verticalMove) { Rectangle before = GuiRectangle.GetGuiRectangle(0, lastPos.Y - 2, this.Width+2, 45); - Rectangle after = GuiRectangle.GetGuiRectangle(0, cursorPos.Y - 2, this.Width+2, 45); + Rectangle after = GuiRectangle.GetGuiRectangle(0, bitmapPos.Y - 2, this.Width+2, 45); Invalidate(before); Invalidate(after); } if (horizontalMove) { Rectangle before = GuiRectangle.GetGuiRectangle(lastPos.X - 2, 0, 75, this.Height+2); - Rectangle after = GuiRectangle.GetGuiRectangle(cursorPos.X -2, 0, 75, this.Height+2); + Rectangle after = GuiRectangle.GetGuiRectangle(bitmapPos.X -2, 0, 75, this.Height+2); Invalidate(before); Invalidate(after); } diff --git a/Greenshot/Forms/ZoomForm.cs b/Greenshot/Forms/ZoomForm.cs index dee4b3be3..4364157f7 100644 --- a/Greenshot/Forms/ZoomForm.cs +++ b/Greenshot/Forms/ZoomForm.cs @@ -33,15 +33,13 @@ namespace Greenshot.Forms { public class ZoomForm : FormWithoutActivation { private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ZoomForm)); private ICapture captureToZoom = null; - private Point mouseLocation = Point.Empty; + private Point zoomLocation = Point.Empty; private const int distanceX = 20; private const int distanceY = 20; - private Rectangle screenBounds; public ZoomForm(ICapture captureToZoom) { InitializeComponent(); this.captureToZoom = captureToZoom; - screenBounds = new Rectangle(Point.Empty, captureToZoom.Image.Size); Zoom = 400; } @@ -56,17 +54,16 @@ namespace Greenshot.Forms { } } + /// + /// Sets the location of the mouse on the screen (using screen coordinates, which might differ from bitmap coordindates in a multi screen setup) + /// public Point MouseLocation { - get { - return mouseLocation; - } set { - mouseLocation = value; - - Rectangle tl = new Rectangle(mouseLocation.X - (distanceX + Width), mouseLocation.Y - (distanceY + Height), Width, Height); - Rectangle tr = new Rectangle(mouseLocation.X + distanceX, mouseLocation.Y - (distanceY + Height), Width, Height); - Rectangle bl = new Rectangle(mouseLocation.X - (distanceX + Width), mouseLocation.Y + distanceY, Width, Height); - Rectangle br = new Rectangle(mouseLocation.X + distanceX, mouseLocation.Y + distanceY, Width, Height); + Rectangle tl = new Rectangle(value.X - (distanceX + Width), value.Y - (distanceY + Height), Width, Height); + Rectangle tr = new Rectangle(value.X + distanceX, value.Y - (distanceY + Height), Width, Height); + Rectangle bl = new Rectangle(value.X - (distanceX + Width), value.Y + distanceY, Width, Height); + Rectangle br = new Rectangle(value.X + distanceX, value.Y + distanceY, Width, Height); + Rectangle screenBounds = Screen.GetBounds(value); if (screenBounds.Contains(br)) { this.Location = br.Location; } else if (screenBounds.Contains(bl)) { @@ -80,6 +77,19 @@ namespace Greenshot.Forms { this.Invalidate(); } } + + /// + /// Gets or sets the location of the bitmap to be displayed in zoom (using bitmap coordinates, which might differ from screen coordinates in a multi screen setup) + /// + public Point ZoomLocation { + get { + return zoomLocation; + } + set { + zoomLocation = value; + } + + } public int Zoom { get; @@ -106,7 +116,7 @@ namespace Greenshot.Forms { int sourceWidth = (int)(Width * zoom); int sourceHeight = (int)(Height * zoom); - Rectangle sourceRectangle = new Rectangle(MouseLocation.X - (sourceWidth / 2), MouseLocation.Y - (sourceHeight / 2), sourceWidth, sourceHeight); + Rectangle sourceRectangle = new Rectangle(ZoomLocation.X - (sourceWidth / 2), ZoomLocation.Y - (sourceHeight / 2), sourceWidth, sourceHeight); Rectangle destinationRectangle = new Rectangle(0, 0, Width, Height); graphics.DrawImage(captureToZoom.Image, destinationRectangle, sourceRectangle, GraphicsUnit.Pixel);