Refactoring: ui.Init now returns gl.Context object

This commit is contained in:
Hajime Hoshi 2016-02-20 20:08:53 +09:00
parent 63f2c3cb9f
commit 408444842a
3 changed files with 10 additions and 4 deletions

View File

@ -22,6 +22,5 @@ import (
var glContext *opengl.Context var glContext *opengl.Context
func init() { func init() {
ui.Init() glContext = ui.Init()
glContext = opengl.NewContext()
} }

View File

@ -31,7 +31,8 @@ func Now() int64 {
var currentUI *userInterface var currentUI *userInterface
func Init() { func Init() *opengl.Context {
// TODO: Is this OK to lock OS thread only for UI?
runtime.LockOSThread() runtime.LockOSThread()
err := glfw.Init() err := glfw.Init()
@ -58,6 +59,8 @@ func Init() {
}() }()
currentUI = u currentUI = u
return opengl.NewContext()
} }
func Start(width, height, scale int, title string) (actualScale int, err error) { func Start(width, height, scale int, title string) (actualScale int, err error) {

View File

@ -111,7 +111,7 @@ func (*userInterface) swapBuffers() {
// Do nothing. // Do nothing.
} }
func Init() { func Init() *opengl.Context {
// Do nothing in node.js. // Do nothing in node.js.
if js.Global.Get("require") != js.Undefined { if js.Global.Get("require") != js.Undefined {
return return
@ -143,6 +143,8 @@ func Init() {
bodyStyle.Set("height", "100%") bodyStyle.Set("height", "100%")
bodyStyle.Set("margin", "0") bodyStyle.Set("margin", "0")
bodyStyle.Set("padding", "0") bodyStyle.Set("padding", "0")
// TODO: This is OK as long as the game is in an independent iframe.
// What if the canvas is embedded in a HTML directly?
doc.Get("body").Call("addEventListener", "click", func() { doc.Get("body").Call("addEventListener", "click", func() {
canvas.Call("focus") canvas.Call("focus")
}) })
@ -214,6 +216,8 @@ func Init() {
window.Call("addEventListener", "gamepadconnected", func(e *js.Object) { window.Call("addEventListener", "gamepadconnected", func(e *js.Object) {
// Do nothing. // Do nothing.
}) })
return opengl.NewContext()
} }
func setMouseCursorFromEvent(e *js.Object) { func setMouseCursorFromEvent(e *js.Object) {