From 3741435f1906ea31f84e35f8c5b9bc9f458ab75e Mon Sep 17 00:00:00 2001 From: L1Q <0xL1Q@ex.ua> Date: Tue, 24 Oct 2017 05:31:02 +0300 Subject: [PATCH] Pan editor on resize --- .../Forms/RegionCaptureForm.cs | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs b/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs index 8b4e51805..3405ae6b6 100644 --- a/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/RegionCaptureForm.cs @@ -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);