-
Couldn't load subscription status.
- Fork 202
Expanded mouse functionality #342
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
base: main
Are you sure you want to change the base?
Conversation
Removes usage of old mouse enum. Introduces new mouse built-in object that is backwards compatible with old mouse enum. Old projects can stay the same and should continue working. Functions of new mouse: - `mouse.pressed` to get a tuple of all button states. - `mouse.pressed_left` to get just the state of the left mouse button. `pressed_right` and `pressed_middle` are also available. - `mouse.pos` gives the current position. Can also be set to change the mouse position. - `mouse.rel` gives the last relative position change of the mouse. - `mouse.visible` gives the boolean of the visibility state. Can also be set. - `mouse.focused` gives the boolean of whether the window is focused. - `mouse.cursor` gives the current cursor name if it is of type `system` or a custom cursor image. Can also be set to a few different system cursors or a custom image. If a custom image is used, a hotspot can be given as well. - `mouse.cursor_name` gives just the name of the cursor. Can't be set. Same goes for `mouse.cursor_hotspot`. Functionality of a deque of recent positions as well as updated documentation will be added in further commits.
Added deques of the last relative position changes by mouse-move events as well as the absolute positions after all those movements. - `mouse.recent_rel` and `mouse.recent_pos` to access a tuple of those movements. - `mouse.recent_rel_max` and `mouse.recent_pos_max` control how many move events back are recorded. Reworked the majority of attributes to perform better and more consistently. - `mouse.pressed` is now not recalculated every call. Same goes for the individual buttons. - Same for `mouse.pos` and `mouse.rel`. Rel additionally sums the relative movement of all move events over one frame which makes it consistent with calling `pygame.mouse.get_rel()` every frame. - To retain the function of `get_rel()` separately, `mouse.last_called_rel` and `mouse.last_called_pos` were added. These give the position and relative change from when they were last accessed.
|
This looks very good. I need to do a more detailed review though. |
|
Thanks for the heads up, the one thing I am unsure about currently is whether to put the cursor functionality in attributes too. In the meantime, I'll try to suss out the reason for the failed test. It doesn't reproduce immediately on my system but I'll try to look into it more. |
|
Hopefully the tests run fine now, it was a dumb oversight by me. |
|
Okay, at this point I'm somewhat confused. The error that we had beforehand with the test is fixed by importing the new mouse, which made sense to me. However, now flake8 acts up because we don't use it in that specific file. |
|
@lordmauve Any idea how to not import the unused mouse but not have the tests fail? |
|
I added a full suite of unittests for the new mouse now. These aren't quite optimal yet, since some functionality relies of triggering Pygame events and I haven't found a way to wait for one of those to resolve before doing an assert, but I am quite certain that the assumptions made getting around those restrictions will always remain static, so I hope they are still good tests. Again, I'm not that familiar with testing yet, so feedback would be appreciated. |
|
@lordmauve I think the code fails on MacOS with a strange error about the cursor. From my understanding, that shouldn't really happen since when an OS doesn't support a certain system cursor type, it should fall back to the default cursor, which it for some reason did not do here. I'll try to find out what's going on but if it's a bug in Pygame, maybe we take out access to the cursor for now and add that back in later? |
|
After some research and testing, I couldn't find a good way to get reproducible results or more info on the cause of the error. In the interest of not bricking MacOS, I've removed the cursor customization for now and propose we look at it again once the other stuff is sorted out successfully. |
|
@lordmauve I've got a workaround where if a system cursor is not available, it simply ignores the requested change and prints a warning. That would be an easy adjustment and I've also got the tests working again I think. The question remains if we want to split the capabilities based on platform like this. Another option would be to only allow custom cursors from images instead. This way, the normal errors if an image aren't available are already familiar and there is no disconnect between platforms. What to do you think? |
Removes usage of old mouse enum.
Introduces new mouse built-in object that is backwards compatible with old mouse enum. Old projects can stay the same and should continue working.
Functions of new mouse:
mouse.pressedto get a tuple of all button states.mouse.pressed_leftto get just the state of the left mouse button.pressed_rightandpressed_middleare also available.mouse.posgives the current position. Can also be set to change the mouse position.mouse.relgives the relative position change of the mouse since the last frame.mouse.last_called_posandlast_called_relgive the position and change since the last time this property was accessed.mouse.recent_posandrecent_relgive tuples of the last n positions and relative changes of the mouse. Default for n is 60 and can be changed viamouse.recent_pos_maxandrecent_rel_max.mouse.visiblegives the boolean of the visibility state. Can also be set.mouse.focusedgives the boolean of whether the window is focused.mouse.cursorgives the current cursor name if it is of typesystemor a custom cursor image. Can also be set to a few different system cursors or a custom image. If a custom image is used, a hotspot can be given as well.mouse.cursor_namegives just the name of the cursor. Can't be set. Same goes formouse.cursor_hotspot.Documentation has been updated.
Fixes #334. Fixes #212.