MCPcopy
hub / github.com/EngoEngine/engo / CreateWindow

Function CreateWindow

engo_js.go:37–212  ·  view source on GitHub ↗

CreateWindow creates a window with the specified parameters

(title string, width, height int, fullscreen bool, msaa int)

Source from the content-addressed store, hash-verified

35
36// CreateWindow creates a window with the specified parameters
37func CreateWindow(title string, width, height int, fullscreen bool, msaa int) {
38 rafPolyfill()
39 CurrentBackEnd = BackEndWeb
40 canvas = document.Call("createElement", "canvas")
41
42 devicePixelRatio = js.Global().Get("devicePixelRatio").Float()
43 canvas.Set("width", int(float64(width)+0.5)) // Nearest non-negative int.
44 canvas.Set("height", int(float64(height)+0.5)) // Nearest non-negative int.
45
46 if document.Get("body").IsNull() {
47 document.Set("body", document.Call("createElement", "body"))
48 }
49 body := document.Get("body")
50
51 body.Get("style").Set("margin", "0")
52 body.Get("style").Set("padding", "0")
53
54 canvas.Call("setAttribute", "tabindex", 1)
55 canvas.Get("style").Set("outline", "none")
56 body.Call("appendChild", canvas)
57
58 document.Set("title", title)
59
60 Gl, _ = gl.NewContext(canvas, nil)
61
62 Gl.GetExtension("OES_texture_float")
63
64 gameWidth = float32(width)
65 gameHeight = float32(height)
66 windowWidth = WindowWidth()
67 windowHeight = WindowHeight()
68
69 ResizeXOffset = gameWidth - CanvasWidth()
70 ResizeYOffset = gameHeight - CanvasHeight()
71
72 canvas.Call("addEventListener", "keypress", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
73 // TODO: Not sure what to do here, come back
74 //ke := ev.(*dom.KeyboardEvent)
75 //responser.Type(rune(keyStates[Key(ke.KeyCode)]))
76 return nil
77 }))
78
79 canvas.Call("addEventListener", "keydown", js.FuncOf(func(this js.Value, args []js.Value) interface{} {
80 event := args[0]
81 ke := event.Get("code") // TODO: preventdefault if it's a special key so it doesn't scroll when you press it!
82 if ke.Type() == js.TypeUndefined {
83 kc := event.Get("keyCode").Int()
84 go func(i int) {
85 pollLock.Lock()
86 poll[i] = true
87 pollLock.Unlock()
88 }(kc)
89 k := Key(kc)
90 if k == KeyArrowUp || k == KeyArrowDown || k == KeyArrowLeft || k == KeyArrowRight || k == KeyTab || k == KeyBackspace || k == KeySpace {
91 event.Call("preventDefault")
92 }
93 return nil
94 }

Callers 1

RunFunction · 0.70

Calls 11

rafPolyfillFunction · 0.85
KeyTypeAlias · 0.85
checkModifiersFunction · 0.85
GetMethod · 0.80
DispatchMethod · 0.80
WindowWidthFunction · 0.70
WindowHeightFunction · 0.70
CanvasWidthFunction · 0.70
CanvasHeightFunction · 0.70
TypeMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected