In the code below I'd like to get the mouse-click coords prior to the Motion::MouseCursor(loc) => {.
Is there a way to do this in the piston world?
When I try to do it with e.mouse_cursor_args(), the "if" is never true; except when it is outside the match it returns mouse coords just fine.
Motion::MouseCursor(loc) seems to return only coordinates of mouse movement, not a single click coord without movement.
pub fn on_input(&mut self, inp: &Input, e: &Event) {
if let Some(pos) = e.mouse_cursor_args() {
println!("Happened!");
}
match inp {
Input::Button(btn) => match btn.state {
ButtonState::Press => match btn.button {
Button::Keyboard(Key::Up) => self.up_d = true,
Button::Keyboard(Key::Down) => self.down_d = true,
Button::Keyboard(Key::Left) => self.left_d = true,
Button::Keyboard(Key::Right) => self.right_d = true,
Button::Mouse(MouseButton::Left) => {
if let Some(pos) = e.mouse_cursor_args() {
println!("Happened!");
let (posx, posy) = (pos[0] as f64, pos[1] as f64);
self.piece_being_dragged = self.board_display.is_piece_on_square(posx, posy);
}
},
_ => (),
},
ButtonState::Release => match btn.button {
Button::Keyboard(Key::Up) => self.up_d = false,
Button::Keyboard(Key::Down) => self.down_d = false,
Button::Keyboard(Key::Left) => self.left_d = false,
Button::Keyboard(Key::Right) => self.right_d = false,
Button::Mouse(MouseButton::Left) => {}
_ => (),
},
},
Input:: Move(mot) => match &mot {
// catch the mouse movement
Motion::MouseCursor(loc) => {
// if self.piece_being_dragged {
// if self.board_display.is_piece_on_square(loc[0], loc[1]) {
// }
// }
}
_ => (),
},
_ => (),
}
}