Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/engine/src/core/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ impl ApplicationHandler for Application {
// Applications that redraw continously can render here instead.
self.window.as_ref().unwrap().request_redraw();
}
WindowEvent::Resized(physical_size) => {
self.engine.dispatch(Event::Window(
super::event::window_event::WindowEvent::Resized(
physical_size.width,
physical_size.height,
),
));
}
WindowEvent::KeyboardInput {
device_id: _,
event,
Expand Down Expand Up @@ -152,6 +160,23 @@ impl ApplicationHandler for Application {
),
));
}
WindowEvent::MouseWheel {
device_id: _,
delta,
phase: _,
} => match delta {
winit::event::MouseScrollDelta::LineDelta(
vertical,
horizontal,
) => {
self.engine.dispatch(Event::Mouse(
super::event::mouse_event::MouseEvent::Scroll(
vertical, horizontal,
),
));
}
winit::event::MouseScrollDelta::PixelDelta(_) => (),
},
_ => (),
}
}
Expand Down
7 changes: 4 additions & 3 deletions packages/engine/src/core/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Default for Engine {
// The logger is started here to make sure we have logging always
// available

// We do not want a env_logger during tests
// We do not want an env_logger during tests
#[cfg(not(test))]
{
// Read the env values that configure the logger
Expand Down Expand Up @@ -103,6 +103,7 @@ impl Engine {
match self.data.state {
EngineState::Running => {
self.data.state = EngineState::Stopping;
self.dispatch(Event::Engine(event::EngineEvent::Shutdown));
self.stop();
}
_ => {
Expand All @@ -125,14 +126,14 @@ impl Engine {
pub fn start(&mut self) {
// TODO: there should be something here to start the engine
self.data.state = EngineState::Running;
log::info!("Successfully started engine");
self.dispatch(Event::Engine(event::EngineEvent::Started));
}

/// Internal function that handles the engine's stop.
pub fn stop(&mut self) {
// TODO: there should be something hete to stop the engine
self.data.state = EngineState::Stopped;
log::info!("Successfully stopped engine");
self.dispatch(Event::Engine(event::EngineEvent::Stopped));
}

/// Internal function that updates the engine.
Expand Down
4 changes: 3 additions & 1 deletion packages/engine/src/core/event/mouse_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub enum MouseEvent {
Pressed(MouseButton),
/// The attached `MouseButton` was released.
Released(MouseButton),
/// The mouse was moved
/// The mouse was moved.
Moved(u32, u32),
/// The wheel was moved.
Scroll(f32, f32),
}
5 changes: 4 additions & 1 deletion packages/engine/src/core/event/window_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ use strum::Display;

/// Events produced by a window.
#[derive(Debug, Display)]
pub enum WindowEvent {}
pub enum WindowEvent {
/// The window was resized.
Resized(u32, u32),
}