pub mod sys;
pub use sys::*;
pub mod types;
pub use types::*;
pub mod particle;
pub use particle::*;
#[derive(Clone,PartialEq)]
pub struct LexSdlOptions {
pub vsync: bool,
pub hardware_acceleration: Option<bool>,
pub fullscreen: bool,
pub title: String,
pub window_size: lexlib::Vec2,
pub window_resizable: bool,
pub window_decorations: bool,
}
impl Default for LexSdlOptions {
fn default() -> Self {
Self {
vsync: true,
hardware_acceleration: None,
fullscreen: false,
title: "lexSDL window".to_owned(),
window_size: lexlib::Vec2::new(800,600),
window_resizable: true,
window_decorations: true,
}
}
}
pub fn init(options: &LexSdlOptions) -> Result<(),i32> {
unsafe {
let err = LEXSDL_Init(0);
if err != 0 {
return Err(err);}
}
unsafe {
let err = LEXSDL_InitIMG(0);
if err != 0 {
return Err(err);}
}
unsafe {
let mut window_flags = 0;
if options.fullscreen {
window_flags |= 0x00000001;}
if !options.window_decorations {
window_flags |= 0x00000010;}
#[allow(temporary_cstring_as_ptr)] let err = LEXSDL_CreateWindowSized(std::ffi::CString::new(&*options.title).expect("invalid window title, does it contain a 0 byte?").as_ptr(), options.window_size.x,options.window_size.y, window_flags);
if err.is_null() {
return Err(-1);}
}
unsafe {
let mut renderer_flags = 0;
if options.vsync {
renderer_flags |= 0x00000004;}
match options.hardware_acceleration {
Some(v) => if v {
renderer_flags |= 0x00000002;
} else {
renderer_flags |= 0x00000001;
}
None => {}
}
let err = LEXSDL_CreateRenderer(renderer_flags);
if err.is_null(){
return Err(-2);}
}
Ok(())
}
pub fn quit(){
unsafe{
LEXSDL_Terminate();
LEXSDL_Quit();
}
}
pub fn run<F>(instructions: F)
where F: Fn() {
while unsafe {LEXSDL_EventQuit()} == 0 {
unsafe {
LEXSDL_HandleEvents();
LEXSDL_NewFrame();
}
instructions();
unsafe {
LEXSDL_ShowFrame();
}
}
}