aboutsummaryrefslogtreecommitdiff
path: root/games/rstnode/rst-client/src/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'games/rstnode/rst-client/src/input.rs')
-rw-r--r--games/rstnode/rst-client/src/input.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/games/rstnode/rst-client/src/input.rs b/games/rstnode/rst-client/src/input.rs
index 4e901b8ade06..281386986434 100644
--- a/games/rstnode/rst-client/src/input.rs
+++ b/games/rstnode/rst-client/src/input.rs
@@ -1,50 +1,55 @@
//! Advanced input handler
+use crate::{graphics::Vector2, viewport::Viewport};
use ggez::{
event::EventHandler,
input::mouse::{self, MouseButton},
Context, GameResult,
};
-use mint::Point2;
pub struct InputHandle {
/// The mouse position on the viewport
- pub mouse_pos: Point2<f32>,
+ pub mouse_pos: Vector2,
/// Whether the left mouse button is pressed this frame
pub left_pressed: bool,
+ /// Whether the middle mouse button is pressed this frame
+ pub middle_pressed: bool,
/// Whether the right mouse button is pressed this frame
pub right_pressed: bool,
/// Set when pressing left mouse and unset when releasing it
- pub drag_point: Option<Point2<f32>>,
+ pub drag_point: Option<Vector2>,
}
impl InputHandle {
pub fn new() -> Self {
Self {
- mouse_pos: [0.0, 0.0].into(),
+ mouse_pos: Vector2::new(0.0, 0.0),
left_pressed: false,
+ middle_pressed: false,
right_pressed: false,
drag_point: None,
}
}
/// Get the unprojected mouse coordinates
- pub fn unproject(&self) -> Point2<f32> {
- self.mouse_pos.clone();
+ pub fn unproject(&self, vp: &Viewport) -> Vector2 {
+ // self.mouse_pos.clone() - vp.start().clone()
+
todo!()
}
}
impl EventHandler for InputHandle {
fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
- self.mouse_pos = mouse::position(&ctx);
+ self.mouse_pos = mouse::position(&ctx).into();
self.left_pressed = mouse::button_pressed(ctx, MouseButton::Left);
+ self.middle_pressed = mouse::button_pressed(ctx, MouseButton::Middle);
self.right_pressed = mouse::button_pressed(ctx, MouseButton::Right);
// Only set the drag_point once and unset when we release Left button
- if self.left_pressed && self.drag_point.is_none() {
+ if self.middle_pressed && self.drag_point.is_none() {
self.drag_point = Some(self.mouse_pos.clone());
- } else if !self.left_pressed {
+ } else if !self.middle_pressed {
self.drag_point = None;
}