2020-04-06 23:15:59 +00:00
|
|
|
use bevy::{
|
2020-04-30 20:52:11 +00:00
|
|
|
input::mouse::{MouseButtonInput, MouseMotionInput},
|
2020-04-06 23:15:59 +00:00
|
|
|
prelude::*,
|
|
|
|
};
|
2020-04-05 06:42:39 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
App::build()
|
|
|
|
.add_default_plugins()
|
2020-05-01 20:12:47 +00:00
|
|
|
.init_resource::<State>()
|
2020-04-30 20:52:11 +00:00
|
|
|
.add_system(mouse_input_system.system())
|
2020-04-05 06:42:39 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-05-27 22:49:27 +00:00
|
|
|
#[derive(FromResources)]
|
2020-04-30 20:52:11 +00:00
|
|
|
struct State {
|
|
|
|
mouse_button_event_reader: EventReader<MouseButtonInput>,
|
|
|
|
mouse_motion_event_reader: EventReader<MouseMotionInput>,
|
|
|
|
}
|
|
|
|
|
2020-04-07 04:32:19 +00:00
|
|
|
/// prints out mouse events as they come in
|
2020-04-30 20:52:11 +00:00
|
|
|
fn mouse_input_system(
|
2020-05-14 00:52:47 +00:00
|
|
|
mut state: ResMut<State>,
|
|
|
|
mouse_button_input_events: Com<Events<MouseButtonInput>>,
|
|
|
|
mouse_motion_events: Com<Events<MouseMotionInput>>,
|
2020-04-30 20:52:11 +00:00
|
|
|
) {
|
|
|
|
for event in state
|
|
|
|
.mouse_button_event_reader
|
|
|
|
.iter(&mouse_button_input_events)
|
|
|
|
{
|
|
|
|
println!("{:?}", event);
|
|
|
|
}
|
2020-04-05 07:32:53 +00:00
|
|
|
|
2020-04-30 20:52:11 +00:00
|
|
|
for event in state.mouse_motion_event_reader.iter(&mouse_motion_events) {
|
|
|
|
println!("{:?}", event);
|
|
|
|
}
|
2020-04-06 23:15:59 +00:00
|
|
|
}
|