[][src]Struct riddle_input::InputSystem

pub struct InputSystem { /* fields omitted */ }

The Riddle input system core state, along with InputMainThreadState.

This stores the thread safe input state which can be queried to inspect the status of input devices. It is updated by InputMainThreadState::process_input.

Implementations

impl InputSystem[src]

pub fn new(
    sys_events: &EventPub<PlatformEvent>
) -> Result<(InputSystemHandle, InputMainThreadState), InputError>
[src]

Create the input system, initializing any input device libraries needed.

This will be instantiated automatically if riddle is being used.

Returns a pair of objects, one of which is the system state which is like most other riddle system states - it is thread safe, stored in RiddleState and is the main means by which client code interacts with the system.

The other return value stores the portion of this object's state that should stay on the main thread - InputMainThreadState.

pub fn take_input_events(&self) -> Vec<InputEvent>[src]

Collect any buffered InputEvents emitted by the input system.

This clears the system's buffer, so should only be called from a single location.

Do not call this if you are using riddle. riddle manages taking these events and passing them to the main application closure.

Example

let platform_events: EventPub<PlatformEvent> = EventPub::new();
let (input_system, mut main_thread_state) = InputSystem::new(&platform_events)?;

// Platform dispatches an event, and input processes it
platform_events.dispatch(PlatformEvent::MouseButtonDown{
    window: WindowId::new(0),
    button: MouseButton::Left});
main_thread_state.process_input();

// Having processed the incoming platform event, there is now an InputEvent available
let input_events: Vec<InputEvent> = input_system.take_input_events();

assert_eq!(vec![InputEvent::MouseButtonDown{
    window: WindowId::new(0),
    button: MouseButton::Left
}], input_events);

pub fn mouse_pos(&self, window: WindowId) -> LogicalPosition[src]

Query the cursor position with respect to a given window.

If no mouse position infomation is available for the given window, the position will be (0,0)

Example

// The initial mouse position is (0,0)
assert_eq!(LogicalPosition{ x: 0, y: 0}, input_system.mouse_pos(window));

// The platform system emits cursor move events
// [..]

// The reported mouse position has changed
assert_ne!(LogicalPosition{ x: 0, y: 0}, input_system.mouse_pos(window));

pub fn is_key_down(&self, window: WindowId, scancode: Scancode) -> bool[src]

Query the keyboard scancode state with respect to a given window. See Scancode for details on what a scancode represents.

If no keyboard infomation is available for the given window, the button will be considered to not be down.

Example

// The initial key state is that the button is unpressed
assert_eq!(false, input_system.is_key_down(window, Scancode::Escape));

// The platform system emits key press event
// [..]

// The reported key state has changed
assert_eq!(true, input_system.is_key_down(window, Scancode::Escape));

pub fn is_vkey_down(&self, window: WindowId, vkey: VirtualKey) -> bool[src]

Query the keyboard virtual key state with respect to a given window. See VirtualKey for details on what a virtual key represents.

If no keyboard infomation is available for the given window, the button will be considered to not be down.

Example

// The initial key state is that the button is unpressed
assert_eq!(false, input_system.is_vkey_down(window, VirtualKey::Escape));

// The platform system emits key press event
// [..]

// The reported key state has changed
assert_eq!(true, input_system.is_vkey_down(window, VirtualKey::Escape));

pub fn keyboard_modifiers(&self, window: WindowId) -> KeyboardModifiers[src]

The current state of keyboard modifiers with respect to a given window.

If no state has been set all modifiers are considered unset.

Example

// The initial mouse position is (0,0)
assert_eq!(false, input_system.keyboard_modifiers(window).ctrl);

// The platform system emits key down event for Ctrl key
// [..]

// The reported mouse position has changed
assert_eq!(true, input_system.keyboard_modifiers(window).ctrl);

pub fn is_gamepad_button_down(
    &self,
    gamepad: GamePadId,
    button: GamePadButton
) -> bool
[src]

Check if a specific button is pressed for a given gamepad.

If no state has been set all buttons are considered not to be down.

// The initial button state is false
assert_eq!(false, input_system.is_gamepad_button_down(gamepad, GamePadButton::North));

// Controller button press events are processed
// [..]

// The reported button state has changed
assert_eq!(true, input_system.is_gamepad_button_down(gamepad, GamePadButton::North));

Trait Implementations

impl CloneHandle for InputSystem[src]

type Handle = InputSystemHandle

The type which represents a strong reference, and which may be dereferenced as Self. Read more

type WeakHandle = InputSystemWeak

The type which represents a weak reference.

Auto Trait Implementations

impl RefUnwindSafe for InputSystem

impl Send for InputSystem

impl Sync for InputSystem

impl Unpin for InputSystem

impl UnwindSafe for InputSystem

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.