mod key;
mod sdl;
-use std::sync::Arc;
+use std::rc::Rc;
use narcissus_core::{flags_def, raw_window::AsRawWindow, Upcast};
}
pub trait App {
- fn create_window(&self, desc: &WindowDesc) -> Arc<dyn Window>;
- fn destroy_window(&self, window: Arc<dyn Window>);
+ fn create_window(&self, desc: &WindowDesc) -> Rc<dyn Window>;
+ fn destroy_window(&self, window: Rc<dyn Window>);
- fn window(&self, window_id: WindowId) -> Arc<dyn Window>;
+ fn window(&self, window_id: WindowId) -> Rc<dyn Window>;
fn poll_event(&self) -> Option<Event>;
}
-use std::{collections::HashMap, ffi::CString, mem::MaybeUninit, sync::Arc};
+use std::{collections::HashMap, ffi::CString, mem::MaybeUninit, rc::Rc};
use crate::{App, Button, Event, Key, ModifierFlags, PressedState, Window, WindowId};
}
pub struct SdlApp {
- windows: Mutex<HashMap<WindowId, Arc<SdlWindow>>>,
+ windows: Mutex<HashMap<WindowId, Rc<SdlWindow>>>,
}
impl SdlApp {
}
impl App for SdlApp {
- fn create_window(&self, desc: &crate::WindowDesc) -> Arc<dyn Window> {
+ fn create_window(&self, desc: &crate::WindowDesc) -> Rc<dyn Window> {
let title = CString::new(desc.title).unwrap();
let window = unsafe {
sdl::SDL_CreateWindow(
};
assert!(!window.is_null());
let window_id = WindowId(unsafe { sdl::SDL_GetWindowID(window) } as u64);
- let window = Arc::new(SdlWindow { window });
+ let window = Rc::new(SdlWindow { window });
self.windows.lock().insert(window_id, window.clone());
window
}
- fn destroy_window(&self, window: Arc<dyn Window>) {
+ fn destroy_window(&self, window: Rc<dyn Window>) {
let window_id = window.id();
drop(window);
if let Some(mut window) = self.windows.lock().remove(&window_id) {
- let window = Arc::get_mut(&mut window)
+ let window = Rc::get_mut(&mut window)
.expect("tried to destroy a window while there are outstanding references");
unsafe { sdl::SDL_DestroyWindow(window.window) };
}
Some(e)
}
- fn window(&self, window_id: WindowId) -> Arc<dyn Window> {
+ fn window(&self, window_id: WindowId) -> Rc<dyn Window> {
self.windows.lock().get(&window_id).unwrap().clone()
}
}