void _UpdateDPad(DirectInputDPad dPad, DPadGaugeUC gauge, int dPadIndex) { gauge.Vector.Text = dPad.Vector.ToStringF4(); gauge.Lenght.Text = dPad.Vector.Length().ToString("F4"); #if DEBUG gauge.VectorRaw.Text = //dPad.ParentDevice.RawDPadsStates[dPadIndex].ToString(); dPad.AngleRad.ToString(); #endif _X = Cmn.RangeConversion(-1, 0, DPadGaugeUC.RatioX, dPad.Vector.X); _Y = Cmn.RangeConversion(1, 0, DPadGaugeUC.RatioY, dPad.Vector.Y); gauge.Line.X2 = _X; gauge.Line.Y2 = _Y; gauge.Thumb.Margin = new Thickness(_X - 10d, _Y - 10d, 0d, 0d); if (dPad.Up == ButtonState.Pressed) { gauge.ButtonUp.Background = Brushes.YellowGreen; } else { gauge.ButtonUp.Background = null; } _UpdateButtonIndicator(gauge.ButtonUp, dPad.Up); _UpdateButtonIndicator(gauge.ButtonDown, dPad.Down); _UpdateButtonIndicator(gauge.ButtonLeft, dPad.Left); _UpdateButtonIndicator(gauge.ButtonRight, dPad.Right); }
public void CreateJoyPad(int deadZone) { joypadPresent = false; joyDeadZone = deadZone; // Initialize DirectInput var directInput = new DirectInput(); dPad = new DirectInputDPad(); // if refreshing an old reference, first unacquire joypad if (joypad != null) { joypad.Unacquire(); } // Find a Joystick Guid var joystickGuid = Guid.Empty; foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly)) { joystickGuid = deviceInstance.InstanceGuid; joypadPresent = true; // stop at first break; } // If Joystick not found, throws an error if (joystickGuid == Guid.Empty) { throw new Exception("No joystick found: aborting"); } // Instantiate the joystick joypad = new Joystick(directInput, joystickGuid); // Acquire the joystick joypad.Acquire(); }
public Input2D_GenericController_DPad(DirectInputGamepad parentDevice, int dPadIndex) { ParentDPad = parentDevice.DPads[dPadIndex]; DPadIndex = dPadIndex; }