/// <summary> /// Handles a mouse up event. /// </summary> /// <param name="e">The mouse event.</param> public void MouseUpHandler(MouseEventArgs e) { if (_isMoving) { Int32 square = VisualPosition.SquareAt(e.Location); Int32 piece = _currentPosition.Square[square]; if (piece != Piece.Empty && (piece & Colour.Mask) == _currentPosition.SideToMove) { _initialSquare = (_initialSquare == square) ? Position.InvalidSquare : square; } else { _finalSquare = square; _waitForMove.Set(); } } }
/// <summary> /// Handles a mouse up event in the main window. The selected piece /// in the analysis control panel is set at the mouse position on the /// board. This is an unusual thing to do, so this method has to /// handle the nuances of position state itself. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="e">The mouse event.</param> public void WindowMouseUpHandler(MouseEventArgs e) { if (_isSearching) { return; } Int32 square = VisualPosition.SquareAt(e.Location); if (_selectedPiece == ArrowCode) { if (_selectedSquare == Position.InvalidSquare) { if (_position.Square[square] != Piece.Empty) { _selectedSquare = square; } } else if (_selectedSquare == square) { _selectedSquare = Position.InvalidSquare; } else { Int32 initialSquare = _selectedSquare; SetPieceAt(_position.Square[initialSquare], square); SetPieceAt(Piece.Empty, initialSquare); _selectedSquare = Position.InvalidSquare; UpdatePosition(_position); VisualPosition.Make(TMove.Create(_position, initialSquare, square)); } } else { SetPieceAt(_selectedPiece, square); UpdatePosition(_position); VisualPosition.Set(_position); } }