1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
use std::ffi::CString; use std::ptr; use video::Window; use get_error; use SdlResult; use util::CStringExt; use sys::messagebox as ll; bitflags! { flags MessageBoxFlag: u32 { const MESSAGEBOX_ERROR = ll::SDL_MESSAGEBOX_ERROR, const MESSAGEBOX_WARNING = ll::SDL_MESSAGEBOX_WARNING, const MESSAGEBOX_INFORMATION = ll::SDL_MESSAGEBOX_INFORMATION } } pub fn show_simple_message_box(flags: MessageBoxFlag, title: &str, message: &str, window: Option<&Window>) -> SdlResult<()> { let result = unsafe { let title = CString::new(title).remove_nul(); let message = CString::new(message).remove_nul(); ll::SDL_ShowSimpleMessageBox(flags.bits(), title.as_ptr(), message.as_ptr(), window.map_or(ptr::null_mut(), |win| win.raw())) } == 0; if result { Ok(()) } else { Err(get_error()) } }