mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 13:33:27 -07:00
Keep center of visible area static on zoom when possible
This commit is contained in:
parent
4c0277be90
commit
e6e2ed523a
2 changed files with 24 additions and 3 deletions
|
@ -1890,7 +1890,7 @@ namespace Greenshot.Drawing
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the rectangle bounding the part of this Surface currently visible in the editor (in surface coordinate space).
|
/// Get the rectangle bounding the part of this Surface currently visible in the editor (in surface coordinate space).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private Rectangle GetVisibleRectangle()
|
public Rectangle GetVisibleRectangle()
|
||||||
{
|
{
|
||||||
var bounds = Bounds;
|
var bounds = Bounds;
|
||||||
var clientArea = Parent.ClientRectangle;
|
var clientArea = Parent.ClientRectangle;
|
||||||
|
|
|
@ -1572,8 +1572,24 @@ namespace Greenshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ZoomSetValue(int value) {
|
private void ZoomSetValue(int value) {
|
||||||
|
var surface = Surface as Surface;
|
||||||
|
var panel = surface?.Parent as Panel;
|
||||||
|
if (panel == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store old scroll position
|
||||||
|
var rc = surface.GetVisibleRectangle();
|
||||||
|
var size = surface.Size;
|
||||||
|
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
|
||||||
_zoomValue = value;
|
_zoomValue = value;
|
||||||
Surface.ZoomFactor = 1f * value / 100;
|
Surface.ZoomFactor = 1f * value / 100;
|
||||||
|
Size = GetOptimalWindowSize();
|
||||||
|
AlignCanvasPositionAfterResize();
|
||||||
|
|
||||||
// Update zoom controls
|
// Update zoom controls
|
||||||
string valueString = value.ToString();
|
string valueString = value.ToString();
|
||||||
|
@ -1584,8 +1600,13 @@ namespace Greenshot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Size = GetOptimalWindowSize();
|
// Restore scroll position
|
||||||
AlignCanvasPositionAfterResize();
|
rc = surface.GetVisibleRectangle();
|
||||||
|
size = surface.Size;
|
||||||
|
panel.AutoScrollPosition = new Point(
|
||||||
|
(int)(horizontalCenter * size.Width) - rc.Width / 2,
|
||||||
|
(int)(verticalCenter * size.Height) - rc.Height / 2
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue