mirror of
https://github.com/greenshot/greenshot
synced 2025-07-30 11:40:40 -07:00
Smarter zoom - keep selected elements in sight
This commit is contained in:
parent
d93c9d6a3a
commit
ef5b5deb7a
4 changed files with 62 additions and 11 deletions
|
@ -235,6 +235,30 @@ namespace Greenshot.Drawing {
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A rectangle containing DrawingBounds of all drawableContainers in this list,
|
||||
/// or empty rectangle if nothing is there.
|
||||
/// </summary>
|
||||
public Rectangle DrawingBounds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Count == 0)
|
||||
{
|
||||
return Rectangle.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = this[0].DrawingBounds;
|
||||
for (int i = 1; i < Count; i++)
|
||||
{
|
||||
result = Rectangle.Union(result, this[i].DrawingBounds);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers all elements in the list ot be redrawn.
|
||||
/// </summary>
|
||||
|
|
|
@ -1922,6 +1922,13 @@ namespace Greenshot.Drawing
|
|||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the rectangle bounding all selected elements (in surface coordinates space),
|
||||
/// or empty rectangle if nothing is selcted.
|
||||
/// </summary>
|
||||
public Rectangle GetSelectionRectangle()
|
||||
=> ToSurfaceCoordinates(selectedElements.DrawingBounds);
|
||||
|
||||
/// <summary>
|
||||
/// Duplicate all the selecteded elements
|
||||
/// </summary>
|
||||
|
|
|
@ -1580,21 +1580,37 @@ namespace Greenshot {
|
|||
{
|
||||
return;
|
||||
}
|
||||
if (value == Surface.ZoomFactor)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Store old scroll position
|
||||
// When no scroll is currently needed - prefer top left corner.
|
||||
var horizontalCenter = 0.0;
|
||||
var verticalCenter = 0.0;
|
||||
var rc = surface.GetVisibleRectangle();
|
||||
// Store scroll position
|
||||
var rc = surface.GetVisibleRectangle(); // use visible rc by default
|
||||
var size = surface.Size;
|
||||
if (size.Width > rc.Width)
|
||||
if (value > Surface.ZoomFactor) // being smart on zoom-in
|
||||
{
|
||||
horizontalCenter = 1.0 * (rc.Left + rc.Width / 2) / size.Width;
|
||||
}
|
||||
if (size.Height > rc.Height)
|
||||
{
|
||||
verticalCenter = 1.0 * (rc.Top + rc.Height / 2) / size.Height;
|
||||
var sel = surface.GetSelectionRectangle();
|
||||
if (sel != Rectangle.Empty)
|
||||
{
|
||||
rc.Intersect(sel); // zoom to visible part of selection
|
||||
}
|
||||
else
|
||||
{
|
||||
// if image fits completely to currently visible rc and there are no things to focus on
|
||||
// - prefer top left corner to zoom-in as less disorienting for screenshots
|
||||
if (size.Width < rc.Width)
|
||||
{
|
||||
rc.Width = 0;
|
||||
}
|
||||
if (size.Height < rc.Height)
|
||||
{
|
||||
rc.Height = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
var horizontalCenter = 1.0 * (rc.Left + rc.Width / 2) / size.Width;
|
||||
var verticalCenter = 1.0 * (rc.Top + rc.Height / 2) / size.Height;
|
||||
|
||||
// Set the new zoom value
|
||||
Surface.ZoomFactor = value;
|
||||
|
|
|
@ -145,6 +145,10 @@ namespace GreenshotPlugin.Interfaces.Drawing
|
|||
get;
|
||||
set;
|
||||
}
|
||||
Rectangle DrawingBounds
|
||||
{
|
||||
get;
|
||||
}
|
||||
void MakeBoundsChangeUndoable(bool allowMerge);
|
||||
void Transform(Matrix matrix);
|
||||
void MoveBy(int dx, int dy);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue