예제 #1
0
        public unsafe GlfwInputContext(IView window)
        {
            void OnConnectionChanged(IInputDevice a, bool b) => ConnectionChanged?.Invoke(a, b);

            if (!(window is GlfwWindow))
            {
                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 _mice)
                {
                    updatable.Update();
                }

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

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

            _window = window;
        }
예제 #2
0
        public override unsafe void CoreDispose()
        {
            GlfwInputPlatform.UnregisterWindow((WindowHandle *)Handle, _subscribers);
            foreach (var gamepad in _gamepads)
            {
                gamepad.Dispose();
            }

            foreach (var joystick in _joysticks)
            {
                joystick.Dispose();
            }

            foreach (var mouse in _mice)
            {
                mouse.Dispose();
            }
        }
예제 #3
0
        public unsafe void Dispose()
        {
            _window.Update -= _update;
            GlfwInputPlatform.UnregisterWindow((WindowHandle *)Handle, _subscribers);
            foreach (var gamepad in _gamepads)
            {
                gamepad.Dispose();
            }

            foreach (var joystick in _joysticks)
            {
                joystick.Dispose();
            }

            foreach (var mouse in _mice)
            {
                mouse.Dispose();
            }
        }