xinput/flags/
buttons.rs

1#![allow(deprecated)] // Guide button flags! impl
2
3#[cfg(doc)] use crate::*;
4use bytemuck::{Pod, Zeroable};
5use winapi::um::xinput::*;
6
7
8
9/// \[[microsoft.com](https://learn.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_gamepad#members)\]
10/// XINPUT_GAMEPAD_\*
11///
12/// Bitmask of the device digital buttons of an Xbox 360 style gamepad.
13///
14/// ### See Also
15/// *   [Xbox 360 controller: Layout](https://en.wikipedia.org/wiki/Xbox_360_controller#Layout) (Wikipedia)
16#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
17#[derive(Pod, Zeroable)]
18#[repr(transparent)] pub struct Buttons(u16);
19
20flags! { Buttons => u16; None, DPadUp, DPadDown, DPadLeft, DPadRight, Start, Guide, Back, LeftThumb, RightThumb, LeftShoulder, RightShoulder, A, B, X, Y }
21
22impl Buttons {
23    /// Returns `true` if any button from `buttons` is set in `self`
24    pub fn any_held(&self, buttons: Buttons) -> bool { self.0 & buttons.0 != 0 }
25
26    /// Returns `true` if **all** buttons from `buttons` are set in `self`
27    pub fn all_held(&self, buttons: Buttons) -> bool { self.0 & buttons.0 == buttons.0 }
28}
29
30#[allow(non_upper_case_globals)] impl Buttons {
31    /// No buttons are held.
32    pub const None          : Buttons = Buttons(0);
33
34    /// | Controller    | Where |
35    /// | ------------- | ----- |
36    /// | Xbox 360      | Directional pad on the bottom left of the face
37    /// | Xbox One      | Directional pad on the bottom left of the face
38    pub const DPadUp : Buttons = Buttons(XINPUT_GAMEPAD_DPAD_UP as _);
39
40    /// | Controller    | Where |
41    /// | ------------- | ------ |
42    /// | Xbox 360      | Directional pad on the bottom left of the face
43    /// | Xbox One      | Directional pad on the bottom left of the face
44    pub const DPadDown : Buttons = Buttons(XINPUT_GAMEPAD_DPAD_DOWN as _);
45
46    /// | Controller    | Where |
47    /// | ------------- | ----- |
48    /// | Xbox 360      | Directional pad on the bottom left of the face
49    /// | Xbox One      | Directional pad on the bottom left of the face
50    pub const DPadLeft : Buttons = Buttons(XINPUT_GAMEPAD_DPAD_LEFT as _);
51
52    /// | Controller    | Where |
53    /// | ------------- | ----- |
54    /// | Xbox 360      | Directional pad on the bottom left of the face
55    /// | Xbox One      | Directional pad on the bottom left of the face
56    pub const DPadRight : Buttons = Buttons(XINPUT_GAMEPAD_DPAD_RIGHT as _);
57
58    /// | Controller    | Legend    | Where |
59    /// | ------------- | --------- | ----- |
60    /// | Xbox 360      | Start `ᐅ` | Right button of the middle face cluster
61    /// | Xbox One      | Menu `≡`  | Right button of the middle face cluster
62    pub const Start : Buttons = Buttons(XINPUT_GAMEPAD_START as _);
63
64    /// | Controller    | Legend    | Where |
65    /// | ------------- | --------- | ----- |
66    /// | Xbox 360      | Back `ᐊ` | Left button of the middle face cluster
67    /// | Xbox One      | View `⧉` | Left button of the middle face cluster
68    pub const Back : Buttons = Buttons(XINPUT_GAMEPAD_BACK as _);
69
70    /// | Controller    | Legend    | When  |
71    /// | ------------- | --------- | ----- |
72    /// | Xbox 360      | `L`       | Pressing the left thumbstick into the controller
73    /// | Xbox One      | `L`       | Pressing the left thumbstick into the controller
74    pub const LeftThumb : Buttons = Buttons(XINPUT_GAMEPAD_LEFT_THUMB as _);
75
76    /// | Controller    | Legend    | When  |
77    /// | ------------- | --------- | ----- |
78    /// | Xbox 360      | `R`       | Pressing the right thumbstick into the controller
79    /// | Xbox One      | `R`       | Pressing the right thumbstick into the controller
80    pub const RightThumb : Buttons = Buttons(XINPUT_GAMEPAD_RIGHT_THUMB as _);
81
82    /// | Controller    | Legend    | Where |
83    /// | ------------- | --------- | ----- |
84    /// | Xbox 360      | `LB`      | Top left on the controller
85    /// | Xbox One      | `LB`      | Top left on the controller
86    pub const LeftShoulder : Buttons = Buttons(XINPUT_GAMEPAD_LEFT_SHOULDER as _);
87
88    /// | Controller    | Legend    | Where |
89    /// | ------------- | --------- | ----- |
90    /// | Xbox 360      | `RB`      | Top right on the controller
91    /// | Xbox One      | `RB`      | Top right on the controller
92    pub const RightShoulder : Buttons = Buttons(XINPUT_GAMEPAD_RIGHT_SHOULDER as _);
93
94    #[cfg(doc)]
95    /// ❌ **NOTE** ❌ Not actually exposed by XInput as [`Buttons`], see [`Gamepad::left_trigger`] instead.
96    ///
97    /// | Controller    | Legend    | Where |
98    /// | ------------- | --------- | ----- |
99    /// | Xbox 360      | `LT`      | Under the top left of the controller
100    /// | Xbox One      | `LT`      | Under the top left of the controller
101    pub const LeftTrigger : () = ();
102
103    #[cfg(doc)]
104    /// ❌ **NOTE** ❌ Not actually available as part of [`Buttons`], see [`Gamepad::right_trigger`] instead.
105    ///
106    /// | Controller    | Legend    | Where |
107    /// | ------------- | --------- | ----- |
108    /// | Xbox 360      | `RT`      | Under the top right on the controller
109    /// | Xbox One      | `RT`      | Under the top right on the controller
110    pub const RightTrigger : () = ();
111
112    /// ⚠️ **NOTE** ⚠️ This undocumented button is not returned by most APIs, being reserved for system software.
113    ///
114    /// Specifically, you must use the undocumented `XInputGetStateEx` function (same API as [`XInputGetState`](https://learn.microsoft.com/en-us/windows/win32/api/xinput/nf-xinput-xinputgetstate)?) to ever retrieve this value.
115    /// Additionally, this is generally meant to be reserved by the system software.
116    /// Windows, Steam, and other store apps all hook this globally regardless of what app/window has focus.
117    ///
118    /// | Controller    | Legend    | Where |
119    /// | ------------- | --------- | ----- |
120    /// | Xbox 360      | Guide     | Center of the middle face cluster.
121    /// | Xbox One      | Xbox      | Center of the middle face cluster.
122    ///
123    /// #### Conflicting Software: Xbox Game Bar (Windows 8+)
124    ///
125    /// To disable:
126    /// *   Launch `Xbox Game Bar` from the start menu
127    /// *   Open `Settings` (Gear icon on the right of the top menu bar)
128    /// *   Under `Shortcuts` > `Controller`,
129    /// *   Unselect `Open Xbox Game Bar using (X) button on a controller`
130    ///
131    /// #### Conflicting Software: Steam
132    ///
133    /// To disable, close Steam, or:
134    /// *   Open Steam's Settings
135    ///     *   `Settings` after right clicking the Steam system tray icon, or
136    ///     *   `Steam` > `Settings` in Steam's menu bar
137    /// *   Under `Controller` > `Guide Button Chord Configuration`:
138    ///     *   Choose `Browse Configs`
139    ///     *   Select `Templates` > `Gamepad` (inert/do-nothing template)
140    /// *   Under `Controller` > `General Controller Settings`:
141    ///     *   Disable `Guide Button Focuses Steam`
142    ///
143    #[cfg(feature = "undocumented")] #[cfg_attr(doc_cfg, doc(cfg(feature = "undocumented")))]
144    pub const Guide : Buttons = Buttons(1 << 10);
145
146    #[cfg(not(feature = "undocumented"))]
147    pub(crate) const Guide : Buttons = Buttons(1 << 10);
148
149    /// Typically synonymous select/accept in menus on Xbox 360 style controllers/games/console.
150    ///
151    /// | Controller    | Legend    | Where |
152    /// | ------------- | --------- | ----- |
153    /// | Xbox 360      | Green A   | Bottom button of the right face cluster
154    /// | Xbox One      | A         | Bottom button of the right face cluster
155    pub const A : Buttons = Buttons(XINPUT_GAMEPAD_A as _);
156
157    /// Typically synonymous back/cancel in menus on Xbox 360 style controllers/games/console.
158    ///
159    /// | Controller    | Legend    | Where |
160    /// | ------------- | --------- | ----- |
161    /// | Xbox 360      | Red B     | Right button of the right face cluster
162    /// | Xbox One      | B         | Right button of the right face cluster
163    pub const B : Buttons = Buttons(XINPUT_GAMEPAD_B as _);
164
165    /// | Controller    | Legend    | Where |
166    /// | ------------- | --------- | ----- |
167    /// | Xbox 360      | Blue X    | Left button of the right face cluster
168    /// | Xbox One      | X         | Left button of the right face cluster
169    pub const X : Buttons = Buttons(XINPUT_GAMEPAD_X as _);
170
171    /// | Controller    | Legend    | Where |
172    /// | ------------- | --------- | ----- |
173    /// | Xbox 360      | Yellow Y  | Top button of the right face cluster
174    /// | Xbox One      | Y         | Top button of the right face cluster
175    pub const Y : Buttons = Buttons(XINPUT_GAMEPAD_Y as _);
176}
177
178
179
180//#cpp2rust XINPUT_GAMEPAD_DPAD_UP          = xinput::Buttons::DPadUp
181//#cpp2rust XINPUT_GAMEPAD_DPAD_DOWN        = xinput::Buttons::DPadDown
182//#cpp2rust XINPUT_GAMEPAD_DPAD_LEFT        = xinput::Buttons::DPadLeft
183//#cpp2rust XINPUT_GAMEPAD_DPAD_RIGHT       = xinput::Buttons::DPadRight
184//#cpp2rust XINPUT_GAMEPAD_START            = xinput::Buttons::Start
185//#cpp2rust XINPUT_GAMEPAD_BACK             = xinput::Buttons::Back
186//#cpp2rust XINPUT_GAMEPAD_LEFT_THUMB       = xinput::Buttons::LeftThumb
187//#cpp2rust XINPUT_GAMEPAD_RIGHT_THUMB      = xinput::Buttons::RightThumb
188//#cpp2rust XINPUT_GAMEPAD_LEFT_SHOULDER    = xinput::Buttons::LeftShoulder
189//#cpp2rust XINPUT_GAMEPAD_RIGHT_SHOULDER   = xinput::Buttons::RightShoulder
190//#cpp2rust XINPUT_GAMEPAD_A                = xinput::Buttons::A
191//#cpp2rust XINPUT_GAMEPAD_B                = xinput::Buttons::B
192//#cpp2rust XINPUT_GAMEPAD_X                = xinput::Buttons::X
193//#cpp2rust XINPUT_GAMEPAD_Y                = xinput::Buttons::Y