Update mouse.rs
docs in bevy_input
(#4518)
# Objective - Part of the splitting process of #3692. ## Solution - Document `mouse.rs` inside of `bevy_input`. Co-authored-by: KDecay <KDecayMusic@protonmail.com>
This commit is contained in:
parent
00f83941b1
commit
50a14703ea
@ -2,46 +2,93 @@ use crate::{ButtonState, Input};
|
|||||||
use bevy_ecs::{event::EventReader, system::ResMut};
|
use bevy_ecs::{event::EventReader, system::ResMut};
|
||||||
use bevy_math::Vec2;
|
use bevy_math::Vec2;
|
||||||
|
|
||||||
/// A mouse button input event
|
/// A mouse button input event.
|
||||||
|
///
|
||||||
|
/// This event is the translated version of the `WindowEvent::MouseInput` from the `winit` crate.
|
||||||
|
///
|
||||||
|
/// ## Usage
|
||||||
|
///
|
||||||
|
/// The event is read inside of the [`mouse_button_input_system`](crate::mouse::mouse_button_input_system)
|
||||||
|
/// to update the [`Input<MouseButton>`](crate::Input<MouseButton>) resource.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MouseButtonInput {
|
pub struct MouseButtonInput {
|
||||||
|
/// The mouse button assigned to the event.
|
||||||
pub button: MouseButton,
|
pub button: MouseButton,
|
||||||
|
/// The pressed state of the button.
|
||||||
pub state: ButtonState,
|
pub state: ButtonState,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A button on a mouse device
|
/// A button on a mouse device.
|
||||||
|
///
|
||||||
|
/// ## Usage
|
||||||
|
///
|
||||||
|
/// It is used as the generic `T` value of an [`Input`](crate::Input) to create a `bevy`
|
||||||
|
/// resource.
|
||||||
|
///
|
||||||
|
/// ## Updating
|
||||||
|
///
|
||||||
|
/// The resource is updated inside of the [`mouse_button_input_system`](crate::mouse::mouse_button_input_system).
|
||||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
|
||||||
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub enum MouseButton {
|
pub enum MouseButton {
|
||||||
|
/// The left mouse button.
|
||||||
Left,
|
Left,
|
||||||
|
/// The right mouse button.
|
||||||
Right,
|
Right,
|
||||||
|
/// The middle mouse button.
|
||||||
Middle,
|
Middle,
|
||||||
|
/// Another mouse button with the associated number.
|
||||||
Other(u16),
|
Other(u16),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A mouse motion event
|
/// A mouse motion event.
|
||||||
|
///
|
||||||
|
/// This event is the translated version of the `DeviceEvent::MouseMotion` from the `winit` crate.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MouseMotion {
|
pub struct MouseMotion {
|
||||||
|
/// The delta of the previous and current mouse positions.
|
||||||
pub delta: Vec2,
|
pub delta: Vec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unit of scroll
|
/// The scroll unit.
|
||||||
|
///
|
||||||
|
/// Describes how a value of a [`MouseWheel`](crate::mouse::MouseWheel) event has to be interpreted.
|
||||||
|
///
|
||||||
|
/// The value of the event can either be interpreted as the amount of lines or the amount of pixels
|
||||||
|
/// to scroll.
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum MouseScrollUnit {
|
pub enum MouseScrollUnit {
|
||||||
|
/// The line scroll unit.
|
||||||
|
///
|
||||||
|
/// The delta of the associated [`MouseWheel`](crate::mouse::MouseWheel) event corresponds
|
||||||
|
/// to the amount of lines or rows to scroll.
|
||||||
Line,
|
Line,
|
||||||
|
/// The pixel scroll unit.
|
||||||
|
///
|
||||||
|
/// The delta of the associated [`MouseWheel`](crate::mouse::MouseWheel) event corresponds
|
||||||
|
/// to the amount of pixels to scroll.
|
||||||
Pixel,
|
Pixel,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A mouse scroll wheel event, where x represents horizontal scroll and y represents vertical
|
/// A mouse wheel event.
|
||||||
/// scroll.
|
///
|
||||||
|
/// This event is the translated version of the `WindowEvent::MouseWheel` from the `winit` crate.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MouseWheel {
|
pub struct MouseWheel {
|
||||||
|
/// The mouse scroll unit.
|
||||||
pub unit: MouseScrollUnit,
|
pub unit: MouseScrollUnit,
|
||||||
|
/// The horizontal scroll value.
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
|
/// The vertical scroll value.
|
||||||
pub y: f32,
|
pub y: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the `Input<MouseButton>` resource with the latest `MouseButtonInput` events
|
/// Updates the [`Input<MouseButton>`] resource with the latest [`MouseButtonInput`] events.
|
||||||
|
///
|
||||||
|
/// ## Differences
|
||||||
|
///
|
||||||
|
/// The main difference between the [`MouseButtonInput`] event and the [`Input<MouseButton>`] resource is that
|
||||||
|
/// the latter has convenient functions like [`Input::pressed`], [`Input::just_pressed`] and [`Input::just_released`].
|
||||||
pub fn mouse_button_input_system(
|
pub fn mouse_button_input_system(
|
||||||
mut mouse_button_input: ResMut<Input<MouseButton>>,
|
mut mouse_button_input: ResMut<Input<MouseButton>>,
|
||||||
mut mouse_button_input_events: EventReader<MouseButtonInput>,
|
mut mouse_button_input_events: EventReader<MouseButtonInput>,
|
||||||
|
Loading…
Reference in New Issue
Block a user