Add registration of user events.

This commit is contained in:
Maarten Hoogendoorn
2016-01-29 23:19:25 +01:00
parent 99a216ef96
commit 8d03a3255c
+12
View File
@@ -103,6 +103,18 @@ impl ::EventSubsystem {
}
}
}
/// Registers a custom events.
/// If `Ok(nr) = register_event(2);`, then the caller has sucessfully created the custom events `nr` and `nr + 1`
pub fn register_events(&self, nr: u32) -> SdlResult<u32> {
let result = unsafe { ll::SDL_RegisterEvents(nr as ::libc::c_int) };
const ERR_NR:u32 = ::std::u32::MAX - 1;
match result {
ERR_NR => { Err(ErrorMessage("No more user events can be created; SDL_LASTEVENT reached".to_owned())) },
_ => Ok(result)
}
}
}
/// Types of events that can be delivered.