ebiten/ui/glfw/ui.go

37 lines
649 B
Go
Raw Normal View History

2014-12-05 18:26:02 +01:00
package glfw
import (
2014-12-06 20:14:35 +01:00
"errors"
2014-12-05 18:26:02 +01:00
glfw "github.com/go-gl/glfw3"
"github.com/hajimehoshi/ebiten/ui"
"log"
)
func init() {
2014-12-06 14:56:57 +01:00
glfw.SetErrorCallback(func(err glfw.ErrorCode, desc string) {
2014-12-05 18:26:02 +01:00
log.Fatalf("%v: %v\n", err, desc)
})
}
type UI struct {
canvas *Canvas
}
2014-12-06 20:14:35 +01:00
func (u *UI) Start(width, height, scale int, title string) (ui.Canvas, error) {
2014-12-05 18:26:02 +01:00
if !glfw.Init() {
2014-12-06 20:14:35 +01:00
return nil, errors.New("glfw.Init() fails")
2014-12-05 18:26:02 +01:00
}
glfw.WindowHint(glfw.Resizable, glfw.False)
u.canvas = NewCanvas(width, height, scale, title)
2014-12-06 20:14:35 +01:00
return u.canvas, nil
2014-12-05 18:26:02 +01:00
}
func (u *UI) DoEvents() {
2014-12-06 14:56:57 +01:00
glfw.PollEvents()
2014-12-05 19:10:17 +01:00
u.canvas.update()
2014-12-05 18:26:02 +01:00
}
func (u *UI) Terminate() {
glfw.Terminate()
}