Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

winit 0.30 #35

Merged
merged 1 commit into from
Sep 27, 2024
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
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ image = "0.25"
ash = "0.38"
ash-window = "0.13"
raw-window-handle = "0.6"
winit = "0.29"
winit = "0.30"
gltf = "1.3"
egui = "0.28"
egui-winit = "0.28"
egui-ash-renderer = { version = "0.5", features = ["dynamic-rendering"] }
egui = "0.29"
egui-winit = "0.29"
egui-ash-renderer = { version = "0.6", features = ["dynamic-rendering"] }

[patch.crates-io.gltf]
git = "https://github.com/adrien-ben/gltf"
Expand Down
120 changes: 60 additions & 60 deletions crates/viewer/src/controls.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use vulkan::winit::{
event::{
DeviceEvent, ElementState, Event, KeyEvent, MouseButton, MouseScrollDelta, WindowEvent,
},
event::{DeviceEvent, ElementState, KeyEvent, MouseButton, MouseScrollDelta, WindowEvent},
keyboard::{KeyCode, PhysicalKey},
};

Expand All @@ -20,7 +18,15 @@ pub struct InputState {
}

impl InputState {
pub fn update(self, event: &Event<()>) -> Self {
pub fn reset(self) -> Self {
Self {
cursor_delta: [0.0, 0.0],
wheel_delta: 0.0,
..self
}
}

pub fn handle_window_event(self, event: &WindowEvent) -> Self {
let mut is_forward_pressed = None;
let mut is_backward_pressed = None;
let mut is_left_pressed = None;
Expand All @@ -30,63 +36,43 @@ impl InputState {
let mut is_left_clicked = None;
let mut is_right_clicked = None;
let mut wheel_delta = self.wheel_delta;
let mut cursor_delta = self.cursor_delta;

if let Event::NewEvents(_) = event {
return Self {
cursor_delta: [0.0, 0.0],
wheel_delta: 0.0,
..self
};
}

if let Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::MouseInput { button, state, .. } => {
let clicked = matches!(state, ElementState::Pressed);
match button {
MouseButton::Left => is_left_clicked = Some(clicked),
MouseButton::Right => is_right_clicked = Some(clicked),
_ => {}
};
}
WindowEvent::MouseWheel {
delta: MouseScrollDelta::LineDelta(_, v_lines),
..
} => {
wheel_delta += v_lines;
}
WindowEvent::KeyboardInput {
event:
KeyEvent {
physical_key: PhysicalKey::Code(scancode),
state,
..
},
..
} => {
let pressed = matches!(state, ElementState::Pressed);
match scancode {
KeyCode::KeyW => is_forward_pressed = Some(pressed),
KeyCode::KeyS => is_backward_pressed = Some(pressed),
KeyCode::KeyA => is_left_pressed = Some(pressed),
KeyCode::KeyD => is_right_pressed = Some(pressed),
KeyCode::Space => is_up_pressed = Some(pressed),
KeyCode::ControlLeft => is_down_pressed = Some(pressed),
_ => {}
};
}
_ => {}
match event {
WindowEvent::MouseInput { button, state, .. } => {
let clicked = matches!(state, ElementState::Pressed);
match button {
MouseButton::Left => is_left_clicked = Some(clicked),
MouseButton::Right => is_right_clicked = Some(clicked),
_ => {}
};
}
}

if let Event::DeviceEvent {
event: DeviceEvent::MouseMotion { delta: (x, y) },
..
} = event
{
cursor_delta[0] += *x as f32;
cursor_delta[1] += *y as f32;
WindowEvent::MouseWheel {
delta: MouseScrollDelta::LineDelta(_, v_lines),
..
} => {
wheel_delta += v_lines;
}
WindowEvent::KeyboardInput {
event:
KeyEvent {
physical_key: PhysicalKey::Code(scancode),
state,
..
},
..
} => {
let pressed = matches!(state, ElementState::Pressed);
match scancode {
KeyCode::KeyW => is_forward_pressed = Some(pressed),
KeyCode::KeyS => is_backward_pressed = Some(pressed),
KeyCode::KeyA => is_left_pressed = Some(pressed),
KeyCode::KeyD => is_right_pressed = Some(pressed),
KeyCode::Space => is_up_pressed = Some(pressed),
KeyCode::ControlLeft => is_down_pressed = Some(pressed),
_ => {}
};
}
_ => {}
}

Self {
Expand All @@ -98,8 +84,22 @@ impl InputState {
is_down_pressed: is_down_pressed.unwrap_or(self.is_down_pressed),
is_left_clicked: is_left_clicked.unwrap_or(self.is_left_clicked),
is_right_clicked: is_right_clicked.unwrap_or(self.is_right_clicked),
cursor_delta,
wheel_delta,
..self
}
}

pub fn handle_device_event(self, event: &DeviceEvent) -> Self {
let mut cursor_delta = self.cursor_delta;

if let DeviceEvent::MouseMotion { delta: (x, y) } = event {
cursor_delta[0] += *x as f32;
cursor_delta[1] += *y as f32;
}

Self {
cursor_delta,
..self
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl Gui {

fn init_egui(window: &WinitWindow) -> (Context, EguiWinit) {
let egui = Context::default();
let egui_winit = EguiWinit::new(egui.clone(), ViewportId::ROOT, &window, None, None);
let egui_winit = EguiWinit::new(egui.clone(), ViewportId::ROOT, &window, None, None, None);

(egui, egui_winit)
}
Expand Down
Loading
Loading