faiface / pixel

A hand-crafted 2D game library in Go
MIT License
4.46k stars 246 forks source link

Method to detect when the mouse pointer is outside the window #222

Closed szabba closed 4 years ago

szabba commented 4 years ago

In some RPGs / strategy games the camera pans when the mouse pointer is close to the window edge. That is perfectly doable given the current API.

However when such a game is run in windowed mode and the cursor goes outside the window bounds, the Window.MousePosition remains within the window bounds and near the edge. For this it would be helpful to be able to say if the cursor is actually above the window or not. Window.Focused is not the same thing - and on some OSes it can change behaviour depending on the desktop configuration.

I might've missed something in the current API. If so, I will be happy to learn that. :slightly_smiling_face:

bcvery1 commented 4 years ago

@szabba Is this what you're after: https://github.com/faiface/pixel/blob/master/pixelgl/input.go#L58 MouseInsideWindow returns true if the mouse position is within the Window's Bounds.

szabba commented 4 years ago

Great! I was still on v0.8.0 which did not have that.