mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 13:33:27 -07:00
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:
parent
8b45489b11
commit
136953aa4e
6 changed files with 55 additions and 39 deletions
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
|
@ -123,13 +123,8 @@ namespace Greenshot.Drawing.Adorners
|
|||
{
|
||||
get
|
||||
{
|
||||
Point[] points = { Location };
|
||||
var matrix = Owner.Parent.ZoomMatrix;
|
||||
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);
|
||||
Point displayLocation = Owner.Parent.ToSurfaceCoordinates(Location);
|
||||
return new Rectangle(displayLocation.X - _size.Width / 2, displayLocation.Y - _size.Height / 2, _size.Width, _size.Height);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
|
||||
*
|
||||
|
@ -61,26 +61,26 @@ namespace Greenshot.Drawing.Adorners
|
|||
|
||||
Owner.Invalidate();
|
||||
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
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -542,8 +542,7 @@ namespace Greenshot.Drawing {
|
|||
ContextMenuStrip menu = new ContextMenuStrip();
|
||||
AddContextMenuItems(menu, surface);
|
||||
if (menu.Items.Count > 0) {
|
||||
// TODO: cast should be somehow avoided
|
||||
menu.Show((Surface)surface, e.Location);
|
||||
menu.Show(surface, surface.ToSurfaceCoordinates(e.Location));
|
||||
while (true) {
|
||||
if (menu.Visible) {
|
||||
Application.DoEvents();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Greenshot - a free and open source screenshot tool
|
||||
* 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]
|
||||
private float _zoomFactor = 1.0f;
|
||||
public float ZoomFactor
|
||||
|
@ -310,12 +312,11 @@ namespace Greenshot.Drawing
|
|||
set
|
||||
{
|
||||
_zoomFactor = value;
|
||||
ZoomMatrix = new Matrix(_zoomFactor, 0, 0, _zoomFactor, 0, 0);
|
||||
_zoomMatrix = new Matrix(_zoomFactor, 0, 0, _zoomFactor, 0, 0);
|
||||
UpdateSize();
|
||||
}
|
||||
}
|
||||
|
||||
public Matrix ZoomMatrix { get; private set; } = new Matrix(1, 0, 0, 1, 0, 0);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the surface size as zoomed image size.
|
||||
|
@ -2108,5 +2109,26 @@ namespace Greenshot.Drawing
|
|||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -442,20 +442,15 @@ namespace Greenshot.Drawing
|
|||
correction = -1;
|
||||
}
|
||||
Rectangle absRectangle = GuiRectangle.GetGuiRectangle(Left, Top, Width, Height);
|
||||
Point[] points = { absRectangle.Location, absRectangle.Location + absRectangle.Size };
|
||||
var matrix = Parent.ZoomMatrix;
|
||||
if (!matrix.IsIdentity)
|
||||
{
|
||||
matrix.TransformPoints(points);
|
||||
}
|
||||
_textBox.Left = points[0].X + lineWidth;
|
||||
_textBox.Top = points[0].Y + lineWidth;
|
||||
Rectangle displayRectangle = Parent.ToSurfaceCoordinates(absRectangle);
|
||||
_textBox.Left = displayRectangle.X + lineWidth;
|
||||
_textBox.Top = displayRectangle.Y + lineWidth;
|
||||
if (lineThickness <= 1)
|
||||
{
|
||||
lineWidth = 0;
|
||||
}
|
||||
_textBox.Width = points[1].X - points[0].X - 2 * lineWidth + correction;
|
||||
_textBox.Height = points[1].Y - points[0].Y - 2 * lineWidth + correction;
|
||||
_textBox.Width = displayRectangle.Width - 2 * lineWidth + correction;
|
||||
_textBox.Height = displayRectangle.Height - 2 * lineWidth + correction;
|
||||
}
|
||||
|
||||
public override void ApplyBounds(RectangleF newBounds)
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using GreenshotPlugin.Effects;
|
||||
|
@ -200,9 +199,15 @@ namespace GreenshotPlugin.Interfaces
|
|||
/// </summary>
|
||||
float ZoomFactor { get; set; }
|
||||
/// <summary>
|
||||
/// Matrix representing zoom applied to the surface.
|
||||
/// Translate a point from image coorditate space to surface coordinate space.
|
||||
/// </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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue