Working on zooming and scrolling of the image. Want to do a full input chain like I did the raycaster, but I don't know if I want to commit to SFML for my windowing...

master
mitchellhansen 6 years ago
parent 5551581a3e
commit a403d13f41

@ -1,25 +1,31 @@
use std::collections::HashSet;
use sfml::window::{Key, Event};
use sfml::window::{Key, Event, mouse::Button};
pub struct Input {
held_keys: HashSet<Key>
held_keys: HashSet<Key>,
held_mouse: HashSet<u8>,
}
impl Input {
pub fn new() -> Input {
let mut container = HashSet::new();
let mut key_container = HashSet::new();
let mut mouse_container = HashSet::new();
Input {
held_keys: container,
held_keys: key_container,
held_mouse: mouse_container,
}
}
pub fn is_held(&self, key: Key) -> bool{
pub fn is_held(&self, key: Key) -> bool {
self.held_keys.contains(&key)
}
pub fn is_mousebutton_held(&self, button: Button) -> bool {
self.held_mouse.contains(&(button as u8))
}
pub fn ingest(&mut self, event: &Event) {
match event {
Event::KeyPressed { code, .. } => {
@ -28,6 +34,12 @@ impl Input {
Event::KeyReleased { code, .. } => {
self.held_keys.remove(code);
}
Event::MouseButtonPressed { button, x, y } => {
self.held_mouse.insert(button.clone() as u8);
},
Event::MouseButtonReleased { button, x, y } => {
self.held_mouse.insert(button.clone() as u8);
},
_ => {}
}
}

@ -92,21 +92,30 @@ fn main() {
if code == Key::Escape {
return;
}
}
},
Event::MouseButtonPressed { button, x, y } => {
if button == Button::Left {
return;
}
},
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));
} 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));
}
},
_ => {}
}
input.ingest(&event)
}
if input.is_held(Key::W) {}
if input.is_held(Key::A) {}
if input.is_held(Key::S) {}
if input.is_held(Key::D) {}
if input.is_mousebutton_held(Button::Left) {
}
elapsed_time = timer.elap_time();
delta_time = elapsed_time - current_time;

Loading…
Cancel
Save