Skip to content

Add mouse capture example#614

Closed
eliaspekkala wants to merge 1 commit intobevyengine:masterfrom
eliaspekkala:mouse-capture-example
Closed

Add mouse capture example#614
eliaspekkala wants to merge 1 commit intobevyengine:masterfrom
eliaspekkala:mouse-capture-example

Conversation

@eliaspekkala
Copy link
Copy Markdown
Contributor

This pull request adds an example for how to capture the mouse cursor (grab it and hide it).

@Moxinilian Moxinilian added C-Feature A new feature, making something new possible C-Examples An addition or correction to our examples A-Input Player input via keyboard, mouse, gamepad, and more labels Oct 2, 2020
@cart
Copy link
Copy Markdown
Member

cart commented Oct 5, 2020

This is definitely an important feature to illustrate, but I don't consider the winit api a part of the "bevy api" and therefore its not something I want in our examples. In general, I don't want to encourage users to use the winit api directly because it then ties their app to winit backends (which we might not always use on every platform).

As you are probably aware, bevy doesn't have an "abstract" mouse capture api (which means users must use winit for it currently). Additionally our Window abstraction as it stands today isn't very dynamic. It doesn't let you set window properties on demand like you can with winit. I chose to expose WinitWindows because I acknowledge that the gaps as they stand prevent people from building useful things. But I also dont want "official learning material" to include this because it actively encourages non-future proof code.

In the short term, I'm cool with tacking these properties onto the existing WindowDescriptor to unblock scenarios like this. But medium term I think we need to revisit our Window abstraction and either:

  1. Expose a way to easily / dynamically set window properties at runtime
  2. Fully embrace winit as our windowing abstraction (which implicitly means that we must extend winit whenever we want to support new platforms, such as consoles). This is a pretty big commitment, so I'm pretty hesitant to do this. But it would certainly simplify the code / immediately expose a bunch of nice features.

@smokku
Copy link
Copy Markdown
Member

smokku commented Oct 5, 2020

There is a very similar example in the cookbook: https://github.com/jamadazi/bevy-cookbook/blob/master/bevy-cookbook.md#grabbing-the-mouse

@eliaspekkala
Copy link
Copy Markdown
Contributor Author

Thanks for taking the time to write about the design considerations. I'll close this pull request, and then we can refer to it (or the cookbook) if someone wants to know how to do mouse capturing currently. Shall we create an issue for a mouse capture API and another for the window abstraction?

@cart
Copy link
Copy Markdown
Member

cart commented Oct 6, 2020

That would be much appreciated!

This was referenced Oct 7, 2020
@eliaspekkala eliaspekkala deleted the mouse-capture-example branch October 19, 2020 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Input Player input via keyboard, mouse, gamepad, and more C-Examples An addition or correction to our examples C-Feature A new feature, making something new possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants