Merge pull request #6118 from EricTetz/develop

Fix panning regression (panning at limit accumulates invisible changes)
This commit is contained in:
Jaex 2022-02-21 01:09:29 +03:00 committed by GitHub
commit e2ecdf7d0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 58 deletions

View file

@ -64,7 +64,6 @@ public sealed class RegionCaptureForm : Form
public Point CurrentPosition { get; private set; } public Point CurrentPosition { get; private set; }
public SimpleWindowInfo SelectedWindow { get; private set; } public SimpleWindowInfo SelectedWindow { get; private set; }
internal PointF PanningStrech = new PointF();
internal Vector2 CanvasCenterOffset { get; set; } = new Vector2(0f, 0f); internal Vector2 CanvasCenterOffset { get; set; } = new Vector2(0f, 0f);
internal float ZoomFactor internal float ZoomFactor
@ -419,19 +418,8 @@ private void OnMoved()
} }
} }
private void Pan(float deltaX, float deltaY, bool usePanningStretch = true) private bool Pan(float deltaX, float deltaY)
{ {
if (deltaX == 0 && deltaY == 0)
{
return;
}
if (usePanningStretch)
{
PanningStrech.X -= deltaX;
PanningStrech.Y -= deltaY;
}
SizeF panLimitSize = new SizeF(Math.Min(ClientArea.Width * 0.25f, CanvasRectangle.Width), SizeF panLimitSize = new SizeF(Math.Min(ClientArea.Width * 0.25f, CanvasRectangle.Width),
Math.Min(ClientArea.Height * 0.25f, CanvasRectangle.Height)); Math.Min(ClientArea.Height * 0.25f, CanvasRectangle.Height));
@ -448,15 +436,9 @@ private void Pan(float deltaX, float deltaY, bool usePanningStretch = true)
deltaY = Math.Max(deltaY, limitRectangle.Top - CanvasRectangle.Bottom); deltaY = Math.Max(deltaY, limitRectangle.Top - CanvasRectangle.Bottom);
deltaY = Math.Min(deltaY, limitRectangle.Bottom - CanvasRectangle.Top); deltaY = Math.Min(deltaY, limitRectangle.Bottom - CanvasRectangle.Top);
if (usePanningStretch) if (deltaX == 0 && deltaY == 0)
{ {
deltaX -= Math.Min(Math.Max(deltaX, 0), Math.Max(0, PanningStrech.X)); return false;
deltaX -= Math.Max(Math.Min(deltaX, 0), Math.Min(0, PanningStrech.X));
deltaY -= Math.Min(Math.Max(deltaY, 0), Math.Max(0, PanningStrech.Y));
deltaY -= Math.Max(Math.Min(deltaY, 0), Math.Min(0, PanningStrech.Y));
PanningStrech.X += deltaX;
PanningStrech.Y += deltaY;
} }
CanvasRectangle = CanvasRectangle.LocationOffset(deltaX, deltaY); CanvasRectangle = CanvasRectangle.LocationOffset(deltaX, deltaY);
@ -470,14 +452,11 @@ private void Pan(float deltaX, float deltaY, bool usePanningStretch = true)
{ {
ShapeManager.MoveAll(deltaX, deltaY); ShapeManager.MoveAll(deltaX, deltaY);
} }
return true;
} }
private void Pan(Point delta) public void PanToOffset(Vector2 centerOffset)
{
Pan(delta.X, delta.Y);
}
private void AutomaticPan(Vector2 centerOffset)
{ {
if (IsEditorMode) if (IsEditorMode)
{ {
@ -488,25 +467,16 @@ private void AutomaticPan(Vector2 centerOffset)
float newY = y - (canvas.Height / 2); float newY = y - (canvas.Height / 2);
float deltaX = (newX - canvas.X) / ZoomFactor; float deltaX = (newX - canvas.X) / ZoomFactor;
float deltaY = (newY - canvas.Y) / ZoomFactor; float deltaY = (newY - canvas.Y) / ZoomFactor;
Pan(deltaX, deltaY, false); if (Pan(deltaX, deltaY))
{
CanvasCenterOffset = centerOffset;
}
} }
} }
public void AutomaticPan()
{
AutomaticPan(CanvasCenterOffset);
}
private void UpdateCenterOffset()
{
CanvasCenterOffset = new Vector2(CanvasRectangle.X + (CanvasRectangle.Width / 2f) - (ClientArea.Width / 2f),
CanvasRectangle.Y + (CanvasRectangle.Height / 2f) - (ClientArea.Height / 2f));
}
public void CenterCanvas() public void CenterCanvas()
{ {
CanvasCenterOffset = new Vector2(0f, ToolbarHeight / 2f); PanToOffset(new Vector2(0f, ToolbarHeight / 2f));
AutomaticPan(CanvasCenterOffset / ZoomFactor);
} }
public void ZoomTransform(Graphics g, bool invertZoom = false) public void ZoomTransform(Graphics g, bool invertZoom = false)
@ -576,7 +546,7 @@ private void RegionCaptureForm_Shown(object sender, EventArgs e)
private void RegionCaptureForm_Resize(object sender, EventArgs e) private void RegionCaptureForm_Resize(object sender, EventArgs e)
{ {
OnMoved(); OnMoved();
AutomaticPan(); PanToOffset(CanvasCenterOffset);
} }
private void RegionCaptureForm_LocationChanged(object sender, EventArgs e) private void RegionCaptureForm_LocationChanged(object sender, EventArgs e)
@ -752,9 +722,11 @@ private void Zoom(bool zoomIn, bool atMouse = true)
} }
PointF scaledCenterAfter = atMouse ? ScaledClientMousePosition : clientCenter.Scale(1 / zoomFactor); PointF scaledCenterAfter = atMouse ? ScaledClientMousePosition : clientCenter.Scale(1 / zoomFactor);
Pan(scaledCenterAfter.X - scaledCenterBefore.X, scaledCenterAfter.Y - scaledCenterBefore.Y); if (Pan(scaledCenterAfter.X - scaledCenterBefore.X, scaledCenterAfter.Y - scaledCenterBefore.Y))
CanvasCenterOffset = new Vector2((CanvasRectangle.X + CanvasRectangle.Width / 2f) * ZoomFactor - clientCenter.X, {
(CanvasRectangle.Y + CanvasRectangle.Height / 2f) * ZoomFactor - clientCenter.Y); CanvasCenterOffset = new Vector2((CanvasRectangle.X + CanvasRectangle.Width / 2f) * ZoomFactor - clientCenter.X,
(CanvasRectangle.Y + CanvasRectangle.Height / 2f) * ZoomFactor - clientCenter.Y);
}
UpdateTitle(); UpdateTitle();
} }
@ -850,8 +822,8 @@ private void UpdateCoordinates()
if (ShapeManager.IsPanning) if (ShapeManager.IsPanning)
{ {
CanvasCenterOffset = new Vector2(CanvasCenterOffset.X + InputManager.MouseVelocity.X, CanvasCenterOffset.Y + InputManager.MouseVelocity.Y); Vector2 offset = new Vector2(CanvasCenterOffset.X + InputManager.MouseVelocity.X, CanvasCenterOffset.Y + InputManager.MouseVelocity.Y);
AutomaticPan(); PanToOffset(offset);
} }
if (Options.EnableAnimations) if (Options.EnableAnimations)

View file

@ -198,16 +198,10 @@ private void Scroll(Point position)
float centerOffsetNew = ((trackLengthInternal / 2.0f) - mousePositionLocal) / trackLengthInternal * inImageSize; float centerOffsetNew = ((trackLengthInternal / 2.0f) - mousePositionLocal) / trackLengthInternal * inImageSize;
if (Orientation == Orientation.Horizontal) Vector2 canvasCenterOffset = Orientation == Orientation.Horizontal
{ ? new Vector2(centerOffsetNew, form.CanvasCenterOffset.Y)
form.CanvasCenterOffset = new Vector2(centerOffsetNew, form.CanvasCenterOffset.Y); : new Vector2(form.CanvasCenterOffset.X, centerOffsetNew);
} form.PanToOffset(canvasCenterOffset);
else
{
form.CanvasCenterOffset = new Vector2(form.CanvasCenterOffset.X, centerOffsetNew);
}
form.AutomaticPan();
} }
} }
} }

View file

@ -1029,7 +1029,6 @@ public void EndRegionSelection()
private void StartPanning() private void StartPanning()
{ {
IsPanning = true; IsPanning = true;
Form.PanningStrech = new Point(0, 0);
Options.ShowEditorPanTip = false; Options.ShowEditorPanTip = false;
} }