2014-12-09 15:16:04 +01:00
|
|
|
/*
|
|
|
|
Copyright 2014 Hajime Hoshi
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|