mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
ui: Rename currentUI -> theUI
This commit is contained in:
parent
6b8516c7a5
commit
a4a129e3af
@ -77,7 +77,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
currentUI = &userInterface{
|
theUI = &userInterface{
|
||||||
origPosX: invalidPos,
|
origPosX: invalidPos,
|
||||||
origPosY: invalidPos,
|
origPosY: invalidPos,
|
||||||
initCursorVisible: true,
|
initCursorVisible: true,
|
||||||
@ -109,14 +109,14 @@ func initialize() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// TODO: Fix this hack. currentMonitorImpl now requires u.window on POSIX.
|
// TODO: Fix this hack. currentMonitorImpl now requires u.window on POSIX.
|
||||||
currentUI.window = w
|
theUI.window = w
|
||||||
currentUI.initMonitor = currentUI.currentMonitorFromPosition()
|
theUI.initMonitor = theUI.currentMonitorFromPosition()
|
||||||
v := currentUI.initMonitor.GetVideoMode()
|
v := theUI.initMonitor.GetVideoMode()
|
||||||
s := glfwScale()
|
s := glfwScale()
|
||||||
currentUI.initFullscreenWidth = int(float64(v.Width) / s)
|
theUI.initFullscreenWidth = int(float64(v.Width) / s)
|
||||||
currentUI.initFullscreenHeight = int(float64(v.Height) / s)
|
theUI.initFullscreenHeight = int(float64(v.Height) / s)
|
||||||
currentUI.window.Destroy()
|
theUI.window.Destroy()
|
||||||
currentUI.window = nil
|
theUI.window = nil
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -164,11 +164,11 @@ func getCachedMonitor(wx, wy int) (*cachedMonitor, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Loop(ch <-chan error) error {
|
func Loop(ch <-chan error) error {
|
||||||
currentUI.setRunning(true)
|
theUI.setRunning(true)
|
||||||
if err := mainthread.Loop(ch); err != nil {
|
if err := mainthread.Loop(ch); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
currentUI.setRunning(false)
|
theUI.setRunning(false)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ func (u *userInterface) setInitIconImages(iconImages []image.Image) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ScreenSizeInFullscreen() (int, int) {
|
func ScreenSizeInFullscreen() (int, int) {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return u.initFullscreenWidth, u.initFullscreenHeight
|
return u.initFullscreenWidth, u.initFullscreenHeight
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ func ScreenSizeInFullscreen() (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetScreenSize(width, height int) {
|
func SetScreenSize(width, height int) {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
panic("ui: Run is not called yet")
|
panic("ui: Run is not called yet")
|
||||||
}
|
}
|
||||||
@ -292,7 +292,7 @@ func SetScreenSize(width, height int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetScreenScale(scale float64) bool {
|
func SetScreenScale(scale float64) bool {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
panic("ui: Run is not called yet")
|
panic("ui: Run is not called yet")
|
||||||
}
|
}
|
||||||
@ -306,7 +306,7 @@ func SetScreenScale(scale float64) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ScreenScale() float64 {
|
func ScreenScale() float64 {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -327,7 +327,7 @@ func (u *userInterface) isFullscreen() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsFullscreen() bool {
|
func IsFullscreen() bool {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return u.isInitFullscreen()
|
return u.isInitFullscreen()
|
||||||
}
|
}
|
||||||
@ -340,28 +340,28 @@ func IsFullscreen() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetFullscreen(fullscreen bool) {
|
func SetFullscreen(fullscreen bool) {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
u.setInitFullscreen(fullscreen)
|
u.setInitFullscreen(fullscreen)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = mainthread.Run(func() error {
|
_ = mainthread.Run(func() error {
|
||||||
u := currentUI
|
u := theUI
|
||||||
u.setScreenSize(u.width, u.height, u.scale, fullscreen, u.vsync)
|
u.setScreenSize(u.width, u.height, u.scale, fullscreen, u.vsync)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetRunnableInBackground(runnableInBackground bool) {
|
func SetRunnableInBackground(runnableInBackground bool) {
|
||||||
currentUI.setRunnableInBackground(runnableInBackground)
|
theUI.setRunnableInBackground(runnableInBackground)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsRunnableInBackground() bool {
|
func IsRunnableInBackground() bool {
|
||||||
return currentUI.isRunnableInBackground()
|
return theUI.isRunnableInBackground()
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetVsyncEnabled(enabled bool) {
|
func SetVsyncEnabled(enabled bool) {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
// In general, m is used for locking init* values.
|
// In general, m is used for locking init* values.
|
||||||
// m is not used for updating vsync in setScreenSize so far, but
|
// m is not used for updating vsync in setScreenSize so far, but
|
||||||
@ -373,14 +373,14 @@ func SetVsyncEnabled(enabled bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = mainthread.Run(func() error {
|
_ = mainthread.Run(func() error {
|
||||||
u := currentUI
|
u := theUI
|
||||||
u.setScreenSize(u.width, u.height, u.scale, u.isFullscreen(), enabled)
|
u.setScreenSize(u.width, u.height, u.scale, u.isFullscreen(), enabled)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsVsyncEnabled() bool {
|
func IsVsyncEnabled() bool {
|
||||||
u := currentUI
|
u := theUI
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
r := u.vsync
|
r := u.vsync
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
@ -388,28 +388,28 @@ func IsVsyncEnabled() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetWindowTitle(title string) {
|
func SetWindowTitle(title string) {
|
||||||
if !currentUI.isRunning() {
|
if !theUI.isRunning() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = mainthread.Run(func() error {
|
_ = mainthread.Run(func() error {
|
||||||
currentUI.window.SetTitle(title)
|
theUI.window.SetTitle(title)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetWindowIcon(iconImages []image.Image) {
|
func SetWindowIcon(iconImages []image.Image) {
|
||||||
if !currentUI.isRunning() {
|
if !theUI.isRunning() {
|
||||||
currentUI.setInitIconImages(iconImages)
|
theUI.setInitIconImages(iconImages)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = mainthread.Run(func() error {
|
_ = mainthread.Run(func() error {
|
||||||
currentUI.window.SetIcon(iconImages)
|
theUI.window.SetIcon(iconImages)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ScreenPadding() (x0, y0, x1, y1 float64) {
|
func ScreenPadding() (x0, y0, x1, y1 float64) {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return 0, 0, 0, 0
|
return 0, 0, 0, 0
|
||||||
}
|
}
|
||||||
@ -452,34 +452,34 @@ func ScreenPadding() (x0, y0, x1, y1 float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AdjustPosition(x, y int) (int, int) {
|
func AdjustPosition(x, y int) (int, int) {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return x, y
|
return x, y
|
||||||
}
|
}
|
||||||
ox, oy, _, _ := ScreenPadding()
|
ox, oy, _, _ := ScreenPadding()
|
||||||
s := 0.0
|
s := 0.0
|
||||||
_ = mainthread.Run(func() error {
|
_ = mainthread.Run(func() error {
|
||||||
s = currentUI.actualScreenScale()
|
s = theUI.actualScreenScale()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return x - int(ox/s), y - int(oy/s)
|
return x - int(ox/s), y - int(oy/s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsCursorVisible() bool {
|
func IsCursorVisible() bool {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return u.isInitCursorVisible()
|
return u.isInitCursorVisible()
|
||||||
}
|
}
|
||||||
v := false
|
v := false
|
||||||
_ = mainthread.Run(func() error {
|
_ = mainthread.Run(func() error {
|
||||||
v = currentUI.window.GetInputMode(glfw.CursorMode) == glfw.CursorNormal
|
v = theUI.window.GetInputMode(glfw.CursorMode) == glfw.CursorNormal
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetCursorVisible(visible bool) {
|
func SetCursorVisible(visible bool) {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
u.setInitCursorVisible(visible)
|
u.setInitCursorVisible(visible)
|
||||||
return
|
return
|
||||||
@ -489,26 +489,26 @@ func SetCursorVisible(visible bool) {
|
|||||||
if !visible {
|
if !visible {
|
||||||
c = glfw.CursorHidden
|
c = glfw.CursorHidden
|
||||||
}
|
}
|
||||||
currentUI.window.SetInputMode(glfw.CursorMode, c)
|
theUI.window.SetInputMode(glfw.CursorMode, c)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsWindowDecorated() bool {
|
func IsWindowDecorated() bool {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return u.isInitWindowDecorated()
|
return u.isInitWindowDecorated()
|
||||||
}
|
}
|
||||||
v := false
|
v := false
|
||||||
_ = mainthread.Run(func() error {
|
_ = mainthread.Run(func() error {
|
||||||
v = currentUI.window.GetAttrib(glfw.Decorated) == glfw.True
|
v = theUI.window.GetAttrib(glfw.Decorated) == glfw.True
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetWindowDecorated(decorated bool) {
|
func SetWindowDecorated(decorated bool) {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
u.setInitWindowDecorated(decorated)
|
u.setInitWindowDecorated(decorated)
|
||||||
return
|
return
|
||||||
@ -525,26 +525,26 @@ func SetWindowDecorated(decorated bool) {
|
|||||||
// v = glfw.True
|
// v = glfw.True
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
// currentUI.window.SetAttrib(glfw.Decorated, v)
|
// theUI.window.SetAttrib(glfw.Decorated, v)
|
||||||
// return nil
|
// return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsWindowResizable() bool {
|
func IsWindowResizable() bool {
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return u.isInitWindowResizable()
|
return u.isInitWindowResizable()
|
||||||
}
|
}
|
||||||
v := false
|
v := false
|
||||||
_ = mainthread.Run(func() error {
|
_ = mainthread.Run(func() error {
|
||||||
v = currentUI.window.GetAttrib(glfw.Resizable) == glfw.True
|
v = theUI.window.GetAttrib(glfw.Resizable) == glfw.True
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetWindowResizable(resizable bool) {
|
func SetWindowResizable(resizable bool) {
|
||||||
if !currentUI.isRunning() {
|
if !theUI.isRunning() {
|
||||||
currentUI.setInitWindowResizable(resizable)
|
theUI.setInitWindowResizable(resizable)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -555,7 +555,7 @@ func SetWindowResizable(resizable bool) {
|
|||||||
|
|
||||||
func DeviceScaleFactor() float64 {
|
func DeviceScaleFactor() float64 {
|
||||||
f := 0.0
|
f := 0.0
|
||||||
u := currentUI
|
u := theUI
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return devicescale.GetAt(u.initMonitor.GetPos())
|
return devicescale.GetAt(u.initMonitor.GetPos())
|
||||||
}
|
}
|
||||||
@ -569,7 +569,7 @@ func DeviceScaleFactor() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Run(width, height int, scale float64, title string, g driver.GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error {
|
func Run(width, height int, scale float64, title string, g driver.GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error {
|
||||||
u := currentUI
|
u := theUI
|
||||||
_ = mainthread.Run(func() error {
|
_ = mainthread.Run(func() error {
|
||||||
u.graphics = graphics
|
u.graphics = graphics
|
||||||
u.input = input
|
u.input = input
|
||||||
@ -750,7 +750,7 @@ func (u *userInterface) update(g driver.GraphicsContext) error {
|
|||||||
|
|
||||||
_ = mainthread.Run(func() error {
|
_ = mainthread.Run(func() error {
|
||||||
if u.isInitFullscreen() {
|
if u.isInitFullscreen() {
|
||||||
u := currentUI
|
u := theUI
|
||||||
u.setScreenSize(u.width, u.height, u.scale, true, u.vsync)
|
u.setScreenSize(u.width, u.height, u.scale, true, u.vsync)
|
||||||
u.setInitFullscreen(false)
|
u.setInitFullscreen(false)
|
||||||
}
|
}
|
||||||
@ -851,7 +851,7 @@ func (u *userInterface) forceSetScreenSize(width, height int, scale float64, ful
|
|||||||
// To prevent hanging up, return asap if the width is too small.
|
// To prevent hanging up, return asap if the width is too small.
|
||||||
// 252 is an arbitrary number and I guess this is small enough.
|
// 252 is an arbitrary number and I guess this is small enough.
|
||||||
minWindowWidth := 252
|
minWindowWidth := 252
|
||||||
if currentUI.window.GetAttrib(glfw.Decorated) == glfw.False {
|
if theUI.window.GetAttrib(glfw.Decorated) == glfw.False {
|
||||||
minWindowWidth = 1
|
minWindowWidth = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ type userInterface struct {
|
|||||||
input inputDriver
|
input inputDriver
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentUI = &userInterface{
|
var theUI = &userInterface{
|
||||||
sizeChanged: true,
|
sizeChanged: true,
|
||||||
windowFocus: true,
|
windowFocus: true,
|
||||||
pageVisible: true,
|
pageVisible: true,
|
||||||
@ -75,39 +75,39 @@ func ScreenSizeInFullscreen() (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetScreenSize(width, height int) bool {
|
func SetScreenSize(width, height int) bool {
|
||||||
return currentUI.setScreenSize(width, height, currentUI.scale, currentUI.fullscreen)
|
return theUI.setScreenSize(width, height, theUI.scale, theUI.fullscreen)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetScreenScale(scale float64) bool {
|
func SetScreenScale(scale float64) bool {
|
||||||
return currentUI.setScreenSize(currentUI.width, currentUI.height, scale, currentUI.fullscreen)
|
return theUI.setScreenSize(theUI.width, theUI.height, scale, theUI.fullscreen)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ScreenScale() float64 {
|
func ScreenScale() float64 {
|
||||||
return currentUI.scale
|
return theUI.scale
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetFullscreen(fullscreen bool) {
|
func SetFullscreen(fullscreen bool) {
|
||||||
currentUI.setScreenSize(currentUI.width, currentUI.height, currentUI.scale, fullscreen)
|
theUI.setScreenSize(theUI.width, theUI.height, theUI.scale, fullscreen)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsFullscreen() bool {
|
func IsFullscreen() bool {
|
||||||
return currentUI.fullscreen
|
return theUI.fullscreen
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetRunnableInBackground(runnableInBackground bool) {
|
func SetRunnableInBackground(runnableInBackground bool) {
|
||||||
currentUI.runnableInBackground = runnableInBackground
|
theUI.runnableInBackground = runnableInBackground
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsRunnableInBackground() bool {
|
func IsRunnableInBackground() bool {
|
||||||
return currentUI.runnableInBackground
|
return theUI.runnableInBackground
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetVsyncEnabled(enabled bool) {
|
func SetVsyncEnabled(enabled bool) {
|
||||||
currentUI.vsync = enabled
|
theUI.vsync = enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsVsyncEnabled() bool {
|
func IsVsyncEnabled() bool {
|
||||||
return currentUI.vsync
|
return theUI.vsync
|
||||||
}
|
}
|
||||||
|
|
||||||
func ScreenPadding() (x0, y0, x1, y1 float64) {
|
func ScreenPadding() (x0, y0, x1, y1 float64) {
|
||||||
@ -118,7 +118,7 @@ func AdjustPosition(x, y int) (int, int) {
|
|||||||
rect := canvas.Call("getBoundingClientRect")
|
rect := canvas.Call("getBoundingClientRect")
|
||||||
x -= rect.Get("left").Int()
|
x -= rect.Get("left").Int()
|
||||||
y -= rect.Get("top").Int()
|
y -= rect.Get("top").Int()
|
||||||
scale := currentUI.getScale()
|
scale := theUI.getScale()
|
||||||
return int(float64(x) / scale), int(float64(y) / scale)
|
return int(float64(x) / scale), int(float64(y) / scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,31 +259,31 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.Call("addEventListener", "focus", js.NewCallback(func([]js.Value) {
|
window.Call("addEventListener", "focus", js.NewCallback(func([]js.Value) {
|
||||||
currentUI.windowFocus = true
|
theUI.windowFocus = true
|
||||||
if currentUI.suspended() {
|
if theUI.suspended() {
|
||||||
hooks.SuspendAudio()
|
hooks.SuspendAudio()
|
||||||
} else {
|
} else {
|
||||||
hooks.ResumeAudio()
|
hooks.ResumeAudio()
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
window.Call("addEventListener", "blur", js.NewCallback(func([]js.Value) {
|
window.Call("addEventListener", "blur", js.NewCallback(func([]js.Value) {
|
||||||
currentUI.windowFocus = false
|
theUI.windowFocus = false
|
||||||
if currentUI.suspended() {
|
if theUI.suspended() {
|
||||||
hooks.SuspendAudio()
|
hooks.SuspendAudio()
|
||||||
} else {
|
} else {
|
||||||
hooks.ResumeAudio()
|
hooks.ResumeAudio()
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
document.Call("addEventListener", "visibilitychange", js.NewCallback(func([]js.Value) {
|
document.Call("addEventListener", "visibilitychange", js.NewCallback(func([]js.Value) {
|
||||||
currentUI.pageVisible = !document.Get("hidden").Bool()
|
theUI.pageVisible = !document.Get("hidden").Bool()
|
||||||
if currentUI.suspended() {
|
if theUI.suspended() {
|
||||||
hooks.SuspendAudio()
|
hooks.SuspendAudio()
|
||||||
} else {
|
} else {
|
||||||
hooks.ResumeAudio()
|
hooks.ResumeAudio()
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
window.Call("addEventListener", "resize", js.NewCallback(func([]js.Value) {
|
window.Call("addEventListener", "resize", js.NewCallback(func([]js.Value) {
|
||||||
currentUI.updateScreenSize()
|
theUI.updateScreenSize()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Adjust the initial scale to 1.
|
// Adjust the initial scale to 1.
|
||||||
@ -329,38 +329,38 @@ func init() {
|
|||||||
// Keyboard
|
// Keyboard
|
||||||
// Don't 'preventDefault' on keydown events or keypress events wouldn't work (#715).
|
// Don't 'preventDefault' on keydown events or keypress events wouldn't work (#715).
|
||||||
canvas.Call("addEventListener", "keydown", js.NewEventCallback(0, func(e js.Value) {
|
canvas.Call("addEventListener", "keydown", js.NewEventCallback(0, func(e js.Value) {
|
||||||
currentUI.input.Update(e)
|
theUI.input.Update(e)
|
||||||
}))
|
}))
|
||||||
canvas.Call("addEventListener", "keypress", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
canvas.Call("addEventListener", "keypress", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
||||||
currentUI.input.Update(e)
|
theUI.input.Update(e)
|
||||||
}))
|
}))
|
||||||
canvas.Call("addEventListener", "keyup", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
canvas.Call("addEventListener", "keyup", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
||||||
currentUI.input.Update(e)
|
theUI.input.Update(e)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Mouse
|
// Mouse
|
||||||
canvas.Call("addEventListener", "mousedown", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
canvas.Call("addEventListener", "mousedown", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
||||||
currentUI.input.Update(e)
|
theUI.input.Update(e)
|
||||||
}))
|
}))
|
||||||
canvas.Call("addEventListener", "mouseup", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
canvas.Call("addEventListener", "mouseup", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
||||||
currentUI.input.Update(e)
|
theUI.input.Update(e)
|
||||||
}))
|
}))
|
||||||
canvas.Call("addEventListener", "mousemove", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
canvas.Call("addEventListener", "mousemove", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
||||||
currentUI.input.Update(e)
|
theUI.input.Update(e)
|
||||||
}))
|
}))
|
||||||
canvas.Call("addEventListener", "wheel", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
canvas.Call("addEventListener", "wheel", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
||||||
currentUI.input.Update(e)
|
theUI.input.Update(e)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Touch
|
// Touch
|
||||||
canvas.Call("addEventListener", "touchstart", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
canvas.Call("addEventListener", "touchstart", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
||||||
currentUI.input.Update(e)
|
theUI.input.Update(e)
|
||||||
}))
|
}))
|
||||||
canvas.Call("addEventListener", "touchend", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
canvas.Call("addEventListener", "touchend", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
||||||
currentUI.input.Update(e)
|
theUI.input.Update(e)
|
||||||
}))
|
}))
|
||||||
canvas.Call("addEventListener", "touchmove", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
canvas.Call("addEventListener", "touchmove", js.NewEventCallback(js.PreventDefault, func(e js.Value) {
|
||||||
currentUI.input.Update(e)
|
theUI.input.Update(e)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Gamepad
|
// Gamepad
|
||||||
@ -374,10 +374,10 @@ func init() {
|
|||||||
|
|
||||||
// Context
|
// Context
|
||||||
canvas.Call("addEventListener", "webglcontextlost", js.NewEventCallback(js.PreventDefault, func(js.Value) {
|
canvas.Call("addEventListener", "webglcontextlost", js.NewEventCallback(js.PreventDefault, func(js.Value) {
|
||||||
currentUI.contextLost = true
|
theUI.contextLost = true
|
||||||
}))
|
}))
|
||||||
canvas.Call("addEventListener", "webglcontextrestored", js.NewCallback(func(e []js.Value) {
|
canvas.Call("addEventListener", "webglcontextrestored", js.NewCallback(func(e []js.Value) {
|
||||||
currentUI.contextLost = false
|
theUI.contextLost = false
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +386,7 @@ func Loop(ch <-chan error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Run(width, height int, scale float64, title string, g driver.GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error {
|
func Run(width, height int, scale float64, title string, g driver.GraphicsContext, mainloop bool, graphics driver.Graphics, input driver.Input) error {
|
||||||
u := currentUI
|
u := theUI
|
||||||
u.input = input.(inputDriver)
|
u.input = input.(inputDriver)
|
||||||
|
|
||||||
document.Set("title", title)
|
document.Set("title", title)
|
||||||
|
@ -41,7 +41,7 @@ var (
|
|||||||
glContextCh = make(chan gl.Context)
|
glContextCh = make(chan gl.Context)
|
||||||
renderCh = make(chan struct{})
|
renderCh = make(chan struct{})
|
||||||
renderChEnd = make(chan struct{})
|
renderChEnd = make(chan struct{})
|
||||||
currentUI = &userInterface{}
|
theUI = &userInterface{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func Render(chError <-chan error) error {
|
func Render(chError <-chan error) error {
|
||||||
@ -153,7 +153,7 @@ func Run(width, height int, scale float64, title string, g driver.GraphicsContex
|
|||||||
panic("ui: graphics driver must be OpenGL")
|
panic("ui: graphics driver must be OpenGL")
|
||||||
}
|
}
|
||||||
|
|
||||||
u := currentUI
|
u := theUI
|
||||||
|
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
u.width = width
|
u.width = width
|
||||||
@ -211,7 +211,7 @@ func (u *userInterface) updateGraphicsContext(g driver.GraphicsContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func actualScale() float64 {
|
func actualScale() float64 {
|
||||||
return currentUI.actualScale()
|
return theUI.actualScale()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) actualScale() float64 {
|
func (u *userInterface) actualScale() float64 {
|
||||||
@ -255,7 +255,7 @@ render:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func screenSize() (int, int) {
|
func screenSize() (int, int) {
|
||||||
return currentUI.screenSize()
|
return theUI.screenSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) screenSize() (int, int) {
|
func (u *userInterface) screenSize() (int, int) {
|
||||||
@ -272,7 +272,7 @@ func ScreenSizeInFullscreen() (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetScreenSize(width, height int) bool {
|
func SetScreenSize(width, height int) bool {
|
||||||
currentUI.setScreenSize(width, height)
|
theUI.setScreenSize(width, height)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ func (u *userInterface) setScreenSize(width, height int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetScreenScale(scale float64) bool {
|
func SetScreenScale(scale float64) bool {
|
||||||
currentUI.setScreenScale(scale)
|
theUI.setScreenScale(scale)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ func (u *userInterface) setScreenScale(scale float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ScreenScale() float64 {
|
func ScreenScale() float64 {
|
||||||
u := currentUI
|
u := theUI
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
s := u.scale
|
s := u.scale
|
||||||
u.m.RUnlock()
|
u.m.RUnlock()
|
||||||
@ -310,7 +310,7 @@ func ScreenScale() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setFullscreen(widthPx, heightPx int) {
|
func setFullscreen(widthPx, heightPx int) {
|
||||||
currentUI.setFullscreen(widthPx, heightPx)
|
theUI.setFullscreen(widthPx, heightPx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) setFullscreen(widthPx, heightPx int) {
|
func (u *userInterface) setFullscreen(widthPx, heightPx int) {
|
||||||
@ -338,7 +338,7 @@ func (u *userInterface) updateFullscreenScaleIfNeeded() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ScreenPadding() (x0, y0, x1, y1 float64) {
|
func ScreenPadding() (x0, y0, x1, y1 float64) {
|
||||||
return currentUI.screenPadding()
|
return theUI.screenPadding()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) screenPadding() (x0, y0, x1, y1 float64) {
|
func (u *userInterface) screenPadding() (x0, y0, x1, y1 float64) {
|
||||||
@ -359,7 +359,7 @@ func (u *userInterface) screenPaddingImpl() (x0, y0, x1, y1 float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func AdjustPosition(x, y int) (int, int) {
|
func AdjustPosition(x, y int) (int, int) {
|
||||||
return currentUI.adjustPosition(x, y)
|
return theUI.adjustPosition(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) adjustPosition(x, y int) (int, int) {
|
func (u *userInterface) adjustPosition(x, y int) (int, int) {
|
||||||
|
@ -25,9 +25,9 @@ import (
|
|||||||
|
|
||||||
func glfwScale() float64 {
|
func glfwScale() float64 {
|
||||||
// This function must be called on the main thread.
|
// This function must be called on the main thread.
|
||||||
cm, ok := getCachedMonitor(currentUI.window.GetPos())
|
cm, ok := getCachedMonitor(theUI.window.GetPos())
|
||||||
if !ok {
|
if !ok {
|
||||||
return devicescale.GetAt(currentUI.currentMonitor().GetPos())
|
return devicescale.GetAt(theUI.currentMonitor().GetPos())
|
||||||
}
|
}
|
||||||
return devicescale.GetAt(cm.x, cm.y)
|
return devicescale.GetAt(cm.x, cm.y)
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ func getMonitorInfoW(hMonitor uintptr, lpmi *monitorInfo) error {
|
|||||||
|
|
||||||
func glfwScale() float64 {
|
func glfwScale() float64 {
|
||||||
// This function must be called on the main thread.
|
// This function must be called on the main thread.
|
||||||
return devicescale.GetAt(currentUI.currentMonitor().GetPos())
|
return devicescale.GetAt(theUI.currentMonitor().GetPos())
|
||||||
}
|
}
|
||||||
|
|
||||||
func adjustWindowPosition(x, y int) (int, int) {
|
func adjustWindowPosition(x, y int) (int, int) {
|
||||||
|
Loading…
Reference in New Issue
Block a user