mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 09:47:22 +13:00
BaseShape refactor, shape update logic moved to BaseShape
This commit is contained in:
parent
5c80ba8b94
commit
c0ab0507f3
13 changed files with 84 additions and 84 deletions
|
@ -94,39 +94,70 @@ public virtual bool Intersects(Point position)
|
|||
return Rectangle.Contains(position);
|
||||
}
|
||||
|
||||
public virtual void AddShapePath(GraphicsPath gp, Rectangle rect)
|
||||
public void AddShapePath(GraphicsPath gp, int sizeOffset = 0)
|
||||
{
|
||||
gp.AddRectangle(rect);
|
||||
Rectangle rect = Rectangle;
|
||||
|
||||
if (sizeOffset != 0)
|
||||
{
|
||||
rect = rect.SizeOffset(sizeOffset);
|
||||
}
|
||||
|
||||
OnShapePathRequested(gp, rect);
|
||||
}
|
||||
|
||||
public void AddShapePath(GraphicsPath gp)
|
||||
{
|
||||
AddShapePath(gp, Rectangle);
|
||||
}
|
||||
|
||||
public void AddShapePath(GraphicsPath gp, int sizeOffset)
|
||||
{
|
||||
Rectangle rect = Rectangle.SizeOffset(sizeOffset);
|
||||
AddShapePath(gp, rect);
|
||||
}
|
||||
|
||||
public virtual void UpdateShapeConfig()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void ApplyShapeConfig()
|
||||
public virtual void OnCreated()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnUpdate()
|
||||
{
|
||||
if (Manager.IsMoving)
|
||||
{
|
||||
Manager.ResizeManager.MoveCurrentArea(InputManager.MouseVelocity.X, InputManager.MouseVelocity.Y);
|
||||
}
|
||||
else if (Manager.IsCreating && !Rectangle.IsEmpty)
|
||||
{
|
||||
Point currentPosition = InputManager.MousePosition0Based;
|
||||
|
||||
if (Manager.IsCornerMoving)
|
||||
{
|
||||
StartPosition = StartPosition.Add(InputManager.MouseVelocity.X, InputManager.MouseVelocity.Y);
|
||||
}
|
||||
else if (Manager.IsProportionalResizing)
|
||||
{
|
||||
if (NodeType == NodeType.Rectangle)
|
||||
{
|
||||
currentPosition = CaptureHelpers.SnapPositionToDegree(StartPosition, currentPosition, 90, 45);
|
||||
}
|
||||
else if (NodeType == NodeType.Line)
|
||||
{
|
||||
currentPosition = CaptureHelpers.SnapPositionToDegree(StartPosition, currentPosition, 45, 0);
|
||||
}
|
||||
}
|
||||
else if (Manager.IsSnapResizing)
|
||||
{
|
||||
currentPosition = Manager.SnapPosition(StartPosition, currentPosition);
|
||||
}
|
||||
|
||||
EndPosition = currentPosition;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnShapeCreated()
|
||||
public virtual void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
|
||||
{
|
||||
gp.AddRectangle(rect);
|
||||
}
|
||||
|
||||
public virtual void OnConfigLoad()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnShapeDoubleClicked()
|
||||
public virtual void OnConfigSave()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnDoubleClicked()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,14 +33,14 @@ public abstract class BaseDrawingShape : BaseShape
|
|||
public int BorderSize { get; set; }
|
||||
public Color FillColor { get; set; }
|
||||
|
||||
public override void UpdateShapeConfig()
|
||||
public override void OnConfigLoad()
|
||||
{
|
||||
BorderColor = AnnotationOptions.BorderColor;
|
||||
BorderSize = AnnotationOptions.BorderSize;
|
||||
FillColor = AnnotationOptions.FillColor;
|
||||
}
|
||||
|
||||
public override void ApplyShapeConfig()
|
||||
public override void OnConfigSave()
|
||||
{
|
||||
AnnotationOptions.BorderColor = BorderColor;
|
||||
AnnotationOptions.BorderSize = BorderSize;
|
||||
|
|
|
@ -55,7 +55,7 @@ public override void OnDraw(Graphics g)
|
|||
g.SmoothingMode = SmoothingMode.None;
|
||||
}
|
||||
|
||||
public override void AddShapePath(GraphicsPath gp, Rectangle rect)
|
||||
public override void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
|
||||
{
|
||||
gp.AddEllipse(rect);
|
||||
}
|
||||
|
|
|
@ -35,15 +35,15 @@ public class RoundedRectangleDrawingShape : BaseDrawingShape
|
|||
|
||||
public float Radius { get; set; }
|
||||
|
||||
public override void UpdateShapeConfig()
|
||||
public override void OnConfigLoad()
|
||||
{
|
||||
base.UpdateShapeConfig();
|
||||
base.OnConfigLoad();
|
||||
Radius = AnnotationOptions.RoundedRectangleRadius;
|
||||
}
|
||||
|
||||
public override void ApplyShapeConfig()
|
||||
public override void OnConfigSave()
|
||||
{
|
||||
base.ApplyShapeConfig();
|
||||
base.OnConfigSave();
|
||||
AnnotationOptions.RoundedRectangleRadius = (int)Radius;
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ public override void OnDraw(Graphics g)
|
|||
}
|
||||
}
|
||||
|
||||
public override void AddShapePath(GraphicsPath gp, Rectangle rect)
|
||||
public override void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
|
||||
{
|
||||
gp.AddRoundedRectangle(rect, Radius);
|
||||
}
|
||||
|
|
|
@ -44,14 +44,14 @@ public StepDrawingShape()
|
|||
Rectangle = new Rectangle(0, 0, DefaultSize, DefaultSize);
|
||||
}
|
||||
|
||||
public override void UpdateShapeConfig()
|
||||
public override void OnConfigLoad()
|
||||
{
|
||||
BorderColor = AnnotationOptions.StepBorderColor;
|
||||
BorderSize = AnnotationOptions.StepBorderSize;
|
||||
FillColor = AnnotationOptions.StepFillColor;
|
||||
}
|
||||
|
||||
public override void ApplyShapeConfig()
|
||||
public override void OnConfigSave()
|
||||
{
|
||||
AnnotationOptions.StepBorderColor = BorderColor;
|
||||
AnnotationOptions.StepBorderSize = BorderSize;
|
||||
|
@ -113,7 +113,7 @@ public override void OnDraw(Graphics g)
|
|||
}
|
||||
}
|
||||
|
||||
public override void AddShapePath(GraphicsPath gp, Rectangle rect)
|
||||
public override void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
|
||||
{
|
||||
gp.AddEllipse(rect);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public class TextDrawingShape : RectangleDrawingShape
|
|||
public string Text { get; set; }
|
||||
public TextDrawingOptions Options { get; set; }
|
||||
|
||||
public override void UpdateShapeConfig()
|
||||
public override void OnConfigLoad()
|
||||
{
|
||||
Options = AnnotationOptions.TextOptions.Copy();
|
||||
BorderColor = AnnotationOptions.TextBorderColor;
|
||||
|
@ -44,7 +44,7 @@ public override void UpdateShapeConfig()
|
|||
FillColor = AnnotationOptions.TextFillColor;
|
||||
}
|
||||
|
||||
public override void ApplyShapeConfig()
|
||||
public override void OnConfigSave()
|
||||
{
|
||||
AnnotationOptions.TextOptions = Options;
|
||||
AnnotationOptions.TextBorderColor = BorderColor;
|
||||
|
@ -69,12 +69,12 @@ public override void OnDraw(Graphics g)
|
|||
}
|
||||
}
|
||||
|
||||
public override void OnShapeCreated()
|
||||
public override void OnCreated()
|
||||
{
|
||||
UpdateText();
|
||||
}
|
||||
|
||||
public override void OnShapeDoubleClicked()
|
||||
public override void OnDoubleClicked()
|
||||
{
|
||||
UpdateText();
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ private void UpdateText()
|
|||
{
|
||||
inputBox.ShowDialog();
|
||||
Text = inputBox.InputText;
|
||||
ApplyShapeConfig();
|
||||
OnConfigSave();
|
||||
}
|
||||
|
||||
Manager.ResumeForm();
|
||||
|
|
|
@ -34,12 +34,12 @@ public class BlurEffectShape : BaseEffectShape
|
|||
|
||||
public int BlurRadius { get; set; }
|
||||
|
||||
public override void UpdateShapeConfig()
|
||||
public override void OnConfigLoad()
|
||||
{
|
||||
BlurRadius = AnnotationOptions.BlurRadius;
|
||||
}
|
||||
|
||||
public override void ApplyShapeConfig()
|
||||
public override void OnConfigSave()
|
||||
{
|
||||
AnnotationOptions.BlurRadius = BlurRadius;
|
||||
}
|
||||
|
|
|
@ -34,12 +34,12 @@ public class HighlightEffectShape : BaseEffectShape
|
|||
|
||||
public Color HighlightColor { get; set; }
|
||||
|
||||
public override void UpdateShapeConfig()
|
||||
public override void OnConfigLoad()
|
||||
{
|
||||
HighlightColor = AnnotationOptions.HighlightColor;
|
||||
}
|
||||
|
||||
public override void ApplyShapeConfig()
|
||||
public override void OnConfigSave()
|
||||
{
|
||||
AnnotationOptions.HighlightColor = HighlightColor;
|
||||
}
|
||||
|
|
|
@ -34,12 +34,12 @@ public class PixelateEffectShape : BaseEffectShape
|
|||
|
||||
public int PixelSize { get; set; }
|
||||
|
||||
public override void UpdateShapeConfig()
|
||||
public override void OnConfigLoad()
|
||||
{
|
||||
PixelSize = AnnotationOptions.PixelateSize;
|
||||
}
|
||||
|
||||
public override void ApplyShapeConfig()
|
||||
public override void OnConfigSave()
|
||||
{
|
||||
AnnotationOptions.PixelateSize = PixelSize;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class EllipseRegionShape : BaseRegionShape
|
|||
{
|
||||
public override ShapeType ShapeType { get; } = ShapeType.RegionEllipse;
|
||||
|
||||
public override void AddShapePath(GraphicsPath gp, Rectangle rect)
|
||||
public override void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
|
||||
{
|
||||
gp.AddEllipse(rect);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public override void OnUpdate()
|
|||
}
|
||||
}
|
||||
|
||||
public override void AddShapePath(GraphicsPath gp, Rectangle rect)
|
||||
public override void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
|
||||
{
|
||||
int len = points.Count;
|
||||
|
||||
|
|
|
@ -35,17 +35,17 @@ public class RoundedRectangleRegionShape : BaseRegionShape
|
|||
|
||||
public float Radius { get; set; }
|
||||
|
||||
public override void UpdateShapeConfig()
|
||||
public override void OnConfigLoad()
|
||||
{
|
||||
Radius = AnnotationOptions.RoundedRectangleRadius;
|
||||
}
|
||||
|
||||
public override void ApplyShapeConfig()
|
||||
public override void OnConfigSave()
|
||||
{
|
||||
AnnotationOptions.RoundedRectangleRadius = (int)Radius;
|
||||
}
|
||||
|
||||
public override void AddShapePath(GraphicsPath gp, Rectangle rect)
|
||||
public override void OnShapePathRequested(GraphicsPath gp, Rectangle rect)
|
||||
{
|
||||
gp.AddRoundedRectangle(rect, Radius);
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ private set
|
|||
|
||||
if (currentShape != null)
|
||||
{
|
||||
currentShape.ApplyShapeConfig();
|
||||
currentShape.OnConfigSave();
|
||||
}
|
||||
|
||||
OnCurrentShapeChanged(currentShape);
|
||||
|
@ -871,7 +871,7 @@ private void form_MouseDoubleClick(object sender, MouseEventArgs e)
|
|||
}
|
||||
else if (CurrentShape != null && !IsCreating)
|
||||
{
|
||||
CurrentShape.OnShapeDoubleClicked();
|
||||
CurrentShape.OnDoubleClicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1045,37 +1045,6 @@ public void Update()
|
|||
if (shape != null)
|
||||
{
|
||||
shape.OnUpdate();
|
||||
|
||||
if (IsMoving)
|
||||
{
|
||||
ResizeManager.MoveCurrentArea(InputManager.MouseVelocity.X, InputManager.MouseVelocity.Y);
|
||||
}
|
||||
else if (IsCreating && !CurrentRectangle.IsEmpty)
|
||||
{
|
||||
Point currentPosition = InputManager.MousePosition0Based;
|
||||
|
||||
if (IsCornerMoving)
|
||||
{
|
||||
shape.StartPosition = shape.StartPosition.Add(InputManager.MouseVelocity.X, InputManager.MouseVelocity.Y);
|
||||
}
|
||||
else if (IsProportionalResizing)
|
||||
{
|
||||
if (shape.NodeType == NodeType.Rectangle)
|
||||
{
|
||||
currentPosition = CaptureHelpers.SnapPositionToDegree(shape.StartPosition, currentPosition, 90, 45);
|
||||
}
|
||||
else if (shape.NodeType == NodeType.Line)
|
||||
{
|
||||
currentPosition = CaptureHelpers.SnapPositionToDegree(shape.StartPosition, currentPosition, 45, 0);
|
||||
}
|
||||
}
|
||||
else if (IsSnapResizing)
|
||||
{
|
||||
currentPosition = SnapPosition(shape.StartPosition, currentPosition);
|
||||
}
|
||||
|
||||
shape.EndPosition = currentPosition;
|
||||
}
|
||||
}
|
||||
|
||||
CheckHover();
|
||||
|
@ -1161,7 +1130,7 @@ private void EndRegionSelection()
|
|||
{
|
||||
if (wasCreating)
|
||||
{
|
||||
shape.OnShapeCreated();
|
||||
shape.OnCreated();
|
||||
}
|
||||
|
||||
SelectShape();
|
||||
|
@ -1255,7 +1224,7 @@ public BaseShape CreateShape(ShapeType shapeType)
|
|||
|
||||
shape.Manager = this;
|
||||
|
||||
shape.UpdateShapeConfig();
|
||||
shape.OnConfigLoad();
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
@ -1266,7 +1235,7 @@ private void UpdateCurrentShape()
|
|||
|
||||
if (shape != null)
|
||||
{
|
||||
shape.UpdateShapeConfig();
|
||||
shape.OnConfigLoad();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1294,7 +1263,7 @@ private void OpenOptionsMenu()
|
|||
}
|
||||
}
|
||||
|
||||
private Point SnapPosition(Point posOnClick, Point posCurrent)
|
||||
public Point SnapPosition(Point posOnClick, Point posCurrent)
|
||||
{
|
||||
Size currentSize = CaptureHelpers.CreateRectangle(posOnClick, posCurrent).Size;
|
||||
Vector2 vector = new Vector2(currentSize.Width, currentSize.Height);
|
||||
|
|
Loading…
Reference in a new issue