internal/ui: unify the receivers for UI

This commit is contained in:
Hajime Hoshi 2023-10-15 02:51:23 +09:00
parent 77bdbac244
commit 69f1fa5f29
16 changed files with 230 additions and 230 deletions

View File

@ -68,12 +68,12 @@ func newContext(game Game) *context {
}
}
func (c *context) updateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64, ui *userInterfaceImpl, swapBuffersForGL func()) error {
func (c *context) updateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64, ui *UserInterface, swapBuffersForGL func()) error {
// TODO: If updateCount is 0 and vsync is disabled, swapping buffers can be skipped.
return c.updateFrameImpl(graphicsDriver, clock.UpdateFrame(), outsideWidth, outsideHeight, deviceScaleFactor, ui, false, swapBuffersForGL)
}
func (c *context) forceUpdateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64, ui *userInterfaceImpl, swapBuffersForGL func()) error {
func (c *context) forceUpdateFrame(graphicsDriver graphicsdriver.Graphics, outsideWidth, outsideHeight float64, deviceScaleFactor float64, ui *UserInterface, swapBuffersForGL func()) error {
n := 1
if graphicsDriver.IsDirectX() {
// On DirectX, both framebuffers in the swap chain should be updated.
@ -88,7 +88,7 @@ func (c *context) forceUpdateFrame(graphicsDriver graphicsdriver.Graphics, outsi
return nil
}
func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, updateCount int, outsideWidth, outsideHeight float64, deviceScaleFactor float64, ui *userInterfaceImpl, forceDraw bool, swapBuffersForGL func()) (err error) {
func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, updateCount int, outsideWidth, outsideHeight float64, deviceScaleFactor float64, ui *UserInterface, forceDraw bool, swapBuffersForGL func()) (err error) {
ui.beginFrame()
defer ui.endFrame()

View File

@ -31,7 +31,7 @@ var glfwMouseButtonToMouseButton = map[glfw.MouseButton]MouseButton{
glfw.MouseButton5: MouseButton4,
}
func (u *userInterfaceImpl) registerInputCallbacks() error {
func (u *UserInterface) registerInputCallbacks() error {
if _, err := u.window.SetCharModsCallback(func(w *glfw.Window, char rune, mods glfw.ModifierKey) {
// As this function is called from GLFW callbacks, the current thread is main.
u.m.Lock()
@ -54,7 +54,7 @@ func (u *userInterfaceImpl) registerInputCallbacks() error {
return nil
}
func (u *userInterfaceImpl) updateInputState() error {
func (u *UserInterface) updateInputState() error {
var err error
u.mainThread.Call(func() {
err = u.updateInputStateImpl()
@ -63,7 +63,7 @@ func (u *userInterfaceImpl) updateInputState() error {
}
// updateInputStateImpl must be called from the main thread.
func (u *userInterfaceImpl) updateInputStateImpl() error {
func (u *UserInterface) updateInputStateImpl() error {
u.m.Lock()
defer u.m.Unlock()
@ -126,7 +126,7 @@ func KeyName(key Key) string {
return theUI.keyName(key)
}
func (u *userInterfaceImpl) keyName(key Key) string {
func (u *UserInterface) keyName(key Key) string {
if !u.isRunning() {
return ""
}
@ -151,7 +151,7 @@ func (u *userInterfaceImpl) keyName(key Key) string {
return name
}
func (u *userInterfaceImpl) saveCursorPosition() {
func (u *UserInterface) saveCursorPosition() {
u.m.Lock()
defer u.m.Unlock()

View File

@ -57,7 +57,7 @@ var codeToMouseButton = map[int]MouseButton{
4: MouseButton4,
}
func (u *userInterfaceImpl) keyDown(code js.Value) {
func (u *UserInterface) keyDown(code js.Value) {
id := jsKeyToID(code)
if id < 0 {
return
@ -65,7 +65,7 @@ func (u *userInterfaceImpl) keyDown(code js.Value) {
u.inputState.KeyPressed[id] = true
}
func (u *userInterfaceImpl) keyUp(code js.Value) {
func (u *UserInterface) keyUp(code js.Value) {
id := jsKeyToID(code)
if id < 0 {
return
@ -73,15 +73,15 @@ func (u *userInterfaceImpl) keyUp(code js.Value) {
u.inputState.KeyPressed[id] = false
}
func (u *userInterfaceImpl) mouseDown(code int) {
func (u *UserInterface) mouseDown(code int) {
u.inputState.MouseButtonPressed[codeToMouseButton[code]] = true
}
func (u *userInterfaceImpl) mouseUp(code int) {
func (u *UserInterface) mouseUp(code int) {
u.inputState.MouseButtonPressed[codeToMouseButton[code]] = false
}
func (u *userInterfaceImpl) updateInputFromEvent(e js.Value) error {
func (u *UserInterface) updateInputFromEvent(e js.Value) error {
// Avoid using js.Value.String() as String creates a Uint8Array via a TextEncoder and causes a heavy
// overhead (#1437).
switch t := e.Get("type"); {
@ -114,7 +114,7 @@ func (u *userInterfaceImpl) updateInputFromEvent(e js.Value) error {
return nil
}
func (u *userInterfaceImpl) setMouseCursorFromEvent(e js.Value) {
func (u *UserInterface) setMouseCursorFromEvent(e js.Value) {
if u.context == nil {
return
}
@ -132,12 +132,12 @@ func (u *userInterfaceImpl) setMouseCursorFromEvent(e js.Value) {
u.cursorYInClient = u.origCursorYInClient
}
func (u *userInterfaceImpl) recoverCursorPosition() {
func (u *UserInterface) recoverCursorPosition() {
u.cursorXInClient = u.origCursorXInClient
u.cursorYInClient = u.origCursorYInClient
}
func (u *userInterfaceImpl) updateTouchesFromEvent(e js.Value) {
func (u *UserInterface) updateTouchesFromEvent(e js.Value) {
u.touchesInClient = u.touchesInClient[:0]
touches := e.Get("targetTouches")
@ -203,7 +203,7 @@ func KeyName(key Key) string {
return theUI.keyName(key)
}
func (u *userInterfaceImpl) keyName(key Key) string {
func (u *UserInterface) keyName(key Key) string {
if !u.running {
return ""
}
@ -231,7 +231,7 @@ func UpdateInputFromEvent(e js.Value) {
theUI.updateInputFromEvent(e)
}
func (u *userInterfaceImpl) saveCursorPosition() {
func (u *UserInterface) saveCursorPosition() {
u.savedCursorX = u.inputState.CursorX
u.savedCursorY = u.inputState.CursorY
w, h := u.outsideSize()
@ -239,7 +239,7 @@ func (u *userInterfaceImpl) saveCursorPosition() {
u.savedOutsideHeight = h
}
func (u *userInterfaceImpl) updateInputState() error {
func (u *UserInterface) updateInputState() error {
s := u.DeviceScaleFactor()
if !math.IsNaN(u.savedCursorX) && !math.IsNaN(u.savedCursorY) {

View File

@ -26,7 +26,7 @@ type TouchForInput struct {
Y float64
}
func (u *userInterfaceImpl) updateInputStateFromOutside(keys map[Key]struct{}, runes []rune, touches []TouchForInput) {
func (u *UserInterface) updateInputStateFromOutside(keys map[Key]struct{}, runes []rune, touches []TouchForInput) {
u.m.Lock()
defer u.m.Unlock()
@ -43,7 +43,7 @@ func (u *userInterfaceImpl) updateInputStateFromOutside(keys map[Key]struct{}, r
}
}
func (u *userInterfaceImpl) updateInputState() error {
func (u *UserInterface) updateInputState() error {
u.m.Lock()
defer u.m.Unlock()

View File

@ -29,7 +29,7 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
)
func (u *userInterfaceImpl) updateInputState() error {
func (u *UserInterface) updateInputState() error {
var err error
u.mainThread.Call(func() {
err = u.updateInputStateImpl()
@ -38,7 +38,7 @@ func (u *userInterfaceImpl) updateInputState() error {
}
// updateInputStateImpl must be called from the main thread.
func (u *userInterfaceImpl) updateInputStateImpl() error {
func (u *UserInterface) updateInputStateImpl() error {
if err := gamepad.Update(); err != nil {
return err
}

View File

@ -25,7 +25,7 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/thread"
)
func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
func (u *UserInterface) Run(game Game, options *RunOptions) error {
u.context = newContext(game)
u.mainThread = thread.NewOSThread()

View File

@ -21,7 +21,7 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/thread"
)
func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
func (u *UserInterface) Run(game Game, options *RunOptions) error {
u.context = newContext(game)
// Initialize the main thread first so the thread is available at u.run (#809).

View File

@ -211,7 +211,7 @@ func dipToGLFWPixel(x float64, monitor *Monitor) float64 {
return x
}
func (u *userInterfaceImpl) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) {
func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) {
return x, y
}
@ -302,11 +302,11 @@ func monitorFromWindowByOS(w *glfw.Window) (*Monitor, error) {
return nil, nil
}
func (u *userInterfaceImpl) nativeWindow() (uintptr, error) {
func (u *UserInterface) nativeWindow() (uintptr, error) {
return u.window.GetCocoaWindow()
}
func (u *userInterfaceImpl) isNativeFullscreen() (bool, error) {
func (u *UserInterface) isNativeFullscreen() (bool, error) {
w, err := u.window.GetCocoaWindow()
if err != nil {
return false, err
@ -314,13 +314,13 @@ func (u *userInterfaceImpl) isNativeFullscreen() (bool, error) {
return cocoa.NSWindow{ID: objc.ID(w)}.StyleMask()&cocoa.NSWindowStyleMaskFullScreen != 0, nil
}
func (u *userInterfaceImpl) isNativeFullscreenAvailable() bool {
func (u *UserInterface) isNativeFullscreenAvailable() bool {
// TODO: If the window is transparent, we should use GLFW's windowed fullscreen (#1822, #1857).
// However, if the user clicks the green button, should this window be in native fullscreen mode?
return true
}
func (u *userInterfaceImpl) setNativeFullscreen(fullscreen bool) error {
func (u *UserInterface) setNativeFullscreen(fullscreen bool) error {
// Toggling fullscreen might ignore events like keyUp. Ensure that events are fired.
if err := glfw.WaitEventsTimeout(0.1); err != nil {
return err
@ -351,7 +351,7 @@ func (u *userInterfaceImpl) setNativeFullscreen(fullscreen bool) error {
return nil
}
func (u *userInterfaceImpl) adjustViewSizeAfterFullscreen() error {
func (u *UserInterface) adjustViewSizeAfterFullscreen() error {
if u.graphicsDriver.IsGL() {
return nil
}
@ -382,7 +382,7 @@ func (u *userInterfaceImpl) adjustViewSizeAfterFullscreen() error {
return nil
}
func (u *userInterfaceImpl) isFullscreenAllowedFromUI(mode WindowResizingMode) bool {
func (u *UserInterface) isFullscreenAllowedFromUI(mode WindowResizingMode) bool {
if u.maxWindowWidthInDIP != glfw.DontCare || u.maxWindowHeightInDIP != glfw.DontCare {
return false
}
@ -395,7 +395,7 @@ func (u *userInterfaceImpl) isFullscreenAllowedFromUI(mode WindowResizingMode) b
return false
}
func (u *userInterfaceImpl) setWindowResizingModeForOS(mode WindowResizingMode) error {
func (u *UserInterface) setWindowResizingModeForOS(mode WindowResizingMode) error {
var collectionBehavior uint
if u.isFullscreenAllowedFromUI(mode) {
collectionBehavior |= cocoa.NSWindowCollectionBehaviorManaged
@ -424,6 +424,6 @@ func initializeWindowAfterCreation(w *glfw.Window) error {
return nil
}
func (u *userInterfaceImpl) skipTaskbar() error {
func (u *UserInterface) skipTaskbar() error {
return nil
}

View File

@ -142,7 +142,7 @@ func init() {
savedCursorX: math.NaN(),
savedCursorY: math.NaN(),
}
theUI.iwindow.ui = &theUI.userInterfaceImpl
theUI.iwindow.ui = theUI
hideConsoleWindowOnWindows()
@ -245,25 +245,25 @@ func initialize() error {
return nil
}
func (u *userInterfaceImpl) setInitMonitor(m *Monitor) {
func (u *UserInterface) setInitMonitor(m *Monitor) {
u.m.Lock()
defer u.m.Unlock()
u.initMonitor = m
}
func (u *userInterfaceImpl) getInitMonitor() *Monitor {
func (u *UserInterface) getInitMonitor() *Monitor {
u.m.RLock()
defer u.m.RUnlock()
return u.initMonitor
}
// AppendMonitors appends the current monitors to the passed in mons slice and returns it.
func (u *userInterfaceImpl) AppendMonitors(monitors []*Monitor) []*Monitor {
func (u *UserInterface) AppendMonitors(monitors []*Monitor) []*Monitor {
return theMonitors.append(monitors)
}
// Monitor returns the window's current monitor. Returns nil if there is no current monitor yet.
func (u *userInterfaceImpl) Monitor() *Monitor {
func (u *UserInterface) Monitor() *Monitor {
if !u.isRunning() {
return nil
}
@ -282,15 +282,15 @@ func (u *userInterfaceImpl) Monitor() *Monitor {
return monitor
}
func (u *userInterfaceImpl) isRunning() bool {
func (u *UserInterface) isRunning() bool {
return atomic.LoadUint32(&u.running) != 0 && !u.isTerminated()
}
func (u *userInterfaceImpl) isTerminated() bool {
func (u *UserInterface) isTerminated() bool {
return atomic.LoadUint32(&u.terminated) != 0
}
func (u *userInterfaceImpl) setRunning(running bool) {
func (u *UserInterface) setRunning(running bool) {
if running {
atomic.StoreUint32(&u.running, 1)
} else {
@ -298,12 +298,12 @@ func (u *userInterfaceImpl) setRunning(running bool) {
}
}
func (u *userInterfaceImpl) setTerminated() {
func (u *UserInterface) setTerminated() {
atomic.StoreUint32(&u.terminated, 1)
}
// setWindowMonitor must be called on the main thread.
func (u *userInterfaceImpl) setWindowMonitor(monitor *Monitor) error {
func (u *UserInterface) setWindowMonitor(monitor *Monitor) error {
if microsoftgdk.IsXbox() {
return nil
}
@ -365,7 +365,7 @@ func (u *userInterfaceImpl) setWindowMonitor(monitor *Monitor) error {
return nil
}
func (u *userInterfaceImpl) getWindowSizeLimitsInDIP() (minw, minh, maxw, maxh int) {
func (u *UserInterface) getWindowSizeLimitsInDIP() (minw, minh, maxw, maxh int) {
if microsoftgdk.IsXbox() {
return glfw.DontCare, glfw.DontCare, glfw.DontCare, glfw.DontCare
}
@ -375,7 +375,7 @@ func (u *userInterfaceImpl) getWindowSizeLimitsInDIP() (minw, minh, maxw, maxh i
return u.minWindowWidthInDIP, u.minWindowHeightInDIP, u.maxWindowWidthInDIP, u.maxWindowHeightInDIP
}
func (u *userInterfaceImpl) setWindowSizeLimitsInDIP(minw, minh, maxw, maxh int) bool {
func (u *UserInterface) setWindowSizeLimitsInDIP(minw, minh, maxw, maxh int) bool {
if microsoftgdk.IsXbox() {
// Do nothing. The size is always fixed.
return false
@ -393,45 +393,45 @@ func (u *userInterfaceImpl) setWindowSizeLimitsInDIP(minw, minh, maxw, maxh int)
return true
}
func (u *userInterfaceImpl) isWindowMaximizable() bool {
func (u *UserInterface) isWindowMaximizable() bool {
_, _, maxw, maxh := u.getWindowSizeLimitsInDIP()
return maxw == glfw.DontCare && maxh == glfw.DontCare
}
func (u *userInterfaceImpl) isInitFullscreen() bool {
func (u *UserInterface) isInitFullscreen() bool {
u.m.RLock()
v := u.initFullscreen
u.m.RUnlock()
return v
}
func (u *userInterfaceImpl) setInitFullscreen(initFullscreen bool) {
func (u *UserInterface) setInitFullscreen(initFullscreen bool) {
u.m.Lock()
u.initFullscreen = initFullscreen
u.m.Unlock()
}
func (u *userInterfaceImpl) getInitCursorMode() CursorMode {
func (u *UserInterface) getInitCursorMode() CursorMode {
u.m.RLock()
v := u.initCursorMode
u.m.RUnlock()
return v
}
func (u *userInterfaceImpl) setInitCursorMode(mode CursorMode) {
func (u *UserInterface) setInitCursorMode(mode CursorMode) {
u.m.Lock()
u.initCursorMode = mode
u.m.Unlock()
}
func (u *userInterfaceImpl) getCursorShape() CursorShape {
func (u *UserInterface) getCursorShape() CursorShape {
u.m.RLock()
v := u.cursorShape
u.m.RUnlock()
return v
}
func (u *userInterfaceImpl) setCursorShape(shape CursorShape) CursorShape {
func (u *UserInterface) setCursorShape(shape CursorShape) CursorShape {
u.m.Lock()
old := u.cursorShape
u.cursorShape = shape
@ -439,33 +439,33 @@ func (u *userInterfaceImpl) setCursorShape(shape CursorShape) CursorShape {
return old
}
func (u *userInterfaceImpl) isInitWindowDecorated() bool {
func (u *UserInterface) isInitWindowDecorated() bool {
u.m.RLock()
v := u.initWindowDecorated
u.m.RUnlock()
return v
}
func (u *userInterfaceImpl) setInitWindowDecorated(decorated bool) {
func (u *UserInterface) setInitWindowDecorated(decorated bool) {
u.m.Lock()
u.initWindowDecorated = decorated
u.m.Unlock()
}
func (u *userInterfaceImpl) isRunnableOnUnfocused() bool {
func (u *UserInterface) isRunnableOnUnfocused() bool {
u.m.RLock()
v := u.runnableOnUnfocused
u.m.RUnlock()
return v
}
func (u *userInterfaceImpl) setRunnableOnUnfocused(runnableOnUnfocused bool) {
func (u *UserInterface) setRunnableOnUnfocused(runnableOnUnfocused bool) {
u.m.Lock()
u.runnableOnUnfocused = runnableOnUnfocused
u.m.Unlock()
}
func (u *userInterfaceImpl) getAndResetIconImages() []image.Image {
func (u *UserInterface) getAndResetIconImages() []image.Image {
u.m.RLock()
defer u.m.RUnlock()
s := u.iconImages
@ -473,7 +473,7 @@ func (u *userInterfaceImpl) getAndResetIconImages() []image.Image {
return s
}
func (u *userInterfaceImpl) setIconImages(iconImages []image.Image) {
func (u *UserInterface) setIconImages(iconImages []image.Image) {
u.m.Lock()
defer u.m.Unlock()
@ -484,7 +484,7 @@ func (u *userInterfaceImpl) setIconImages(iconImages []image.Image) {
copy(u.iconImages, iconImages)
}
func (u *userInterfaceImpl) getInitWindowPositionInDIP() (int, int) {
func (u *UserInterface) getInitWindowPositionInDIP() (int, int) {
if microsoftgdk.IsXbox() {
return 0, 0
}
@ -497,7 +497,7 @@ func (u *userInterfaceImpl) getInitWindowPositionInDIP() (int, int) {
return invalidPos, invalidPos
}
func (u *userInterfaceImpl) setInitWindowPositionInDIP(x, y int) {
func (u *UserInterface) setInitWindowPositionInDIP(x, y int) {
if microsoftgdk.IsXbox() {
return
}
@ -510,7 +510,7 @@ func (u *userInterfaceImpl) setInitWindowPositionInDIP(x, y int) {
u.initWindowPositionYInDIP = y
}
func (u *userInterfaceImpl) getInitWindowSizeInDIP() (int, int) {
func (u *UserInterface) getInitWindowSizeInDIP() (int, int) {
if microsoftgdk.IsXbox() {
return microsoftgdk.MonitorResolution()
}
@ -520,7 +520,7 @@ func (u *userInterfaceImpl) getInitWindowSizeInDIP() (int, int) {
return u.initWindowWidthInDIP, u.initWindowHeightInDIP
}
func (u *userInterfaceImpl) setInitWindowSizeInDIP(width, height int) {
func (u *UserInterface) setInitWindowSizeInDIP(width, height int) {
if microsoftgdk.IsXbox() {
return
}
@ -530,7 +530,7 @@ func (u *userInterfaceImpl) setInitWindowSizeInDIP(width, height int) {
u.m.Unlock()
}
func (u *userInterfaceImpl) isInitWindowFloating() bool {
func (u *UserInterface) isInitWindowFloating() bool {
if microsoftgdk.IsXbox() {
return false
}
@ -541,7 +541,7 @@ func (u *userInterfaceImpl) isInitWindowFloating() bool {
return f
}
func (u *userInterfaceImpl) setInitWindowFloating(floating bool) {
func (u *UserInterface) setInitWindowFloating(floating bool) {
if microsoftgdk.IsXbox() {
return
}
@ -551,7 +551,7 @@ func (u *userInterfaceImpl) setInitWindowFloating(floating bool) {
u.m.Unlock()
}
func (u *userInterfaceImpl) isInitWindowMaximized() bool {
func (u *UserInterface) isInitWindowMaximized() bool {
// TODO: Is this always true on Xbox?
u.m.RLock()
m := u.initWindowMaximized
@ -559,38 +559,38 @@ func (u *userInterfaceImpl) isInitWindowMaximized() bool {
return m
}
func (u *userInterfaceImpl) setInitWindowMaximized(maximized bool) {
func (u *UserInterface) setInitWindowMaximized(maximized bool) {
u.m.Lock()
u.initWindowMaximized = maximized
u.m.Unlock()
}
func (u *userInterfaceImpl) isInitWindowMousePassthrough() bool {
func (u *UserInterface) isInitWindowMousePassthrough() bool {
u.m.RLock()
defer u.m.RUnlock()
return u.initWindowMousePassthrough
}
func (u *userInterfaceImpl) setInitWindowMousePassthrough(enabled bool) {
func (u *UserInterface) setInitWindowMousePassthrough(enabled bool) {
u.m.Lock()
defer u.m.Unlock()
u.initWindowMousePassthrough = enabled
}
func (u *userInterfaceImpl) isWindowClosingHandled() bool {
func (u *UserInterface) isWindowClosingHandled() bool {
u.m.RLock()
v := u.windowClosingHandled
u.m.RUnlock()
return v
}
func (u *userInterfaceImpl) setWindowClosingHandled(handled bool) {
func (u *UserInterface) setWindowClosingHandled(handled bool) {
u.m.Lock()
u.windowClosingHandled = handled
u.m.Unlock()
}
func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
if u.isTerminated() {
return 0, 0
}
@ -621,7 +621,7 @@ func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
}
// isFullscreen must be called from the main thread.
func (u *userInterfaceImpl) isFullscreen() (bool, error) {
func (u *UserInterface) isFullscreen() (bool, error) {
if !u.isRunning() {
panic("ui: isFullscreen can't be called before the main loop starts")
}
@ -636,7 +636,7 @@ func (u *userInterfaceImpl) isFullscreen() (bool, error) {
return m != nil || n, nil
}
func (u *userInterfaceImpl) IsFullscreen() bool {
func (u *UserInterface) IsFullscreen() bool {
if microsoftgdk.IsXbox() {
return false
}
@ -662,7 +662,7 @@ func (u *userInterfaceImpl) IsFullscreen() bool {
return fullscreen
}
func (u *userInterfaceImpl) SetFullscreen(fullscreen bool) {
func (u *UserInterface) SetFullscreen(fullscreen bool) {
if microsoftgdk.IsXbox() {
return
}
@ -694,7 +694,7 @@ func (u *userInterfaceImpl) SetFullscreen(fullscreen bool) {
})
}
func (u *userInterfaceImpl) IsFocused() bool {
func (u *UserInterface) IsFocused() bool {
if !u.isRunning() {
return false
}
@ -714,15 +714,15 @@ func (u *userInterfaceImpl) IsFocused() bool {
return focused
}
func (u *userInterfaceImpl) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
func (u *UserInterface) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
u.setRunnableOnUnfocused(runnableOnUnfocused)
}
func (u *userInterfaceImpl) IsRunnableOnUnfocused() bool {
func (u *UserInterface) IsRunnableOnUnfocused() bool {
return u.isRunnableOnUnfocused()
}
func (u *userInterfaceImpl) SetFPSMode(mode FPSModeType) {
func (u *UserInterface) SetFPSMode(mode FPSModeType) {
if u.isTerminated() {
return
}
@ -748,7 +748,7 @@ func (u *userInterfaceImpl) SetFPSMode(mode FPSModeType) {
})
}
func (u *userInterfaceImpl) ScheduleFrame() {
func (u *UserInterface) ScheduleFrame() {
if !u.isRunning() {
return
}
@ -760,7 +760,7 @@ func (u *userInterfaceImpl) ScheduleFrame() {
}
}
func (u *userInterfaceImpl) CursorMode() CursorMode {
func (u *UserInterface) CursorMode() CursorMode {
if u.isTerminated() {
return 0
}
@ -795,7 +795,7 @@ func (u *userInterfaceImpl) CursorMode() CursorMode {
return v
}
func (u *userInterfaceImpl) SetCursorMode(mode CursorMode) {
func (u *UserInterface) SetCursorMode(mode CursorMode) {
if u.isTerminated() {
return
}
@ -820,11 +820,11 @@ func (u *userInterfaceImpl) SetCursorMode(mode CursorMode) {
})
}
func (u *userInterfaceImpl) CursorShape() CursorShape {
func (u *UserInterface) CursorShape() CursorShape {
return u.getCursorShape()
}
func (u *userInterfaceImpl) SetCursorShape(shape CursorShape) {
func (u *UserInterface) SetCursorShape(shape CursorShape) {
if u.isTerminated() {
return
}
@ -847,7 +847,7 @@ func (u *userInterfaceImpl) SetCursorShape(shape CursorShape) {
})
}
func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
func (u *UserInterface) DeviceScaleFactor() float64 {
if u.isTerminated() {
return 0
}
@ -873,7 +873,7 @@ func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
// createWindow creates a GLFW window.
//
// createWindow must be called from the main thread.
func (u *userInterfaceImpl) createWindow() error {
func (u *UserInterface) createWindow() error {
if u.window != nil {
panic("ui: u.window must not exist at createWindow")
}
@ -941,14 +941,14 @@ func (u *userInterfaceImpl) createWindow() error {
return nil
}
func (u *userInterfaceImpl) beginFrame() {
func (u *UserInterface) beginFrame() {
}
func (u *userInterfaceImpl) endFrame() {
func (u *UserInterface) endFrame() {
}
// registerWindowCloseCallback must be called from the main thread.
func (u *userInterfaceImpl) registerWindowCloseCallback() error {
func (u *UserInterface) registerWindowCloseCallback() error {
if u.closeCallback == nil {
u.closeCallback = func(_ *glfw.Window) {
u.m.Lock()
@ -975,7 +975,7 @@ func (u *userInterfaceImpl) registerWindowCloseCallback() error {
}
// registerWindowFramebufferSizeCallback must be called from the main thread.
func (u *userInterfaceImpl) registerWindowFramebufferSizeCallback() error {
func (u *UserInterface) registerWindowFramebufferSizeCallback() error {
if u.defaultFramebufferSizeCallback == nil && runtime.GOOS != "darwin" {
// When the window gets resized (either by manual window resize or a window
// manager), glfw sends a framebuffer size callback which we need to handle (#1960).
@ -1023,7 +1023,7 @@ func (u *userInterfaceImpl) registerWindowFramebufferSizeCallback() error {
return nil
}
func (u *userInterfaceImpl) registerDropCallback() error {
func (u *UserInterface) registerDropCallback() error {
if u.dropCallback == nil {
u.dropCallback = func(_ *glfw.Window, names []string) {
u.m.Lock()
@ -1042,7 +1042,7 @@ func (u *userInterfaceImpl) registerDropCallback() error {
// If the callback is not invoked for a while, waitForFramebufferSizeCallback times out and return.
//
// waitForFramebufferSizeCallback must be called from the main thread.
func (u *userInterfaceImpl) waitForFramebufferSizeCallback(window *glfw.Window, f func() error) error {
func (u *UserInterface) waitForFramebufferSizeCallback(window *glfw.Window, f func() error) error {
u.framebufferSizeCallbackCh = make(chan struct{}, 1)
if u.framebufferSizeCallback == nil {
@ -1093,7 +1093,7 @@ event:
return nil
}
func (u *userInterfaceImpl) initOnMainThread(options *RunOptions) error {
func (u *UserInterface) initOnMainThread(options *RunOptions) error {
if err := glfw.WindowHint(glfw.AutoIconify, glfw.False); err != nil {
return err
}
@ -1236,7 +1236,7 @@ func (u *userInterfaceImpl) initOnMainThread(options *RunOptions) error {
return nil
}
func (u *userInterfaceImpl) outsideSize() (float64, float64, error) {
func (u *UserInterface) outsideSize() (float64, float64, error) {
f, err := u.isFullscreen()
if err != nil {
return 0, 0, err
@ -1286,7 +1286,7 @@ func (u *userInterfaceImpl) outsideSize() (float64, float64, error) {
}
// setFPSMode must be called from the main thread.
func (u *userInterfaceImpl) setFPSMode(fpsMode FPSModeType) error {
func (u *UserInterface) setFPSMode(fpsMode FPSModeType) error {
needUpdate := u.fpsMode != fpsMode || !u.fpsModeInited
u.fpsMode = fpsMode
u.fpsModeInited = true
@ -1310,7 +1310,7 @@ func (u *userInterfaceImpl) setFPSMode(fpsMode FPSModeType) error {
}
// update must be called from the main thread.
func (u *userInterfaceImpl) update() (float64, float64, error) {
func (u *UserInterface) update() (float64, float64, error) {
if err := theGlobalState.error(); err != nil {
return 0, 0, err
}
@ -1402,7 +1402,7 @@ func (u *userInterfaceImpl) update() (float64, float64, error) {
return u.outsideSize()
}
func (u *userInterfaceImpl) loopGame() (ferr error) {
func (u *UserInterface) loopGame() (ferr error) {
defer func() {
// Post a task to the render thread to ensure all the queued functions are executed.
// glfw.Terminate will remove the context and any graphics calls after that will be invalidated.
@ -1431,7 +1431,7 @@ func (u *userInterfaceImpl) loopGame() (ferr error) {
}
}
func (u *userInterfaceImpl) updateGame() error {
func (u *UserInterface) updateGame() error {
var unfocused bool
// On Windows, the focusing state might be always false (#987).
@ -1508,7 +1508,7 @@ func (u *userInterfaceImpl) updateGame() error {
return nil
}
func (u *userInterfaceImpl) updateIconIfNeeded() error {
func (u *UserInterface) updateIconIfNeeded() error {
// In the fullscreen mode, SetIcon fails (#1578).
f, err := u.isFullscreen()
if err != nil {
@ -1560,7 +1560,7 @@ func (u *userInterfaceImpl) updateIconIfNeeded() error {
return nil
}
func (u *userInterfaceImpl) swapBuffersOnRenderThread() error {
func (u *UserInterface) swapBuffersOnRenderThread() error {
if u.graphicsDriver.IsGL() {
if err := u.window.SwapBuffers(); err != nil {
return err
@ -1570,7 +1570,7 @@ func (u *userInterfaceImpl) swapBuffersOnRenderThread() error {
}
// updateWindowSizeLimits must be called from the main thread.
func (u *userInterfaceImpl) updateWindowSizeLimits() error {
func (u *UserInterface) updateWindowSizeLimits() error {
m, err := u.currentMonitor()
if err != nil {
return err
@ -1618,13 +1618,13 @@ func (u *userInterfaceImpl) updateWindowSizeLimits() error {
// In order to enable the size limitation, call updateWindowSizeLimits.
//
// disableWindowSizeLimits must be called from the main thread.
func (u *userInterfaceImpl) disableWindowSizeLimits() error {
func (u *UserInterface) disableWindowSizeLimits() error {
return u.window.SetSizeLimits(glfw.DontCare, glfw.DontCare, glfw.DontCare, glfw.DontCare)
}
// adjustWindowSizeBasedOnSizeLimitsInDIP adjust the size based on the window size limits.
// width and height are in device-independent pixels.
func (u *userInterfaceImpl) adjustWindowSizeBasedOnSizeLimitsInDIP(width, height int) (int, int) {
func (u *UserInterface) adjustWindowSizeBasedOnSizeLimitsInDIP(width, height int) (int, int) {
minw, minh, maxw, maxh := u.getWindowSizeLimitsInDIP()
if minw >= 0 && width < minw {
width = minw
@ -1642,7 +1642,7 @@ func (u *userInterfaceImpl) adjustWindowSizeBasedOnSizeLimitsInDIP(width, height
}
// setWindowSize must be called from the main thread.
func (u *userInterfaceImpl) setWindowSizeInDIP(width, height int, callSetSize bool) error {
func (u *UserInterface) setWindowSizeInDIP(width, height int, callSetSize bool) error {
if microsoftgdk.IsXbox() {
// Do nothing. The size is always fixed.
return nil
@ -1708,7 +1708,7 @@ func (u *userInterfaceImpl) setWindowSizeInDIP(width, height int, callSetSize bo
}
// setOrigWindowPosWithCurrentPos must be called from the main thread.
func (u *userInterfaceImpl) setOrigWindowPosWithCurrentPos() error {
func (u *UserInterface) setOrigWindowPosWithCurrentPos() error {
if x, y := u.origWindowPos(); x == invalidPos || y == invalidPos {
x, y, err := u.window.GetPos()
if err != nil {
@ -1720,7 +1720,7 @@ func (u *userInterfaceImpl) setOrigWindowPosWithCurrentPos() error {
}
// setFullscreen must be called from the main thread.
func (u *userInterfaceImpl) setFullscreen(fullscreen bool) error {
func (u *UserInterface) setFullscreen(fullscreen bool) error {
f, err := u.isFullscreen()
if err != nil {
return err
@ -1843,7 +1843,7 @@ func (u *userInterfaceImpl) setFullscreen(fullscreen bool) error {
return nil
}
func (u *userInterfaceImpl) minimumWindowWidth() (int, error) {
func (u *UserInterface) minimumWindowWidth() (int, error) {
a, err := u.window.GetAttrib(glfw.Decorated)
if err != nil {
return 0, err
@ -1864,7 +1864,7 @@ func (u *userInterfaceImpl) minimumWindowWidth() (int, error) {
return 1, nil
}
func (u *userInterfaceImpl) updateVsyncOnRenderThread() error {
func (u *UserInterface) updateVsyncOnRenderThread() error {
if u.graphicsDriver.IsGL() {
// SwapInterval is affected by the current monitor of the window.
// This needs to be called at least after SetMonitor.
@ -1890,7 +1890,7 @@ func (u *userInterfaceImpl) updateVsyncOnRenderThread() error {
// currentMonitor returns the current active monitor.
//
// currentMonitor must be called on the main thread.
func (u *userInterfaceImpl) currentMonitor() (*Monitor, error) {
func (u *UserInterface) currentMonitor() (*Monitor, error) {
if u.window == nil {
return u.getInitMonitor(), nil
}
@ -1927,13 +1927,13 @@ func (u *userInterfaceImpl) currentMonitor() (*Monitor, error) {
return theMonitors.primaryMonitor(), nil
}
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
func (u *UserInterface) readInputState(inputState *InputState) {
u.m.Lock()
defer u.m.Unlock()
u.inputState.copyAndReset(inputState)
}
func (u *userInterfaceImpl) Window() Window {
func (u *UserInterface) Window() Window {
if microsoftgdk.IsXbox() {
return &nullWindow{}
}
@ -1945,7 +1945,7 @@ func (u *userInterfaceImpl) Window() Window {
// disable the callback temporarily.
// maximizeWindow must be called from the main thread.
func (u *userInterfaceImpl) maximizeWindow() error {
func (u *UserInterface) maximizeWindow() error {
n, err := u.isNativeFullscreen()
if err != nil {
return err
@ -1985,7 +1985,7 @@ func (u *userInterfaceImpl) maximizeWindow() error {
}
// iconifyWindow must be called from the main thread.
func (u *userInterfaceImpl) iconifyWindow() error {
func (u *UserInterface) iconifyWindow() error {
// Iconifying a native fullscreen window on macOS is forbidden.
n, err := u.isNativeFullscreen()
if err != nil {
@ -2017,7 +2017,7 @@ func (u *userInterfaceImpl) iconifyWindow() error {
}
// restoreWindow must be called from the main thread.
func (u *userInterfaceImpl) restoreWindow() error {
func (u *UserInterface) restoreWindow() error {
if err := u.window.Restore(); err != nil {
return err
}
@ -2048,7 +2048,7 @@ func (u *userInterfaceImpl) restoreWindow() error {
}
// setWindowDecorated must be called from the main thread.
func (u *userInterfaceImpl) setWindowDecorated(decorated bool) error {
func (u *UserInterface) setWindowDecorated(decorated bool) error {
if microsoftgdk.IsXbox() {
return nil
}
@ -2072,7 +2072,7 @@ func (u *userInterfaceImpl) setWindowDecorated(decorated bool) error {
}
// setWindowFloating must be called from the main thread.
func (u *userInterfaceImpl) setWindowFloating(floating bool) error {
func (u *UserInterface) setWindowFloating(floating bool) error {
if microsoftgdk.IsXbox() {
return nil
}
@ -2089,7 +2089,7 @@ func (u *userInterfaceImpl) setWindowFloating(floating bool) error {
}
// setWindowResizingMode must be called from the main thread.
func (u *userInterfaceImpl) setWindowResizingMode(mode WindowResizingMode) error {
func (u *UserInterface) setWindowResizingMode(mode WindowResizingMode) error {
if microsoftgdk.IsXbox() {
return nil
}
@ -2119,7 +2119,7 @@ func (u *userInterfaceImpl) setWindowResizingMode(mode WindowResizingMode) error
// x and y are the position in device-independent pixels.
//
// setWindowPositionInDIP must be called from the main thread.
func (u *userInterfaceImpl) setWindowPositionInDIP(x, y int, monitor *Monitor) error {
func (u *UserInterface) setWindowPositionInDIP(x, y int, monitor *Monitor) error {
if microsoftgdk.IsXbox() {
// Do nothing. The position is always fixed.
return nil
@ -2146,12 +2146,12 @@ func (u *userInterfaceImpl) setWindowPositionInDIP(x, y int, monitor *Monitor) e
}
// setWindowTitle must be called from the main thread.
func (u *userInterfaceImpl) setWindowTitle(title string) error {
func (u *UserInterface) setWindowTitle(title string) error {
return u.window.SetTitle(title)
}
// isWindowMaximized must be called from the main thread.
func (u *userInterfaceImpl) isWindowMaximized() (bool, error) {
func (u *UserInterface) isWindowMaximized() (bool, error) {
a, err := u.window.GetAttrib(glfw.Maximized)
if err != nil {
return false, err
@ -2163,17 +2163,17 @@ func (u *userInterfaceImpl) isWindowMaximized() (bool, error) {
return a == glfw.True && !n, nil
}
func (u *userInterfaceImpl) origWindowPos() (int, int) {
func (u *UserInterface) origWindowPos() (int, int) {
return u.origWindowPosX, u.origWindowPosY
}
func (u *userInterfaceImpl) setOrigWindowPos(x, y int) {
func (u *UserInterface) setOrigWindowPos(x, y int) {
u.origWindowPosX = x
u.origWindowPosY = y
}
// setWindowMousePassthrough must be called from the main thread.
func (u *userInterfaceImpl) setWindowMousePassthrough(enabled bool) error {
func (u *UserInterface) setWindowMousePassthrough(enabled bool) error {
if microsoftgdk.IsXbox() {
return nil
}

View File

@ -73,7 +73,7 @@ func IsGL() (bool, error) {
return theUI.isGL()
}
func (u *userInterfaceImpl) setUIView(uiview uintptr) error {
func (u *UserInterface) setUIView(uiview uintptr) error {
select {
case err := <-u.errCh:
return err
@ -87,7 +87,7 @@ func (u *userInterfaceImpl) setUIView(uiview uintptr) error {
return nil
}
func (u *userInterfaceImpl) isGL() (bool, error) {
func (u *UserInterface) isGL() (bool, error) {
select {
case err := <-u.errCh:
return false, err

View File

@ -129,11 +129,11 @@ var (
documentHidden = js.Global().Get("Object").Call("getOwnPropertyDescriptor", js.Global().Get("Document").Get("prototype"), "hidden").Get("get").Call("bind", document)
)
func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
return window.Get("innerWidth").Int(), window.Get("innerHeight").Int()
}
func (u *userInterfaceImpl) SetFullscreen(fullscreen bool) {
func (u *UserInterface) SetFullscreen(fullscreen bool) {
if !canvas.Truthy() {
return
}
@ -164,7 +164,7 @@ func (u *userInterfaceImpl) SetFullscreen(fullscreen bool) {
f.Call("bind", document).Invoke()
}
func (u *userInterfaceImpl) IsFullscreen() bool {
func (u *UserInterface) IsFullscreen() bool {
if !document.Truthy() {
return false
}
@ -174,34 +174,34 @@ func (u *userInterfaceImpl) IsFullscreen() bool {
return true
}
func (u *userInterfaceImpl) IsFocused() bool {
func (u *UserInterface) IsFocused() bool {
return u.isFocused()
}
func (u *userInterfaceImpl) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
func (u *UserInterface) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
u.runnableOnUnfocused = runnableOnUnfocused
}
func (u *userInterfaceImpl) IsRunnableOnUnfocused() bool {
func (u *UserInterface) IsRunnableOnUnfocused() bool {
return u.runnableOnUnfocused
}
func (u *userInterfaceImpl) SetFPSMode(mode FPSModeType) {
func (u *UserInterface) SetFPSMode(mode FPSModeType) {
u.fpsMode = mode
}
func (u *userInterfaceImpl) ScheduleFrame() {
func (u *UserInterface) ScheduleFrame() {
u.renderingScheduled = true
}
func (u *userInterfaceImpl) CursorMode() CursorMode {
func (u *UserInterface) CursorMode() CursorMode {
if !canvas.Truthy() {
return CursorModeHidden
}
return u.cursorMode
}
func (u *userInterfaceImpl) SetCursorMode(mode CursorMode) {
func (u *UserInterface) SetCursorMode(mode CursorMode) {
if mode == CursorModeCaptured && !u.canCaptureCursor() {
u.captureCursorLater = true
return
@ -209,7 +209,7 @@ func (u *userInterfaceImpl) SetCursorMode(mode CursorMode) {
u.setCursorMode(mode)
}
func (u *userInterfaceImpl) setCursorMode(mode CursorMode) {
func (u *UserInterface) setCursorMode(mode CursorMode) {
u.captureCursorLater = false
if !canvas.Truthy() {
@ -235,21 +235,21 @@ func (u *userInterfaceImpl) setCursorMode(mode CursorMode) {
}
}
func (u *userInterfaceImpl) recoverCursorMode() {
func (u *UserInterface) recoverCursorMode() {
if theUI.cursorPrevMode == CursorModeCaptured {
panic("ui: cursorPrevMode must not be CursorModeCaptured at recoverCursorMode")
}
u.SetCursorMode(u.cursorPrevMode)
}
func (u *userInterfaceImpl) CursorShape() CursorShape {
func (u *UserInterface) CursorShape() CursorShape {
if !canvas.Truthy() {
return CursorShapeDefault
}
return u.cursorShape
}
func (u *userInterfaceImpl) SetCursorShape(shape CursorShape) {
func (u *UserInterface) SetCursorShape(shape CursorShape) {
if !canvas.Truthy() {
return
}
@ -263,7 +263,7 @@ func (u *userInterfaceImpl) SetCursorShape(shape CursorShape) {
}
}
func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
func (u *UserInterface) DeviceScaleFactor() float64 {
if u.deviceScaleFactor != 0 {
return u.deviceScaleFactor
}
@ -276,7 +276,7 @@ func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
return u.deviceScaleFactor
}
func (u *userInterfaceImpl) outsideSize() (float64, float64) {
func (u *UserInterface) outsideSize() (float64, float64) {
if document.Truthy() {
body := document.Get("body")
bw := body.Get("clientWidth").Float()
@ -288,14 +288,14 @@ func (u *userInterfaceImpl) outsideSize() (float64, float64) {
return 640, 480
}
func (u *userInterfaceImpl) suspended() bool {
func (u *UserInterface) suspended() bool {
if u.runnableOnUnfocused {
return false
}
return !u.isFocused()
}
func (u *userInterfaceImpl) isFocused() bool {
func (u *UserInterface) isFocused() bool {
if !documentHasFocus.Invoke().Bool() {
return false
}
@ -314,12 +314,12 @@ func (u *userInterfaceImpl) isFocused() bool {
// > Pointer lock is a transient activation-gated API, therefore a requestPointerLock() call
// > MUST fail if the relevant global object of this does not have transient activation.
// > This prevents locking upon initial navigation or re-acquiring lock without user's attention.
func (u *userInterfaceImpl) canCaptureCursor() bool {
func (u *UserInterface) canCaptureCursor() bool {
// 1.5 [sec] seems enough in the real world.
return time.Now().Sub(u.lastCaptureExitTime) >= 1500*time.Millisecond
}
func (u *userInterfaceImpl) update() error {
func (u *UserInterface) update() error {
if u.captureCursorLater && u.canCaptureCursor() {
u.setCursorMode(CursorModeCaptured)
}
@ -333,7 +333,7 @@ func (u *userInterfaceImpl) update() error {
return u.updateImpl(false)
}
func (u *userInterfaceImpl) updateImpl(force bool) error {
func (u *UserInterface) updateImpl(force bool) error {
// Guard updateImpl as this function cannot be invoked until this finishes (#2339).
u.m.Lock()
defer u.m.Unlock()
@ -368,7 +368,7 @@ func (u *userInterfaceImpl) updateImpl(force bool) error {
return nil
}
func (u *userInterfaceImpl) needsUpdate() bool {
func (u *UserInterface) needsUpdate() bool {
if u.fpsMode != FPSModeVsyncOffMinimum {
return true
}
@ -382,7 +382,7 @@ func (u *userInterfaceImpl) needsUpdate() bool {
return false
}
func (u *userInterfaceImpl) loop(game Game) <-chan error {
func (u *UserInterface) loop(game Game) <-chan error {
u.context = newContext(game)
errCh := make(chan error, 1)
@ -705,7 +705,7 @@ func setCanvasEventHandlers(v js.Value) {
}))
}
func (u *userInterfaceImpl) appendDroppedFiles(data js.Value) {
func (u *UserInterface) appendDroppedFiles(data js.Value) {
u.dropFileM.Lock()
defer u.dropFileM.Unlock()
@ -718,7 +718,7 @@ func (u *userInterfaceImpl) appendDroppedFiles(data js.Value) {
u.inputState.DroppedFiles = file.NewFileEntryFS(fs)
}
func (u *userInterfaceImpl) forceUpdateOnMinimumFPSMode() {
func (u *UserInterface) forceUpdateOnMinimumFPSMode() {
if u.fpsMode != FPSModeVsyncOffMinimum {
return
}
@ -732,7 +732,7 @@ func (u *userInterfaceImpl) forceUpdateOnMinimumFPSMode() {
}()
}
func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
func (u *UserInterface) Run(game Game, options *RunOptions) error {
if !options.InitUnfocused && window.Truthy() {
// Do not focus the canvas when the current document is in an iframe.
// Otherwise, the parent page tries to focus the iframe on every loading, which is annoying (#1373).
@ -759,7 +759,7 @@ func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
return <-u.loop(game)
}
func (u *userInterfaceImpl) updateScreenSize() {
func (u *UserInterface) updateScreenSize() {
if document.Truthy() {
body := document.Get("body")
bw := int(body.Get("clientWidth").Float() * u.DeviceScaleFactor())
@ -769,12 +769,12 @@ func (u *userInterfaceImpl) updateScreenSize() {
}
}
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
func (u *UserInterface) readInputState(inputState *InputState) {
u.inputState.copyAndReset(inputState)
u.keyboardLayoutMap = js.Value{}
}
func (u *userInterfaceImpl) Window() Window {
func (u *UserInterface) Window() Window {
return &nullWindow{}
}
@ -793,21 +793,21 @@ func (m *Monitor) Name() string {
return ""
}
func (u *userInterfaceImpl) AppendMonitors(mons []*Monitor) []*Monitor {
func (u *UserInterface) AppendMonitors(mons []*Monitor) []*Monitor {
return append(mons, theMonitor)
}
func (u *userInterfaceImpl) Monitor() *Monitor {
func (u *UserInterface) Monitor() *Monitor {
return theMonitor
}
func (u *userInterfaceImpl) beginFrame() {
func (u *UserInterface) beginFrame() {
}
func (u *userInterfaceImpl) endFrame() {
func (u *UserInterface) endFrame() {
}
func (u *userInterfaceImpl) updateIconIfNeeded() error {
func (u *UserInterface) updateIconIfNeeded() error {
return nil
}

View File

@ -121,7 +121,7 @@ func dipToGLFWPixel(x float64, monitor *Monitor) float64 {
return x * monitor.deviceScaleFactor()
}
func (u *userInterfaceImpl) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) {
func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) {
return x, y
}
@ -149,28 +149,28 @@ func monitorFromWindowByOS(_ *glfw.Window) (*Monitor, error) {
return nil, nil
}
func (u *userInterfaceImpl) nativeWindow() (uintptr, error) {
func (u *UserInterface) nativeWindow() (uintptr, error) {
// TODO: Implement this.
return 0, nil
}
func (u *userInterfaceImpl) isNativeFullscreen() (bool, error) {
func (u *UserInterface) isNativeFullscreen() (bool, error) {
return false, nil
}
func (u *userInterfaceImpl) isNativeFullscreenAvailable() bool {
func (u *UserInterface) isNativeFullscreenAvailable() bool {
return false
}
func (u *userInterfaceImpl) setNativeFullscreen(fullscreen bool) error {
func (u *UserInterface) setNativeFullscreen(fullscreen bool) error {
panic(fmt.Sprintf("ui: setNativeFullscreen is not implemented in this environment: %s", runtime.GOOS))
}
func (u *userInterfaceImpl) adjustViewSizeAfterFullscreen() error {
func (u *UserInterface) adjustViewSizeAfterFullscreen() error {
return nil
}
func (u *userInterfaceImpl) setWindowResizingModeForOS(mode WindowResizingMode) error {
func (u *UserInterface) setWindowResizingModeForOS(mode WindowResizingMode) error {
return nil
}
@ -188,6 +188,6 @@ func initializeWindowAfterCreation(w *glfw.Window) error {
return nil
}
func (u *userInterfaceImpl) skipTaskbar() error {
func (u *UserInterface) skipTaskbar() error {
return nil
}

View File

@ -66,7 +66,7 @@ func init() {
// Update is called from mobile/ebitenmobileview.
//
// Update must be called on the rendering thread.
func (u *userInterfaceImpl) Update() error {
func (u *UserInterface) Update() error {
select {
case err := <-u.errCh:
return err
@ -127,7 +127,7 @@ type userInterfaceImpl struct {
}
// appMain is the main routine for gomobile-build mode.
func (u *userInterfaceImpl) appMain(a app.App) {
func (u *UserInterface) appMain(a app.App) {
var glctx gl.Context
var sizeInited bool
@ -223,7 +223,7 @@ func (u *userInterfaceImpl) appMain(a app.App) {
}
}
func (u *userInterfaceImpl) SetForeground(foreground bool) error {
func (u *UserInterface) SetForeground(foreground bool) error {
var v int32
if foreground {
v = 1
@ -237,7 +237,7 @@ func (u *userInterfaceImpl) SetForeground(foreground bool) error {
}
}
func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
func (u *UserInterface) Run(game Game, options *RunOptions) error {
u.setGBuildSizeCh = make(chan struct{})
go func() {
if err := u.run(game, true, options); err != nil {
@ -253,7 +253,7 @@ func RunWithoutMainLoop(game Game, options *RunOptions) {
theUI.runWithoutMainLoop(game, options)
}
func (u *userInterfaceImpl) runWithoutMainLoop(game Game, options *RunOptions) {
func (u *UserInterface) runWithoutMainLoop(game Game, options *RunOptions) {
go func() {
if err := u.run(game, false, options); err != nil {
u.errCh <- err
@ -261,7 +261,7 @@ func (u *userInterfaceImpl) runWithoutMainLoop(game Game, options *RunOptions) {
}()
}
func (u *userInterfaceImpl) run(game Game, mainloop bool, options *RunOptions) (err error) {
func (u *UserInterface) run(game Game, mainloop bool, options *RunOptions) (err error) {
// Convert the panic to a regular error so that Java/Objective-C layer can treat this easily e.g., for
// Crashlytics. A panic is treated as SIGABRT, and there is no way to handle this on Java/Objective-C layer
// unfortunately.
@ -306,7 +306,7 @@ func (u *userInterfaceImpl) run(game Game, mainloop bool, options *RunOptions) (
}
// outsideSize must be called on the same goroutine as update().
func (u *userInterfaceImpl) outsideSize() (float64, float64) {
func (u *UserInterface) outsideSize() (float64, float64) {
var outsideWidth, outsideHeight float64
u.m.RLock()
@ -324,7 +324,7 @@ func (u *userInterfaceImpl) outsideSize() (float64, float64) {
return outsideWidth, outsideHeight
}
func (u *userInterfaceImpl) update() error {
func (u *UserInterface) update() error {
<-renderCh
defer func() {
renderEndCh <- struct{}{}
@ -337,7 +337,7 @@ func (u *userInterfaceImpl) update() error {
return nil
}
func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
// TODO: This function should return gbuildWidthPx, gbuildHeightPx,
// but these values are not initialized until the main loop starts.
return 0, 0
@ -346,7 +346,7 @@ func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
// SetOutsideSize is called from mobile/ebitenmobileview.
//
// SetOutsideSize is concurrent safe.
func (u *userInterfaceImpl) SetOutsideSize(outsideWidth, outsideHeight float64) {
func (u *UserInterface) SetOutsideSize(outsideWidth, outsideHeight float64) {
u.m.Lock()
if u.outsideWidth != outsideWidth || u.outsideHeight != outsideHeight {
u.outsideWidth = outsideWidth
@ -355,7 +355,7 @@ func (u *userInterfaceImpl) SetOutsideSize(outsideWidth, outsideHeight float64)
u.m.Unlock()
}
func (u *userInterfaceImpl) setGBuildSize(widthPx, heightPx int) {
func (u *UserInterface) setGBuildSize(widthPx, heightPx int) {
u.m.Lock()
u.gbuildWidthPx = widthPx
u.gbuildHeightPx = heightPx
@ -366,55 +366,55 @@ func (u *userInterfaceImpl) setGBuildSize(widthPx, heightPx int) {
})
}
func (u *userInterfaceImpl) CursorMode() CursorMode {
func (u *UserInterface) CursorMode() CursorMode {
return CursorModeHidden
}
func (u *userInterfaceImpl) SetCursorMode(mode CursorMode) {
func (u *UserInterface) SetCursorMode(mode CursorMode) {
// Do nothing
}
func (u *userInterfaceImpl) CursorShape() CursorShape {
func (u *UserInterface) CursorShape() CursorShape {
return CursorShapeDefault
}
func (u *userInterfaceImpl) SetCursorShape(shape CursorShape) {
func (u *UserInterface) SetCursorShape(shape CursorShape) {
// Do nothing
}
func (u *userInterfaceImpl) IsFullscreen() bool {
func (u *UserInterface) IsFullscreen() bool {
return false
}
func (u *userInterfaceImpl) SetFullscreen(fullscreen bool) {
func (u *UserInterface) SetFullscreen(fullscreen bool) {
// Do nothing
}
func (u *userInterfaceImpl) IsFocused() bool {
func (u *UserInterface) IsFocused() bool {
return atomic.LoadInt32(&u.foreground) != 0
}
func (u *userInterfaceImpl) IsRunnableOnUnfocused() bool {
func (u *UserInterface) IsRunnableOnUnfocused() bool {
return false
}
func (u *userInterfaceImpl) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
func (u *UserInterface) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
// Do nothing
}
func (u *userInterfaceImpl) SetFPSMode(mode FPSModeType) {
func (u *UserInterface) SetFPSMode(mode FPSModeType) {
u.fpsMode = mode
u.updateExplicitRenderingModeIfNeeded()
}
func (u *userInterfaceImpl) updateExplicitRenderingModeIfNeeded() {
func (u *UserInterface) updateExplicitRenderingModeIfNeeded() {
if u.renderRequester == nil {
return
}
u.renderRequester.SetExplicitRenderingMode(u.fpsMode == FPSModeVsyncOffMinimum)
}
func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
func (u *UserInterface) DeviceScaleFactor() float64 {
// Assume that the device scale factor never changes on mobiles.
u.deviceScaleFactorOnce.Do(func() {
u.deviceScaleFactor = deviceScaleFactorImpl()
@ -422,13 +422,13 @@ func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
return u.deviceScaleFactor
}
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
func (u *UserInterface) readInputState(inputState *InputState) {
u.m.Lock()
defer u.m.Unlock()
u.inputState.copyAndReset(inputState)
}
func (u *userInterfaceImpl) Window() Window {
func (u *UserInterface) Window() Window {
return &nullWindow{}
}
@ -445,15 +445,15 @@ func (m *Monitor) Name() string {
return ""
}
func (u *userInterfaceImpl) AppendMonitors(mons []*Monitor) []*Monitor {
func (u *UserInterface) AppendMonitors(mons []*Monitor) []*Monitor {
return append(mons, theMonitor)
}
func (u *userInterfaceImpl) Monitor() *Monitor {
func (u *UserInterface) Monitor() *Monitor {
return theMonitor
}
func (u *userInterfaceImpl) UpdateInput(keys map[Key]struct{}, runes []rune, touches []TouchForInput) {
func (u *UserInterface) UpdateInput(keys map[Key]struct{}, runes []rune, touches []TouchForInput) {
u.updateInputStateFromOutside(keys, runes, touches)
if u.fpsMode == FPSModeVsyncOffMinimum {
u.renderRequester.RequestRenderIfNeeded()
@ -465,24 +465,24 @@ type RenderRequester interface {
RequestRenderIfNeeded()
}
func (u *userInterfaceImpl) SetRenderRequester(renderRequester RenderRequester) {
func (u *UserInterface) SetRenderRequester(renderRequester RenderRequester) {
u.renderRequester = renderRequester
u.updateExplicitRenderingModeIfNeeded()
}
func (u *userInterfaceImpl) ScheduleFrame() {
func (u *UserInterface) ScheduleFrame() {
if u.renderRequester != nil && u.fpsMode == FPSModeVsyncOffMinimum {
u.renderRequester.RequestRenderIfNeeded()
}
}
func (u *userInterfaceImpl) beginFrame() {
func (u *UserInterface) beginFrame() {
}
func (u *userInterfaceImpl) endFrame() {
func (u *UserInterface) endFrame() {
}
func (u *userInterfaceImpl) updateIconIfNeeded() error {
func (u *UserInterface) updateIconIfNeeded() error {
return nil
}

View File

@ -74,7 +74,7 @@ type userInterfaceImpl struct {
m sync.Mutex
}
func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
func (u *UserInterface) Run(game Game, options *RunOptions) error {
u.context = newContext(game)
g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}, options.GraphicsLibrary)
if err != nil {
@ -132,59 +132,59 @@ func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
return nil
}
func (*userInterfaceImpl) DeviceScaleFactor() float64 {
func (*UserInterface) DeviceScaleFactor() float64 {
return deviceScaleFactor
}
func (*userInterfaceImpl) IsFocused() bool {
func (*UserInterface) IsFocused() bool {
return true
}
func (*userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
func (*UserInterface) ScreenSizeInFullscreen() (int, int) {
return 0, 0
}
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
func (u *UserInterface) readInputState(inputState *InputState) {
u.m.Lock()
defer u.m.Unlock()
u.inputState.copyAndReset(inputState)
}
func (*userInterfaceImpl) CursorMode() CursorMode {
func (*UserInterface) CursorMode() CursorMode {
return CursorModeHidden
}
func (*userInterfaceImpl) SetCursorMode(mode CursorMode) {
func (*UserInterface) SetCursorMode(mode CursorMode) {
}
func (*userInterfaceImpl) CursorShape() CursorShape {
func (*UserInterface) CursorShape() CursorShape {
return CursorShapeDefault
}
func (*userInterfaceImpl) SetCursorShape(shape CursorShape) {
func (*UserInterface) SetCursorShape(shape CursorShape) {
}
func (*userInterfaceImpl) IsFullscreen() bool {
func (*UserInterface) IsFullscreen() bool {
return false
}
func (*userInterfaceImpl) SetFullscreen(fullscreen bool) {
func (*UserInterface) SetFullscreen(fullscreen bool) {
}
func (*userInterfaceImpl) IsRunnableOnUnfocused() bool {
func (*UserInterface) IsRunnableOnUnfocused() bool {
return false
}
func (*userInterfaceImpl) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
func (*UserInterface) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
}
func (*userInterfaceImpl) SetFPSMode(mode FPSModeType) {
func (*UserInterface) SetFPSMode(mode FPSModeType) {
}
func (*userInterfaceImpl) ScheduleFrame() {
func (*UserInterface) ScheduleFrame() {
}
func (*userInterfaceImpl) Window() Window {
func (*UserInterface) Window() Window {
return &nullWindow{}
}
@ -201,21 +201,21 @@ func (m *Monitor) Name() string {
return ""
}
func (u *userInterfaceImpl) AppendMonitors(mons []*Monitor) []*Monitor {
func (u *UserInterface) AppendMonitors(mons []*Monitor) []*Monitor {
return append(mons, theMonitor)
}
func (u *userInterfaceImpl) Monitor() *Monitor {
func (u *UserInterface) Monitor() *Monitor {
return theMonitor
}
func (u *userInterfaceImpl) beginFrame() {
func (u *UserInterface) beginFrame() {
}
func (u *userInterfaceImpl) endFrame() {
func (u *UserInterface) endFrame() {
}
func (u *userInterfaceImpl) updateIconIfNeeded() error {
func (u *UserInterface) updateIconIfNeeded() error {
return nil
}

View File

@ -101,7 +101,7 @@ func dipToGLFWPixel(x float64, monitor *Monitor) float64 {
return x * monitor.deviceScaleFactor()
}
func (u *userInterfaceImpl) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) {
func (u *UserInterface) adjustWindowPosition(x, y int, monitor *Monitor) (int, int) {
if microsoftgdk.IsXbox() {
return x, y
}
@ -178,28 +178,28 @@ func monitorFromWin32Window(w windows.HWND) *Monitor {
return nil
}
func (u *userInterfaceImpl) nativeWindow() (uintptr, error) {
func (u *UserInterface) nativeWindow() (uintptr, error) {
w, err := u.window.GetWin32Window()
return uintptr(w), err
}
func (u *userInterfaceImpl) isNativeFullscreen() (bool, error) {
func (u *UserInterface) isNativeFullscreen() (bool, error) {
return false, nil
}
func (u *userInterfaceImpl) isNativeFullscreenAvailable() bool {
func (u *UserInterface) isNativeFullscreenAvailable() bool {
return false
}
func (u *userInterfaceImpl) setNativeFullscreen(fullscreen bool) error {
func (u *UserInterface) setNativeFullscreen(fullscreen bool) error {
panic(fmt.Sprintf("ui: setNativeFullscreen is not implemented in this environment: %s", runtime.GOOS))
}
func (u *userInterfaceImpl) adjustViewSizeAfterFullscreen() error {
func (u *UserInterface) adjustViewSizeAfterFullscreen() error {
return nil
}
func (u *userInterfaceImpl) setWindowResizingModeForOS(mode WindowResizingMode) error {
func (u *UserInterface) setWindowResizingModeForOS(mode WindowResizingMode) error {
return nil
}
@ -207,7 +207,7 @@ func initializeWindowAfterCreation(w *glfw.Window) error {
return nil
}
func (u *userInterfaceImpl) skipTaskbar() error {
func (u *UserInterface) skipTaskbar() error {
// S_FALSE is returned when CoInitializeEx is nested. This is a successful case.
if err := windows.CoInitializeEx(0, windows.COINIT_MULTITHREADED); err != nil && !errors.Is(err, syscall.Errno(windows.S_FALSE)) {
return err

View File

@ -24,7 +24,7 @@ import (
)
type glfwWindow struct {
ui *userInterfaceImpl
ui *UserInterface
}
func (w *glfwWindow) IsDecorated() bool {