Example #1
0
 /// <summary>
 /// OnQueryPiece:       Trigger the QueryPiece event
 /// </summary>
 /// <param name="e">    Event arguments</param>
 protected virtual void OnQueryPiece(QueryPieceEventArgs e)
 {
     if (QueryPiece != null)
     {
         QueryPiece(this, e);
     }
 }
 /// <summary>
 /// OnQueryPiece:       Trigger the QueryPiece event
 /// </summary>
 /// <param name="e">    Event arguments</param>
 protected virtual void OnQueryPiece(QueryPieceEventArgs e)
 {
     if (QueryPiece != null) {
         QueryPiece(this, e);
     }
 }
        /// <summary>
        /// Intercept Mouse click
        /// </summary>
        /// <param name="e">    Event Parameter</param>
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            IntPoint pt;
            ChessBoard.MovePosS tMove;
            ChessBoard.ValidPawnPromotionE eValidPawnPromotion;
            QueryPieceEventArgs eQueryPieceEventArgs;
            int iPos;
            ChessBoard.PieceE ePiece;
            QueryPawnPromotionTypeEventArgs eventArg;
            bool bWhiteToMove;
            bool bWhitePiece;

            base.OnMouseDown(e);
            if (e.ChangedButton == MouseButton.Left)
            {
                if (e.ClickCount == 2)
                {
                    //RenderBmps(100);
                }
                else
                {
                    if (BoardDesignMode)
                    {
                        if (GetCellFromPoint(e, out pt))
                        {
                            iPos = pt.X + (pt.Y << 3);
                            eQueryPieceEventArgs = new QueryPieceEventArgs(iPos, ChessBoard[iPos]);
                            OnQueryPiece(eQueryPieceEventArgs);
                            ChessBoard[iPos] = eQueryPieceEventArgs.Piece;
                            RefreshCell(iPos);
                        }
                    }
                    else if (AutoSelection)
                    {
                        if (GetCellFromPoint(e, out pt))
                        {
                            iPos = pt.X + (pt.Y << 3);
                            if (SelectedCell.X == -1 || SelectedCell.Y == -1)
                            {
                                ePiece = m_board[iPos];
                                bWhiteToMove = (m_board.NextMoveColor == SrcChess2.ChessBoard.PlayerColorE.White);
                                bWhitePiece = (ePiece & SrcChess2.ChessBoard.PieceE.Black) == 0;
                                if (ePiece != SrcChess2.ChessBoard.PieceE.None && bWhiteToMove == bWhitePiece)
                                {
                                    SelectedCell = pt;
                                }
                                else
                                {
                                    System.Console.Beep();
                                }
                            }
                            else
                            {
                                if (SelectedCell.X == pt.X && SelectedCell.Y == pt.Y)
                                {
                                    SelectedCell = new IntPoint(-1, -1);
                                }
                                else
                                {
                                    tMove = ChessBoard.FindIfValid(m_board.NextMoveColor,
                                                                    SelectedCell.X + (SelectedCell.Y << 3),
                                                                    iPos);
                                    if (tMove.StartPos != 255)
                                    {
                                        eValidPawnPromotion = ChessBoard.FindValidPawnPromotion(m_board.NextMoveColor,
                                                                                                SelectedCell.X + (SelectedCell.Y << 3),
                                                                                                iPos);
                                        if (eValidPawnPromotion != ChessBoard.ValidPawnPromotionE.None)
                                        {
                                            eventArg = new QueryPawnPromotionTypeEventArgs(eValidPawnPromotion);
                                            OnQueryPawnPromotionType(eventArg);
                                            if (eventArg.PawnPromotionType == ChessBoard.MoveTypeE.Normal)
                                            {
                                                tMove.StartPos = 255;
                                            }
                                            else
                                            {
                                                tMove.Type &= ~ChessBoard.MoveTypeE.MoveTypeMask;
                                                tMove.Type |= eventArg.PawnPromotionType;
                                            }
                                        }
                                    }
                                    SelectedCell = new IntPoint(-1, -1);
                                    if (tMove.StartPos == 255)
                                    {
                                        System.Console.Beep();
                                    }
                                    else
                                    {
                                        OnMoveSelected(new MoveSelectedEventArgs(tMove));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else if (e.ChangedButton == MouseButton.Right)
            {
                mnu = new System.Windows.Controls.ContextMenu();
                mnu.StaysOpen = false;
                this.ContextMenu = mnu;

                MenuItem mi = new MenuItem();
                mi.Header = "_Raise Comment (Test)";
                mi.Click += mi_Click;

                MenuItem toAvi = new MenuItem();
                toAvi.InputGestureText = "F6";
                toAvi.Click += toAvi_Click;
                DependencyObject parentObject = Window.GetWindow(this);
                MainWindow parent = parentObject as MainWindow;
                toAvi.IsEnabled = parent.m_moveViewer.listViewMoveList.Items.Count > 0;
                toAvi.Header = "_Export Game to Video";

                MenuItem toImg = new MenuItem();
                toImg.Click += toImg_Click;
                toImg.Header = "_Export to Picture";

                MenuItem option = new MenuItem();
                option.InputGestureText = "Ctrl+`";
                option.Click += option_Click;
                option.Header = "_Board Settings";

                mnu.Items.Add(mi);
                mnu.Items.Add(toImg);
                mnu.Items.Add(toAvi);
                mnu.Items.Add(new Separator());
                mnu.Items.Add(option);
            }
            else if (e.ChangedButton == MouseButton.Middle)
            {
                if (e.ClickCount == 2)
                    ZoomExtend();
                else
                    ClearComments();
            }
            else
            {
            }
        }
        /// <summary>
        /// Intercept Mouse click
        /// </summary>
        /// <param name="e">    Event Parameter</param>
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            IntPoint                        pt;
            ChessBoard.MovePosS             tMove;
            ChessBoard.ValidPawnPromotionE  eValidPawnPromotion;
            QueryPieceEventArgs             eQueryPieceEventArgs;
            int                             iPos;
            ChessBoard.PieceE               ePiece;
            QueryPawnPromotionTypeEventArgs eventArg;
            bool                            bWhiteToMove;
            bool                            bWhitePiece;

            base.OnMouseDown(e);
            if (BoardDesignMode) {
                if (GetCellFromPoint(e, out pt)) {
                    iPos                 = pt.X + (pt.Y << 3);
                    eQueryPieceEventArgs = new QueryPieceEventArgs(iPos, ChessBoard[iPos]);
                    OnQueryPiece(eQueryPieceEventArgs);
                    ChessBoard[iPos] = eQueryPieceEventArgs.Piece;
                    RefreshCell(iPos);
                }
            } else if (AutoSelection) {
                if (GetCellFromPoint(e, out pt)) {
                    iPos = pt.X + (pt.Y << 3);
                    if (SelectedCell.X == -1 || SelectedCell.Y == -1) {
                        ePiece          = m_board[iPos];
                        bWhiteToMove    = (m_board.NextMoveColor == SrcChess2.ChessBoard.PlayerColorE.White);
                        bWhitePiece     = (ePiece & SrcChess2.ChessBoard.PieceE.Black) == 0;
                        if (ePiece != SrcChess2.ChessBoard.PieceE.None && bWhiteToMove == bWhitePiece) {
                            SelectedCell = pt;
                        } else {
                            System.Console.Beep();
                        }
                    } else {
                        if (SelectedCell.X == pt.X  && SelectedCell.Y == pt.Y) {
                            SelectedCell = new IntPoint(-1, -1);
                        } else {
                            tMove = ChessBoard.FindIfValid(m_board.NextMoveColor,
                                                            SelectedCell.X + (SelectedCell.Y << 3),
                                                            iPos);
                            if (tMove.StartPos != 255) {
                                eValidPawnPromotion = ChessBoard.FindValidPawnPromotion(m_board.NextMoveColor,
                                                                                        SelectedCell.X + (SelectedCell.Y << 3),
                                                                                        iPos);
                                if (eValidPawnPromotion != ChessBoard.ValidPawnPromotionE.None) {
                                    eventArg = new QueryPawnPromotionTypeEventArgs(eValidPawnPromotion);
                                    OnQueryPawnPromotionType(eventArg);
                                    if (eventArg.PawnPromotionType == ChessBoard.MoveTypeE.Normal) {
                                        tMove.StartPos = 255;
                                    } else {
                                        tMove.Type &= ~ChessBoard.MoveTypeE.MoveTypeMask;
                                        tMove.Type |= eventArg.PawnPromotionType;
                                    }
                                }
                            }
                            SelectedCell = new IntPoint(-1, -1);
                            if (tMove.StartPos == 255) {
                                System.Console.Beep();
                            } else {
                                OnMoveSelected(new MoveSelectedEventArgs(tMove));
                            }
                        }
                    }
                }
            }
        }
Example #5
0
 //*********************************************************     
 //
 /// <summary>
 /// Called when the mouse is clicked down
 /// </summary>
 /// <param name="e">        Event argument</param>
 //  
 //*********************************************************     
 protected override void OnMouseDown(MouseEventArgs e) {            
     Point                           pt;
     ChessBoard.MovePosS             tMove;
     ChessBoard.ValidPawnPromotionE  eValidPawnPromotion;
     QueryPieceEventArgs             eQueryPieceEventArgs;
     int                             iPos;
     Graphics                        gr;
     QueryPawnPromotionTypeEventArgs eventArg;
     
     base.OnMouseDown(e);
     if (BoardDesignMode) {
         pt = GetCaseFromPoint(new Point(e.X, e.Y));
         if (pt.X != -1) {
             iPos                 = pt.X + (pt.Y << 3);
             eQueryPieceEventArgs = new QueryPieceEventArgs(iPos, ChessBoard[iPos]);
             OnQueryPiece(eQueryPieceEventArgs);
             ChessBoard[iPos] = eQueryPieceEventArgs.Piece;
             using(gr = CreateGraphics()) {
                 DrawCase(gr, pt.Y, pt.X, false);
             }
         }
     } else if (AutoSelection) {
         pt = GetCaseFromPoint(new Point(e.X, e.Y));
         if (pt.X == -1) {
             SelectedCase = pt;
         } else {
             if (SelectedCase.X == -1) {
                 SelectedCase = pt;
             } else {
                 if (SelectedCase.X == pt.X  &&
                     SelectedCase.Y == pt.Y) {
                     pt.X         = -1;
                     pt.Y         = -1;
                     SelectedCase = pt;
                 } else {
                     tMove = ChessBoard.FindIfValid(m_board.NextMoveColor,
                                                    SelectedCase.X + (SelectedCase.Y << 3),
                                                    pt.X + (pt.Y << 3));
                     if (tMove.StartPos != 255) {                                                           
                         eValidPawnPromotion = ChessBoard.FindValidPawnPromotion(m_board.NextMoveColor, 
                                                                                 SelectedCase.X + (SelectedCase.Y << 3),
                                                                                 pt.X + (pt.Y << 3));
                         if (eValidPawnPromotion != ChessBoard.ValidPawnPromotionE.None) {
                             eventArg = new QueryPawnPromotionTypeEventArgs(eValidPawnPromotion);
                             OnQueryPawnPromotionType(eventArg);
                             if (eventArg.PawnPromotionType == ChessBoard.MoveTypeE.Normal) {
                                 tMove.StartPos = 255;
                             } else {
                                 tMove.Type &= ~ChessBoard.MoveTypeE.MoveTypeMask;
                                 tMove.Type |= eventArg.PawnPromotionType;
                             }
                         }
                     }
                     pt.X = -1;
                     pt.Y = -1;
                     SelectedCase = pt;
                     if (tMove.StartPos == 255) {
                         System.Console.Beep();
                     } else {
                         OnMoveSelected(new MoveSelectedEventArgs(tMove));
                     }
                 }
             }
         }
     }
 }