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

Add support for cursor capture and relative mouse motion #555

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

cyberarm
Copy link
Collaborator

@cyberarm cyberarm commented Dec 8, 2020

Useful for windowed mouse look games like jcaster, i-mic-fps, etc.

cyberarm added a commit to cyberarm/ffi-gosu that referenced this pull request Dec 8, 2020
include/Gosu/Window.hpp Outdated Show resolved Hide resolved
cyberarm added a commit to cyberarm/ffi-gosu that referenced this pull request Dec 11, 2020
jlnr added a commit that referenced this pull request Jan 17, 2021
This is a manual import of half of the changes in the following PR from @cyberarm:

#555
jlnr added a commit that referenced this pull request Jan 17, 2021
This is a manual import of half of the changes in the following PR from @cyberarm:

#555
@jlnr jlnr mentioned this pull request Jan 17, 2021
jlnr added a commit that referenced this pull request Jan 17, 2021
This is a manual import of half of the changes in the following PR from @cyberarm:

#555
jlnr added a commit that referenced this pull request Jan 17, 2021
This is a manual import of half of the changes in the following PR from @cyberarm:

#555
jlnr added a commit that referenced this pull request Jan 17, 2021
This is a manual import of half of the changes in the following PR from @cyberarm:

#555
jlnr added a commit that referenced this pull request Jan 17, 2021
This is a manual import of half of the changes in the following PR from @cyberarm:

#555
jlnr added a commit that referenced this pull request Jan 17, 2021
This is a manual import of half of the changes in the following PR from @cyberarm:

#555
cyberarm added a commit to cyberarm/ffi-gosu that referenced this pull request Jan 19, 2021
cyberarm added a commit to cyberarm/ffi-gosu that referenced this pull request Jan 19, 2021
jlnr added a commit that referenced this pull request Jan 20, 2021
This is a manual import of half of the changes in the following PR from @cyberarm:

#555
@cyberarm cyberarm changed the title Add support for borderless windows, cursor capture, and sdl hit test Add support for window controls (minimize/maximize/restore), cursor capture, and sdl hit test Jan 28, 2021
@cyberarm
Copy link
Collaborator Author

@jlnr What are your thoughts on this PR?

  • The hit test callback will enable borderless windows to be draggable and resizable
  • The capture_cursor callback will enable applications that rely on the mouse being confined to the window area (e.g. FPS camera controller without jumping from lost input because mouse left window)

@jlnr
Copy link
Member

jlnr commented Jul 17, 2021

@cyberarm Mixed:

  • I love the idea of capturing the cursor.
  • After using Macs for 15 years, having a "maximize" function seems very Windows-like, and I'd have to check how it even works on macOS. (Usually apps just use fullscreen mode.) I'm also not sure when an app that I used ever minimized or restored itself. What are the use cases for it (sorry if I've asked this before)?
  • Similarly skeptical about the hit-testing use cases, and having another enum in Gosu is not something I am looking forward to :/

I guess the dividing line is that I'd merge anything that helps building great 2D games for desktop and mobile, but I need some convincing with almost-finished projects for anything that goes into the UI toolkit area.

@cyberarm
Copy link
Collaborator Author

  • After using Macs for 15 years, having a "maximize" function seems very Windows-like, and I'd have to check how it even works on macOS. (Usually apps just use fullscreen mode.) I'm also not sure when an app that I used ever minimized or restored itself. What are the use cases for it (sorry if I've asked this before)?
  • Similarly skeptical about the hit-testing use cases, and having another enum in Gosu is not something I am looking forward to :/

Having minimize, maximize and restore functions would be useful for windowed borderless applications and games that want a fully custom appearance, e.g. the TimeCrafters Configuration Tool that I wrote for the robotics team would benefit from both the hit-testing and min/maximize functions.
Screenshot-2021-07-19-080332

@jlnr
Copy link
Member

jlnr commented Aug 21, 2021

Aah, I see! Makes sense that borderless windows would need a way to recreate the window decorations. I have to say I prefer how some portable apps (Spotify comes to mind) have native macOS window controls in a non-native window. I've never looked into how it works, but that seems much nicer than manually recreating controls that don't respect the rest of the OS (left vs right window edge, some distros don't have a minimize button, etc.)

Bildschirmfoto 2021-08-21 um 12 29 35

(It doesn't seem to be trivial because Spotify doesn't do the same thing on Linux :/ It'd probably have to be in SDL2 proper for me to consider it)

Anyway, that's pretty deep in UI toolkit land for me. I'd prefer to only merge the cursor capture for now.

@cyberarm cyberarm force-pushed the sdl2_extras branch 2 times, most recently from 629bbf4 to 065b217 Compare September 3, 2021 15:51
@cyberarm
Copy link
Collaborator Author

cyberarm commented Sep 3, 2021

@jlnr I've removed the window controls and hit testing from this PR.
I think I added everything needed to merge except for a git diff patch for capture_cursor? ➡️ protected_capture_cursor? in gosu_SWIG_RENAME_PATCH.patch

Copy link
Member

@jlnr jlnr left a comment

Choose a reason for hiding this comment

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

  1. Can you please rebase on master?
  2. Hmm, isn't this PR missing something to work for something like a 3D shooter? Because if you were to implement mouse camera movements, you wouldn't just want the cursor to be confined to the window, because then once you hit any edge, you cannot move any further. Probably not an issue in other frameworks that have a mouseMove(dx, dy) event, but Gosu doesn't. :/ Or is the intention that users of capture_mouse still need to move the mouse back to the window center every tick?

@cyberarm
Copy link
Collaborator Author

cyberarm commented Sep 4, 2021

Or is the intention that users of capture_mouse still need to move the mouse back to the window center every tick?

This was the original intention, however we could use SDL_SetRelativeMouseMode and add Window#relative_mouse_x/y to accomplish the same with perhaps more consistent/smoother mouse movement since the mouse doesn't need to be re-centered each update.

SDL_SetRelativeMouseMode does hide the cursor and prevent it from "moving" according to the wiki, so it might be desirable to keep capture_cursor and add another callback, perhaps Window#relative_mouse_motion to enable/disable relative mouse motion.

@cyberarm cyberarm changed the title Add support for window controls (minimize/maximize/restore), cursor capture, and sdl hit test Add support for cursor capture and relative mouse motion Sep 4, 2021
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

Successfully merging this pull request may close these issues.

None yet

2 participants