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


C# InputState.IsMouseMoved方法代码示例

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


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

示例1: HandleInput

        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            int dirX = 0, dirY = 0;
            //figure out the directions to move
            if (input.IsMenuUp(ControllingPlayer))
                dirX = -1;
            if (input.IsMenuDown(ControllingPlayer))
                dirX = 1;
            if (input.IsMenuLeft(ControllingPlayer))
                dirY = -1;
            if (input.IsMenuRight(ControllingPlayer))
                dirY = 1;
            //if horizontal orientation, swap directions
            if (!IsVertical) {
                int temp = dirX;
                dirX = dirY;
                dirY = temp;
            }
            //process row movement
            if (dirX != 0) {
                if (selectedEntry.Column < 0 || selectedEntry.Column >= menuColumns.Length)
                    selectedEntry.Column = 0;
                int length = menuColumns[selectedEntry.Column].Count;
                do {
                    selectedEntry.Row += dirX;
                    if (selectedEntry.Row < 0)
                        selectedEntry.Row = length - 1;
                    selectedEntry.Row %= length;
                } while (!Selected.Enabled);
            }

            //handle column selection (left/right)
            //ultimately, index selection will also be in here
            //  if the index can go up/down, let it. otherwise, change columns. easy.
            if (dirY != 0) {
                if (selectedEntry.Row < 0 || selectedEntry.Row >= menuColumns[selectedEntry.Column].Count)
                    selectedEntry.Row = 0;
                if (relativeSelection)
                    ChangeColumnsRelative(dirY);
                else
                    ChangeColumns(dirY);
            }

            // Accept or cancel the menu? We pass in our ControllingPlayer, which may
            // either be null (to accept input from any player) or a specific index.
            // If we pass a null controlling player, the InputState helper returns to
            // us which player actually provided the input. We pass that through to
            // OnSelectEntry and OnCancel, so they can tell which player triggered them.
            PlayerIndex playerIndex;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex)) {
                OnSelectEntry(selectedEntry, playerIndex);
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex)) {
                OnCancel(playerIndex);
            }

            #region Mouse Handling
            #if WINDOWS
            bool clicked = input.IsNewMouseButtonPress(MouseButtons.Left);
            if (input.IsMouseMoved() || clicked) {
                mousePosition.X = input.CurrentMouseState.X;
                mousePosition.Y = input.CurrentMouseState.Y;
                //check mouse pos against each menu entry and update selection if necessary
                if (AllowEmptySelection)
                    selectedEntry.Column = selectedEntry.Row = selectedEntry.Index = -5;
                for (int col = 0; col < menuColumns.Length; col++) {
                    for (int i = 0; i < menuColumns[col].Count; i++) {
                        MenuEntry menuEntry = menuColumns[col][i];

                        if (menuEntry.Contains(mousePosition) && menuEntry.Enabled) {
                            selectedEntry.Column = col;
                            selectedEntry.Row = i;
                            if (clicked)
                                OnSelectEntry(selectedEntry, PlayerIndex.One);

                        }
                    }
                }
            }
            #endif

            HandleSpecialInput(input, Selected);
            #endregion
        }
开发者ID:giladgray,项目名称:XNA-ScreenManager,代码行数:89,代码来源:FancyMenuScreen.cs


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