use graphics::Graphics;
use raii_counter::Counter;
use std::ops::{Deref, DerefMut};
use super::{ApplicationContext, KeyManager, MouseState};
mod handles;
pub use self::handles::SpawnHandles;
mod manager;
pub use self::manager::{DelegateManager, DelegateSpawner};
pub trait Delegate {
fn on_spawn(
&mut self,
_delegate_spawner: &mut DelegateSpawner,
) {}
fn tick(
&mut self,
context: &mut ApplicationContext,
key_manager: &KeyManager,
mouse_state: &MouseState,
delegate_spawner: &mut DelegateSpawner,
);
fn render(&self, graphics: &mut Graphics);
fn render_order(&self) -> i32 { 0 }
}
pub trait SpawnableDelegate : Delegate {
type Handle: Clone;
fn handle(&self) -> Self::Handle;
}
#[derive(Clone)]
pub struct SpawnHandle<H> {
handle: H,
_counter: Counter,
}
impl<H> Deref for SpawnHandle<H> {
type Target = H;
fn deref(&self) -> &H {
&self.handle
}
}
impl<H> DerefMut for SpawnHandle<H> {
fn deref_mut(&mut self) -> &mut H {
&mut self.handle
}
}