Struct sdl2::EventSubsystem [] [src]

pub struct EventSubsystem { /* fields omitted */ }

Methods

impl EventSubsystem
[src]

Removes all events in the event queue that match the specified event type.

Removes all events in the event queue that match the specified type range.

Reads the events at the front of the event queue, until the maximum amount of events is read.

The events will not be removed from the queue.

Example

use sdl2::event::Event;

let sdl_context = sdl2::init().unwrap();
let event_subsystem = sdl_context.event().unwrap();

// Read up to 1024 events
let events: Vec<Event> = event_subsystem.peek_events(1024);

// Print each one
for event in events {
    println!("{:?}", event);
}

Pushes an event to the event queue.

Register a custom SDL event.

When pushing a user event, you must make sure that the type_ field is set to a registered SDL event number.

The code, data1, and data2 fields can be used to store user defined data.

See the SDL documentation for more information.

Example

let sdl = sdl2::init().unwrap();
let ev = sdl.event().unwrap();

let custom_event_type_id = unsafe { ev.register_event().unwrap() };
let event = sdl2::event::Event::User {
   timestamp: 0,
   window_id: 0,
   type_: custom_event_type_id,
   code: 456,
   data1: 0x1234 as *mut ::sdl2::libc::c_void,
   data2: 0x5678 as *mut ::sdl2::libc::c_void,
};

ev.push_event(event);

Registers custom SDL events.

Returns an error, if no more user events can be created.

Register a custom event

It returns an error when the same type is registered twice.

Example

See push_custom_event

Push a custom event

If the event type T was not registered using register_custom_event, this method will panic.

Example: pushing and receiving a custom event

struct SomeCustomEvent {
    a: i32
}

let sdl = sdl2::init().unwrap();
let ev = sdl.event().unwrap();
let mut ep = sdl.event_pump().unwrap();

ev.register_custom_event::<SomeCustomEvent>().unwrap();

let event = SomeCustomEvent { a: 42 };

ev.push_custom_event(event);

let received = ep.poll_event().unwrap(); // or within a for event in ep.poll_iter()
if received.is_user_event() {
    let e2 = received.as_user_event_type::<SomeCustomEvent>().unwrap();
    assert_eq!(e2.a, 42);
}

impl EventSubsystem
[src]

Obtain an SDL context.

Trait Implementations

impl Sync for EventSubsystem
[src]