emoon / rust_minifb

Cross platfrom window and framebuffer crate for Rust
MIT License
980 stars 92 forks source link

5 button mouse support and more #312

Open AaronKutch opened 1 year ago

AaronKutch commented 1 year ago

I moved to rust_minifb from piston_window, but am missing its extensive button system. There are an awful lot of obscure key codes, but it would be nice to support as many as possible in one fell swoop. One thing I have available is a 5 button mouse, but only 3 buttons are currently available in the mouse enum.

What I would recommend is:

emoon commented 1 year ago

Hi,

As minifb is mainly a prototyping library supporting all of this feels a bit out of scope for the library. In your case maybe something like winit would be a better fit as it's a bit more complete lib. Now I'm not saying that you can't use minifb to build a complete application, but you may find areas were it doesn't support all the things you want.

AaronKutch commented 1 year ago

I love minifb because of how minimal it is. In this specific case, it seems to me that it just needs a little more extending. I don't mean for all the Controller and Hat stuff, just some missing stuff from the already existing keyboard and mouse support. I don't know what the mouse cross platform stuff looks like, but 5 button mouses are fairly common.

AaronKutch commented 1 year ago

The Unknown(u32 (?)) I mentioned should allow for automatically including the extra stuff without needing to waste time coming up with new variants.

emoon commented 1 year ago

Cool. Yeah, but what should the value for the Unknown(u32) be? should be like Unknown(0) = can be mouse 4, 1 can be mouse 5 etc?

AaronKutch commented 1 year ago

My understanding is that most operating systems give key codes, typically 2 or 4 bytes, to the program. If minifb doesn't recognize a code, it can return something (and gui layer keybindings can ask for the button to be pressed when assigning a control, and it will know what code corresponds to what action, it doesn't have to be stable across OSes as long as it is a stable and unique code for the given run). For example, https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event the dwFlags code would be put into MouseButton::Unknown(... as u32). It seems that other interfaces merge mouse buttons with keyboard buttons (https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes), but as long as it is mapped to some Key::Unknown or MouseButton::Unknown, that works for me because I can make my own Button struct combining things if necessary.