mirror of
https://github.com/ivanizag/izapple2.git
synced 2026-10-24 12:06:34 +00:00
The mouse the frontends share is little more than a scale, so a2ebiten can have one now. Ebitengine has no mouse events, the pointer is polled when the frame is updated, and its position is taken on the picture instead of on the window, so it lands on the same place whatever the size of the window is. The models with a mouse, like desktop, are of some use there now. A pointer outside the window stays on the edge instead of wrapping around, which Ebitengine reports as soon as the pointer leaves the picture. NewMixer is now NewFrontMixer, so that it does not look like the NewMixer of the audio package. The methods that the machine calls are marked as the implementations of izapple2.MouseProvider and izapple2.JoysticksProvider, and the note about SDL_WarpMouseInWindow is gone: it came from the SDL2 mouse and means nothing in a package that knows nothing about SDL.
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package shared
|
|
|
|
// Mouse is the position and the button of the pointer, as the mouse card of
|
|
// the machine reads them
|
|
type Mouse struct {
|
|
x uint16
|
|
y uint16
|
|
pressed bool
|
|
}
|
|
|
|
func NewMouse() *Mouse {
|
|
var m Mouse
|
|
return &m
|
|
}
|
|
|
|
// SetPosition places the pointer, from where it is on a window of the given
|
|
// size
|
|
func (m *Mouse) SetPosition(x int, y int, width int, height int) {
|
|
if width <= 0 || height <= 0 {
|
|
// The window is not sized yet
|
|
return
|
|
}
|
|
|
|
m.x = mousePosition(x, width)
|
|
m.y = mousePosition(y, height)
|
|
}
|
|
|
|
// SetButton presses or releases the button of the mouse
|
|
func (m *Mouse) SetButton(pressed bool) {
|
|
m.pressed = pressed
|
|
}
|
|
|
|
// mousePosition turns a position on the window into the full range the machine
|
|
// reads the mouse in, keeping what is outside the window on the edge
|
|
func mousePosition(position int, size int) uint16 {
|
|
return uint16(max(min(65536*position/size, 65535), 0))
|
|
}
|
|
|
|
// izapple2.MouseProvider implementation
|
|
|
|
// ReadMouse returns the position of the pointer on the window and whether its
|
|
// button is pressed
|
|
func (m *Mouse) ReadMouse() (x uint16, y uint16, pressed bool) {
|
|
return m.x, m.y, m.pressed
|
|
}
|