当前位置: 首页>>代码示例>>C#>>正文


C# InputState.IsMousePressed方法代码示例

本文整理汇总了C#中InputState.IsMousePressed方法的典型用法代码示例。如果您正苦于以下问题:C# InputState.IsMousePressed方法的具体用法?C# InputState.IsMousePressed怎么用?C# InputState.IsMousePressed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InputState的用法示例。


在下文中一共展示了InputState.IsMousePressed方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleInput

        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public void HandleInput(InputState input)
        {
            Vector2 mouseFocus = new Vector2(-1, -1);

            // Check NumPad and Number Keys for manual number entering
            String keyString;
            Keys key = new Keys();
            int keyboardInt = -1;
            for (int i = 0; i < 10; i++)
            {
                keyString = "D" + i.ToString();
                key = (Keys)Enum.Parse(typeof(Keys), keyString);
                if (input.IsNewKeyPress(key))
                    keyboardInt = i;
                keyString = "NumPad" + i.ToString();
                key = (Keys)Enum.Parse(typeof(Keys), keyString);
                if (input.IsNewKeyPress(key))
                    keyboardInt = i;
            }

            if (keyboardInt != -1)
                AddToAnswer(keyboardInt.ToString());

            if ( input.IsMouseChanged() ||input.IsMousePressed())
                mouseFocus = buttonTable.CheckFocus(input);

            if (mouseFocus.X != -1)
            {
                focus = mouseFocus;
                if (input.IsNewMouseReleased())
                    HandleButtonInput();
            }
            else
            {
                buttonTable.SetPressed(focus, false);
                buttonTable.SetFocus(focus, false);
                // Move up?
                if (input.IsMenuUp())
                {
                    focus = new Vector2(focus.X, focus.Y - 1);

                    if (focus.Y < 1)
                        focus.Y = buttonTable.Rows;
                }

                // Move down?
                if (input.IsMenuDown())
                {
                    focus = new Vector2(focus.X, focus.Y + 1);

                    if (focus.Y > buttonTable.Rows)
                        focus.Y = 1;
                }

                // Move left?
                if (input.IsMenuLeft())
                {
                    focus = new Vector2(focus.X - 1, focus.Y);

                    if (focus.X < 1)
                        focus.X = buttonTable.Cols;
                }

                // Move right?
                if (input.IsMenuRight())
                {
                    focus = new Vector2(focus.X + 1, focus.Y);

                    if (focus.X > buttonTable.Cols)
                        focus.X = 1;
                }
                buttonTable.SetFocus(focus, true);
            }

            // Check if the button is being pressed or if the user
            // is asking to exit the screen.

            if (input.IsMenuSelect())
            {
                HandleButtonInput();
                buttonTable.SetPressed(focus, true);
            }
            else if (input.IsMenuCancel())
            {
                Exiting = true;
            }
        }
开发者ID:Ben-Cortina,项目名称:Times-Table,代码行数:91,代码来源:Test.cs


注:本文中的InputState.IsMousePressed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。