ebiten/glfw/mouse.go

31 lines
660 B
Go
Raw Normal View History

2014-12-08 14:51:40 +01:00
package glfw
import (
glfw "github.com/go-gl/glfw3"
2014-12-09 14:09:22 +01:00
"github.com/hajimehoshi/ebiten"
2014-12-08 14:51:40 +01:00
"math"
)
type mouse struct {
2014-12-09 14:09:22 +01:00
buttonPressed [ebiten.MouseButtonMax]bool
2014-12-08 14:51:40 +01:00
x int
y int
}
2014-12-09 14:09:22 +01:00
func (m *mouse) CursorPosition() (x, y int) {
2014-12-08 14:51:40 +01:00
return m.x, m.y
}
2014-12-09 14:09:22 +01:00
func (m *mouse) IsMouseButtonPressed(button ebiten.MouseButton) bool {
2014-12-08 14:51:40 +01:00
return m.buttonPressed[button]
}
func (m *mouse) update(window *glfw.Window) {
x, y := window.GetCursorPosition()
m.x = int(math.Floor(x))
m.y = int(math.Floor(y))
2014-12-09 14:09:22 +01:00
for i := ebiten.MouseButtonLeft; i < ebiten.MouseButtonMax; i++ {
2014-12-08 14:51:40 +01:00
m.buttonPressed[i] = window.GetMouseButton(glfw.MouseButton(i)) == glfw.Press
}
}