From c3a2c45e2140787addc03b061eb3c0a4848cb755 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sat, 6 Jul 2019 20:56:23 -0700 Subject: [PATCH] added dragging --- src/input.rs | 2 +- src/main.rs | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/input.rs b/src/input.rs index 9964f826..735c6507 100644 --- a/src/input.rs +++ b/src/input.rs @@ -38,7 +38,7 @@ impl Input { self.held_mouse.insert(button.clone() as u8); }, Event::MouseButtonReleased { button, x, y } => { - self.held_mouse.insert(button.clone() as u8); + self.held_mouse.remove(&(button.clone() as u8)); }, _ => {} } diff --git a/src/main.rs b/src/main.rs index 649707ce..d82bbdb2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,9 @@ use sfml::graphics::{ }; use sfml::system::*; use sfml::window::{Event, Key, Style}; -use sfml::window::mouse::Button; +use sfml::window::mouse::*; +use sfml::window::mouse; + use vulkano::sync; use std::sync::Arc; @@ -84,7 +86,10 @@ fn main() { let mut accumulator_time: f32 = 0.0; let mut current_time: f32 = timer.elap_time(); + let mut mouse_xy = Vector2i::new(0,0); + while window.is_open() { + while let Some(event) = window.poll_event() { match event { Event::Closed => return, @@ -94,18 +99,13 @@ fn main() { } }, Event::MouseButtonPressed { button, x, y } => { - + mouse_xy = mouse::desktop_position(); }, Event::MouseWheelScrolled { wheel, delta, x, y } => { - if delta > 0.0 { - println!("{:?}", delta); - println!("{:?}", background_sprite.get_scale()); - background_sprite.set_scale(background_sprite.get_scale()+Vector2f::new(0.1,0.1)); + background_sprite.set_scale(background_sprite.get_scale()*Vector2f::new(1.1,1.1)); } else { - println!("{:?}", delta); - println!("{:?}", background_sprite.get_scale()+Vector2f::new(-0.1,-0.1)); - background_sprite.set_scale(background_sprite.get_scale()+Vector2f::new(-0.1,-0.1)); + background_sprite.set_scale(background_sprite.get_scale()*Vector2f::new(0.9,0.9)); } }, _ => {} @@ -114,7 +114,14 @@ fn main() { } if input.is_mousebutton_held(Button::Left) { - + + let delta = mouse_xy - mouse::desktop_position(); + mouse_xy = mouse::desktop_position(); + + println!("{:?}", delta); + background_sprite.set_position( + background_sprite.position() - Vector2f::new(delta.x as f32, delta.y as f32) + ); } elapsed_time = timer.elap_time();