Added OnCreating function to BaseShape

This commit is contained in:
Jaex 2016-08-23 16:03:48 +03:00
parent 6507364db5
commit 8469f3065d
3 changed files with 28 additions and 23 deletions

View file

@ -39,8 +39,6 @@ public abstract class BaseShape : IDisposable
public Rectangle Rectangle { get; set; }
protected AnnotationOptions AnnotationOptions => Manager.Config.AnnotationOptions;
private Point startPosition;
public Point StartPosition
@ -79,10 +77,12 @@ public Point EndPosition
public virtual bool ShowResizeNodes { get; } = true;
public virtual bool FixedSize { get; } = false;
internal ShapeManager Manager { get; set; }
protected RegionCaptureOptions Options => Manager.Config;
protected AnnotationOptions AnnotationOptions => Manager.Config.AnnotationOptions;
private Point tempNodePos, tempStartPos, tempEndPos;
public virtual bool Intersects(Point position)
@ -124,6 +124,22 @@ public virtual void Resize(int x, int y, bool fromBottomRight)
}
}
public virtual void OnCreating()
{
Point pos = InputManager.MousePosition0Based;
if (Options.IsFixedSize && IsRegionShape)
{
Manager.IsMoving = true;
Rectangle = new Rectangle(new Point(pos.X - Options.FixedSize.Width / 2, pos.Y - Options.FixedSize.Height / 2), Options.FixedSize);
}
else
{
Manager.IsCreating = true;
StartPosition = EndPosition = pos;
}
}
public virtual void OnCreated()
{
}

View file

@ -36,7 +36,6 @@ public class StepDrawingShape : BaseDrawingShape
public override ShapeType ShapeType { get; } = ShapeType.DrawingStep;
public override bool ShowResizeNodes { get; } = false;
public override bool FixedSize { get; } = true;
public int Number { get; set; }
@ -45,6 +44,13 @@ public StepDrawingShape()
Rectangle = new Rectangle(0, 0, DefaultSize, DefaultSize);
}
public override void OnCreating()
{
Manager.IsMoving = true;
Point pos = InputManager.MousePosition0Based;
Rectangle = new Rectangle(new Point(pos.X - Rectangle.Width / 2, pos.Y - Rectangle.Height / 2), Rectangle.Size);
}
public override void OnConfigLoad()
{
BorderColor = AnnotationOptions.StepBorderColor;

View file

@ -1190,24 +1190,7 @@ private void StartRegionSelection()
DeselectCurrentShape();
shape = AddShape();
Point pos = InputManager.MousePosition0Based;
if (shape.FixedSize)
{
IsMoving = true;
shape.Rectangle = new Rectangle(new Point(pos.X - shape.Rectangle.Width / 2, pos.Y - shape.Rectangle.Height / 2), shape.Rectangle.Size);
}
else if (Config.IsFixedSize && IsCurrentShapeTypeRegion)
{
IsMoving = true;
shape.Rectangle = new Rectangle(new Point(pos.X - Config.FixedSize.Width / 2, pos.Y - Config.FixedSize.Height / 2), Config.FixedSize);
}
else
{
IsCreating = true;
shape.StartPosition = shape.EndPosition = pos;
}
shape.OnCreating();
}
}