mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-05 06:30:36 +12:00
Improvements to panning
This commit is contained in:
parent
3e9d67dc7a
commit
cadd9c7fca
|
@ -57,8 +57,6 @@ public sealed class RegionCaptureForm : Form
|
|||
public bool IsAnnotated => ShapeManager != null && ShapeManager.IsAnnotated;
|
||||
|
||||
public Point CurrentPosition { get; private set; }
|
||||
private Size oldSize;
|
||||
private Vector2 panError = new Vector2(0f, 0f);
|
||||
|
||||
public Color CurrentColor
|
||||
{
|
||||
|
@ -80,6 +78,8 @@ public Color CurrentColor
|
|||
|
||||
public SimpleWindowInfo SelectedWindow { get; private set; }
|
||||
|
||||
public Vector2 CanvasCenterPoint { get; set; } = new Vector2(0.5f, 0.5f);
|
||||
|
||||
internal ShapeManager ShapeManager { get; private set; }
|
||||
internal List<DrawableObject> DrawableObjects { get; private set; }
|
||||
|
||||
|
@ -107,7 +107,6 @@ public RegionCaptureForm(RegionCaptureMode mode)
|
|||
Mode = mode;
|
||||
|
||||
ScreenRectangle0Based = CaptureHelpers.GetScreenBounds0Based();
|
||||
oldSize = ScreenRectangle0Based.Size;
|
||||
ImageRectangle = ScreenRectangle0Based;
|
||||
|
||||
InitializeComponent();
|
||||
|
@ -217,6 +216,8 @@ internal void InitBackground(Image img)
|
|||
|
||||
if (IsEditorMode)
|
||||
{
|
||||
ImageRectangle = new Rectangle(ImageRectangle.X, ImageRectangle.Y, Image.Width, Image.Height);
|
||||
|
||||
using (Bitmap background = new Bitmap(Image.Width, Image.Height))
|
||||
using (Graphics g = Graphics.FromImage(background))
|
||||
{
|
||||
|
@ -259,29 +260,6 @@ internal void InitBackground(Image img)
|
|||
}
|
||||
}
|
||||
|
||||
private void CenterCanvas(bool updateCoordinates = true)
|
||||
{
|
||||
if (updateCoordinates)
|
||||
{
|
||||
UpdateCoordinates();
|
||||
}
|
||||
|
||||
Rectangle rect = ScreenRectangle0Based;
|
||||
|
||||
/*if (Image.Width > rect.Width || Image.Height > rect.Height)
|
||||
{
|
||||
rect = ScreenRectangle0Based;
|
||||
}*/
|
||||
|
||||
ImageRectangle = new Rectangle(rect.X + rect.Width / 2 - Image.Width / 2, rect.Y + rect.Height / 2 - Image.Height / 2, Image.Width, Image.Height);
|
||||
|
||||
if (backgroundBrush != null)
|
||||
{
|
||||
backgroundBrush.ResetTransform();
|
||||
backgroundBrush.TranslateTransform(ImageRectangle.X, ImageRectangle.Y);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMoved()
|
||||
{
|
||||
if (ShapeManager != null)
|
||||
|
@ -300,23 +278,49 @@ private void OnMoved()
|
|||
}
|
||||
}
|
||||
|
||||
private void UpdatePan()
|
||||
private void Pan(int deltaX, int deltaY, bool updateCenterPoint = false)
|
||||
{
|
||||
Size NewSize = ScreenRectangle0Based.Size;
|
||||
if (oldSize == NewSize)
|
||||
ImageRectangle = ImageRectangle.LocationOffset(deltaX, deltaY);
|
||||
backgroundBrush.TranslateTransform(deltaX, deltaY);
|
||||
ShapeManager.MoveAll(deltaX, deltaY);
|
||||
|
||||
if (updateCenterPoint)
|
||||
{
|
||||
return;
|
||||
UpdateCenterPoint();
|
||||
}
|
||||
}
|
||||
|
||||
panError += new Vector2((float)(NewSize.Width - oldSize.Width) / 2, (float)(NewSize.Height - oldSize.Height) / 2);
|
||||
Point ResizeDelta = new Point((int)panError.X, (int)panError.Y);
|
||||
private void Pan(Point delta, bool updateCenterPoint = false)
|
||||
{
|
||||
Pan(delta.X, delta.Y, updateCenterPoint);
|
||||
}
|
||||
|
||||
panError.X %= 1;
|
||||
panError.Y %= 1;
|
||||
private void UpdatePan(Vector2 center)
|
||||
{
|
||||
int x = (int)Math.Round(ScreenRectangle0Based.Width * center.X);
|
||||
int y = (int)Math.Round(ScreenRectangle0Based.Height * center.Y);
|
||||
int newX = x - ImageRectangle.Width / 2;
|
||||
int newY = y - ImageRectangle.Height / 2;
|
||||
int deltaX = newX - ImageRectangle.X;
|
||||
int deltaY = newY - ImageRectangle.Y;
|
||||
Pan(deltaX, deltaY);
|
||||
}
|
||||
|
||||
Pan(ResizeDelta);
|
||||
private void UpdatePan()
|
||||
{
|
||||
UpdatePan(CanvasCenterPoint);
|
||||
}
|
||||
|
||||
oldSize = ScreenRectangle0Based.Size;
|
||||
private void UpdateCenterPoint()
|
||||
{
|
||||
CanvasCenterPoint = new Vector2((ImageRectangle.X + ImageRectangle.Width / 2f) / ScreenRectangle0Based.Width,
|
||||
(ImageRectangle.Y + ImageRectangle.Height / 2f) / ScreenRectangle0Based.Height);
|
||||
}
|
||||
|
||||
private void CenterCanvas()
|
||||
{
|
||||
CanvasCenterPoint = new Vector2(0.5f, 0.5f);
|
||||
UpdatePan();
|
||||
}
|
||||
|
||||
public void SetDefaultCursor()
|
||||
|
@ -527,7 +531,7 @@ private new void Update()
|
|||
|
||||
if (ShapeManager.IsPanning)
|
||||
{
|
||||
Pan(InputManager.MouseVelocity);
|
||||
Pan(InputManager.MouseVelocity, true);
|
||||
}
|
||||
|
||||
borderDotPen.DashOffset = (float)timerStart.Elapsed.TotalSeconds * -15;
|
||||
|
@ -535,14 +539,6 @@ 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);
|
||||
|
|
Loading…
Reference in a new issue