コード例 #1
0
ファイル: GameWindow.cs プロジェクト: smack0007/Snowball_v1
        /// <summary>
        /// Constructor.
        /// </summary>
        public GameWindow()
            : base()
        {
            this.Cursor = Cursors.Arrow;
            this.FormBorderStyle = FormBorderStyle.Fixed3D;
            this.MaximizeBox = false;
            this.ClientSize = new System.Drawing.Size(800, 600);
            this.KeyPreview = true;

            this.Icon = Snowball.GameFramework.Properties.Resources.Icon;

            this.gameWindowKeyPressEventArgs = new GameWindowKeyPressEventArgs();

            this.closeEventArgs = new CancelEventArgs();
        }
コード例 #2
0
ファイル: GameConsole.cs プロジェクト: smack0007/Snowball_v1
        /// <summary>
        /// Called when the KeyPress event occurs on the game window.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_KeyPress(object sender, GameWindowKeyPressEventArgs e)
        {
            this.EnsureFont();

            if (e.KeyCode == this.ToggleKeyCode)
            {
                this.Toggle();
            }

            if (this.IsVisible)
            {
                if (e.KeyChar == 8) // backspace
                {
                    if (this.cursorPosition > 0)
                    {
                        this.input.Remove(this.cursorPosition - 1, 1);
                        this.cursorPosition--;
                    }
                }
                else if (e.KeyChar == 13)
                {
                    if (this.InputReceived != null)
                    {
                        this.inputReceivedEventArgs.Text = this.input.ToString();
                        this.InputReceived(this, this.inputReceivedEventArgs);
                    }

                    this.input.Clear();
                    this.cursorPosition = 0;
                }
                else if (e.KeyChar != '`' && this.Font.ContainsCharacter(e.KeyChar))
                {
                    this.input.Append(e.KeyChar);
                    this.cursorPosition++;
                }
            }
        }