Beispiel #1
0
 /// <summary>
 /// Create a new base instance of an input device. The device manager
 /// needs to be passed in for updates.
 /// </summary>
 /// <param name="deviceManager">The device manager that owns this device.</param>
 /// <param name="inputPoller">The poller to check input state from.</param>
 /// <param name="enabled">If the control should start enabled or not.</param>
 protected InputDevice(IInputDeviceManager deviceManager, IInputPoller inputPoller)
 {
     DeviceManager = deviceManager;
     InputPoller   = inputPoller;
     DeviceManager.OnDeviceUpdate += DeviceManager_OnUpdate;
     Enabled = true;
 }
Beispiel #2
0
 /// <summary>
 /// Process the input from the input poller.
 /// </summary>
 ///<param name="inputPoller">The currnet input state checker.</param>
 protected override void Update(IInputPoller inputPoller)
 {
     for (int i = 0, keyHandlerCount = keyHandlers.Count; i < keyHandlerCount; i++)
     {
         keyHandlers[i].Update(inputPoller);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Update this handler using the input state poller
        /// passed in.
        /// </summary>
        /// <param name="inputPoller">The poller to check input state.</param>
        public void Update(IInputPoller inputPoller)
        {
            float value = 0.0f;

            switch (Axis)
            {
            case MouseAxis.Horizontal:
                value = inputPoller.GetAxis("Mouse X");
                break;

            case MouseAxis.Vertical:
                value = inputPoller.GetAxis("Mouse Y");
                break;

            case MouseAxis.ScrollWheel:
                value = inputPoller.GetAxis("Mouse ScrollWheel");
                break;
            }

            if (value > 0.0001f || value < -0.0001f)
            {
                if (!isActive)
                {
                    isActive = true;
                }
                NotifyListeners(value);
            }
            else if (isActive)
            {
                isActive = false;
                NotifyListeners(0.0f);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Create a new instance of the keyboard device. Only
 /// one is permitted at any time.
 /// </summary>
 /// <param name="deviceManager">The manager that owns this device.</param>
 /// <param name="inputPoller">The poller to check input state from.</param>
 public Keyboard(IInputDeviceManager deviceManager, IInputPoller inputPoller) : base(deviceManager, inputPoller)
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         throw new Exception("There is already a keyboard instance present. Did you call InputModule.GetDevice<Keyboard>()?");
     }
 }
Beispiel #5
0
        /// <summary>
        /// Create a new instance of the mouse device. Only one
        /// is permitted at any time.
        /// </summary>
        /// <param name="deviceManager">The manager that owns this device.</param>
        /// <param name="inputPoller">The poller to check input state from.</param>
        public Mouse(IInputDeviceManager deviceManager, IInputPoller inputPoller) : base(deviceManager, inputPoller)
        {
            if (instance == null)
            {
                instance = this;
            }
            else
            {
                throw new Exception("There is already a mouse instance present. Did you call InputModule.GetDevice<Mouse>()?");
            }

            Cursor = inputPoller.Cursor;
        }
Beispiel #6
0
        /// <summary>
        /// Process the input from the input poller.
        /// </summary>
        /// <param name="inputPoller">Checks the current input state of the engine.</param>
        protected override void Update(IInputPoller inputPoller)
        {
            if (buttonHandlers != null)
            {
                for (int i = 0, buttonHandlerCount = buttonHandlers.Count; i < buttonHandlerCount; i++)
                {
                    buttonHandlers[i].Update(inputPoller);
                }
            }

            if (axisHandlers != null)
            {
                for (int i = 0, axisHandlerCount = axisHandlers.Count; i < axisHandlerCount; i++)
                {
                    axisHandlers[i].Update(inputPoller);
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// Update this handler and propogate the input for any
 /// of it's listeners.
 /// </summary>
 /// <param name="inputPoller">The poller to get current input.</param>
 public void Update(IInputPoller inputPoller)
 {
     if (downListeners != null && inputPoller.IsMouseButtonDown((int)Button))
     {
         for (int i = 0, downCount = downListeners.Count; i < downCount; i++)
         {
             downListeners[i](Button, MouseButtonAction.Down);
         }
     }
     if (pressedListeners != null && inputPoller.IsMouseButtonPressed((int)Button))
     {
         for (int i = 0, pressedCount = pressedListeners.Count; i < pressedCount; i++)
         {
             pressedListeners[i](Button, MouseButtonAction.Pressed);
         }
     }
     if (upListeners != null && inputPoller.IsMouseButtonUp((int)Button))
     {
         for (int i = 0, upCount = upListeners.Count; i < upCount; i++)
         {
             upListeners[i](Button, MouseButtonAction.Up);
         }
     }
 }
Beispiel #8
0
 /// <summary>
 /// Update this handler and propogate the input for any
 /// of it's listeners.
 /// </summary>
 /// <param name="inputPoller">The poller to get current input.</param>
 public void Update(IInputPoller inputPoller)
 {
     if (downListeners != null && inputPoller.IsButtonDown(code))
     {
         for (int i = 0, downCount = downListeners.Count; i < downCount; i++)
         {
             downListeners[i](Key, KeyboardKeyAction.Down);
         }
     }
     if (pressedListeners != null && inputPoller.IsButtonPressed(code))
     {
         for (int i = 0, pressedCount = pressedListeners.Count; i < pressedCount; i++)
         {
             pressedListeners[i](Key, KeyboardKeyAction.Pressed);
         }
     }
     if (upListeners != null && inputPoller.IsButtonUp(code))
     {
         for (int i = 0, upCount = upListeners.Count; i < upCount; i++)
         {
             upListeners[i](Key, KeyboardKeyAction.Up);
         }
     }
 }
Beispiel #9
0
 /// <summary>
 /// Update the state of the controller.
 /// </summary>
 /// <param name="inputPoller">Check current input state from.</param>
 protected abstract void Update(IInputPoller inputPoller);
Beispiel #10
0
 /// <summary>
 /// Create a new instance of the
 /// </summary>
 /// <param name="engine">The parent engine instance.</param>
 public InputModule(GameEngine engine) : base(engine)
 {
     this.inputPoller = engine.GetService <IInputPoller>();
 }