Skip to content

Commit

Permalink
Emit events on change
Browse files Browse the repository at this point in the history
  • Loading branch information
IDEDARY committed Jul 14, 2024
1 parent a02826d commit 73a653f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 12 additions & 2 deletions crates/bevy_lunex/src/logic/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ fn cursor_move_virtual_pointer(
fn cursor_mouse_pick_events(
// Input
mut mouse_inputs: EventReader<MouseButtonInput>,
mut cursor_last: Local<HashMap<PointerId, Vec2>>,
pointers: Query<(&PointerId, &PointerLocation), (With<Cursor2d>, Without<GamepadCursor>)>,
// Output
mut pointer_move: EventWriter<InputMove>,
Expand All @@ -216,14 +217,18 @@ fn cursor_mouse_pick_events(
// Send mouse movement events
for (pointer, location) in &pointers {
if let Some(location) = &location.location {
let last = cursor_last.get(pointer).unwrap_or(&Vec2::ZERO);
if *last == location.position { continue; }

pointer_move.send(InputMove::new(
*pointer,
Location {
target: location.target.clone(),
position: location.position,
},
location.position,
location.position - *last,
));
cursor_last.insert(*pointer, location.position);
}
}

Expand Down Expand Up @@ -257,6 +262,7 @@ fn cursor_mouse_pick_events(
fn cursor_gamepad_pick_events(
// Input
mut gamepad_inputs: EventReader<GamepadButtonChangedEvent>,
mut cursor_last: Local<HashMap<PointerId, Vec2>>,
pointers: Query<(&PointerId, &PointerLocation, &GamepadCursor), With<Cursor2d>>,
// Output
mut pointer_move: EventWriter<InputMove>,
Expand All @@ -265,14 +271,18 @@ fn cursor_gamepad_pick_events(
// Send mouse movement events
for (pointer, location, _) in &pointers {
if let Some(location) = &location.location {
let last = cursor_last.get(pointer).unwrap_or(&Vec2::ZERO);
if *last == location.position { continue; }

pointer_move.send(InputMove::new(
*pointer,
Location {
target: location.target.clone(),
position: location.position,
},
location.position,
location.position - *last,
));
cursor_last.insert(*pointer, location.position);
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/bevy_lunex/src/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ pub fn rendered_texture_picking(
) {
for event in events.read() {
if let Ok(texture_handle) = texture_viewports.get(event.target) {
//info!("{:?}", event);
let position = event.pointer_location.position;
pointer_move.send(pointer::InputMove {
pointer_id: event.pointer_id,
Expand Down

0 comments on commit 73a653f

Please sign in to comment.