use crate::timer::AppTimer;
use crate::{Backend, WindowBackend};
#[cfg(feature = "audio")]
use notan_audio::Audio;
use notan_input::keyboard::Keyboard;
use notan_input::mouse::Mouse;
use notan_input::touch::Touch;
pub trait AppState {}
impl AppState for () {}
pub struct App {
pub backend: Box<dyn Backend>,
pub mouse: Mouse,
pub keyboard: Keyboard,
pub touch: Touch,
pub system_timer: AppTimer,
pub timer: AppTimer,
#[cfg(feature = "audio")]
pub audio: Audio,
pub(crate) closed: bool,
}
impl App {
pub(crate) fn new(backend: Box<dyn Backend>, #[cfg(feature = "audio")] audio: Audio) -> Self {
let mouse = Default::default();
let keyboard = Default::default();
let touch = Default::default();
Self {
backend,
#[cfg(feature = "audio")]
audio,
mouse,
keyboard,
touch,
system_timer: AppTimer::default(),
timer: AppTimer::default(),
closed: false,
}
}
#[inline]
#[cfg(feature = "links")]
pub fn open_link(&self, url: &str) {
self.backend.open_link(url, false);
}
#[inline]
#[cfg(feature = "links")]
pub fn open_link_new_tab(&self, url: &str) {
self.backend.open_link(url, true);
}
#[inline]
pub fn date_now(&self) -> u64 {
self.backend.system_timestamp()
}
#[inline]
pub fn exit(&mut self) {
self.closed = true;
self.backend.exit();
}
#[inline]
pub fn window(&mut self) -> &mut dyn WindowBackend {
self.backend.window()
}
#[inline]
pub fn backend<T: Backend>(&mut self) -> Result<&mut T, String> {
self.backend
.downcast_mut::<T>()
.ok_or_else(|| "Invalid backend type.".to_string())
}
}