JFLib

ui/pads.rs#

Source: lib/ui/pads.rs

pads -- (G7a part 2) the game pads for the app and the test scripts (plat::pads)

  ui.gamepads()            the pads connected now with the edges of their buttons in this batch;
                           the first call starts watching (plat::pad_watch; a headless run: the
                           script's pads only); refused by the manifest (no `gamepad`), it starts
                           once an ask line is answered yes (policy::gamepad_granted)
  ui.gamepads_watching()   pads are being watched (false where the platform has none)
  pads_event(data)         (E_GAMEPAD) the pads anew, the edges added up until the batch's first
                           pass took them (pads_clear_edges); App::command(UIC_GAMEPAD, data) for a
                           pad that came or went
  sc_pad                   the script command `pad ...` (auto.rs)

Pads belong to the app, not to a window: E_GAMEPAD comes for window 0 and every window's pass sees
the same list.  plat reports pads as nothing held while no window of the app is active.

impl Ui

  • fn gamepads(&mut self) -> &[Gamepad] (G7a) the game pads connected now (plat::Gamepad: index, name, style, the W3C standard layout's buttons with analog values, the sticks in -1 ..= 1 right and down positive, the triggers as buttons PAD_LT / PAD_RT), each with the buttons that went down and up since the last batch (down, up: a tap between two frames is in both). The first call starts watching for pads (plat::pad_watch): they appear in later frames, each change gives a pass, a pad that comes or goes gives App::command(UIC_GAMEPAD, index | PADEV_* << 8). While none of the app's windows has the focus every pad reports nothing held. Windows: XInput (Xbox-compatible pads); Linux: evdev; macOS: GameController; the browser: the Gamepad API (a pad appears after one of its buttons was pressed in the page); Android and iOS: none. An app with a PERMISSIONS file needs its line gamepad (else no pads, PERMDENY gamepad; ask gamepad asks at the first call and watching starts in the frame after a yes). A headless run has the pads of its script (pad ..., no permission: the script's own input)
  • fn gamepads_watching(&self) -> bool (G7a) pads are being watched: ui.gamepads was called and the platform has pads (false on Android and iOS, on Windows without XInput); a headless run: after ui.gamepads

Source: docs/API.md in the JFLib repository.