Update the version of GLFW to 3.1

This commit is contained in:
Hajime Hoshi 2015-06-20 18:52:17 +09:00
parent 2a8bcbfa18
commit 4b9c740ee8
4 changed files with 13 additions and 28 deletions

View File

@ -114,7 +114,7 @@ const uiKeysGlfwTmpl = `{{.License}}
package ui package ui
import ( import (
glfw "github.com/go-gl/glfw/v3.0/glfw" glfw "github.com/go-gl/glfw/v3.1/glfw"
) )
var glfwKeyCodeToKey = map[glfw.Key]Key{ var glfwKeyCodeToKey = map[glfw.Key]Key{

View File

@ -17,7 +17,7 @@
package ui package ui
import ( import (
glfw "github.com/go-gl/glfw/v3.0/glfw" glfw "github.com/go-gl/glfw/v3.1/glfw"
"math" "math"
) )
@ -38,17 +38,14 @@ func (i *input) update(window *glfw.Window, scale int) error {
for g, e := range glfwMouseButtonToMouseButton { for g, e := range glfwMouseButtonToMouseButton {
i.mouseButtonPressed[e] = window.GetMouseButton(g) == glfw.Press i.mouseButtonPressed[e] = window.GetMouseButton(g) == glfw.Press
} }
x, y := window.GetCursorPosition() x, y := window.GetCursorPos()
i.cursorX = int(math.Floor(x)) / scale i.cursorX = int(math.Floor(x)) / scale
i.cursorY = int(math.Floor(y)) / scale i.cursorY = int(math.Floor(y)) / scale
for id := glfw.Joystick(0); id < glfw.Joystick(len(i.gamepads)); id++ { for id := glfw.Joystick(0); id < glfw.Joystick(len(i.gamepads)); id++ {
if !glfw.JoystickPresent(id) { if !glfw.JoystickPresent(id) {
continue continue
} }
axes32, err := glfw.GetJoystickAxes(id) axes32 := glfw.GetJoystickAxes(id)
if err != nil {
return err
}
i.gamepads[id].axisNum = len(axes32) i.gamepads[id].axisNum = len(axes32)
for a := 0; a < len(i.gamepads[id].axes); a++ { for a := 0; a < len(i.gamepads[id].axes); a++ {
if len(axes32) <= a { if len(axes32) <= a {
@ -57,10 +54,7 @@ func (i *input) update(window *glfw.Window, scale int) error {
} }
i.gamepads[id].axes[a] = float64(axes32[a]) i.gamepads[id].axes[a] = float64(axes32[a])
} }
buttons, err := glfw.GetJoystickButtons(id) buttons := glfw.GetJoystickButtons(id)
if err != nil {
return err
}
i.gamepads[id].buttonNum = len(buttons) i.gamepads[id].buttonNum = len(buttons)
for b := 0; b < len(i.gamepads[id].buttonPressed); b++ { for b := 0; b < len(i.gamepads[id].buttonPressed); b++ {
if len(buttons) <= b { if len(buttons) <= b {

View File

@ -19,7 +19,7 @@
package ui package ui
import ( import (
glfw "github.com/go-gl/glfw/v3.0/glfw" glfw "github.com/go-gl/glfw/v3.1/glfw"
) )
var glfwKeyCodeToKey = map[glfw.Key]Key{ var glfwKeyCodeToKey = map[glfw.Key]Key{

View File

@ -18,7 +18,7 @@ package ui
import ( import (
"fmt" "fmt"
glfw "github.com/go-gl/glfw/v3.0/glfw" glfw "github.com/go-gl/glfw/v3.1/glfw"
"runtime" "runtime"
"time" "time"
) )
@ -32,11 +32,9 @@ var currentUI *userInterface
func Init() { func Init() {
runtime.LockOSThread() runtime.LockOSThread()
glfw.SetErrorCallback(func(err glfw.ErrorCode, desc string) { err := glfw.Init()
panic(fmt.Sprintf("%v: %v\n", err, desc)) if err != nil {
}) panic(fmt.Sprintf("glfw.Init() fails: %v", err))
if !glfw.Init() {
panic("glfw.Init() fails")
} }
glfw.WindowHint(glfw.Visible, glfw.False) glfw.WindowHint(glfw.Visible, glfw.False)
glfw.WindowHint(glfw.Resizable, glfw.False) glfw.WindowHint(glfw.Resizable, glfw.False)
@ -112,20 +110,13 @@ type userInterface struct {
} }
func (u *userInterface) start(width, height, scale int, title string) (actualScale int, err error) { func (u *userInterface) start(width, height, scale int, title string) (actualScale int, err error) {
monitor, err := glfw.GetPrimaryMonitor() videoMode := glfw.GetPrimaryMonitor().GetVideoMode()
if err != nil {
return 0, err
}
videoMode, err := monitor.GetVideoMode()
if err != nil {
return 0, err
}
x := (videoMode.Width - width*scale) / 2 x := (videoMode.Width - width*scale) / 2
y := (videoMode.Height - height*scale) / 3 y := (videoMode.Height - height*scale) / 3
u.setScreenSize(width, height, scale) u.setScreenSize(width, height, scale)
u.window.SetTitle(title) u.window.SetTitle(title)
u.window.SetPosition(x, y) u.window.SetPos(x, y)
u.window.Show() u.window.Show()
return u.actualScale, nil return u.actualScale, nil
@ -140,7 +131,7 @@ func (u *userInterface) doEvents() error {
if err := u.pollEvents(); err != nil { if err := u.pollEvents(); err != nil {
return err return err
} }
for u.window.GetAttribute(glfw.Focused) == 0 { for u.window.GetAttrib(glfw.Focused) == 0 {
time.Sleep(time.Second / 60) time.Sleep(time.Second / 60)
if err := u.pollEvents(); err != nil { if err := u.pollEvents(); err != nil {
return err return err