Exemplo n.º 1
0
        protected override void UpdateGamePadStates()
        {
            axisValues = Glfw.GetJoystickAxes(GetJoystickByNumber());
            var buttons = Glfw.GetJoystickButtons(GetJoystickByNumber());

            if (buttons != null && buttons.Length >= 10)
            {
                UpdateAllButtons(buttons);
            }
        }
Exemplo n.º 2
0
        static void DrawJoystick(int index, int x, int y, int width, int height)
        {
            int axisHeight   = 3 * height / 4;
            int buttonHeight = height / 4;

            var axes = Glfw.GetJoystickAxes(m_Joysticks[index]);

            if (axes != null)
            {
                int axis_width = width / axes.Length;

                for (int i = 0; i < axes.Length; i++)
                {
                    float value = axes[i] / 2f + 0.5f;

                    Gl.Color3(0.3f, 0.3f, 0.3f);
                    Gl.Rect(x + i * axis_width,
                            y,
                            x + (i + 1) * axis_width,
                            y + axisHeight);

                    Gl.Color3(1f, 1f, 1f);
                    Gl.Rect(x + i * axis_width,
                            y + (int)(value * (axisHeight - 5)),
                            x + (i + 1) * axis_width,
                            y + 5 + (int)(value * (axisHeight - 5)));
                }
            }

            var buttons = Glfw.GetJoystickButtons(m_Joysticks[index]);

            if (buttons != null)
            {
                int button_width = width / buttons.Length;

                for (int i = 0; i < buttons.Length; i++)
                {
                    if (buttons[i])
                    {
                        Gl.Color3(1f, 1f, 1f);
                    }
                    else
                    {
                        Gl.Color3(0.3f, 0.3f, 0.3f);
                    }

                    Gl.Rect(x + i * button_width,
                            y + axisHeight,
                            x + (i + 1) * button_width,
                            y + axisHeight + buttonHeight);
                }
            }
        }
Exemplo n.º 3
0
        static void JoystickCallback(Glfw.Joystick joy, Glfw.ConnectionEvent evt)
        {
            if (evt == Glfw.ConnectionEvent.Connected)
            {
                var axes    = Glfw.GetJoystickAxes(joy);
                var buttons = Glfw.GetJoystickButtons(joy);

                Log("{0} at {1}: Joystick {2} ({3}) was connected with {4} axes and {5} buttons",
                    m_Counter++, Glfw.GetTime(),
                    joy,
                    Glfw.GetJoystickName(joy),
                    axes.Length,
                    buttons.Length);
            }
            else
            {
                Log("{0} at {1}: Joystick {2} was disconnected",
                    m_Counter++, Glfw.GetTime(), joy);
            }
        }
Exemplo n.º 4
0
        static void JoystickCallback(Glfw.Joystick joy, Glfw.ConnectionEvent evt)
        {
            if (evt == Glfw.ConnectionEvent.Connected)
            {
                var axisCount   = Glfw.GetJoystickAxes(joy).Length;
                var buttonCount = Glfw.GetJoystickButtons(joy).Length;

                Log("Found joystick {0} named \'{1}\' with {2} axes, {3} buttons\n",
                    (int)joy + 1,
                    Glfw.GetJoystickName(joy),
                    axisCount,
                    buttonCount);

                m_Joysticks.Add(joy);
            }
            else if (evt == Glfw.ConnectionEvent.Disconnected)
            {
                m_Joysticks.Remove(joy);
                Log("Lost joystick {0}", (int)joy + 1);
            }
        }
Exemplo n.º 5
0
        public void Update()
        {
            // Check if still connected.
            Connected = Glfw.JoystickPresent(Id) == 1;

            if (!Connected)
            {
                return;
            }

            _axisLastFrame = _axisThisFrame;
            _axisThisFrame = Glfw.GetJoystickAxes(Id, out int axisC);

            _buttonLastFrame = _buttonThisFrame;
            _buttonThisFrame = Glfw.GetJoystickButtons(Id, out int buttonC);

            // If the number of axes or buttons doesn't match the expected amount - the controller is not XInput.
            if (axisC != _expectedAxis || buttonC != _expectedButtons)
            {
                Connected = false;
            }
        }