When holding snap size modifier key region capture will mark all snap sizes on screen

This commit is contained in:
Jaex 2015-08-22 16:13:38 +03:00
parent 9d9396c2f0
commit d4196b10e9
5 changed files with 71 additions and 43 deletions

View file

@ -282,6 +282,38 @@ public static Point ProportionalPosition(Point pos, Point pos2)
return newPosition;
}
public static Point CalculateNewPosition(Point posOnClick, Point posCurrent, Size size)
{
if (posCurrent.X > posOnClick.X)
{
if (posCurrent.Y > posOnClick.Y)
{
return new Point(posOnClick.X + size.Width - 1, posOnClick.Y + size.Height - 1);
}
else
{
return new Point(posOnClick.X + size.Width - 1, posOnClick.Y - size.Height + 1);
}
}
else
{
if (posCurrent.Y > posOnClick.Y)
{
return new Point(posOnClick.X - size.Width + 1, posOnClick.Y + size.Height - 1);
}
else
{
return new Point(posOnClick.X - size.Width + 1, posOnClick.Y - size.Height + 1);
}
}
}
public static Rectangle CalculateNewRectangle(Point posOnClick, Point posCurrent, Size size)
{
Point newPosition = CalculateNewPosition(posOnClick, posCurrent, size);
return CreateRectangle(posOnClick, newPosition);
}
public static Rectangle GetWindowRectangle(IntPtr handle)
{
Rectangle rect = Rectangle.Empty;

View file

@ -190,6 +190,15 @@ protected override void Update()
protected override void Draw(Graphics g)
{
if (AreaManager.IsCreating && AreaManager.IsSnapResizing)
{
foreach (Size size in Config.SnapSizes)
{
Rectangle snapRect = CaptureHelpers.CalculateNewRectangle(AreaManager.PositionOnClick, AreaManager.CurrentPosition, size);
g.DrawRectangleProper(markerPen, snapRect);
}
}
RegionInfo[] areas = AreaManager.ValidAreas;
if (areas.Length > 0 || !AreaManager.CurrentHoverArea.IsEmpty)
@ -385,6 +394,7 @@ protected virtual void WriteTips(StringBuilder sb)
if (AreaManager.IsCreating)
{
sb.AppendLine(Resources.RectangleRegion_WriteTips__Hold_Shift__Proportional_resizing);
sb.AppendLine("[Hold Alt] Snap resizing to preset sizes");
}
if (AreaManager.IsCurrentAreaValid)

View file

@ -51,7 +51,7 @@ public class Surface : Form
protected TextureBrush darkBackgroundBrush, lightBackgroundBrush;
protected GraphicsPath regionFillPath, regionDrawPath;
protected Pen borderPen, borderDotPen, textBackgroundPenWhite, textBackgroundPenBlack;
protected Pen borderPen, borderDotPen, textBackgroundPenWhite, textBackgroundPenBlack, markerPen;
protected Brush nodeBackgroundBrush, textBackgroundBrush;
protected Font textFont, infoFont;
protected Stopwatch timerStart, timerFPS;
@ -86,6 +86,7 @@ public Surface()
textBackgroundBrush = new SolidBrush(Color.FromArgb(75, Color.Black));
textBackgroundPenWhite = new Pen(Color.FromArgb(50, Color.White));
textBackgroundPenBlack = new Pen(Color.FromArgb(150, Color.Black));
markerPen = new Pen(Color.FromArgb(200, Color.Red)) { DashStyle = DashStyle.Dash };
}
private void InitializeComponent()
@ -411,6 +412,7 @@ protected override void Dispose(bool disposing)
if (textBackgroundBrush != null) textBackgroundBrush.Dispose();
if (textBackgroundPenWhite != null) textBackgroundPenWhite.Dispose();
if (textBackgroundPenBlack != null) textBackgroundPenBlack.Dispose();
if (markerPen != null) markerPen.Dispose();
if (regionFillPath != null)
{

View file

@ -101,6 +101,9 @@ public bool IsCurrentHoverAreaValid
public int RoundedRectangleRadiusIncrement { get; set; }
public TriangleAngle TriangleAngle { get; set; }
public Point CurrentPosition { get; private set; }
public Point PositionOnClick { get; private set; }
public ResizeManager ResizeManager { get; private set; }
public bool IsCreating { get; private set; }
public bool IsMoving { get; private set; }
@ -113,16 +116,15 @@ public bool IsResizing
}
}
public bool IsProportionalResizing { get; private set; }
public bool IsSnapResizing { get; private set; }
public List<Rectangle> Windows { get; set; }
public bool WindowCaptureMode { get; set; }
public bool IncludeControls { get; set; }
public int MinimumSize { get; set; }
private RectangleRegion surface;
private Point currentPosition;
private Point positionOnClick;
private bool proportionalResizing;
private bool snapResizing;
public AreaManager(RectangleRegion surface)
{
@ -165,10 +167,10 @@ private void surface_KeyDown(object sender, KeyEventArgs e)
}
break;
case Keys.ShiftKey:
proportionalResizing = true;
IsProportionalResizing = true;
break;
case Keys.Menu:
snapResizing = true;
IsSnapResizing = true;
break;
case Keys.NumPad1:
ChangeCurrentShape(RegionShape.Rectangle);
@ -231,10 +233,10 @@ private void surface_KeyUp(object sender, KeyEventArgs e)
switch (e.KeyCode)
{
case Keys.ShiftKey:
proportionalResizing = false;
IsProportionalResizing = false;
break;
case Keys.Menu:
snapResizing = false;
IsSnapResizing = false;
break;
case Keys.Delete:
RemoveCurrentArea();
@ -258,21 +260,21 @@ public void Update()
if (IsCreating && !CurrentArea.IsEmpty)
{
currentPosition = InputManager.MousePosition0Based;
CurrentPosition = InputManager.MousePosition0Based;
Point newPosition = currentPosition;
Point newPosition = CurrentPosition;
if (proportionalResizing)
if (IsProportionalResizing)
{
newPosition = CaptureHelpers.ProportionalPosition(positionOnClick, currentPosition);
newPosition = CaptureHelpers.ProportionalPosition(PositionOnClick, CurrentPosition);
}
if (snapResizing)
if (IsSnapResizing)
{
newPosition = SnapPosition(positionOnClick, newPosition);
newPosition = SnapPosition(PositionOnClick, newPosition);
}
CurrentArea = CaptureHelpers.CreateRectangle(positionOnClick, newPosition);
CurrentArea = CaptureHelpers.CreateRectangle(PositionOnClick, newPosition);
}
CheckHover();
@ -290,32 +292,8 @@ private Point SnapPosition(Point posOnClick, Point posCurrent)
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;
}
}
newPosition = CaptureHelpers.CalculateNewPosition(posOnClick, posCurrent, size);
break;
}
}
@ -385,7 +363,7 @@ private void RegionSelection(Point location)
}
int areaIndex = AreaIntersect(InputManager.MousePosition0Based);
positionOnClick = InputManager.MousePosition0Based;
PositionOnClick = InputManager.MousePosition0Based;
if (areaIndex > -1) // Select area
{

View file

@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
@ -76,6 +77,11 @@ public SnapSize(int width, int height)
Height = height;
}
public static implicit operator Size(SnapSize size)
{
return new Size(size.Width, size.Height);
}
public override string ToString()
{
return $"{Width}x{Height}";