mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
fixed #903: Snap resizing support for region capture
This commit is contained in:
parent
251849aeda
commit
460b391910
2 changed files with 76 additions and 0 deletions
|
@ -122,6 +122,7 @@ public bool IsResizing
|
|||
private Point currentPosition;
|
||||
private Point positionOnClick;
|
||||
private bool proportionalResizing;
|
||||
private bool snapResizing;
|
||||
|
||||
public AreaManager(RectangleRegion surface)
|
||||
{
|
||||
|
@ -148,6 +149,9 @@ private void surface_KeyDown(object sender, KeyEventArgs e)
|
|||
case Keys.ShiftKey:
|
||||
proportionalResizing = true;
|
||||
break;
|
||||
case Keys.ControlKey:
|
||||
snapResizing = true;
|
||||
break;
|
||||
case Keys.NumPad1:
|
||||
ChangeCurrentShape(RegionShape.Rectangle);
|
||||
break;
|
||||
|
@ -211,6 +215,9 @@ private void surface_KeyUp(object sender, KeyEventArgs e)
|
|||
case Keys.ShiftKey:
|
||||
proportionalResizing = false;
|
||||
break;
|
||||
case Keys.ControlKey:
|
||||
snapResizing = false;
|
||||
break;
|
||||
case Keys.Delete:
|
||||
RemoveCurrentArea();
|
||||
break;
|
||||
|
@ -238,6 +245,11 @@ public void Update()
|
|||
newPosition = CaptureHelpers.ProportionalPosition(positionOnClick, currentPosition);
|
||||
}
|
||||
|
||||
if (snapResizing)
|
||||
{
|
||||
newPosition = SnapPosition(positionOnClick, newPosition);
|
||||
}
|
||||
|
||||
CurrentArea = CaptureHelpers.CreateRectangle(positionOnClick, newPosition);
|
||||
}
|
||||
|
||||
|
@ -246,6 +258,55 @@ public void Update()
|
|||
ResizeManager.Update();
|
||||
}
|
||||
|
||||
private Point SnapPosition(Point posOnClick, Point posCurrent)
|
||||
{
|
||||
Rectangle currentRect = CaptureHelpers.CreateRectangle(posOnClick, posCurrent);
|
||||
Point newPosition = posCurrent;
|
||||
|
||||
foreach (Size size in surface.Config.SnapSizes)
|
||||
{
|
||||
if (currentRect.Width.IsBetween(size.Width - surface.Config.SnapDistance, size.Width + surface.Config.SnapDistance) ||
|
||||
currentRect.Height.IsBetween(size.Height - surface.Config.SnapDistance, size.Height + surface.Config.SnapDistance))
|
||||
{
|
||||
if (posCurrent.X > posOnClick.X)
|
||||
{
|
||||
if (posCurrent.Y > posOnClick.Y)
|
||||
{
|
||||
newPosition = new Point(posOnClick.X + size.Width - 1, posOnClick.Y + size.Height - 1);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
newPosition = new Point(posOnClick.X + size.Width - 1, posOnClick.Y - size.Height + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (posCurrent.Y > posOnClick.Y)
|
||||
{
|
||||
newPosition = new Point(posOnClick.X - size.Width + 1, posOnClick.Y + size.Height - 1);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
newPosition = new Point(posOnClick.X - size.Width + 1, posOnClick.Y - size.Height + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle newRect = CaptureHelpers.CreateRectangle(posOnClick, newPosition);
|
||||
|
||||
if (surface.ScreenRectangle0Based.Contains(newRect))
|
||||
{
|
||||
return newPosition;
|
||||
}
|
||||
|
||||
return posCurrent;
|
||||
}
|
||||
|
||||
private void CheckHover()
|
||||
{
|
||||
CurrentHoverArea = Rectangle.Empty;
|
||||
|
|
|
@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
|
|||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Drawing;
|
||||
|
@ -91,12 +92,26 @@ public class SurfaceOptions
|
|||
[DefaultValue(typeof(Size), "250, 250"), Description("Fixed shape size.")]
|
||||
public Size FixedSize { get; set; }
|
||||
|
||||
[DefaultValue(10), Description("How much region size must be close to snap size for it to snap.")]
|
||||
public int SnapDistance { get; set; }
|
||||
|
||||
[Description("When you hold snap modifier key it will check these sizes and if your region size close to them then it will snap to this size.")]
|
||||
public List<Size> SnapSizes { get; set; }
|
||||
|
||||
[DefaultValue(RegionShape.Rectangle), Description("Current region shape.")]
|
||||
public RegionShape CurrentRegionShape { get; set; }
|
||||
|
||||
public SurfaceOptions()
|
||||
{
|
||||
this.ApplyDefaultPropertyValues();
|
||||
|
||||
SnapSizes = new List<Size>()
|
||||
{
|
||||
new Size(800, 600),
|
||||
new Size(1280, 720),
|
||||
new Size(1024, 768),
|
||||
new Size(1920, 1080)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue