Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is something goes wrong with if let Some(pos) = e.mouse_cursor_args() #212

Open
ZacRenis opened this issue May 29, 2019 · 0 comments

Comments

@ZacRenis
Copy link

ZacRenis commented May 29, 2019

/// Handles events.
  pub fn event<E: GenericEvent>(&mut self, pos: [f64; 2], size: f64, e: &E) {
      use piston::input::{Button, MouseButton};

      if let Some(pos) = e.mouse_cursor_args() {
______________________________________________________________________________________________________________
          ///////// Did not run here,  SOMEBODY can help me? thank you.///////!!!!!!!!!!!
------------------------------------------------------------------------------------------------------------------
          self.cursor_pos = pos;
      }

      if let Some(Button::Mouse(MouseButton::Left)) = e.press_args() {
          // Find coordinates relative to upper left corner.
          let x = self.cursor_pos[0] - pos[0];
          let y = self.cursor_pos[1] - pos[1];
          // Check that coordinates are inside board boundaries.
          if x >= 0.0 && x < size && y >= 0.0 && y < size {
              // Compute the cell position.
              let cell_x = (x / size * 9.0) as usize;
              let cell_y = (y / size * 9.0) as usize;
              self.selected_cell = Some([cell_x, cell_y]);
          }
      }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant