Bug fix: input

This commit is contained in:
Hajime Hoshi 2013-07-05 21:39:50 +09:00
parent 572f4057a8
commit 50f335d0e9

View File

@ -26,11 +26,13 @@ package main
// #include <GLUT/glut.h>
//
// void display(void);
// void mouse(int button, int state, int x, int y);
// void motion(int x, int y);
// void idle(void);
//
// static void setGlutFuncs(void) {
// glutDisplayFunc(display);
// glutMouseFunc(mouse);
// glutMotionFunc(motion);
// glutIdleFunc(idle);
// }
@ -53,6 +55,7 @@ import (
)
type GlutInputEvent struct {
IsActive bool
X int
Y int
}
@ -73,9 +76,18 @@ func display() {
C.glutSwapBuffers()
}
//export mouse
func mouse(button, state, x, y C.int) {
event := GlutInputEvent{false, -1, -1}
if state == C.GLUT_UP {
currentUI.glutInputting <- event
}
}
//export motion
func motion(x, y C.int) {
currentUI.glutInputting <- GlutInputEvent{
IsActive: true,
X: int(x),
Y: int(y),
}
@ -173,6 +185,7 @@ func main() {
ch := currentUI.glutInputting
for {
event := <-ch
if event.IsActive {
x := event.X / screenScale
y := event.Y / screenScale
if x < 0 {
@ -189,6 +202,13 @@ func main() {
X: x,
Y: y,
}
} else {
input <- ebiten.InputState{
X: -1,
Y: -1,
}
}
}
}()