This commit is contained in:
griffi-gh 2024-02-29 02:19:29 +01:00
parent 407ac29d95
commit 778ae751e7
2 changed files with 28 additions and 5 deletions

View file

@ -4,6 +4,7 @@ use std::hash::{Hash, Hasher};
use glam::Vec2; use glam::Vec2;
use hashbrown::HashMap; use hashbrown::HashMap;
use nohash_hasher::BuildNoHashHasher; use nohash_hasher::BuildNoHashHasher;
use crate::rectangle::Rect;
/// Represents a mouse button. /// Represents a mouse button.
/// ///
@ -81,17 +82,19 @@ pub enum KeyboardKey {
} }
/// Information about a mouse buttons or a touchscreen input that's continuously held down /// Information about the state of a mouse button
pub(crate) struct ActiveMouseButton { pub(crate) struct ActiveMouseButton {
/// Whether the input is currently active (i.e. the button is currently held down)
pub active: bool,
/// The button that initiated the input /// The button that initiated the input
pub button: MouseButton, pub button: MouseButton,
/// Position at which the input was initiated /// Position at which the input was initiated (last time it was pressed **down**)
pub start_position: Vec2, pub start_position: Option<Vec2>,
} }
pub(crate) struct MousePointer { pub(crate) struct MousePointer {
pub current_position: Vec2, pub current_position: Vec2,
pub active_buttons: HashMap<ButtonState, ActiveMouseButton, BuildNoHashHasher<u16>>, pub buttons: HashMap<ButtonState, ActiveMouseButton, BuildNoHashHasher<u16>>,
} }
pub(crate) struct TouchFinger { pub(crate) struct TouchFinger {
@ -126,5 +129,17 @@ impl ActiveMouseButton {
} }
pub(crate) struct UiInputState { pub(crate) struct UiInputState {
pub pointers: Vec<ActiveMouseButton>, pointers: Vec<ActiveMouseButton>,
}
impl UiInputState {
pub fn new() -> Self {
Self {
pointers: Vec::new(),
}
}
pub fn query_pointer(&self, area: Rect) -> bool {
todo!()
}
} }

View file

@ -1,5 +1,13 @@
//! Contains types which represent the sides and corners of a rectangular shape. //! Contains types which represent the sides and corners of a rectangular shape.
use glam::Vec2;
#[derive(Clone, Copy, Debug, PartialEq, Default)]
pub struct Rect {
pub position: Vec2,
pub size: Vec2,
}
/// Represents 4 sides of a rectangular shape. /// Represents 4 sides of a rectangular shape.
#[derive(Default, Clone, Copy, PartialEq, Eq, Debug)] #[derive(Default, Clone, Copy, PartialEq, Eq, Debug)]
pub struct Sides<T> { pub struct Sides<T> {