public abstract void MouseEvent(MouseEventData eventData);
public override void MouseEvent(MouseEventData eventData) { if (_currentSelectionMode != SelectionMode.Arbitrary2Nx2M) { if ((eventData.Event == MouseEventData.EventType.Down || eventData.Event == MouseEventData.EventType.Move) && eventData.Args.Button == MouseButtons.Left) { if (_currentSelection == _newSelection) { var imagePos = _renderer.GetImageCoordinate(new Vector2(eventData.Args.X, eventData.Args.Y)); _currentSelection.MoveTo(imagePos); _drawable.SelectionUpdate(); } } } else { var nw = new Vector2(_currentSelection.X0, _currentSelection.Y0); var sw = new Vector2(_currentSelection.X0, _currentSelection.Y1); var se = new Vector2(_currentSelection.X1, _currentSelection.Y1); var ne = new Vector2(_currentSelection.X1, _currentSelection.Y0); var cur = new Vector2(eventData.Args.X, eventData.Args.Y); cur = _renderer.GetImageCoordinate(cur); var editRadius = 5f; var action = SelectionEditAction.None; if (cur.InRadius(se, editRadius)) { action = SelectionEditAction.ResizeSE; } else if (cur.InRadius(ne, editRadius)) { action = SelectionEditAction.ResizeNE; } else if (cur.InRadius(nw, editRadius)) { action = SelectionEditAction.ResizeNW; } else if (cur.InRadius(sw, editRadius)) { action = SelectionEditAction.ResizeSW; } else if (cur.DistanceToSegment(nw, ne).Abs() < editRadius) { action = SelectionEditAction.ResizeN; } else if (cur.DistanceToSegment(ne, se).Abs() < editRadius) { action = SelectionEditAction.ResizeE; } else if (cur.DistanceToSegment(se, sw).Abs() < editRadius) { action = SelectionEditAction.ResizeS; } else if (cur.DistanceToSegment(nw, sw).Abs() < editRadius) { action = SelectionEditAction.ResizeW; } else if (_currentSelection.GetRectangle().ContainsPoint((int)cur.X, (int)cur.Y)) { action = SelectionEditAction.Move; } if (action == SelectionEditAction.ResizeNW || action == SelectionEditAction.ResizeSE) { Cursor.Current = Cursors.SizeNWSE; } else if (action == SelectionEditAction.ResizeNE || action == SelectionEditAction.ResizeSW) { Cursor.Current = Cursors.SizeNESW; } else if (action == SelectionEditAction.ResizeN || action == SelectionEditAction.ResizeS) { Cursor.Current = Cursors.SizeNS; } else if (action == SelectionEditAction.ResizeW || action == SelectionEditAction.ResizeE) { Cursor.Current = Cursors.SizeWE; } else if (action == SelectionEditAction.Move) { Cursor.Current = Cursors.SizeAll; } else { Cursor.Current = Cursors.Default; } if (eventData.Event == MouseEventData.EventType.Down && eventData.Args.Button == MouseButtons.Left) { _prevCoord = cur; _currentSelectionEditAction = action; } if (eventData.Event == MouseEventData.EventType.Up && eventData.Args.Button == MouseButtons.Left) { _currentSelectionEditAction = SelectionEditAction.None; } if (eventData.Event == MouseEventData.EventType.Move && eventData.Args.Button == MouseButtons.Left) { switch (_currentSelectionEditAction) { case SelectionEditAction.ResizeNW: _currentSelection.X0 = (int)cur.X; _currentSelection.Y0 = (int)cur.Y; break; case SelectionEditAction.ResizeSW: _currentSelection.X0 = (int)cur.X; _currentSelection.Y1 = (int)cur.Y; break; case SelectionEditAction.ResizeSE: _currentSelection.X1 = (int)cur.X; _currentSelection.Y1 = (int)cur.Y; break; case SelectionEditAction.ResizeNE: _currentSelection.X1 = (int)cur.X; _currentSelection.Y0 = (int)cur.Y; break; case SelectionEditAction.ResizeN: _currentSelection.Y0 = (int)cur.Y; break; case SelectionEditAction.ResizeS: _currentSelection.Y1 = (int)cur.Y; break; case SelectionEditAction.ResizeW: _currentSelection.X0 = (int)cur.X; break; case SelectionEditAction.ResizeE: _currentSelection.X1 = (int)cur.X; break; case SelectionEditAction.Move: _currentSelection.MoveBy(cur - _prevCoord); _prevCoord = cur; break; } _currentSelection.Width = _currentSelection.Width - _currentSelection.Width % 2; _currentSelection.Height = _currentSelection.Height - _currentSelection.Height % 2; _drawable.SelectionUpdate(); } } UpdateInfoLabel(); }