Exemplo n.º 1
0
        private void keysHandler(object sender, KeyEventArgs e)
        {
            if (_drag != null)
            {
                _keyHeld = true;
                return;
            }

            Control active = Utils.FindActiveControl(this);

            // ugly as heck
            if (!_keyHeld && (e.KeyCode == Keys.Escape || e.KeyCode == Keys.ControlKey))
            {
                if (!(active is TextBox))
                {
                    if (Transfer.Source != null || Transfer.Dest != null)
                    {
                        ClearSelection();
                        SetSample(null);
                    }
                    else if (toolBox.IsOpen && e.KeyCode == Keys.Escape)
                    {
                        if (!toolBox.HandleEscapeKey(this))
                        {
                            toolBox.Minimise();
                            this.PerformLayout();
                        }
                    }
                }

                inputWnd.Focus(this);
            }

            if (active is TextBox)
            {
                Draw();
                _keyHeld = true;
                return;
            }

            if (e.KeyCode == Keys.Delete)
            {
                spriteWnd.EraseTile();
            }

            if (e.KeyCode == Keys.Enter)
            {
                CopyTile(inputWnd);
                PasteTile(spriteWnd);
                spriteWnd.MoveSelection(1, 0);
                spriteWnd.Draw();
            }

            Keys mod = Control.ModifierKeys;

            if ((mod & Keys.Control) != 0)
            {
                if (e.KeyCode == Keys.G && inputWnd.IsActive)
                {
                    toolBox.CurrentWindow = inputWnd;
                    toolBox.Select("Controls");
                    if (!toolBox.IsOpen)
                    {
                        toolBox.Minimise();
                    }

                    spriteWnd.Centre();
                    this.PerformLayout();
                    this.ActiveControl = toolBox.GetControl("inputOffset");
                }

                if (e.KeyCode == Keys.D0)
                {
                    spriteWnd.Centre();
                }

                int zoom = 0;
                if (e.KeyCode == Keys.OemMinus)
                {
                    zoom = -1;
                }
                else if (e.KeyCode == Keys.Oemplus)
                {
                    zoom = 1;
                }

                if (zoom != 0)
                {
                    spriteWnd.ZoomIn(zoom);
                }

                Action <EdgeKind> moveEdge = spriteWnd.InsertEdge;
                if ((mod & Keys.Shift) != 0)
                {
                    moveEdge = spriteWnd.DeleteEdge;
                }

                if (e.KeyCode == Keys.I)
                {
                    moveEdge(EdgeKind.Top);
                }
                else if (e.KeyCode == Keys.K)
                {
                    moveEdge(EdgeKind.Bottom);
                }
                else if (e.KeyCode == Keys.J)
                {
                    moveEdge(EdgeKind.Left);
                }
                else if (e.KeyCode == Keys.L)
                {
                    moveEdge(EdgeKind.Right);
                }

                Draw();
            }
            else if ((mod & Keys.Shift) != 0)
            {
                bool swap = true;
                int  x = 0, y = 0;

                if (e.KeyCode == Keys.I)
                {
                    y = -1;
                }
                else if (e.KeyCode == Keys.K)
                {
                    y = 1;
                }
                else if (e.KeyCode == Keys.J)
                {
                    x = -1;
                }
                else if (e.KeyCode == Keys.L)
                {
                    x = 1;
                }
                else
                {
                    swap = false;
                }

                if (swap)
                {
                    CopyTile(spriteWnd);
                    spriteWnd.MoveSelection(x, y);
                    SwapTile(spriteWnd);
                }

                if (e.KeyCode == Keys.Tab)
                {
                    if (!toolBox.IsOpen)
                    {
                        toolBox.Minimise();
                    }

                    SwitchToolBoxWindow();
                }
            }
            else
            {
                bool move = true;

                if (e.KeyCode == Keys.W)
                {
                    inputWnd.MoveSelection(0, -1);
                }
                else if (e.KeyCode == Keys.S)
                {
                    inputWnd.MoveSelection(0, 1);
                }
                else if (e.KeyCode == Keys.A)
                {
                    inputWnd.MoveSelection(-1, 0);
                }
                else if (e.KeyCode == Keys.D)
                {
                    inputWnd.MoveSelection(1, 0);
                }

                else if (e.KeyCode == Keys.I)
                {
                    spriteWnd.MoveSelection(0, -1);
                }
                else if (e.KeyCode == Keys.K)
                {
                    spriteWnd.MoveSelection(0, 1);
                }
                else if (e.KeyCode == Keys.J)
                {
                    spriteWnd.MoveSelection(-1, 0);
                }
                else if (e.KeyCode == Keys.L)
                {
                    spriteWnd.MoveSelection(1, 0);
                }

                else
                {
                    move = false;
                }

                if (move)
                {
                    Transfer.Source = inputWnd.CurrentSelection();
                    Transfer.Dest   = spriteWnd.CurrentSelection();
                    Draw();
                }

                if (e.KeyCode == Keys.Tab)
                {
                    if (!toolBox.IsOpen)
                    {
                        toolBox.Minimise();
                    }
                    else
                    {
                        toolBox.Cycle(1);
                        toolBox.RefreshTab();
                        spriteWnd.Centre();
                    }

                    this.PerformLayout();
                }
            }

            _keyHeld = true;
        }