use std::{
path::{Path, PathBuf},
sync::{Arc, Mutex},
};
use fennel_core::{events::{self, WindowEventHandler}, graphics::{self, Graphics}, resources::ResourceManager, Window};
use sdl3::pixels::Color;
struct State;
#[async_trait::async_trait]
impl WindowEventHandler for State {
fn update(&self, _window: &mut Window) -> anyhow::Result<()> {
Ok(())
}
fn draw(&mut self, window: &mut Window) -> anyhow::Result<()> {
window.graphics.canvas.set_draw_color(Color::RGB(0, 0, 0));
window.graphics.canvas.clear();
window
.graphics
.draw_image("assets/example.png".to_string(), (0.0, 0.0))
.expect("failed to draw an image");
window.graphics.canvas.present();
Ok(())
}
}
#[tokio::main]
async fn main() {
let resource_manager = Arc::new(Mutex::new(ResourceManager::new()));
let graphics = graphics::Graphics::new(
String::from("my cool window"),
(500, 500),
resource_manager.clone(),
|graphics| { resource_manager.lock().unwrap().load_dir(PathBuf::from("assets"), graphics).unwrap();
}
).unwrap();
let mut window = Window::new(graphics, resource_manager.clone());
let handler: &'static mut dyn WindowEventHandler = {
let boxed = Box::new(State);
Box::leak(boxed) as &'static mut dyn WindowEventHandler
};
events::run(&mut window, handler).await;
}