mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-16 04:25:00 +01:00
Add basic block selection with mouse
This commit is contained in:
parent
98965a8c86
commit
f07bd9c713
4 changed files with 66 additions and 26 deletions
41
src/input.rs
41
src/input.rs
|
|
@ -1,22 +1,51 @@
|
|||
use fnv::FnvHashSet;
|
||||
use sfml::window::{Event, Key};
|
||||
use sfml::window::{mouse, Event, Key};
|
||||
|
||||
use crate::graphics::ScreenPos;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct KbInput {
|
||||
pub struct Input {
|
||||
down: FnvHashSet<Key>,
|
||||
pressed: FnvHashSet<Key>,
|
||||
pub lmb_down: bool,
|
||||
pub rmb_down: bool,
|
||||
pub mouse_down_loc: ScreenPos,
|
||||
}
|
||||
|
||||
impl KbInput {
|
||||
impl Input {
|
||||
pub fn update_from_event(&mut self, ev: &Event) {
|
||||
match ev {
|
||||
Event::KeyPressed { code, .. } => {
|
||||
self.pressed.insert(*code);
|
||||
self.down.insert(*code);
|
||||
&Event::KeyPressed { code, .. } => {
|
||||
self.pressed.insert(code);
|
||||
self.down.insert(code);
|
||||
}
|
||||
Event::KeyReleased { code, .. } => {
|
||||
self.down.remove(code);
|
||||
}
|
||||
&Event::MouseButtonPressed { button, x, y } => {
|
||||
self.mouse_down_loc = ScreenPos {
|
||||
x: x as i16,
|
||||
y: y as i16,
|
||||
};
|
||||
if button == mouse::Button::Left {
|
||||
self.lmb_down = true;
|
||||
}
|
||||
if button == mouse::Button::Right {
|
||||
self.rmb_down = true;
|
||||
}
|
||||
}
|
||||
&Event::MouseButtonReleased { button, .. } => {
|
||||
if button == mouse::Button::Left {
|
||||
self.lmb_down = false;
|
||||
}
|
||||
if button == mouse::Button::Right {
|
||||
self.rmb_down = false;
|
||||
}
|
||||
}
|
||||
&Event::MouseMoved { x, y } => {
|
||||
self.mouse_down_loc.x = x as i16;
|
||||
self.mouse_down_loc.y = y as i16;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue