/// <summary> /// Function to set the state for a button. /// </summary> /// <param name="name">Name of the button.</param> /// <param name="state">State of the button.</param> public void SetButtonState(XI.GamepadButtonFlags name, bool state) { string enumName = name.ToString(); if (Contains(enumName)) { this[enumName] = new JoystickButtonState(enumName, state); } }
/// <summary> /// Function to retrieve the current point of view hat state. /// </summary> /// <param name="state">The state of the d-pad (pov hat).</param> /// <returns>An angle, in degrees representing the direction of the d-pad.</returns> private static float GetPOVState(XI.GamepadButtonFlags state) { // Get POV, which is on the D-Pad and default to a center value. float pov = -1.0f; // Determine direction. if (((state & XI.GamepadButtonFlags.DPadDown) == XI.GamepadButtonFlags.DPadDown) && ((state & XI.GamepadButtonFlags.DPadRight) == XI.GamepadButtonFlags.DPadRight)) { pov = 135.0f; } if (((state & XI.GamepadButtonFlags.DPadDown) == XI.GamepadButtonFlags.DPadDown) && ((state & XI.GamepadButtonFlags.DPadLeft) == XI.GamepadButtonFlags.DPadLeft)) { pov = 225.0f; } if (((state & XI.GamepadButtonFlags.DPadUp) == XI.GamepadButtonFlags.DPadUp) && ((state & XI.GamepadButtonFlags.DPadLeft) == XI.GamepadButtonFlags.DPadLeft)) { pov = 315.0f; } if (((state & XI.GamepadButtonFlags.DPadUp) == XI.GamepadButtonFlags.DPadUp) && ((state & XI.GamepadButtonFlags.DPadRight) == XI.GamepadButtonFlags.DPadRight)) { pov = 45.0f; } switch (state) { case XI.GamepadButtonFlags.DPadDown: pov = 180.0f; break; case XI.GamepadButtonFlags.DPadUp: pov = 0; break; case XI.GamepadButtonFlags.DPadRight: pov = 90.0f; break; case XI.GamepadButtonFlags.DPadLeft: pov = 270.0f; break; } return(pov); }
private XInputButtons _buttonList; // List of buttons for the controller. #endregion #region Methods. /// <summary> /// Function to retrieve the POV data. /// </summary> /// <param name="buttonState">Button data to parse.</param> private void GetPOVData(XI.GamepadButtonFlags buttonState) { // Get POV, which is on the D-Pad and default to a center value. POV = -1; // Determine direction and set POV value which is -1 (for center) or 0..35900. Divide by 100 to retrieve angle. if (((buttonState & XI.GamepadButtonFlags.DPadDown) == XI.GamepadButtonFlags.DPadDown) && ((buttonState & XI.GamepadButtonFlags.DPadRight) == XI.GamepadButtonFlags.DPadRight)) { POV = 13500; } if (((buttonState & XI.GamepadButtonFlags.DPadDown) == XI.GamepadButtonFlags.DPadDown) && ((buttonState & XI.GamepadButtonFlags.DPadLeft) == XI.GamepadButtonFlags.DPadLeft)) { POV = 22500; } if (((buttonState & XI.GamepadButtonFlags.DPadUp) == XI.GamepadButtonFlags.DPadUp) && ((buttonState & XI.GamepadButtonFlags.DPadLeft) == XI.GamepadButtonFlags.DPadLeft)) { POV = 31500; } if (((buttonState & XI.GamepadButtonFlags.DPadUp) == XI.GamepadButtonFlags.DPadUp) && ((buttonState & XI.GamepadButtonFlags.DPadRight) == XI.GamepadButtonFlags.DPadRight)) { POV = 4500; } if (buttonState == XI.GamepadButtonFlags.DPadDown) { POV = 18000; } if (buttonState == XI.GamepadButtonFlags.DPadUp) { POV = 0; } if (buttonState == XI.GamepadButtonFlags.DPadRight) { POV = 9000; } if (buttonState == XI.GamepadButtonFlags.DPadLeft) { POV = 27000; } }