Holding Ctrl will ignore shape intersection that way user can draw rectangle inside rectangle without select it

This commit is contained in:
Jaex 2018-04-09 12:10:19 +03:00
parent c0ef96641e
commit e2ebf2afc3
3 changed files with 29 additions and 9 deletions

View file

@ -35,7 +35,7 @@ public override void OnCreating()
Point pos = InputManager.ClientMousePosition;
Rectangle = new Rectangle(pos.X, pos.Y, 1, 1);
if (Manager.IsCornerMoving && LoadImageFile(AnnotationOptions.LastImageFilePath, true))
if (Manager.IsCtrlModifier && LoadImageFile(AnnotationOptions.LastImageFilePath, true))
{
OnCreated();
Manager.IsMoving = true;

View file

@ -51,7 +51,7 @@ public override void OnCreating()
Point pos = InputManager.ClientMousePosition;
Rectangle = new Rectangle(pos.X, pos.Y, 1, 1);
if (Manager.IsCornerMoving && LoadSticker(AnnotationOptions.LastStickerPath, AnnotationOptions.StickerSize))
if (Manager.IsCtrlModifier && LoadSticker(AnnotationOptions.LastStickerPath, AnnotationOptions.StickerSize))
{
OnCreated();
Manager.IsMoving = true;

View file

@ -158,6 +158,7 @@ private set
public bool IsPanning { get; set; }
public bool IsResizing { get; set; }
// Is holding Ctrl?
public bool IsCtrlModifier { get; private set; }
public bool IsCornerMoving { get; private set; }
// Is holding Shift?
public bool IsProportionalResizing { get; private set; }
@ -282,7 +283,7 @@ private void form_Shown(object sender, EventArgs e)
private void form_LostFocus(object sender, EventArgs e)
{
IsCornerMoving = IsProportionalResizing = IsSnapResizing = false;
ResetModifiers();
}
private void form_MouseDown(object sender, MouseEventArgs e)
@ -410,7 +411,17 @@ private void form_KeyDown(object sender, KeyEventArgs e)
switch (e.KeyCode)
{
case Keys.ControlKey:
IsCornerMoving = true;
if (!IsCtrlModifier && !IsCornerMoving)
{
if (IsCreating || IsResizing)
{
IsCornerMoving = true;
}
else
{
IsCtrlModifier = true;
}
}
break;
case Keys.ShiftKey:
IsProportionalResizing = true;
@ -638,6 +649,7 @@ private void form_KeyUp(object sender, KeyEventArgs e)
switch (e.KeyCode)
{
case Keys.ControlKey:
IsCtrlModifier = false;
IsCornerMoving = false;
break;
case Keys.ShiftKey:
@ -1262,6 +1274,11 @@ private void DeleteAllShapes()
DeselectCurrentShape();
}
private void ResetModifiers()
{
IsCtrlModifier = IsCornerMoving = IsProportionalResizing = IsSnapResizing = false;
}
private void ClearTools()
{
foreach (BaseTool tool in ToolShapes)
@ -1278,13 +1295,16 @@ public BaseShape GetIntersectShape()
public BaseShape GetIntersectShape(Point position)
{
for (int i = Shapes.Count - 1; i >= 0; i--)
if (!IsCtrlModifier)
{
BaseShape shape = Shapes[i];
if (shape.ShapeType == CurrentTool && shape.Intersects(position))
for (int i = Shapes.Count - 1; i >= 0; i--)
{
return shape;
BaseShape shape = Shapes[i];
if (shape.ShapeType == CurrentTool && shape.Intersects(position))
{
return shape;
}
}
}