mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
internal/ui: pass the canvas element directly instead of an ID
This commit is contained in:
parent
95628ee5f7
commit
71a32d2036
@ -110,7 +110,7 @@ func uint8ArrayToSlice(value js.Value, length int) []byte {
|
|||||||
|
|
||||||
type contextImpl struct {
|
type contextImpl struct {
|
||||||
gl *gl
|
gl *gl
|
||||||
canvasID string
|
canvas js.Value
|
||||||
lastProgramID programID
|
lastProgramID programID
|
||||||
webGLVersion webGLVersion
|
webGLVersion webGLVersion
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ func (c *context) initGL() error {
|
|||||||
|
|
||||||
// TODO: Define id?
|
// TODO: Define id?
|
||||||
if doc := js.Global().Get("document"); doc.Truthy() {
|
if doc := js.Global().Get("document"); doc.Truthy() {
|
||||||
canvas := doc.Call("getElementById", c.canvasID)
|
canvas := c.canvas
|
||||||
attr := js.Global().Get("Object").New()
|
attr := js.Global().Get("Object").New()
|
||||||
attr.Set("alpha", true)
|
attr.Set("alpha", true)
|
||||||
attr.Set("premultipliedAlpha", true)
|
attr.Set("premultipliedAlpha", true)
|
||||||
|
@ -14,6 +14,10 @@
|
|||||||
|
|
||||||
package opengl
|
package opengl
|
||||||
|
|
||||||
func (g *Graphics) SetCanvasID(id string) {
|
import (
|
||||||
g.context.canvasID = id
|
"syscall/js"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (g *Graphics) SetCanvas(canvas js.Value) {
|
||||||
|
g.context.canvas = canvas
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -438,8 +437,6 @@ func init() {
|
|||||||
document.Get("head").Call("appendChild", meta)
|
document.Get("head").Call("appendChild", meta)
|
||||||
|
|
||||||
canvas = document.Call("createElement", "canvas")
|
canvas = document.Call("createElement", "canvas")
|
||||||
now := time.Now().UnixNano()
|
|
||||||
canvas.Set("id", fmt.Sprintf("ebitengine-%d.%d", now/1e9, (now%1e9)/1e6))
|
|
||||||
canvas.Set("width", 16)
|
canvas.Set("width", 16)
|
||||||
canvas.Set("height", 16)
|
canvas.Set("height", 16)
|
||||||
|
|
||||||
@ -620,8 +617,8 @@ func (u *userInterfaceImpl) Run(game Game) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.graphicsDriver = g
|
u.graphicsDriver = g
|
||||||
if g, ok := u.graphicsDriver.(interface{ SetCanvasID(string) }); ok {
|
if g, ok := u.graphicsDriver.(interface{ SetCanvas(js.Value) }); ok {
|
||||||
g.SetCanvasID(canvas.Get("id").String())
|
g.SetCanvas(canvas)
|
||||||
}
|
}
|
||||||
return <-u.loop(game)
|
return <-u.loop(game)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user