1use std::sync::{Arc, Mutex};
3
4use fennel_common::events::{
5 KeyboardEvent, MouseClickEvent, MouseMotionEvent, MouseWheelEvent, WindowEventHandler,
6};
7
8use crate::{audio::Audio, graphics::{Graphics, HasWindow}, resources::ResourceManager};
9
10pub mod audio;
12pub mod events;
14pub mod graphics;
16pub mod resources;
18mod tests;
20
21unsafe impl Send for Window {}
22unsafe impl Sync for Window {}
23
24pub struct Window {
29 pub graphics: Graphics,
31 pub audio: Audio,
33 pub resource_manager: Arc<Mutex<ResourceManager>>,
35}
36
37impl Window {
38 pub fn new(graphics: Graphics, resource_manager: Arc<Mutex<ResourceManager>>) -> Window {
47 Window {
48 graphics,
49 audio: Audio::new(),
50 resource_manager,
51 }
52 }
53}
54
55impl HasWindow for Window {
56 fn window_mut(&mut self) -> &mut Self {
57 self
58 }
59}
60
61pub struct CoreHandler;
62#[async_trait::async_trait]
63impl WindowEventHandler for CoreHandler {
64 type Host = Window;
65
66 fn update(&self, _window: &mut Window) -> anyhow::Result<()> {
67 Ok(())
68 }
69
70 fn draw(&self, _window: &mut Window) -> anyhow::Result<()> {
71 Ok(())
72 }
73
74 fn key_down_event(&self, _window: &mut Window, _event: KeyboardEvent) -> anyhow::Result<()> {
75 Ok(())
76 }
77
78 fn key_up_event(&self, _window: &mut Window, _event: KeyboardEvent) -> anyhow::Result<()> {
79 Ok(())
80 }
81
82 fn mouse_motion_event(
83 &self,
84 _window: &mut Window,
85 _event: MouseMotionEvent,
86 ) -> anyhow::Result<()> {
87 Ok(())
88 }
89
90 fn mouse_button_down_event(
91 &self,
92 _window: &mut Window,
93 _event: MouseClickEvent,
94 ) -> anyhow::Result<()> {
95 Ok(())
96 }
97
98 fn mouse_button_up_event(
99 &self,
100 _window: &mut Window,
101 _event: MouseClickEvent,
102 ) -> anyhow::Result<()> {
103 Ok(())
104 }
105
106 fn mouse_wheel_event(
107 &self,
108 _window: &mut Window,
109 _event: MouseWheelEvent,
110 ) -> anyhow::Result<()> {
111 Ok(())
112 }
113}
114
115pub type BoxedCoreHandler = Box<dyn WindowEventHandler<Host = Window> + Send + Sync>;