Skip to content

Comments

Mouse functionality#1

Open
Mambouna wants to merge 13 commits intomainfrom
mouse
Open

Mouse functionality#1
Mambouna wants to merge 13 commits intomainfrom
mouse

Conversation

@Mambouna
Copy link
Owner

New mouse functionality

Mambouna added 13 commits April 3, 2025 19:29
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.
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.

1 participant