Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

Implement InputHandler for mouse movement #186

Merged
merged 1 commit into from Jun 8, 2017

Conversation

derekdreery
Copy link
Contributor

@derekdreery derekdreery commented Feb 10, 2017

This is my state implementation for mouse movement. It adds to PR #181 .

It suits my needs nicely as I can respond to any change in mouse position since the last frame, so I want to see if the behaviour I want is universal.

One particular aspect I invite comments on is defaulting to (0, 0) rather than using an Option. In my model, a movement of (0, 0) is basically a no-op, where as a position of (0, 0) is not a no-op (it's top left window). Does this seem reasonable?

Copy link
Contributor

@Emilgardis Emilgardis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See CONTRIBUTING.md for how to avoid Merged remote-tracking branch [...] commits, they provide no real usefulness. However git is hard to use sometimes.

I'd prefer it if you completely squashed all of these commits and added a reference to the bug fix you've provided.

I think these additions also show us that we need to supply time information together with InputHandler, for e.g calculating if a series of clicks was a double-click. This can be done in a later stage though.

/// _: &mut Pipeline)
/// -> Trans {
/// // ...
/// input_handler.update(events);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't work. Show how to get input_handler aswell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

pressed_mouse_buttons: HashMap<MouseButton, KeyQueryState>,
// defined to match glium
mouse_position: Option<(i32, i32)>,
previous_mouse_position: Option<(i32, i32)>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does InputHandler store the previous mouse position?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previous_mouse_position is the mouse position the previous time mouse_change was called. It allows us to compare to the current mouse position and get the amount the mouse has moved. Using this information, you can work out for example how much to rotate the camera in the ecs etc.

@@ -48,30 +90,46 @@ impl InputHandler {
// second `Pressed` event.
}
Entry::Vacant(entry) => {
entry.insert(KeyQueryState::Queried);
entry.insert(KeyQueryState::NotQueried);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wierd, I remember that this was working, but following my logic in the code of key_once it shouldn't work.
Note also that you don't reflect this change in the commit.

@Emilgardis
Copy link
Contributor

Also, should #181 be closed inplace of this PR? Seems like they are identical except for b54a4dc

@derekdreery
Copy link
Contributor Author

I split the PR up because I thought that the mouse stuff might be more controversial.

@derekdreery
Copy link
Contributor Author

derekdreery commented Apr 25, 2017

I just rebased this on my other PR.

If you want to add both at the same time, you could just use this PR.

@torkleyy
Copy link
Member

@derekdreery It's not blocked anymore, please rebase onto the current master. I think we can do #225 after this PR is merged.

@kvark kvark changed the title [Blocked] Implement InputHandler for mouse movement Implement InputHandler for mouse movement May 26, 2017
@derekdreery
Copy link
Contributor Author

This is rebased on current upstream/develop.

Copy link
Member

@torkleyy torkleyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nchashch nchashch self-requested a review May 29, 2017 18:24
Copy link
Member

@nchashch nchashch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM.

@nchashch nchashch mentioned this pull request Jun 7, 2017
13 tasks
@nchashch nchashch merged commit 906b95c into amethyst:develop Jun 8, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants