mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2025-01-26 02:36:32 +11:00
55 lines
943 B
Rust
55 lines
943 B
Rust
|
extern crate libc;
|
||
|
use std::ffi::CString;
|
||
|
use std::mem::transmute;
|
||
|
use libc::{c_char, c_int, c_void};
|
||
|
|
||
|
#[link(name = "Cocoa", kind = "framework")]
|
||
|
#[link(name = "minifb_native")]
|
||
|
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();
|
||
|
}
|
||
|
|
||
|
///
|
||
|
/// Open up a window
|
||
|
///
|
||
|
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
|
||
|
///
|
||
|
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
|
||
|
///
|
||
|
pub fn close() {
|
||
|
unsafe {
|
||
|
mfb_close();
|
||
|
}
|
||
|
}
|