rust_minifb/src/lib.rs

81 lines
1.5 KiB
Rust
Raw Normal View History

2015-11-23 04:55:38 +11:00
extern crate libc;
#[cfg(target_os = "windows")]
pub mod windows;
2015-11-28 07:25:50 +11:00
pub use windows::*;
/*
2015-11-24 06:21:11 +11:00
#[cfg(target_os = "macos")]
2015-11-23 04:55:38 +11:00
#[link(name = "Cocoa", kind = "framework")]
extern {
fn mfb_open(name: *const c_char, width: c_int, height: c_int) -> c_int;
fn mfb_update(buffer: *mut c_void) -> c_int;
fn mfb_close();
}
/*
2015-11-24 06:21:11 +11:00
#[cfg(target_os = "windows")]
#[link(name = "gdi32")]
extern {
fn mfb_open(name: *const c_char, width: c_int, height: c_int) -> c_int;
fn mfb_update(buffer: *mut c_void) -> c_int;
fn mfb_close();
}
*/
2015-11-24 06:21:11 +11:00
2015-11-24 06:44:21 +11:00
#[cfg(target_os = "linux")]
#[link(name = "X11")]
extern {
fn mfb_open(name: *const c_char, width: c_int, height: c_int) -> c_int;
fn mfb_update(buffer: *mut c_void) -> c_int;
fn mfb_close();
}
2015-11-24 06:21:11 +11:00
2015-11-23 04:55:38 +11:00
///
/// Open up a window
///
#[cfg(any(target_os = "linux", target_os = "mac"))]
2015-11-23 04:55:38 +11:00
pub fn open(name: &str, width: usize, height: usize) -> bool {
let s = CString::new(name).unwrap();
let ret;
unsafe {
ret = mfb_open(s.as_ptr(), width as c_int, height as c_int);
}
match ret {
0 => false,
_ => true,
}
}
///
/// Update
///
#[cfg(any(target_os = "linux", target_os = "mac"))]
2015-11-23 04:55:38 +11:00
pub fn update(buffer: &[u32]) -> bool {
let ret;
unsafe {
ret = mfb_update(transmute(buffer.as_ptr()));
}
if ret < 0 {
return false;
} else {
return true;
}
}
///
/// Close
///
#[cfg(any(target_os = "linux", target_os = "mac"))]
2015-11-23 04:55:38 +11:00
pub fn close() {
unsafe {
mfb_close();
}
}
2015-11-28 07:25:50 +11:00
*/