mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
Improvements to set shape rectangle automatically
This commit is contained in:
parent
67643f5b0f
commit
2b317a2167
3 changed files with 76 additions and 43 deletions
|
@ -38,7 +38,7 @@ public class AreaManager
|
|||
|
||||
public BaseShape CurrentShape { get; private set; }
|
||||
|
||||
public ShapeType CurrentShapeType { get; set; } = ShapeType.RegionRectangle;
|
||||
public ShapeType CurrentShapeType { get; private set; } = ShapeType.RegionRectangle;
|
||||
|
||||
public Rectangle CurrentRectangle
|
||||
{
|
||||
|
@ -51,13 +51,6 @@ public Rectangle CurrentRectangle
|
|||
|
||||
return Rectangle.Empty;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (CurrentShape != null)
|
||||
{
|
||||
CurrentShape.Rectangle = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BaseShape[] Regions
|
||||
|
@ -110,9 +103,6 @@ public bool IsCurrentShapeTypeRegion
|
|||
}
|
||||
}
|
||||
|
||||
public float RoundedRectangleRadius { get; set; } = 15;
|
||||
public int RoundedRectangleRadiusIncrement { get; set; } = 3;
|
||||
|
||||
public Point CurrentPosition { get; private set; }
|
||||
public Point PositionOnClick { get; private set; }
|
||||
|
||||
|
@ -136,6 +126,9 @@ public bool IsResizing
|
|||
public bool IncludeControls { get; set; }
|
||||
public int MinimumSize { get; set; } = 3;
|
||||
|
||||
public float RoundedRectangleRadius { get; set; } = 15;
|
||||
public int RoundedRectangleRadiusIncrement { get; set; } = 3;
|
||||
|
||||
private RectangleRegionForm surface;
|
||||
private SurfaceOptions config;
|
||||
private ContextMenuStrip cmsContextMenu;
|
||||
|
@ -456,13 +449,15 @@ private void surface_KeyUp(object sender, KeyEventArgs e)
|
|||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (CurrentShape != null)
|
||||
{
|
||||
if (IsMoving)
|
||||
{
|
||||
Rectangle rect = CurrentRectangle;
|
||||
rect.X += InputManager.MouseVelocity.X;
|
||||
rect.Y += InputManager.MouseVelocity.Y;
|
||||
CurrentRectangle = rect;
|
||||
CurrentShape.Rectangle = rect;
|
||||
}
|
||||
|
||||
if (IsCreating && !CurrentRectangle.IsEmpty)
|
||||
|
@ -481,10 +476,7 @@ public void Update()
|
|||
newPosition = SnapPosition(PositionOnClick, newPosition);
|
||||
}
|
||||
|
||||
if (CurrentShape != null)
|
||||
{
|
||||
CurrentShape.EndPosition = newPosition;
|
||||
CurrentShape.Rectangle = CaptureHelpers.CreateRectangle(PositionOnClick, newPosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -177,11 +177,13 @@ public void Update()
|
|||
if (nodes[(int)NodePosition.TopLeft].IsDragging)
|
||||
{
|
||||
IsResizing = true;
|
||||
|
||||
shape.StartPosition = new Point(InputManager.MousePosition0Based.X, InputManager.MousePosition0Based.Y);
|
||||
}
|
||||
else if (nodes[(int)NodePosition.BottomRight].IsDragging)
|
||||
{
|
||||
IsResizing = true;
|
||||
|
||||
shape.EndPosition = new Point(InputManager.MousePosition0Based.X, InputManager.MousePosition0Based.Y);
|
||||
}
|
||||
}
|
||||
|
@ -312,20 +314,29 @@ private void UpdateNodePositions()
|
|||
|
||||
public void MoveCurrentArea(int x, int y)
|
||||
{
|
||||
areaManager.CurrentRectangle = new Rectangle(new Point(areaManager.CurrentRectangle.X + x, areaManager.CurrentRectangle.Y + y), areaManager.CurrentRectangle.Size);
|
||||
BaseShape shape = areaManager.CurrentShape;
|
||||
|
||||
if (shape != null)
|
||||
{
|
||||
shape.StartPosition = shape.StartPosition.Add(x, y);
|
||||
shape.EndPosition = shape.EndPosition.Add(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResizeCurrentArea(int x, int y, bool isBottomRightMoving)
|
||||
{
|
||||
BaseShape shape = areaManager.CurrentShape;
|
||||
|
||||
if (shape != null)
|
||||
{
|
||||
if (isBottomRightMoving)
|
||||
{
|
||||
areaManager.CurrentRectangle = new Rectangle(areaManager.CurrentRectangle.X, areaManager.CurrentRectangle.Y,
|
||||
areaManager.CurrentRectangle.Width + x, areaManager.CurrentRectangle.Height + y);
|
||||
shape.Rectangle = shape.Rectangle.SizeOffset(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
areaManager.CurrentRectangle = new Rectangle(areaManager.CurrentRectangle.X + x, areaManager.CurrentRectangle.Y + y,
|
||||
areaManager.CurrentRectangle.Width - x, areaManager.CurrentRectangle.Height - y);
|
||||
shape.Rectangle = shape.Rectangle.LocationOffset(x, y).SizeOffset(-x, -y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,38 @@ public abstract class BaseShape
|
|||
public virtual NodeType NodeType { get; } = NodeType.Rectangle;
|
||||
|
||||
public Rectangle Rectangle { get; set; }
|
||||
public Point StartPosition { get; set; }
|
||||
public Point EndPosition { get; set; }
|
||||
|
||||
private Point startPosition;
|
||||
|
||||
public Point StartPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return startPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
startPosition = value;
|
||||
|
||||
Rectangle = CaptureHelpers.CreateRectangle(StartPosition, EndPosition);
|
||||
}
|
||||
}
|
||||
|
||||
private Point endPosition;
|
||||
|
||||
public Point EndPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return endPosition;
|
||||
}
|
||||
set
|
||||
{
|
||||
endPosition = value;
|
||||
|
||||
Rectangle = CaptureHelpers.CreateRectangle(StartPosition, EndPosition);
|
||||
}
|
||||
}
|
||||
|
||||
public BaseShape()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue