Пример #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;
        }
Пример #2
0
        public SpriteControlsTab(SpriteWindow wnd)
        {
            _wnd  = wnd;
            _id   = "spriteControlsTab";
            _name = "Controls";

            _tabButton     = new ToolBoxButton(_name);
            _tabButton.Tag = this;

            _panel        = new Panel();
            _panel.Name   = "spriteControlsPanel";
            _panel.Paint += this.drawDivider;

            _folderBrowser = new FolderBrowserDialog();
            var resources = new ComponentResourceManager(typeof(SpriteControlsTab));

            _tileLabel          = new Label();
            _tileLabel.Font     = new Font(Label.DefaultFont, FontStyle.Bold);
            _tileLabel.Name     = "tileLabel";
            _tileLabel.Text     = "Tile";
            _tileLabel.AutoSize = true;
            _tileLabel.Location = new Point(20, 8);

            _outputLabel          = new Label();
            _outputLabel.Font     = new Font(Label.DefaultFont, FontStyle.Bold);
            _outputLabel.Name     = "outputLabel";
            _outputLabel.Text     = "Output";
            _outputLabel.AutoSize = true;
            _outputLabel.Location = new Point(136, 8);

            _rotateLeftBtn           = new Button();
            _rotateLeftBtn.Name      = "rotateLeftBtn";
            _rotateLeftBtn.Size      = new Size(32, 32);
            _rotateLeftBtn.Location  = new Point(26, 30);
            _rotateLeftBtn.BackColor = Color.Transparent;
            _rotateLeftBtn.Image     = (Image)(resources.GetObject("rotateLeftImg"));
            _rotateLeftBtn.Click    += (s, e) => _wnd.FlipTile(Translation.Left);

            _rotateRightBtn           = new Button();
            _rotateRightBtn.Name      = "rotateRightBtn";
            _rotateRightBtn.Size      = new Size(32, 32);
            _rotateRightBtn.Location  = new Point(66, 30);
            _rotateRightBtn.BackColor = Color.Transparent;
            _rotateRightBtn.Image     = (Image)(resources.GetObject("rotateRightImg"));
            _rotateRightBtn.Click    += (s, e) => _wnd.FlipTile(Translation.Right);

            _mirrorHoriBtn           = new Button();
            _mirrorHoriBtn.Name      = "mirrorHoriBtn";
            _mirrorHoriBtn.Size      = new Size(32, 32);
            _mirrorHoriBtn.Location  = new Point(26, 70);
            _mirrorHoriBtn.BackColor = Color.Transparent;
            _mirrorHoriBtn.Image     = (Image)(resources.GetObject("mirrorHoriImg"));
            _mirrorHoriBtn.Click    += (s, e) => _wnd.FlipTile(Translation.Horizontal);

            _mirrorVertBtn           = new Button();
            _mirrorVertBtn.Name      = "mirrorVertBtn";
            _mirrorVertBtn.Size      = new Size(32, 32);
            _mirrorVertBtn.Location  = new Point(66, 70);
            _mirrorVertBtn.BackColor = Color.Transparent;
            _mirrorVertBtn.Image     = (Image)(resources.GetObject("mirrorVertImg"));
            _mirrorVertBtn.Click    += (s, e) => _wnd.FlipTile(Translation.Vertical);

            _eraseBtn           = new Button();
            _eraseBtn.Name      = "eraseBtn";
            _eraseBtn.Text      = "Erase";
            _eraseBtn.AutoSize  = true;
            _eraseBtn.Location  = new Point(25, 110);
            _eraseBtn.BackColor = Color.Transparent;
            _eraseBtn.Click    += (s, e) => _wnd.EraseTile();

            _scaleLabel          = new Label();
            _scaleLabel.Name     = "scaleLabel";
            _scaleLabel.Text     = "Scale:  x";
            _scaleLabel.AutoSize = true;
            _scaleLabel.Location = new Point(142, 32);

            _scaleBox               = new NumericUpDown();
            _scaleBox.Name          = "scaleBox";
            _scaleBox.Size          = new Size(40, 20);
            _scaleBox.Location      = new Point(190, 30);
            _scaleBox.Increment     = 1;
            _scaleBox.Minimum       = 1;
            _scaleBox.Maximum       = 256;
            _scaleBox.Text          = "";
            _scaleBox.ValueChanged += (s, e) => UpdateUI();
            _scaleBox.Leave        += (s, e) => UpdateUI();

            _scaleHint           = new Label();
            _scaleHint.Name      = "scaleHint";
            _scaleHint.Text      = "No scale set";
            _scaleHint.Font      = new Font(Label.DefaultFont, FontStyle.Italic);
            _scaleHint.ForeColor = infoColor;
            _scaleHint.AutoSize  = true;
            _scaleHint.Location  = new Point(234, 33);

            _folderLabel          = new Label();
            _folderLabel.Name     = "folderLabel";
            _folderLabel.Text     = "Folder: ";
            _folderLabel.AutoSize = true;
            _folderLabel.Location = new Point(142, 58);

            _folderBtn           = new Button();
            _folderBtn.Name      = "folderBtn";
            _folderBtn.Text      = "...";
            _folderBtn.Size      = new Size(30, 20);
            _folderBtn.Location  = new Point(189, 55);
            _folderBtn.BackColor = Color.Transparent;
            _folderBtn.Click    += this.browseFolderHandler;

            _folderText              = new Label();
            _folderText.Name         = "folderText";
            _folderText.Text         = "No path set";
            _folderText.Font         = new Font(Label.DefaultFont, FontStyle.Italic);
            _folderText.ForeColor    = infoColor;
            _folderText.AutoEllipsis = true;
            _folderText.Size         = new Size(70, 13);
            _folderText.Location     = new Point(226, 58);

            _nameLabel          = new Label();
            _nameLabel.Name     = "nameLabel";
            _nameLabel.Text     = "Name: ";
            _nameLabel.AutoSize = true;
            _nameLabel.Location = new Point(142, 84);

            _nameBox              = new TextBox();
            _nameBox.Name         = "nameBox";
            _nameBox.Text         = "";
            _nameBox.AutoSize     = true;
            _nameBox.Location     = new Point(190, 81);
            _nameBox.TextChanged += (s, e) => UpdateUI();
            _nameBox.Leave       += (s, e) => UpdateUI();

            _nameHint           = new Label();
            _nameHint.Name      = "nameHint";
            _nameHint.Text      = "No name set";
            _nameHint.Font      = new Font(Label.DefaultFont, FontStyle.Italic);
            _nameHint.ForeColor = infoColor;
            _nameHint.AutoSize  = true;
            _nameHint.Location  = new Point(190, 104);

            _overwriteBtn                 = new RadioButton();
            _overwriteBtn.Name            = "overwriteBtn";
            _overwriteBtn.Text            = "Overwrite";
            _overwriteBtn.AutoSize        = true;
            _overwriteBtn.Location        = new Point(186, 124);
            _overwriteBtn.Checked         = true;
            _overwriteBtn.CheckedChanged += this.writeModeCheck;

            _appendBtn                 = new RadioButton();
            _appendBtn.Name            = "appendBtn";
            _appendBtn.Text            = "Append:";
            _appendBtn.AutoSize        = true;
            _appendBtn.Location        = new Point(186, 144);
            _appendBtn.CheckedChanged += this.writeModeCheck;

            _appendBox          = new TextBox();
            _appendBox.Name     = "appendBox";
            _appendBox.Text     = "_{d2}";
            _appendBox.Size     = new Size(50, 20);
            _appendBox.Location = new Point(254, 143);
            _appendBox.Enabled  = false;
            // No TextChanged event here ;)
            _appendBox.Leave += (s, e) => UpdateUI();

            _saveButton           = new Button();
            _saveButton.Name      = "saveButton";
            _saveButton.Size      = new Size(32, 32);
            _saveButton.Location  = new Point(140, 127);
            _saveButton.BackColor = Color.Transparent;
            _saveButton.Image     = (Image)(resources.GetObject("saveImg"));
            _saveButton.Click    += this.saveButtonHandler;
            _saveButton.Enabled   = false;

            _saveMsg              = new Label();
            _saveMsg.Name         = "saveMsg";
            _saveMsg.Text         = "";
            _saveMsg.Font         = new Font(Label.DefaultFont, FontStyle.Italic);
            _saveMsg.ForeColor    = infoColor;
            _saveMsg.AutoEllipsis = true;
            _saveMsg.Size         = new Size(100, 13);
            _saveMsg.Location     = new Point(142, 172);

            _panel.Controls.Add(_tileLabel);
            _panel.Controls.Add(_outputLabel);

            _panel.Controls.Add(_rotateRightBtn);
            _panel.Controls.Add(_rotateLeftBtn);
            _panel.Controls.Add(_mirrorHoriBtn);
            _panel.Controls.Add(_mirrorVertBtn);
            _panel.Controls.Add(_eraseBtn);

            _panel.Controls.Add(_scaleLabel);
            _panel.Controls.Add(_scaleBox);
            _panel.Controls.Add(_scaleHint);

            _panel.Controls.Add(_folderLabel);
            _panel.Controls.Add(_folderBtn);
            _panel.Controls.Add(_folderText);

            _panel.Controls.Add(_nameLabel);
            _panel.Controls.Add(_nameBox);
            _panel.Controls.Add(_nameHint);

            _panel.Controls.Add(_overwriteBtn);
            _panel.Controls.Add(_appendBtn);
            _panel.Controls.Add(_appendBox);
            _panel.Controls.Add(_saveButton);
            _panel.Controls.Add(_saveMsg);
        }