2020-04-06 23:15:59 +00:00
|
|
|
use bevy::{
|
2020-08-21 00:04:01 +00:00
|
|
|
input::mouse::{MouseButtonInput, MouseMotion, MouseWheel},
|
2020-04-06 23:15:59 +00:00
|
|
|
prelude::*,
|
2020-06-05 06:34:21 +00:00
|
|
|
window::CursorMoved,
|
2020-04-06 23:15:59 +00:00
|
|
|
};
|
2020-04-05 06:42:39 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
App::build()
|
2020-11-03 03:01:17 +00:00
|
|
|
.add_plugins(DefaultPlugins)
|
2020-06-05 06:49:36 +00:00
|
|
|
.add_system(print_mouse_events_system.system())
|
2020-04-05 06:42:39 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-06-04 06:53:00 +00:00
|
|
|
#[derive(Default)]
|
2020-04-30 20:52:11 +00:00
|
|
|
struct State {
|
|
|
|
mouse_button_event_reader: EventReader<MouseButtonInput>,
|
2020-06-05 06:34:21 +00:00
|
|
|
mouse_motion_event_reader: EventReader<MouseMotion>,
|
2020-06-04 06:22:32 +00:00
|
|
|
cursor_moved_event_reader: EventReader<CursorMoved>,
|
2020-08-21 00:04:01 +00:00
|
|
|
mouse_wheel_event_reader: EventReader<MouseWheel>,
|
2020-04-30 20:52:11 +00:00
|
|
|
}
|
|
|
|
|
2020-06-05 06:49:36 +00:00
|
|
|
/// This system prints out all mouse events as they come in
|
|
|
|
fn print_mouse_events_system(
|
2020-10-18 20:20:42 +00:00
|
|
|
mut state: Local<State>,
|
2020-06-04 06:22:32 +00:00
|
|
|
mouse_button_input_events: Res<Events<MouseButtonInput>>,
|
2020-06-05 06:34:21 +00:00
|
|
|
mouse_motion_events: Res<Events<MouseMotion>>,
|
2020-06-04 06:22:32 +00:00
|
|
|
cursor_moved_events: Res<Events<CursorMoved>>,
|
2020-08-21 00:04:01 +00:00
|
|
|
mouse_wheel_events: Res<Events<MouseWheel>>,
|
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-06-04 06:22:32 +00:00
|
|
|
|
|
|
|
for event in state.cursor_moved_event_reader.iter(&cursor_moved_events) {
|
|
|
|
println!("{:?}", event);
|
|
|
|
}
|
2020-08-21 00:04:01 +00:00
|
|
|
|
|
|
|
for event in state.mouse_wheel_event_reader.iter(&mouse_wheel_events) {
|
|
|
|
println!("{:?}", event);
|
|
|
|
}
|
2020-04-06 23:15:59 +00:00
|
|
|
}
|