Pan editor on resize

This commit is contained in:
L1Q 2017-10-24 05:31:02 +03:00
parent 1f5931815e
commit 3741435f19

View file

@ -57,6 +57,7 @@ public sealed class RegionCaptureForm : Form
public bool IsAnnotated => ShapeManager != null && ShapeManager.IsAnnotated;
public Point CurrentPosition { get; private set; }
public Size OldSize;
public Color CurrentColor
{
@ -105,6 +106,7 @@ public RegionCaptureForm(RegionCaptureMode mode)
Mode = mode;
ScreenRectangle0Based = CaptureHelpers.GetScreenBounds0Based();
OldSize = ScreenRectangle0Based.Size;
ImageRectangle = ScreenRectangle0Based;
InitializeComponent();
@ -288,11 +290,6 @@ private void OnMoved()
if (IsEditorMode && WindowState != lastWindowState)
{
lastWindowState = WindowState;
if (WindowState == FormWindowState.Normal || WindowState == FormWindowState.Maximized)
{
CenterCanvas(false);
}
}
if (IsAnnotationMode && ShapeManager.ToolbarCreated)
@ -302,6 +299,21 @@ private void OnMoved()
}
}
private void UpdatePan()
{
Size NewSize = ScreenRectangle0Based.Size;
if (OldSize == NewSize)
{
return;
}
Point ResizeDelta = new Point((NewSize.Width - OldSize.Width) / 2, (NewSize.Height - OldSize.Height) / 2);
Pan(ResizeDelta);
OldSize = ScreenRectangle0Based.Size;
}
public void SetDefaultCursor()
{
if (Cursor != defaultCursor)
@ -320,6 +332,7 @@ private void RegionCaptureForm_Shown(object sender, EventArgs e)
private void RegionCaptureForm_Resize(object sender, EventArgs e)
{
OnMoved();
UpdatePan();
}
private void RegionCaptureForm_LocationChanged(object sender, EventArgs e)
@ -509,10 +522,7 @@ private new void Update()
if (ShapeManager.IsPanning)
{
ImageRectangle = ImageRectangle.LocationOffset(InputManager.MouseVelocity.X, InputManager.MouseVelocity.Y);
backgroundBrush.TranslateTransform(InputManager.MouseVelocity.X, InputManager.MouseVelocity.Y);
ShapeManager.MoveAll(InputManager.MouseVelocity);
Pan(InputManager.MouseVelocity);
}
borderDotPen.DashOffset = (float)timerStart.Elapsed.TotalSeconds * -15;
@ -520,6 +530,14 @@ private new void Update()
ShapeManager.Update();
}
private void Pan(Point delta)
{
ImageRectangle = ImageRectangle.LocationOffset(delta.X, delta.Y);
backgroundBrush.TranslateTransform(delta.X, delta.Y);
ShapeManager.MoveAll(delta);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
//base.OnPaintBackground(e);