Fixes for some identified issues

- better interface for coordinate translation;
- correct context menu location;
- speech bubble tail can be dragged over the whole image.
This commit is contained in:
Killy 2020-04-27 01:13:22 +03:00
commit 136953aa4e
6 changed files with 55 additions and 39 deletions

View file

@ -1,4 +1,4 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
* *
@ -123,13 +123,8 @@ namespace Greenshot.Drawing.Adorners
{ {
get get
{ {
Point[] points = { Location }; Point displayLocation = Owner.Parent.ToSurfaceCoordinates(Location);
var matrix = Owner.Parent.ZoomMatrix; return new Rectangle(displayLocation.X - _size.Width / 2, displayLocation.Y - _size.Height / 2, _size.Width, _size.Height);
if (!matrix.IsIdentity)
{
matrix.TransformPoints(points);
}
return new Rectangle(points[0].X - _size.Width / 2, points[0].Y - _size.Height / 2, _size.Width, _size.Height);
} }
} }

View file

@ -1,4 +1,4 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
* *
@ -61,26 +61,26 @@ namespace Greenshot.Drawing.Adorners
Owner.Invalidate(); Owner.Invalidate();
Point newGripperLocation = new Point(mouseEventArgs.X, mouseEventArgs.Y); Point newGripperLocation = new Point(mouseEventArgs.X, mouseEventArgs.Y);
Rectangle surfaceBounds = new Rectangle(0, 0, Owner.Parent.Width, Owner.Parent.Height); Rectangle imageBounds = new Rectangle(0, 0, Owner.Parent.Image.Width, Owner.Parent.Image.Height);
// Check if gripper inside the parent (surface), if not we need to move it inside // Check if gripper inside the parent (surface), if not we need to move it inside
// This was made for BUG-1682 // This was made for BUG-1682
if (!surfaceBounds.Contains(newGripperLocation)) if (!imageBounds.Contains(newGripperLocation))
{ {
if (newGripperLocation.X > surfaceBounds.Right) if (newGripperLocation.X > imageBounds.Right)
{ {
newGripperLocation.X = surfaceBounds.Right - 5; newGripperLocation.X = imageBounds.Right - 5;
} }
if (newGripperLocation.X < surfaceBounds.Left) if (newGripperLocation.X < imageBounds.Left)
{ {
newGripperLocation.X = surfaceBounds.Left; newGripperLocation.X = imageBounds.Left;
} }
if (newGripperLocation.Y > surfaceBounds.Bottom) if (newGripperLocation.Y > imageBounds.Bottom)
{ {
newGripperLocation.Y = surfaceBounds.Bottom - 5; newGripperLocation.Y = imageBounds.Bottom - 5;
} }
if (newGripperLocation.Y < surfaceBounds.Top) if (newGripperLocation.Y < imageBounds.Top)
{ {
newGripperLocation.Y = surfaceBounds.Top; newGripperLocation.Y = imageBounds.Top;
} }
} }

View file

@ -523,9 +523,9 @@ namespace Greenshot.Drawing {
} }
} }
public virtual void ShowContextMenu(MouseEventArgs e, ISurface surface) public virtual void ShowContextMenu(MouseEventArgs e, ISurface iSurface)
{ {
if (!(surface is Surface)) if (!(iSurface is Surface surface))
{ {
return; return;
} }
@ -542,8 +542,7 @@ namespace Greenshot.Drawing {
ContextMenuStrip menu = new ContextMenuStrip(); ContextMenuStrip menu = new ContextMenuStrip();
AddContextMenuItems(menu, surface); AddContextMenuItems(menu, surface);
if (menu.Items.Count > 0) { if (menu.Items.Count > 0) {
// TODO: cast should be somehow avoided menu.Show(surface, surface.ToSurfaceCoordinates(e.Location));
menu.Show((Surface)surface, e.Location);
while (true) { while (true) {
if (menu.Visible) { if (menu.Visible) {
Application.DoEvents(); Application.DoEvents();

View file

@ -1,4 +1,4 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
* *
@ -302,6 +302,8 @@ namespace Greenshot.Drawing
} }
} }
[NonSerialized]
private Matrix _zoomMatrix = new Matrix(1, 0, 0, 1, 0, 0);
[NonSerialized] [NonSerialized]
private float _zoomFactor = 1.0f; private float _zoomFactor = 1.0f;
public float ZoomFactor public float ZoomFactor
@ -310,12 +312,11 @@ namespace Greenshot.Drawing
set set
{ {
_zoomFactor = value; _zoomFactor = value;
ZoomMatrix = new Matrix(_zoomFactor, 0, 0, _zoomFactor, 0, 0); _zoomMatrix = new Matrix(_zoomFactor, 0, 0, _zoomFactor, 0, 0);
UpdateSize(); UpdateSize();
} }
} }
public Matrix ZoomMatrix { get; private set; } = new Matrix(1, 0, 0, 1, 0, 0);
/// <summary> /// <summary>
/// Sets the surface size as zoomed image size. /// Sets the surface size as zoomed image size.
@ -2108,5 +2109,26 @@ namespace Greenshot.Drawing
{ {
return _elements.Contains(container); return _elements.Contains(container);
} }
public Point ToSurfaceCoordinates(Point point)
{
Point[] points = { point };
_zoomMatrix.TransformPoints(points);
return points[0];
}
public Rectangle ToSurfaceCoordinates(Rectangle rc)
{
if (_zoomMatrix.IsIdentity)
{
return rc;
}
else
{
Point[] points = { rc.Location, rc.Location + rc.Size };
_zoomMatrix.TransformPoints(points);
return new Rectangle(points[0].X, points[0].Y, points[1].X - points[0].X, points[1].Y - points[1].Y);
}
}
} }
} }

View file

@ -442,20 +442,15 @@ namespace Greenshot.Drawing
correction = -1; correction = -1;
} }
Rectangle absRectangle = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height); Rectangle absRectangle = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
Point[] points = { absRectangle.Location, absRectangle.Location + absRectangle.Size }; Rectangle displayRectangle = Parent.ToSurfaceCoordinates(absRectangle);
var matrix = Parent.ZoomMatrix; _textBox.Left = displayRectangle.X + lineWidth;
if (!matrix.IsIdentity) _textBox.Top = displayRectangle.Y + lineWidth;
{
matrix.TransformPoints(points);
}
_textBox.Left = points[0].X + lineWidth;
_textBox.Top = points[0].Y + lineWidth;
if (lineThickness <= 1) if (lineThickness <= 1)
{ {
lineWidth = 0; lineWidth = 0;
} }
_textBox.Width = points[1].X - points[0].X - 2 * lineWidth + correction; _textBox.Width = displayRectangle.Width - 2 * lineWidth + correction;
_textBox.Height = points[1].Y - points[0].Y - 2 * lineWidth + correction; _textBox.Height = displayRectangle.Height - 2 * lineWidth + correction;
} }
public override void ApplyBounds(RectangleF newBounds) public override void ApplyBounds(RectangleF newBounds)

View file

@ -21,7 +21,6 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
using GreenshotPlugin.Effects; using GreenshotPlugin.Effects;
@ -200,9 +199,15 @@ namespace GreenshotPlugin.Interfaces
/// </summary> /// </summary>
float ZoomFactor { get; set; } float ZoomFactor { get; set; }
/// <summary> /// <summary>
/// Matrix representing zoom applied to the surface. /// Translate a point from image coorditate space to surface coordinate space.
/// </summary> /// </summary>
Matrix ZoomMatrix { get; } /// <param name="point">A point in the coordinate space of the image.</param>
Point ToSurfaceCoordinates(Point point);
/// <summary>
/// Translate a rectangle from image coorditate space to surface coordinate space.
/// </summary>
/// <param name="rc">A rectangle in the coordinate space of the image.</param>
Rectangle ToSurfaceCoordinates(Rectangle rc);
void MakeUndoable(IMemento memento, bool allowMerge); void MakeUndoable(IMemento memento, bool allowMerge);
} }