Module: GLFW::Joystick

Defined in:
lib/glfw/stubs/joystick.rb

Overview

Provides methods for interacting and querying joystick and gamepad peripherals.

Class Method Summary collapse

Class Method Details

.axes(jid) ⇒ Array<Float>

Returns the values of all axes of the specified joystick. Each element in the array is a value between -1.0 and 1.0.

Parameters:

  • jid (Integer)

    The joystick index to query.

Returns:

  • (Array<Float>)

    an array where each element represents the joystick axis at the same index



84
85
# File 'lib/glfw/stubs/joystick.rb', line 84

def self.axes(jid)
end

.buttons(jid) ⇒ Array<Boolean>

Returns the state of all buttons of the specified joystick.

Parameters:

  • jid (Integer)

    The joystick index to query.

Returns:

  • (Array<Boolean>)

    an array where each element represents the joystick button at the same index, whose value if either true (pressed) or false (released).



74
75
# File 'lib/glfw/stubs/joystick.rb', line 74

def self.buttons(jid)
end

.gamepad?(jid) ⇒ Boolean

Returns whether the specified joystick is both present and has a gamepad mapping.

Parameters:

  • jid (Integer)

    The joystick index to query.

Returns:

  • (Boolean)

    true if joystick is detected and it has gamepad mappings, otherwise false



53
54
# File 'lib/glfw/stubs/joystick.rb', line 53

def self.gamepad?(jid)
end

.gamepad_name(jid) ⇒ String?

Returns the human-readable name of the gamepad from the gamepad mapping assigned to the specified joystick.

Parameters:

  • jid (Integer)

    The joystick index to query.

Returns:

  • (String?)

    the UTF-8 encoded name of the gamepad, or nil if the joystick is not present, does not have a mapping or an error occurred.



34
35
# File 'lib/glfw/stubs/joystick.rb', line 34

def self.gamepad_name(jid)
end

.gamepad_state(jid) ⇒ GamepadState?

Retrieves the state of the specified joystick remapped to an Xbox-like gamepad.

Parameters:

  • jid (Integer)

    The joystick index to query.

Returns:

  • (GamepadState?)

    the gamepad input state of the joystick or nil if an error occurred.



14
15
# File 'lib/glfw/stubs/joystick.rb', line 14

def self.gamepad_state(jid)
end

.guid(jid) ⇒ String?

Returns the SDL compatible GUID, as a UTF-8 encoded hexadecimal string, of the specified joystick The GUID is what connects a joystick to a gamepad mapping. A connected joystick will always have a GUID even if there is no gamepad mapping assigned to it.

Parameters:

  • jid (Integer)

    The joystick index to query.

Returns:

  • (String?)

    The UTF-8 encoded GUID of the joystick, or nil if the joystick is not present or an error occurred.



64
65
# File 'lib/glfw/stubs/joystick.rb', line 64

def self.guid(jid)
end

.hats(jid) ⇒ Array<Boolean>

Returns the state of all hats of the specified joystick.

Parameters:

  • jid (Integer)

    The joystick index to query.

Returns:

  • (Array<Boolean>)

    an array where each element represents the joystick hats at the same index, whose value if either true (pressed) or false (released).



94
95
# File 'lib/glfw/stubs/joystick.rb', line 94

def self.hats(jid)
end

.name(jid) ⇒ String?

Returns the name, encoded as UTF-8, of the specified joystick.

Parameters:

  • jid (Integer)

    The joystick index to query.

Returns:

  • (String?)

    the UTF-8 encoded name of the gamepad, or nil if the joystick is not present, does not have a mapping or an error occurred.



24
25
# File 'lib/glfw/stubs/joystick.rb', line 24

def self.name(jid)
end

.self.on_connection {|connected| ... } ⇒ Proc? .self.on_connectionProc?

Returns the previous callback that was set, or nil if none existed.

Overloads:

  • .self.on_connection {|connected| ... } ⇒ Proc?

    When called with a block, sets a callback to be invoked when the connection state of a joystick is changed.

    Yield Parameters:

    • connected (Boolean)

      true if device was connected, otherwise false if disconectted.

  • .self.on_connectionProc?

    When called without a block, clears any callback that is set.

Returns:

  • (Proc?)

    the previous callback that was set, or nil if none existed.



122
123
# File 'lib/glfw/stubs/joystick.rb', line 122

def self.on_connection
end

.present?(jid) ⇒ Boolean

Note:

There is no need to call this function before other functions that accept a joystick ID, as they all check for presence before performing any other work.

Returns whether the specified joystick is present.

Parameters:

  • jid (Integer)

    The joystick index to query.

Returns:

  • (Boolean)

    true if joystick is detected, otherwise false.



44
45
# File 'lib/glfw/stubs/joystick.rb', line 44

def self.present?(jid)
end

.update_mappings(*mapping) ⇒ Integer

Note:

The parser supports standard SDL gamepad mappings.

Parses the specified ASCII encoded string(s) and updates the internal list with any gamepad mappings it finds. This string may contain either a single gamepad mapping or many mappings separated by newlines.

If there is already a gamepad mapping for a given GUID in the internal list, it will be replaced by the one passed to this function. If the library is terminated and re-initialized the internal list will revert to the built-in default.

Parameters:

  • mapping (String, Array<String>)

    One or more mappings to update.

Returns:

  • (Integer)

    the number of mappings that were updated.



110
111
# File 'lib/glfw/stubs/joystick.rb', line 110

def self.update_mappings(*mapping)
end