Merge pull request #175 from jdeseno/simple-messagebox

Add simple message box
This commit is contained in:
Tony Aldridge
2014-09-02 08:57:05 +01:00
2 changed files with 42 additions and 0 deletions
+1
View File
@@ -39,3 +39,4 @@ pub mod rwops;
pub mod sdl;
pub mod audio;
pub mod version;
pub mod messagebox;
+41
View File
@@ -0,0 +1,41 @@
use video::Window;
use get_error;
use SdlResult;
#[allow(non_camel_case_types)]
pub mod ll {
use libc::{c_int, c_char, uint32_t};
use video::ll::SDL_Window;
pub enum SDL_MessageBoxFlags {
SDL_MESSAGEBOX_ERROR = 0x00000010,
SDL_MESSAGEBOX_WARNING = 0x00000020,
SDL_MESSAGEBOX_INFORMATION = 0x00000040
}
extern "C" {
pub fn SDL_ShowSimpleMessageBox(flags: uint32_t, title: *const c_char, message: *const c_char, window: *const SDL_Window) -> c_int;
}
}
bitflags!(flags MessageBoxFlag: u32 {
static MessageBoxError = ll::SDL_MESSAGEBOX_ERROR as u32,
static MessageBoxWarning = ll::SDL_MESSAGEBOX_WARNING as u32,
static MessageBoxInformation = ll::SDL_MESSAGEBOX_INFORMATION as u32
})
pub fn show_simple_message_box(flags: MessageBoxFlag, title: &str, message: &str, window: Window) -> SdlResult<()> {
let result = unsafe {
title.with_c_str(|title_cstr| {
message.with_c_str(|message_cstr| {
ll::SDL_ShowSimpleMessageBox(flags.bits(), title_cstr, message_cstr, window.raw())
})
})
} == 0;
if result {
Ok(())
} else {
Err(get_error())
}
}