emoon / rust_minifb

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

Capture cursor #220

Open LoganDark opened 3 years ago

LoganDark commented 3 years ago

I'd like a way to capture the cursor inside the window (to the center, like some games), is it possible for this feature to be added to minifb?

emoon commented 3 years ago

It's certainly possible, but not something I have planned to do. Would it be possible for you to do a PR with this feature?

LoganDark commented 3 years ago

Not sure, especially because I have to reboot to access other OSes and I'm currently focused on another project. I suppose I could just use click and drag instead of cursor locking.

emoon commented 3 years ago

So exactly what do you need to support this? a set_cursor_pos would do the trick?

LoganDark commented 3 years ago

I suppose it could be hacked together by setting the cursor position every frame, yeah. But, I would prefer to use the OS's cursor locking.

LoganDark commented 3 years ago

Also, I just ran into a weird bug where there is a blank space at the top of the window.

image

That has absolutely nothing to do with this, but here it is.

image

emoon commented 3 years ago

I think many games actually just set the cursor pos actually (that is because in an FPS you want to detect the direction the user switches the mouse and then you move it back to the center after detecting it)

Unsure what the issue above is, likely something with client area of the window being calculated wrong or something like.

LoganDark commented 3 years ago

I think many games actually just set the cursor pos actually (that is because in an FPS you want to detect the direction the user switches the mouse and then you move it back to the center after detecting it)

Well, it will probably work just fine :P

likely something with client area of the window being calculated wrong

The window's detected correctly, that's why the buffer is the right size, but the positioning of the buffer gets screwed up.

arvsrn commented 1 year ago

Is setting cursor position still unsupported?

emoon commented 1 year ago

Yes, it's still unsupported.

arvsrn commented 1 year ago

I wrote a function for windows and made a PR: https://github.com/emoon/rust_minifb/pull/321