コード例 #1
0
        private void pbBoard_MouseDown(object sender, MouseEventArgs e)
        {
            UpdateMouse(e);
            var mouseLocation = BoardPainter.GetBoardLocation(_lastMouse);

            if (_model.EditMode)
            {
                if (Movement.IsValidLocation(mouseLocation))
                {
                    _model.SelectionObject = mouseLocation;
                    BoardEditorUpdate();
                    RedrawBoard();
                }

                return;
            }

            if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
            {
                _lmbDown = true;
            }
            else if ((e.Button & MouseButtons.Right) == MouseButtons.Right)
            {
                _rmbDown = true;
            }

            if (!Movement.IsValidLocation(mouseLocation))
            {
                return;
            }
            _lastEventLocation = mouseLocation;
        }
コード例 #2
0
        private void pbBoard_MouseUp(object sender, MouseEventArgs e)
        {
            if (_model.EditMode)
            {
                return;
            }
            UpdateMouse(e);
            var mouseLocation = BoardPainter.GetBoardLocation(_lastMouse);

            if (!Movement.IsValidLocation(mouseLocation))
            {
                return;
            }
            if ((e.Button & MouseButtons.Left) == MouseButtons.Left && _lmbDown)
            {
                _lmbDown = false;
                InputEvent?.Invoke(sender,
                                   new BoardLocationEventArgs
                {
                    Location   = mouseLocation,
                    MouseEvent = _rmbDrag
                            ? BoardMouseEventType.PartialDropContinueDrag
                            : _lmbDrag
                                ? BoardMouseEventType.LeftDragEnd
                                : BoardMouseEventType.LeftClick
                });
                _lmbDrag = false;
            }
            else if ((e.Button & MouseButtons.Right) == MouseButtons.Right && _rmbDown)
            {
                _rmbDown = false;
                InputEvent?.Invoke(sender,
                                   new BoardLocationEventArgs
                {
                    Location   = mouseLocation,
                    MouseEvent = _lmbDrag
                            ? BoardMouseEventType.PartialDropContinueDrag
                            : _rmbDrag
                                ? BoardMouseEventType.RightDragEnd
                                : BoardMouseEventType.RightClick
                });
                _rmbDrag = false;
            }

            _lastEventLocation = mouseLocation;
            BoardEditorUpdate();
        }
コード例 #3
0
 private void btnBoardImageToClipboard_Click(object sender, EventArgs e)
 {
     Clipboard.SetImage(BoardPainter.DrawBoard(_model.EditorState.Flags == 0 ? _model.CommittedState : _model.EditorState, Board.Location.Undefined,
                                               Board.Location.Undefined, null, false, Point.Empty));
 }
コード例 #4
0
        private void pbBoard_MouseMove(object sender, MouseEventArgs e)
        {
            if (_model.EditMode)
            {
                return;
            }
            UpdateMouse(e);
            var mouseLocation = BoardPainter.GetBoardLocation(_lastMouse);

            if (!Movement.IsValidLocation(mouseLocation))
            {
                return;
            }
            if (_lmbDown)
            {
                if (mouseLocation != _lastEventLocation)
                {
                    if (!_lmbDrag && !_rmbDrag)
                    {
                        InputEvent?.Invoke(sender,
                                           new BoardLocationEventArgs
                        {
                            Location = _lastEventLocation, MouseEvent = BoardMouseEventType.LeftDragStart
                        });
                    }

                    InputEvent?.Invoke(sender,
                                       new BoardLocationEventArgs {
                        Location = mouseLocation, MouseEvent = BoardMouseEventType.Hover
                    });
                    _lastEventLocation = mouseLocation;
                    if (!_rmbDrag)
                    {
                        _lmbDrag = true;
                    }
                }
            }
            else if (_rmbDown)
            {
                if (mouseLocation != _lastEventLocation)
                {
                    if (!_lmbDrag && !_rmbDrag)
                    {
                        InputEvent?.Invoke(sender,
                                           new BoardLocationEventArgs
                        {
                            Location = _lastEventLocation, MouseEvent = BoardMouseEventType.RightDragStart
                        });
                    }

                    InputEvent?.Invoke(sender,
                                       new BoardLocationEventArgs {
                        Location = mouseLocation, MouseEvent = BoardMouseEventType.Hover
                    });
                    _lastEventLocation = mouseLocation;
                    if (!_lmbDrag)
                    {
                        _rmbDrag = true;
                    }
                }
            }
            else
            {
                if (mouseLocation != _lastEventLocation)
                {
                    InputEvent?.Invoke(sender,
                                       new BoardLocationEventArgs {
                        Location = mouseLocation, MouseEvent = BoardMouseEventType.Hover
                    });
                    _lastEventLocation = mouseLocation;
                }
            }

            RedrawBoard();
        }
コード例 #5
0
        public void RedrawBoard()
        {
            if (_model.EditMode)
            {
                pbBoard.Image = BoardPainter.DrawBoard(_model.EditorState, _model.SelectionObject,
                                                       Board.Location.Undefined, _model.HighlightLocations, true, Point.Empty);
            }
            else
            {
                var redSide = _model.CommittedState.Flags.IsRedTurn();
                switch (_model.SelectionState)
                {
                case SelectionState.Unselected:
                    pbBoard.Image = BoardPainter.DrawBoard(_model.CommittedState, Board.Location.Undefined,
                                                           Board.Location.Undefined, _model.HighlightLocations, redSide, Point.Empty);
                    break;

                case SelectionState.EmptySelected:
                    pbBoard.Image = BoardPainter.DrawBoard(_model.EditorState, _model.SelectionObject,
                                                           Board.Location.Undefined, _model.HighlightLocations, redSide, Point.Empty);
                    break;

                case SelectionState.PieceInHand:
                case SelectionState.SplitInHand:
                    pbBoard.Image = BoardPainter.DrawBoard(_model.EditorState, _model.SelectionObject,
                                                           Board.Location.Undefined, _model.HighlightLocations, redSide, _lastMouse, _model.InHand);
                    break;

                case SelectionState.MoveSelected:
                    pbBoard.Image = BoardPainter.DrawBoard(_model.EditorState, _model.SelectionObject,
                                                           _model.SelectionTarget, _model.HighlightLocations, redSide, Point.Empty);
                    break;

                //case SelectionState.PartialSplitSelected:
                //    pbBoard.Image = BoardPainter.DrawBoard(_model.EditorState, _model.SelectionObject,
                //        _model.SelectionTarget, _model.HighlightLocations, redSide, _lastMouse, _model.InHand);
                //    break;
                case SelectionState.HistoryView:
                    pbBoard.Image = BoardPainter.DrawBoard(_model.EditorState, Board.Location.Undefined,
                                                           Board.Location.Undefined, null, true, Point.Empty);
                    break;

                default:
                    return;
                }
            }

            foreach (var enableBox in new[]
                     { chkRedT1, chkRedT2, chkBlueT1, chkBlueT2, chkRedKingTaken, chkBlueKingTaken, chkRedWin, chkBlueWin })
            {
                enableBox.Enabled = _model.EditMode;
            }

            chkRedT1.Checked         = _model.EditorState.Flags.HasFlag(StateFlags.RedAction1);
            chkRedT2.Checked         = _model.EditorState.Flags.HasFlag(StateFlags.RedAction2);
            chkBlueT1.Checked        = _model.EditorState.Flags.HasFlag(StateFlags.BlueAction1);
            chkBlueT2.Checked        = _model.EditorState.Flags.HasFlag(StateFlags.BlueAction2);
            chkRedKingTaken.Checked  = _model.EditorState.Flags.HasFlag(StateFlags.RedKingTaken);
            chkBlueKingTaken.Checked = _model.EditorState.Flags.HasFlag(StateFlags.BlueKingTaken);
            chkRedWin.Checked        = _model.EditorState.Flags.HasFlag(StateFlags.RedWin);
            chkBlueWin.Checked       = _model.EditorState.Flags.HasFlag(StateFlags.BlueWin);
        }