Ejemplo n.º 1
0
        public unsafe GlfwInputContext(GlfwWindow window)
        {
            void OnConnectionChanged(IInputDevice a, bool b) => ConnectionChanged?.Invoke(a, b);

            if (window is null)
            {
                throw new ArgumentNullException
                          (nameof(window), "Attempted to create input context for null or non-GLFW window.");
            }

            Handle = window.Handle;
            for (var i = 0; i < _gamepads.Length; i++)
            {
                _gamepads[i] = new GlfwGamepad(i)
                {
                    OnConnectionChanged = OnConnectionChanged
                };
            }

            for (var i = 0; i < _joysticks.Length; i++)
            {
                _joysticks[i] = new GlfwJoystick(i)
                {
                    OnConnectionChanged = OnConnectionChanged
                };
            }

            _subscribers[0] = _keyboards[0] = new GlfwKeyboard();
            _subscribers[1] = _mice[0] = new GlfwMouse();

            Gamepads  = new IsConnectedWrapper <GlfwGamepad>(_gamepads);
            Joysticks = new IsConnectedWrapper <GlfwJoystick>(_joysticks);
            Keyboards = _keyboards;
            Mice      = _mice;

            GlfwInputPlatform.RegisterWindow((WindowHandle *)Handle, _subscribers);
            window.Update += _update = _ =>
            {
                foreach (var updatable in _gamepads)
                {
                    updatable.Update();
                }

                foreach (var updatable in _joysticks)
                {
                    updatable.Update();
                }
            };

            _window = window;
        }
Ejemplo n.º 2
0
        public GlfwInputContext(GlfwWindow window)
        {
            Handle  = window.Handle;
            _window = window;
            InputHandler.RegisterContext(this);

            // initialize auto-properties
            Gamepads  = new GlfwGamepadCollection(this);
            Joysticks = new GlfwJoystickCollection(this);
            Keyboards = new GlfwKeyboardCollection(this);
            Mice      = new GlfwMouseCollection(this);

            // initialize joysticks
            _joysticks = new List <GlfwJoystick>(Enumerable.Range(0, 16).Select(i => new GlfwJoystick(i)));
            _gamepads  = new List <GlfwGamepad>(Enumerable.Range(0, 16).Select(i => new GlfwGamepad(i)));
            _keyboard  = new GlfwKeyboard(this);
            _mouse     = new GlfwMouse(this);
        }