Example #1
0
        public void LeftMouseButtonPressedShouldResultInEdgeSetForButton()
        {
            var mouse = new Mouse();

            var mouseDeviceMock = new Mock<IMouseDevice>();
            mouseDeviceMock.Expect(m => m.IsButtonPressed(MouseButton.Left)).Returns(true);
            var mouseManager = new MouseManager(mouseDeviceMock.Object);
            mouseManager.HandleButtonSignals(mouse);

            Assert.That(mouse.LeftButton.IsEdge,Is.True);
        }
Example #2
0
        public void LeftMouseButtonHeldForMultipleHandlesShouldSetEdgeSignalToFalse()
        {
            var mouse = new Mouse();

            var mouseDeviceMock = new Mock<IMouseDevice>();
            mouseDeviceMock.Expect(m => m.IsButtonPressed(MouseButton.Left)).Returns(true);
            var mouseManager = new MouseManager(mouseDeviceMock.Object);
            for (var i = 0; i < 10; i++)
            {
                mouseManager.HandleButtonSignals(mouse);
            }

            Assert.That(mouse.LeftButton.IsEdge, Is.False);
        }
Example #3
0
        private static MouseButtonState GetMouseButtonStateObjectFromMouse(Mouse mouse, MouseButton button)
        {
            switch( button )
            {
                case MouseButton.Left:
                    {
                        return mouse.LeftButton;
                    }

                case MouseButton.Right:
                    {
                        return mouse.RightButton;
                    }
            }
            return null;
        }
Example #4
0
        public void MousePositionsShouldGetUpdatedFromDevice()
        {
            var mouse = new Mouse();

            var random = new Random();
            var expectedXPosition = random.Next();
            var expectedYPosition = random.Next();

            var mouseDeviceMock = new Mock<IMouseDevice>();
            mouseDeviceMock.Expect(m => m.GetXPosition()).Returns(expectedXPosition);
            mouseDeviceMock.Expect(m => m.GetYPosition()).Returns(expectedYPosition);

            var mouseManager = new MouseManager(mouseDeviceMock.Object);
            mouseManager.HandlePosition(mouse);

            Assert.That(mouse.XPosition, Is.EqualTo(expectedXPosition));
            Assert.That(mouse.YPosition, Is.EqualTo(expectedYPosition));
        }
Example #5
0
        public void HandleButtonSignals(Mouse mouse)
        {
            var buttons = EnumHelper.GetValues<MouseButton>();
            foreach( var button in buttons )
            {
                var mouseButtonState = GetMouseButtonStateObjectFromMouse(mouse, button);
                if (null != mouseButtonState)
                {

                    /*
                    psInput->vEdge = (~psInput->vPrev) & (psInput->vCurrent);
                    psInput->vRepeat = psInput->vEdge;
                     * */

                    mouseButtonState.IsPreviousEdge = mouseButtonState.IsDown;
                    mouseButtonState.IsDown = _mouseDevice.IsButtonPressed(button);
                    mouseButtonState.IsEdge = false;
                    mouseButtonState.IsEdge = (mouseButtonState.IsEdge^!mouseButtonState.IsPreviousEdge) & (mouseButtonState.IsDown);
                }
            }
        }
Example #6
0
 public void HandlePosition(Mouse mouse)
 {
     mouse.XPosition = _mouseDevice.GetXPosition();
     mouse.YPosition = _mouseDevice.GetYPosition();
 }