mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/ui: unify the receivers for UI
This commit is contained in:
parent
77bdbac244
commit
69f1fa5f29
@ -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.
|
// 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)
|
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
|
n := 1
|
||||||
if graphicsDriver.IsDirectX() {
|
if graphicsDriver.IsDirectX() {
|
||||||
// On DirectX, both framebuffers in the swap chain should be updated.
|
// 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
|
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()
|
ui.beginFrame()
|
||||||
defer ui.endFrame()
|
defer ui.endFrame()
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ var glfwMouseButtonToMouseButton = map[glfw.MouseButton]MouseButton{
|
|||||||
glfw.MouseButton5: MouseButton4,
|
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) {
|
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.
|
// As this function is called from GLFW callbacks, the current thread is main.
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
@ -54,7 +54,7 @@ func (u *userInterfaceImpl) registerInputCallbacks() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) updateInputState() error {
|
func (u *UserInterface) updateInputState() error {
|
||||||
var err error
|
var err error
|
||||||
u.mainThread.Call(func() {
|
u.mainThread.Call(func() {
|
||||||
err = u.updateInputStateImpl()
|
err = u.updateInputStateImpl()
|
||||||
@ -63,7 +63,7 @@ func (u *userInterfaceImpl) updateInputState() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// updateInputStateImpl must be called from the main thread.
|
// updateInputStateImpl must be called from the main thread.
|
||||||
func (u *userInterfaceImpl) updateInputStateImpl() error {
|
func (u *UserInterface) updateInputStateImpl() error {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
defer u.m.Unlock()
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ func KeyName(key Key) string {
|
|||||||
return theUI.keyName(key)
|
return theUI.keyName(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) keyName(key Key) string {
|
func (u *UserInterface) keyName(key Key) string {
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ func (u *userInterfaceImpl) keyName(key Key) string {
|
|||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) saveCursorPosition() {
|
func (u *UserInterface) saveCursorPosition() {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
defer u.m.Unlock()
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ var codeToMouseButton = map[int]MouseButton{
|
|||||||
4: MouseButton4,
|
4: MouseButton4,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) keyDown(code js.Value) {
|
func (u *UserInterface) keyDown(code js.Value) {
|
||||||
id := jsKeyToID(code)
|
id := jsKeyToID(code)
|
||||||
if id < 0 {
|
if id < 0 {
|
||||||
return
|
return
|
||||||
@ -65,7 +65,7 @@ func (u *userInterfaceImpl) keyDown(code js.Value) {
|
|||||||
u.inputState.KeyPressed[id] = true
|
u.inputState.KeyPressed[id] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) keyUp(code js.Value) {
|
func (u *UserInterface) keyUp(code js.Value) {
|
||||||
id := jsKeyToID(code)
|
id := jsKeyToID(code)
|
||||||
if id < 0 {
|
if id < 0 {
|
||||||
return
|
return
|
||||||
@ -73,15 +73,15 @@ func (u *userInterfaceImpl) keyUp(code js.Value) {
|
|||||||
u.inputState.KeyPressed[id] = false
|
u.inputState.KeyPressed[id] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) mouseDown(code int) {
|
func (u *UserInterface) mouseDown(code int) {
|
||||||
u.inputState.MouseButtonPressed[codeToMouseButton[code]] = true
|
u.inputState.MouseButtonPressed[codeToMouseButton[code]] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) mouseUp(code int) {
|
func (u *UserInterface) mouseUp(code int) {
|
||||||
u.inputState.MouseButtonPressed[codeToMouseButton[code]] = false
|
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
|
// Avoid using js.Value.String() as String creates a Uint8Array via a TextEncoder and causes a heavy
|
||||||
// overhead (#1437).
|
// overhead (#1437).
|
||||||
switch t := e.Get("type"); {
|
switch t := e.Get("type"); {
|
||||||
@ -114,7 +114,7 @@ func (u *userInterfaceImpl) updateInputFromEvent(e js.Value) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setMouseCursorFromEvent(e js.Value) {
|
func (u *UserInterface) setMouseCursorFromEvent(e js.Value) {
|
||||||
if u.context == nil {
|
if u.context == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -132,12 +132,12 @@ func (u *userInterfaceImpl) setMouseCursorFromEvent(e js.Value) {
|
|||||||
u.cursorYInClient = u.origCursorYInClient
|
u.cursorYInClient = u.origCursorYInClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) recoverCursorPosition() {
|
func (u *UserInterface) recoverCursorPosition() {
|
||||||
u.cursorXInClient = u.origCursorXInClient
|
u.cursorXInClient = u.origCursorXInClient
|
||||||
u.cursorYInClient = u.origCursorYInClient
|
u.cursorYInClient = u.origCursorYInClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) updateTouchesFromEvent(e js.Value) {
|
func (u *UserInterface) updateTouchesFromEvent(e js.Value) {
|
||||||
u.touchesInClient = u.touchesInClient[:0]
|
u.touchesInClient = u.touchesInClient[:0]
|
||||||
|
|
||||||
touches := e.Get("targetTouches")
|
touches := e.Get("targetTouches")
|
||||||
@ -203,7 +203,7 @@ func KeyName(key Key) string {
|
|||||||
return theUI.keyName(key)
|
return theUI.keyName(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) keyName(key Key) string {
|
func (u *UserInterface) keyName(key Key) string {
|
||||||
if !u.running {
|
if !u.running {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -231,7 +231,7 @@ func UpdateInputFromEvent(e js.Value) {
|
|||||||
theUI.updateInputFromEvent(e)
|
theUI.updateInputFromEvent(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) saveCursorPosition() {
|
func (u *UserInterface) saveCursorPosition() {
|
||||||
u.savedCursorX = u.inputState.CursorX
|
u.savedCursorX = u.inputState.CursorX
|
||||||
u.savedCursorY = u.inputState.CursorY
|
u.savedCursorY = u.inputState.CursorY
|
||||||
w, h := u.outsideSize()
|
w, h := u.outsideSize()
|
||||||
@ -239,7 +239,7 @@ func (u *userInterfaceImpl) saveCursorPosition() {
|
|||||||
u.savedOutsideHeight = h
|
u.savedOutsideHeight = h
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) updateInputState() error {
|
func (u *UserInterface) updateInputState() error {
|
||||||
s := u.DeviceScaleFactor()
|
s := u.DeviceScaleFactor()
|
||||||
|
|
||||||
if !math.IsNaN(u.savedCursorX) && !math.IsNaN(u.savedCursorY) {
|
if !math.IsNaN(u.savedCursorX) && !math.IsNaN(u.savedCursorY) {
|
||||||
|
@ -26,7 +26,7 @@ type TouchForInput struct {
|
|||||||
Y float64
|
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()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
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()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
defer u.m.Unlock()
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (u *userInterfaceImpl) updateInputState() error {
|
func (u *UserInterface) updateInputState() error {
|
||||||
var err error
|
var err error
|
||||||
u.mainThread.Call(func() {
|
u.mainThread.Call(func() {
|
||||||
err = u.updateInputStateImpl()
|
err = u.updateInputStateImpl()
|
||||||
@ -38,7 +38,7 @@ func (u *userInterfaceImpl) updateInputState() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// updateInputStateImpl must be called from the main thread.
|
// updateInputStateImpl must be called from the main thread.
|
||||||
func (u *userInterfaceImpl) updateInputStateImpl() error {
|
func (u *UserInterface) updateInputStateImpl() error {
|
||||||
if err := gamepad.Update(); err != nil {
|
if err := gamepad.Update(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/thread"
|
"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.context = newContext(game)
|
||||||
|
|
||||||
u.mainThread = thread.NewOSThread()
|
u.mainThread = thread.NewOSThread()
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/thread"
|
"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.context = newContext(game)
|
||||||
|
|
||||||
// Initialize the main thread first so the thread is available at u.run (#809).
|
// Initialize the main thread first so the thread is available at u.run (#809).
|
||||||
|
@ -211,7 +211,7 @@ func dipToGLFWPixel(x float64, monitor *Monitor) float64 {
|
|||||||
return x
|
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
|
return x, y
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,11 +302,11 @@ func monitorFromWindowByOS(w *glfw.Window) (*Monitor, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) nativeWindow() (uintptr, error) {
|
func (u *UserInterface) nativeWindow() (uintptr, error) {
|
||||||
return u.window.GetCocoaWindow()
|
return u.window.GetCocoaWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isNativeFullscreen() (bool, error) {
|
func (u *UserInterface) isNativeFullscreen() (bool, error) {
|
||||||
w, err := u.window.GetCocoaWindow()
|
w, err := u.window.GetCocoaWindow()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
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
|
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).
|
// 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?
|
// However, if the user clicks the green button, should this window be in native fullscreen mode?
|
||||||
return true
|
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.
|
// Toggling fullscreen might ignore events like keyUp. Ensure that events are fired.
|
||||||
if err := glfw.WaitEventsTimeout(0.1); err != nil {
|
if err := glfw.WaitEventsTimeout(0.1); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -351,7 +351,7 @@ func (u *userInterfaceImpl) setNativeFullscreen(fullscreen bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) adjustViewSizeAfterFullscreen() error {
|
func (u *UserInterface) adjustViewSizeAfterFullscreen() error {
|
||||||
if u.graphicsDriver.IsGL() {
|
if u.graphicsDriver.IsGL() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -382,7 +382,7 @@ func (u *userInterfaceImpl) adjustViewSizeAfterFullscreen() error {
|
|||||||
return nil
|
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 {
|
if u.maxWindowWidthInDIP != glfw.DontCare || u.maxWindowHeightInDIP != glfw.DontCare {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -395,7 +395,7 @@ func (u *userInterfaceImpl) isFullscreenAllowedFromUI(mode WindowResizingMode) b
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setWindowResizingModeForOS(mode WindowResizingMode) error {
|
func (u *UserInterface) setWindowResizingModeForOS(mode WindowResizingMode) error {
|
||||||
var collectionBehavior uint
|
var collectionBehavior uint
|
||||||
if u.isFullscreenAllowedFromUI(mode) {
|
if u.isFullscreenAllowedFromUI(mode) {
|
||||||
collectionBehavior |= cocoa.NSWindowCollectionBehaviorManaged
|
collectionBehavior |= cocoa.NSWindowCollectionBehaviorManaged
|
||||||
@ -424,6 +424,6 @@ func initializeWindowAfterCreation(w *glfw.Window) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) skipTaskbar() error {
|
func (u *UserInterface) skipTaskbar() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ func init() {
|
|||||||
savedCursorX: math.NaN(),
|
savedCursorX: math.NaN(),
|
||||||
savedCursorY: math.NaN(),
|
savedCursorY: math.NaN(),
|
||||||
}
|
}
|
||||||
theUI.iwindow.ui = &theUI.userInterfaceImpl
|
theUI.iwindow.ui = theUI
|
||||||
|
|
||||||
hideConsoleWindowOnWindows()
|
hideConsoleWindowOnWindows()
|
||||||
|
|
||||||
@ -245,25 +245,25 @@ func initialize() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setInitMonitor(m *Monitor) {
|
func (u *UserInterface) setInitMonitor(m *Monitor) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
defer u.m.Unlock()
|
||||||
u.initMonitor = m
|
u.initMonitor = m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) getInitMonitor() *Monitor {
|
func (u *UserInterface) getInitMonitor() *Monitor {
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
defer u.m.RUnlock()
|
defer u.m.RUnlock()
|
||||||
return u.initMonitor
|
return u.initMonitor
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendMonitors appends the current monitors to the passed in mons slice and returns it.
|
// 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)
|
return theMonitors.append(monitors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Monitor returns the window's current monitor. Returns nil if there is no current monitor yet.
|
// 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() {
|
if !u.isRunning() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -282,15 +282,15 @@ func (u *userInterfaceImpl) Monitor() *Monitor {
|
|||||||
return monitor
|
return monitor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isRunning() bool {
|
func (u *UserInterface) isRunning() bool {
|
||||||
return atomic.LoadUint32(&u.running) != 0 && !u.isTerminated()
|
return atomic.LoadUint32(&u.running) != 0 && !u.isTerminated()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isTerminated() bool {
|
func (u *UserInterface) isTerminated() bool {
|
||||||
return atomic.LoadUint32(&u.terminated) != 0
|
return atomic.LoadUint32(&u.terminated) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setRunning(running bool) {
|
func (u *UserInterface) setRunning(running bool) {
|
||||||
if running {
|
if running {
|
||||||
atomic.StoreUint32(&u.running, 1)
|
atomic.StoreUint32(&u.running, 1)
|
||||||
} else {
|
} else {
|
||||||
@ -298,12 +298,12 @@ func (u *userInterfaceImpl) setRunning(running bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setTerminated() {
|
func (u *UserInterface) setTerminated() {
|
||||||
atomic.StoreUint32(&u.terminated, 1)
|
atomic.StoreUint32(&u.terminated, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// setWindowMonitor must be called on the main thread.
|
// 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() {
|
if microsoftgdk.IsXbox() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -365,7 +365,7 @@ func (u *userInterfaceImpl) setWindowMonitor(monitor *Monitor) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) getWindowSizeLimitsInDIP() (minw, minh, maxw, maxh int) {
|
func (u *UserInterface) getWindowSizeLimitsInDIP() (minw, minh, maxw, maxh int) {
|
||||||
if microsoftgdk.IsXbox() {
|
if microsoftgdk.IsXbox() {
|
||||||
return glfw.DontCare, glfw.DontCare, glfw.DontCare, glfw.DontCare
|
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
|
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() {
|
if microsoftgdk.IsXbox() {
|
||||||
// Do nothing. The size is always fixed.
|
// Do nothing. The size is always fixed.
|
||||||
return false
|
return false
|
||||||
@ -393,45 +393,45 @@ func (u *userInterfaceImpl) setWindowSizeLimitsInDIP(minw, minh, maxw, maxh int)
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isWindowMaximizable() bool {
|
func (u *UserInterface) isWindowMaximizable() bool {
|
||||||
_, _, maxw, maxh := u.getWindowSizeLimitsInDIP()
|
_, _, maxw, maxh := u.getWindowSizeLimitsInDIP()
|
||||||
return maxw == glfw.DontCare && maxh == glfw.DontCare
|
return maxw == glfw.DontCare && maxh == glfw.DontCare
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isInitFullscreen() bool {
|
func (u *UserInterface) isInitFullscreen() bool {
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
v := u.initFullscreen
|
v := u.initFullscreen
|
||||||
u.m.RUnlock()
|
u.m.RUnlock()
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setInitFullscreen(initFullscreen bool) {
|
func (u *UserInterface) setInitFullscreen(initFullscreen bool) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
u.initFullscreen = initFullscreen
|
u.initFullscreen = initFullscreen
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) getInitCursorMode() CursorMode {
|
func (u *UserInterface) getInitCursorMode() CursorMode {
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
v := u.initCursorMode
|
v := u.initCursorMode
|
||||||
u.m.RUnlock()
|
u.m.RUnlock()
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setInitCursorMode(mode CursorMode) {
|
func (u *UserInterface) setInitCursorMode(mode CursorMode) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
u.initCursorMode = mode
|
u.initCursorMode = mode
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) getCursorShape() CursorShape {
|
func (u *UserInterface) getCursorShape() CursorShape {
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
v := u.cursorShape
|
v := u.cursorShape
|
||||||
u.m.RUnlock()
|
u.m.RUnlock()
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setCursorShape(shape CursorShape) CursorShape {
|
func (u *UserInterface) setCursorShape(shape CursorShape) CursorShape {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
old := u.cursorShape
|
old := u.cursorShape
|
||||||
u.cursorShape = shape
|
u.cursorShape = shape
|
||||||
@ -439,33 +439,33 @@ func (u *userInterfaceImpl) setCursorShape(shape CursorShape) CursorShape {
|
|||||||
return old
|
return old
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isInitWindowDecorated() bool {
|
func (u *UserInterface) isInitWindowDecorated() bool {
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
v := u.initWindowDecorated
|
v := u.initWindowDecorated
|
||||||
u.m.RUnlock()
|
u.m.RUnlock()
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setInitWindowDecorated(decorated bool) {
|
func (u *UserInterface) setInitWindowDecorated(decorated bool) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
u.initWindowDecorated = decorated
|
u.initWindowDecorated = decorated
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isRunnableOnUnfocused() bool {
|
func (u *UserInterface) isRunnableOnUnfocused() bool {
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
v := u.runnableOnUnfocused
|
v := u.runnableOnUnfocused
|
||||||
u.m.RUnlock()
|
u.m.RUnlock()
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setRunnableOnUnfocused(runnableOnUnfocused bool) {
|
func (u *UserInterface) setRunnableOnUnfocused(runnableOnUnfocused bool) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
u.runnableOnUnfocused = runnableOnUnfocused
|
u.runnableOnUnfocused = runnableOnUnfocused
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) getAndResetIconImages() []image.Image {
|
func (u *UserInterface) getAndResetIconImages() []image.Image {
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
defer u.m.RUnlock()
|
defer u.m.RUnlock()
|
||||||
s := u.iconImages
|
s := u.iconImages
|
||||||
@ -473,7 +473,7 @@ func (u *userInterfaceImpl) getAndResetIconImages() []image.Image {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setIconImages(iconImages []image.Image) {
|
func (u *UserInterface) setIconImages(iconImages []image.Image) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
defer u.m.Unlock()
|
||||||
|
|
||||||
@ -484,7 +484,7 @@ func (u *userInterfaceImpl) setIconImages(iconImages []image.Image) {
|
|||||||
copy(u.iconImages, iconImages)
|
copy(u.iconImages, iconImages)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) getInitWindowPositionInDIP() (int, int) {
|
func (u *UserInterface) getInitWindowPositionInDIP() (int, int) {
|
||||||
if microsoftgdk.IsXbox() {
|
if microsoftgdk.IsXbox() {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
@ -497,7 +497,7 @@ func (u *userInterfaceImpl) getInitWindowPositionInDIP() (int, int) {
|
|||||||
return invalidPos, invalidPos
|
return invalidPos, invalidPos
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setInitWindowPositionInDIP(x, y int) {
|
func (u *UserInterface) setInitWindowPositionInDIP(x, y int) {
|
||||||
if microsoftgdk.IsXbox() {
|
if microsoftgdk.IsXbox() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -510,7 +510,7 @@ func (u *userInterfaceImpl) setInitWindowPositionInDIP(x, y int) {
|
|||||||
u.initWindowPositionYInDIP = y
|
u.initWindowPositionYInDIP = y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) getInitWindowSizeInDIP() (int, int) {
|
func (u *UserInterface) getInitWindowSizeInDIP() (int, int) {
|
||||||
if microsoftgdk.IsXbox() {
|
if microsoftgdk.IsXbox() {
|
||||||
return microsoftgdk.MonitorResolution()
|
return microsoftgdk.MonitorResolution()
|
||||||
}
|
}
|
||||||
@ -520,7 +520,7 @@ func (u *userInterfaceImpl) getInitWindowSizeInDIP() (int, int) {
|
|||||||
return u.initWindowWidthInDIP, u.initWindowHeightInDIP
|
return u.initWindowWidthInDIP, u.initWindowHeightInDIP
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setInitWindowSizeInDIP(width, height int) {
|
func (u *UserInterface) setInitWindowSizeInDIP(width, height int) {
|
||||||
if microsoftgdk.IsXbox() {
|
if microsoftgdk.IsXbox() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -530,7 +530,7 @@ func (u *userInterfaceImpl) setInitWindowSizeInDIP(width, height int) {
|
|||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isInitWindowFloating() bool {
|
func (u *UserInterface) isInitWindowFloating() bool {
|
||||||
if microsoftgdk.IsXbox() {
|
if microsoftgdk.IsXbox() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -541,7 +541,7 @@ func (u *userInterfaceImpl) isInitWindowFloating() bool {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setInitWindowFloating(floating bool) {
|
func (u *UserInterface) setInitWindowFloating(floating bool) {
|
||||||
if microsoftgdk.IsXbox() {
|
if microsoftgdk.IsXbox() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -551,7 +551,7 @@ func (u *userInterfaceImpl) setInitWindowFloating(floating bool) {
|
|||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isInitWindowMaximized() bool {
|
func (u *UserInterface) isInitWindowMaximized() bool {
|
||||||
// TODO: Is this always true on Xbox?
|
// TODO: Is this always true on Xbox?
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
m := u.initWindowMaximized
|
m := u.initWindowMaximized
|
||||||
@ -559,38 +559,38 @@ func (u *userInterfaceImpl) isInitWindowMaximized() bool {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setInitWindowMaximized(maximized bool) {
|
func (u *UserInterface) setInitWindowMaximized(maximized bool) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
u.initWindowMaximized = maximized
|
u.initWindowMaximized = maximized
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isInitWindowMousePassthrough() bool {
|
func (u *UserInterface) isInitWindowMousePassthrough() bool {
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
defer u.m.RUnlock()
|
defer u.m.RUnlock()
|
||||||
return u.initWindowMousePassthrough
|
return u.initWindowMousePassthrough
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setInitWindowMousePassthrough(enabled bool) {
|
func (u *UserInterface) setInitWindowMousePassthrough(enabled bool) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
defer u.m.Unlock()
|
||||||
u.initWindowMousePassthrough = enabled
|
u.initWindowMousePassthrough = enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isWindowClosingHandled() bool {
|
func (u *UserInterface) isWindowClosingHandled() bool {
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
v := u.windowClosingHandled
|
v := u.windowClosingHandled
|
||||||
u.m.RUnlock()
|
u.m.RUnlock()
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setWindowClosingHandled(handled bool) {
|
func (u *UserInterface) setWindowClosingHandled(handled bool) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
u.windowClosingHandled = handled
|
u.windowClosingHandled = handled
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
|
func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
|
||||||
if u.isTerminated() {
|
if u.isTerminated() {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
@ -621,7 +621,7 @@ func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// isFullscreen must be called from the main thread.
|
// isFullscreen must be called from the main thread.
|
||||||
func (u *userInterfaceImpl) isFullscreen() (bool, error) {
|
func (u *UserInterface) isFullscreen() (bool, error) {
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
panic("ui: isFullscreen can't be called before the main loop starts")
|
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
|
return m != nil || n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) IsFullscreen() bool {
|
func (u *UserInterface) IsFullscreen() bool {
|
||||||
if microsoftgdk.IsXbox() {
|
if microsoftgdk.IsXbox() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -662,7 +662,7 @@ func (u *userInterfaceImpl) IsFullscreen() bool {
|
|||||||
return fullscreen
|
return fullscreen
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetFullscreen(fullscreen bool) {
|
func (u *UserInterface) SetFullscreen(fullscreen bool) {
|
||||||
if microsoftgdk.IsXbox() {
|
if microsoftgdk.IsXbox() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -694,7 +694,7 @@ func (u *userInterfaceImpl) SetFullscreen(fullscreen bool) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) IsFocused() bool {
|
func (u *UserInterface) IsFocused() bool {
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -714,15 +714,15 @@ func (u *userInterfaceImpl) IsFocused() bool {
|
|||||||
return focused
|
return focused
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
|
func (u *UserInterface) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
|
||||||
u.setRunnableOnUnfocused(runnableOnUnfocused)
|
u.setRunnableOnUnfocused(runnableOnUnfocused)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) IsRunnableOnUnfocused() bool {
|
func (u *UserInterface) IsRunnableOnUnfocused() bool {
|
||||||
return u.isRunnableOnUnfocused()
|
return u.isRunnableOnUnfocused()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetFPSMode(mode FPSModeType) {
|
func (u *UserInterface) SetFPSMode(mode FPSModeType) {
|
||||||
if u.isTerminated() {
|
if u.isTerminated() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -748,7 +748,7 @@ func (u *userInterfaceImpl) SetFPSMode(mode FPSModeType) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) ScheduleFrame() {
|
func (u *UserInterface) ScheduleFrame() {
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -760,7 +760,7 @@ func (u *userInterfaceImpl) ScheduleFrame() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) CursorMode() CursorMode {
|
func (u *UserInterface) CursorMode() CursorMode {
|
||||||
if u.isTerminated() {
|
if u.isTerminated() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -795,7 +795,7 @@ func (u *userInterfaceImpl) CursorMode() CursorMode {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetCursorMode(mode CursorMode) {
|
func (u *UserInterface) SetCursorMode(mode CursorMode) {
|
||||||
if u.isTerminated() {
|
if u.isTerminated() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -820,11 +820,11 @@ func (u *userInterfaceImpl) SetCursorMode(mode CursorMode) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) CursorShape() CursorShape {
|
func (u *UserInterface) CursorShape() CursorShape {
|
||||||
return u.getCursorShape()
|
return u.getCursorShape()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetCursorShape(shape CursorShape) {
|
func (u *UserInterface) SetCursorShape(shape CursorShape) {
|
||||||
if u.isTerminated() {
|
if u.isTerminated() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -847,7 +847,7 @@ func (u *userInterfaceImpl) SetCursorShape(shape CursorShape) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
|
func (u *UserInterface) DeviceScaleFactor() float64 {
|
||||||
if u.isTerminated() {
|
if u.isTerminated() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -873,7 +873,7 @@ func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
|
|||||||
// createWindow creates a GLFW window.
|
// createWindow creates a GLFW window.
|
||||||
//
|
//
|
||||||
// createWindow must be called from the main thread.
|
// createWindow must be called from the main thread.
|
||||||
func (u *userInterfaceImpl) createWindow() error {
|
func (u *UserInterface) createWindow() error {
|
||||||
if u.window != nil {
|
if u.window != nil {
|
||||||
panic("ui: u.window must not exist at createWindow")
|
panic("ui: u.window must not exist at createWindow")
|
||||||
}
|
}
|
||||||
@ -941,14 +941,14 @@ func (u *userInterfaceImpl) createWindow() error {
|
|||||||
return nil
|
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.
|
// registerWindowCloseCallback must be called from the main thread.
|
||||||
func (u *userInterfaceImpl) registerWindowCloseCallback() error {
|
func (u *UserInterface) registerWindowCloseCallback() error {
|
||||||
if u.closeCallback == nil {
|
if u.closeCallback == nil {
|
||||||
u.closeCallback = func(_ *glfw.Window) {
|
u.closeCallback = func(_ *glfw.Window) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
@ -975,7 +975,7 @@ func (u *userInterfaceImpl) registerWindowCloseCallback() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// registerWindowFramebufferSizeCallback must be called from the main thread.
|
// 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" {
|
if u.defaultFramebufferSizeCallback == nil && runtime.GOOS != "darwin" {
|
||||||
// When the window gets resized (either by manual window resize or a window
|
// 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).
|
// manager), glfw sends a framebuffer size callback which we need to handle (#1960).
|
||||||
@ -1023,7 +1023,7 @@ func (u *userInterfaceImpl) registerWindowFramebufferSizeCallback() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) registerDropCallback() error {
|
func (u *UserInterface) registerDropCallback() error {
|
||||||
if u.dropCallback == nil {
|
if u.dropCallback == nil {
|
||||||
u.dropCallback = func(_ *glfw.Window, names []string) {
|
u.dropCallback = func(_ *glfw.Window, names []string) {
|
||||||
u.m.Lock()
|
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.
|
// If the callback is not invoked for a while, waitForFramebufferSizeCallback times out and return.
|
||||||
//
|
//
|
||||||
// waitForFramebufferSizeCallback must be called from the main thread.
|
// 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)
|
u.framebufferSizeCallbackCh = make(chan struct{}, 1)
|
||||||
|
|
||||||
if u.framebufferSizeCallback == nil {
|
if u.framebufferSizeCallback == nil {
|
||||||
@ -1093,7 +1093,7 @@ event:
|
|||||||
return nil
|
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 {
|
if err := glfw.WindowHint(glfw.AutoIconify, glfw.False); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1236,7 +1236,7 @@ func (u *userInterfaceImpl) initOnMainThread(options *RunOptions) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) outsideSize() (float64, float64, error) {
|
func (u *UserInterface) outsideSize() (float64, float64, error) {
|
||||||
f, err := u.isFullscreen()
|
f, err := u.isFullscreen()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
@ -1286,7 +1286,7 @@ func (u *userInterfaceImpl) outsideSize() (float64, float64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setFPSMode must be called from the main thread.
|
// 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
|
needUpdate := u.fpsMode != fpsMode || !u.fpsModeInited
|
||||||
u.fpsMode = fpsMode
|
u.fpsMode = fpsMode
|
||||||
u.fpsModeInited = true
|
u.fpsModeInited = true
|
||||||
@ -1310,7 +1310,7 @@ func (u *userInterfaceImpl) setFPSMode(fpsMode FPSModeType) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update must be called from the main thread.
|
// 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 {
|
if err := theGlobalState.error(); err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
@ -1402,7 +1402,7 @@ func (u *userInterfaceImpl) update() (float64, float64, error) {
|
|||||||
return u.outsideSize()
|
return u.outsideSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) loopGame() (ferr error) {
|
func (u *UserInterface) loopGame() (ferr error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
// Post a task to the render thread to ensure all the queued functions are executed.
|
// 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.
|
// 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
|
var unfocused bool
|
||||||
|
|
||||||
// On Windows, the focusing state might be always false (#987).
|
// On Windows, the focusing state might be always false (#987).
|
||||||
@ -1508,7 +1508,7 @@ func (u *userInterfaceImpl) updateGame() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) updateIconIfNeeded() error {
|
func (u *UserInterface) updateIconIfNeeded() error {
|
||||||
// In the fullscreen mode, SetIcon fails (#1578).
|
// In the fullscreen mode, SetIcon fails (#1578).
|
||||||
f, err := u.isFullscreen()
|
f, err := u.isFullscreen()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1560,7 +1560,7 @@ func (u *userInterfaceImpl) updateIconIfNeeded() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) swapBuffersOnRenderThread() error {
|
func (u *UserInterface) swapBuffersOnRenderThread() error {
|
||||||
if u.graphicsDriver.IsGL() {
|
if u.graphicsDriver.IsGL() {
|
||||||
if err := u.window.SwapBuffers(); err != nil {
|
if err := u.window.SwapBuffers(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1570,7 +1570,7 @@ func (u *userInterfaceImpl) swapBuffersOnRenderThread() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// updateWindowSizeLimits must be called from the main thread.
|
// updateWindowSizeLimits must be called from the main thread.
|
||||||
func (u *userInterfaceImpl) updateWindowSizeLimits() error {
|
func (u *UserInterface) updateWindowSizeLimits() error {
|
||||||
m, err := u.currentMonitor()
|
m, err := u.currentMonitor()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1618,13 +1618,13 @@ func (u *userInterfaceImpl) updateWindowSizeLimits() error {
|
|||||||
// In order to enable the size limitation, call updateWindowSizeLimits.
|
// In order to enable the size limitation, call updateWindowSizeLimits.
|
||||||
//
|
//
|
||||||
// disableWindowSizeLimits must be called from the main thread.
|
// 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)
|
return u.window.SetSizeLimits(glfw.DontCare, glfw.DontCare, glfw.DontCare, glfw.DontCare)
|
||||||
}
|
}
|
||||||
|
|
||||||
// adjustWindowSizeBasedOnSizeLimitsInDIP adjust the size based on the window size limits.
|
// adjustWindowSizeBasedOnSizeLimitsInDIP adjust the size based on the window size limits.
|
||||||
// width and height are in device-independent pixels.
|
// 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()
|
minw, minh, maxw, maxh := u.getWindowSizeLimitsInDIP()
|
||||||
if minw >= 0 && width < minw {
|
if minw >= 0 && width < minw {
|
||||||
width = minw
|
width = minw
|
||||||
@ -1642,7 +1642,7 @@ func (u *userInterfaceImpl) adjustWindowSizeBasedOnSizeLimitsInDIP(width, height
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setWindowSize must be called from the main thread.
|
// 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() {
|
if microsoftgdk.IsXbox() {
|
||||||
// Do nothing. The size is always fixed.
|
// Do nothing. The size is always fixed.
|
||||||
return nil
|
return nil
|
||||||
@ -1708,7 +1708,7 @@ func (u *userInterfaceImpl) setWindowSizeInDIP(width, height int, callSetSize bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setOrigWindowPosWithCurrentPos must be called from the main thread.
|
// 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 {
|
if x, y := u.origWindowPos(); x == invalidPos || y == invalidPos {
|
||||||
x, y, err := u.window.GetPos()
|
x, y, err := u.window.GetPos()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -1720,7 +1720,7 @@ func (u *userInterfaceImpl) setOrigWindowPosWithCurrentPos() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setFullscreen must be called from the main thread.
|
// 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()
|
f, err := u.isFullscreen()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1843,7 +1843,7 @@ func (u *userInterfaceImpl) setFullscreen(fullscreen bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) minimumWindowWidth() (int, error) {
|
func (u *UserInterface) minimumWindowWidth() (int, error) {
|
||||||
a, err := u.window.GetAttrib(glfw.Decorated)
|
a, err := u.window.GetAttrib(glfw.Decorated)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@ -1864,7 +1864,7 @@ func (u *userInterfaceImpl) minimumWindowWidth() (int, error) {
|
|||||||
return 1, nil
|
return 1, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) updateVsyncOnRenderThread() error {
|
func (u *UserInterface) updateVsyncOnRenderThread() error {
|
||||||
if u.graphicsDriver.IsGL() {
|
if u.graphicsDriver.IsGL() {
|
||||||
// SwapInterval is affected by the current monitor of the window.
|
// SwapInterval is affected by the current monitor of the window.
|
||||||
// This needs to be called at least after SetMonitor.
|
// 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 returns the current active monitor.
|
||||||
//
|
//
|
||||||
// currentMonitor must be called on the main thread.
|
// currentMonitor must be called on the main thread.
|
||||||
func (u *userInterfaceImpl) currentMonitor() (*Monitor, error) {
|
func (u *UserInterface) currentMonitor() (*Monitor, error) {
|
||||||
if u.window == nil {
|
if u.window == nil {
|
||||||
return u.getInitMonitor(), nil
|
return u.getInitMonitor(), nil
|
||||||
}
|
}
|
||||||
@ -1927,13 +1927,13 @@ func (u *userInterfaceImpl) currentMonitor() (*Monitor, error) {
|
|||||||
return theMonitors.primaryMonitor(), nil
|
return theMonitors.primaryMonitor(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
|
func (u *UserInterface) readInputState(inputState *InputState) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
defer u.m.Unlock()
|
||||||
u.inputState.copyAndReset(inputState)
|
u.inputState.copyAndReset(inputState)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) Window() Window {
|
func (u *UserInterface) Window() Window {
|
||||||
if microsoftgdk.IsXbox() {
|
if microsoftgdk.IsXbox() {
|
||||||
return &nullWindow{}
|
return &nullWindow{}
|
||||||
}
|
}
|
||||||
@ -1945,7 +1945,7 @@ func (u *userInterfaceImpl) Window() Window {
|
|||||||
// disable the callback temporarily.
|
// disable the callback temporarily.
|
||||||
|
|
||||||
// maximizeWindow must be called from the main thread.
|
// maximizeWindow must be called from the main thread.
|
||||||
func (u *userInterfaceImpl) maximizeWindow() error {
|
func (u *UserInterface) maximizeWindow() error {
|
||||||
n, err := u.isNativeFullscreen()
|
n, err := u.isNativeFullscreen()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -1985,7 +1985,7 @@ func (u *userInterfaceImpl) maximizeWindow() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// iconifyWindow must be called from the main thread.
|
// 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.
|
// Iconifying a native fullscreen window on macOS is forbidden.
|
||||||
n, err := u.isNativeFullscreen()
|
n, err := u.isNativeFullscreen()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -2017,7 +2017,7 @@ func (u *userInterfaceImpl) iconifyWindow() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// restoreWindow must be called from the main thread.
|
// 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 {
|
if err := u.window.Restore(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -2048,7 +2048,7 @@ func (u *userInterfaceImpl) restoreWindow() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setWindowDecorated must be called from the main thread.
|
// 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() {
|
if microsoftgdk.IsXbox() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -2072,7 +2072,7 @@ func (u *userInterfaceImpl) setWindowDecorated(decorated bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setWindowFloating must be called from the main thread.
|
// 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() {
|
if microsoftgdk.IsXbox() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -2089,7 +2089,7 @@ func (u *userInterfaceImpl) setWindowFloating(floating bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setWindowResizingMode must be called from the main thread.
|
// 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() {
|
if microsoftgdk.IsXbox() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -2119,7 +2119,7 @@ func (u *userInterfaceImpl) setWindowResizingMode(mode WindowResizingMode) error
|
|||||||
// x and y are the position in device-independent pixels.
|
// x and y are the position in device-independent pixels.
|
||||||
//
|
//
|
||||||
// setWindowPositionInDIP must be called from the main thread.
|
// 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() {
|
if microsoftgdk.IsXbox() {
|
||||||
// Do nothing. The position is always fixed.
|
// Do nothing. The position is always fixed.
|
||||||
return nil
|
return nil
|
||||||
@ -2146,12 +2146,12 @@ func (u *userInterfaceImpl) setWindowPositionInDIP(x, y int, monitor *Monitor) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setWindowTitle must be called from the main thread.
|
// 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)
|
return u.window.SetTitle(title)
|
||||||
}
|
}
|
||||||
|
|
||||||
// isWindowMaximized must be called from the main thread.
|
// 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)
|
a, err := u.window.GetAttrib(glfw.Maximized)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@ -2163,17 +2163,17 @@ func (u *userInterfaceImpl) isWindowMaximized() (bool, error) {
|
|||||||
return a == glfw.True && !n, nil
|
return a == glfw.True && !n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) origWindowPos() (int, int) {
|
func (u *UserInterface) origWindowPos() (int, int) {
|
||||||
return u.origWindowPosX, u.origWindowPosY
|
return u.origWindowPosX, u.origWindowPosY
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setOrigWindowPos(x, y int) {
|
func (u *UserInterface) setOrigWindowPos(x, y int) {
|
||||||
u.origWindowPosX = x
|
u.origWindowPosX = x
|
||||||
u.origWindowPosY = y
|
u.origWindowPosY = y
|
||||||
}
|
}
|
||||||
|
|
||||||
// setWindowMousePassthrough must be called from the main thread.
|
// 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() {
|
if microsoftgdk.IsXbox() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ func IsGL() (bool, error) {
|
|||||||
return theUI.isGL()
|
return theUI.isGL()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setUIView(uiview uintptr) error {
|
func (u *UserInterface) setUIView(uiview uintptr) error {
|
||||||
select {
|
select {
|
||||||
case err := <-u.errCh:
|
case err := <-u.errCh:
|
||||||
return err
|
return err
|
||||||
@ -87,7 +87,7 @@ func (u *userInterfaceImpl) setUIView(uiview uintptr) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isGL() (bool, error) {
|
func (u *UserInterface) isGL() (bool, error) {
|
||||||
select {
|
select {
|
||||||
case err := <-u.errCh:
|
case err := <-u.errCh:
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -129,11 +129,11 @@ var (
|
|||||||
documentHidden = js.Global().Get("Object").Call("getOwnPropertyDescriptor", js.Global().Get("Document").Get("prototype"), "hidden").Get("get").Call("bind", document)
|
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()
|
return window.Get("innerWidth").Int(), window.Get("innerHeight").Int()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetFullscreen(fullscreen bool) {
|
func (u *UserInterface) SetFullscreen(fullscreen bool) {
|
||||||
if !canvas.Truthy() {
|
if !canvas.Truthy() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ func (u *userInterfaceImpl) SetFullscreen(fullscreen bool) {
|
|||||||
f.Call("bind", document).Invoke()
|
f.Call("bind", document).Invoke()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) IsFullscreen() bool {
|
func (u *UserInterface) IsFullscreen() bool {
|
||||||
if !document.Truthy() {
|
if !document.Truthy() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -174,34 +174,34 @@ func (u *userInterfaceImpl) IsFullscreen() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) IsFocused() bool {
|
func (u *UserInterface) IsFocused() bool {
|
||||||
return u.isFocused()
|
return u.isFocused()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
|
func (u *UserInterface) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
|
||||||
u.runnableOnUnfocused = runnableOnUnfocused
|
u.runnableOnUnfocused = runnableOnUnfocused
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) IsRunnableOnUnfocused() bool {
|
func (u *UserInterface) IsRunnableOnUnfocused() bool {
|
||||||
return u.runnableOnUnfocused
|
return u.runnableOnUnfocused
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetFPSMode(mode FPSModeType) {
|
func (u *UserInterface) SetFPSMode(mode FPSModeType) {
|
||||||
u.fpsMode = mode
|
u.fpsMode = mode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) ScheduleFrame() {
|
func (u *UserInterface) ScheduleFrame() {
|
||||||
u.renderingScheduled = true
|
u.renderingScheduled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) CursorMode() CursorMode {
|
func (u *UserInterface) CursorMode() CursorMode {
|
||||||
if !canvas.Truthy() {
|
if !canvas.Truthy() {
|
||||||
return CursorModeHidden
|
return CursorModeHidden
|
||||||
}
|
}
|
||||||
return u.cursorMode
|
return u.cursorMode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetCursorMode(mode CursorMode) {
|
func (u *UserInterface) SetCursorMode(mode CursorMode) {
|
||||||
if mode == CursorModeCaptured && !u.canCaptureCursor() {
|
if mode == CursorModeCaptured && !u.canCaptureCursor() {
|
||||||
u.captureCursorLater = true
|
u.captureCursorLater = true
|
||||||
return
|
return
|
||||||
@ -209,7 +209,7 @@ func (u *userInterfaceImpl) SetCursorMode(mode CursorMode) {
|
|||||||
u.setCursorMode(mode)
|
u.setCursorMode(mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setCursorMode(mode CursorMode) {
|
func (u *UserInterface) setCursorMode(mode CursorMode) {
|
||||||
u.captureCursorLater = false
|
u.captureCursorLater = false
|
||||||
|
|
||||||
if !canvas.Truthy() {
|
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 {
|
if theUI.cursorPrevMode == CursorModeCaptured {
|
||||||
panic("ui: cursorPrevMode must not be CursorModeCaptured at recoverCursorMode")
|
panic("ui: cursorPrevMode must not be CursorModeCaptured at recoverCursorMode")
|
||||||
}
|
}
|
||||||
u.SetCursorMode(u.cursorPrevMode)
|
u.SetCursorMode(u.cursorPrevMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) CursorShape() CursorShape {
|
func (u *UserInterface) CursorShape() CursorShape {
|
||||||
if !canvas.Truthy() {
|
if !canvas.Truthy() {
|
||||||
return CursorShapeDefault
|
return CursorShapeDefault
|
||||||
}
|
}
|
||||||
return u.cursorShape
|
return u.cursorShape
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetCursorShape(shape CursorShape) {
|
func (u *UserInterface) SetCursorShape(shape CursorShape) {
|
||||||
if !canvas.Truthy() {
|
if !canvas.Truthy() {
|
||||||
return
|
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 {
|
if u.deviceScaleFactor != 0 {
|
||||||
return u.deviceScaleFactor
|
return u.deviceScaleFactor
|
||||||
}
|
}
|
||||||
@ -276,7 +276,7 @@ func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
|
|||||||
return u.deviceScaleFactor
|
return u.deviceScaleFactor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) outsideSize() (float64, float64) {
|
func (u *UserInterface) outsideSize() (float64, float64) {
|
||||||
if document.Truthy() {
|
if document.Truthy() {
|
||||||
body := document.Get("body")
|
body := document.Get("body")
|
||||||
bw := body.Get("clientWidth").Float()
|
bw := body.Get("clientWidth").Float()
|
||||||
@ -288,14 +288,14 @@ func (u *userInterfaceImpl) outsideSize() (float64, float64) {
|
|||||||
return 640, 480
|
return 640, 480
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) suspended() bool {
|
func (u *UserInterface) suspended() bool {
|
||||||
if u.runnableOnUnfocused {
|
if u.runnableOnUnfocused {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return !u.isFocused()
|
return !u.isFocused()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isFocused() bool {
|
func (u *UserInterface) isFocused() bool {
|
||||||
if !documentHasFocus.Invoke().Bool() {
|
if !documentHasFocus.Invoke().Bool() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -314,12 +314,12 @@ func (u *userInterfaceImpl) isFocused() bool {
|
|||||||
// > Pointer lock is a transient activation-gated API, therefore a requestPointerLock() call
|
// > 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.
|
// > 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.
|
// > 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.
|
// 1.5 [sec] seems enough in the real world.
|
||||||
return time.Now().Sub(u.lastCaptureExitTime) >= 1500*time.Millisecond
|
return time.Now().Sub(u.lastCaptureExitTime) >= 1500*time.Millisecond
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) update() error {
|
func (u *UserInterface) update() error {
|
||||||
if u.captureCursorLater && u.canCaptureCursor() {
|
if u.captureCursorLater && u.canCaptureCursor() {
|
||||||
u.setCursorMode(CursorModeCaptured)
|
u.setCursorMode(CursorModeCaptured)
|
||||||
}
|
}
|
||||||
@ -333,7 +333,7 @@ func (u *userInterfaceImpl) update() error {
|
|||||||
return u.updateImpl(false)
|
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).
|
// Guard updateImpl as this function cannot be invoked until this finishes (#2339).
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
defer u.m.Unlock()
|
||||||
@ -368,7 +368,7 @@ func (u *userInterfaceImpl) updateImpl(force bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) needsUpdate() bool {
|
func (u *UserInterface) needsUpdate() bool {
|
||||||
if u.fpsMode != FPSModeVsyncOffMinimum {
|
if u.fpsMode != FPSModeVsyncOffMinimum {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -382,7 +382,7 @@ func (u *userInterfaceImpl) needsUpdate() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) loop(game Game) <-chan error {
|
func (u *UserInterface) loop(game Game) <-chan error {
|
||||||
u.context = newContext(game)
|
u.context = newContext(game)
|
||||||
|
|
||||||
errCh := make(chan error, 1)
|
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()
|
u.dropFileM.Lock()
|
||||||
defer u.dropFileM.Unlock()
|
defer u.dropFileM.Unlock()
|
||||||
|
|
||||||
@ -718,7 +718,7 @@ func (u *userInterfaceImpl) appendDroppedFiles(data js.Value) {
|
|||||||
u.inputState.DroppedFiles = file.NewFileEntryFS(fs)
|
u.inputState.DroppedFiles = file.NewFileEntryFS(fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) forceUpdateOnMinimumFPSMode() {
|
func (u *UserInterface) forceUpdateOnMinimumFPSMode() {
|
||||||
if u.fpsMode != FPSModeVsyncOffMinimum {
|
if u.fpsMode != FPSModeVsyncOffMinimum {
|
||||||
return
|
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() {
|
if !options.InitUnfocused && window.Truthy() {
|
||||||
// Do not focus the canvas when the current document is in an iframe.
|
// 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).
|
// 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)
|
return <-u.loop(game)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) updateScreenSize() {
|
func (u *UserInterface) updateScreenSize() {
|
||||||
if document.Truthy() {
|
if document.Truthy() {
|
||||||
body := document.Get("body")
|
body := document.Get("body")
|
||||||
bw := int(body.Get("clientWidth").Float() * u.DeviceScaleFactor())
|
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.inputState.copyAndReset(inputState)
|
||||||
u.keyboardLayoutMap = js.Value{}
|
u.keyboardLayoutMap = js.Value{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) Window() Window {
|
func (u *UserInterface) Window() Window {
|
||||||
return &nullWindow{}
|
return &nullWindow{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -793,21 +793,21 @@ func (m *Monitor) Name() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) AppendMonitors(mons []*Monitor) []*Monitor {
|
func (u *UserInterface) AppendMonitors(mons []*Monitor) []*Monitor {
|
||||||
return append(mons, theMonitor)
|
return append(mons, theMonitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) Monitor() *Monitor {
|
func (u *UserInterface) Monitor() *Monitor {
|
||||||
return theMonitor
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ func dipToGLFWPixel(x float64, monitor *Monitor) float64 {
|
|||||||
return x * monitor.deviceScaleFactor()
|
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
|
return x, y
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,28 +149,28 @@ func monitorFromWindowByOS(_ *glfw.Window) (*Monitor, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) nativeWindow() (uintptr, error) {
|
func (u *UserInterface) nativeWindow() (uintptr, error) {
|
||||||
// TODO: Implement this.
|
// TODO: Implement this.
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isNativeFullscreen() (bool, error) {
|
func (u *UserInterface) isNativeFullscreen() (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isNativeFullscreenAvailable() bool {
|
func (u *UserInterface) isNativeFullscreenAvailable() bool {
|
||||||
return false
|
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))
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setWindowResizingModeForOS(mode WindowResizingMode) error {
|
func (u *UserInterface) setWindowResizingModeForOS(mode WindowResizingMode) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,6 +188,6 @@ func initializeWindowAfterCreation(w *glfw.Window) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) skipTaskbar() error {
|
func (u *UserInterface) skipTaskbar() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func init() {
|
|||||||
// Update is called from mobile/ebitenmobileview.
|
// Update is called from mobile/ebitenmobileview.
|
||||||
//
|
//
|
||||||
// Update must be called on the rendering thread.
|
// Update must be called on the rendering thread.
|
||||||
func (u *userInterfaceImpl) Update() error {
|
func (u *UserInterface) Update() error {
|
||||||
select {
|
select {
|
||||||
case err := <-u.errCh:
|
case err := <-u.errCh:
|
||||||
return err
|
return err
|
||||||
@ -127,7 +127,7 @@ type userInterfaceImpl struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// appMain is the main routine for gomobile-build mode.
|
// 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 glctx gl.Context
|
||||||
var sizeInited bool
|
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
|
var v int32
|
||||||
if foreground {
|
if foreground {
|
||||||
v = 1
|
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{})
|
u.setGBuildSizeCh = make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
if err := u.run(game, true, options); err != nil {
|
if err := u.run(game, true, options); err != nil {
|
||||||
@ -253,7 +253,7 @@ func RunWithoutMainLoop(game Game, options *RunOptions) {
|
|||||||
theUI.runWithoutMainLoop(game, options)
|
theUI.runWithoutMainLoop(game, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) runWithoutMainLoop(game Game, options *RunOptions) {
|
func (u *UserInterface) runWithoutMainLoop(game Game, options *RunOptions) {
|
||||||
go func() {
|
go func() {
|
||||||
if err := u.run(game, false, options); err != nil {
|
if err := u.run(game, false, options); err != nil {
|
||||||
u.errCh <- err
|
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
|
// 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
|
// Crashlytics. A panic is treated as SIGABRT, and there is no way to handle this on Java/Objective-C layer
|
||||||
// unfortunately.
|
// 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().
|
// 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
|
var outsideWidth, outsideHeight float64
|
||||||
|
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
@ -324,7 +324,7 @@ func (u *userInterfaceImpl) outsideSize() (float64, float64) {
|
|||||||
return outsideWidth, outsideHeight
|
return outsideWidth, outsideHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) update() error {
|
func (u *UserInterface) update() error {
|
||||||
<-renderCh
|
<-renderCh
|
||||||
defer func() {
|
defer func() {
|
||||||
renderEndCh <- struct{}{}
|
renderEndCh <- struct{}{}
|
||||||
@ -337,7 +337,7 @@ func (u *userInterfaceImpl) update() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
|
func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
|
||||||
// TODO: This function should return gbuildWidthPx, gbuildHeightPx,
|
// TODO: This function should return gbuildWidthPx, gbuildHeightPx,
|
||||||
// but these values are not initialized until the main loop starts.
|
// but these values are not initialized until the main loop starts.
|
||||||
return 0, 0
|
return 0, 0
|
||||||
@ -346,7 +346,7 @@ func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
|
|||||||
// SetOutsideSize is called from mobile/ebitenmobileview.
|
// SetOutsideSize is called from mobile/ebitenmobileview.
|
||||||
//
|
//
|
||||||
// SetOutsideSize is concurrent safe.
|
// SetOutsideSize is concurrent safe.
|
||||||
func (u *userInterfaceImpl) SetOutsideSize(outsideWidth, outsideHeight float64) {
|
func (u *UserInterface) SetOutsideSize(outsideWidth, outsideHeight float64) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
if u.outsideWidth != outsideWidth || u.outsideHeight != outsideHeight {
|
if u.outsideWidth != outsideWidth || u.outsideHeight != outsideHeight {
|
||||||
u.outsideWidth = outsideWidth
|
u.outsideWidth = outsideWidth
|
||||||
@ -355,7 +355,7 @@ func (u *userInterfaceImpl) SetOutsideSize(outsideWidth, outsideHeight float64)
|
|||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setGBuildSize(widthPx, heightPx int) {
|
func (u *UserInterface) setGBuildSize(widthPx, heightPx int) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
u.gbuildWidthPx = widthPx
|
u.gbuildWidthPx = widthPx
|
||||||
u.gbuildHeightPx = heightPx
|
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
|
return CursorModeHidden
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetCursorMode(mode CursorMode) {
|
func (u *UserInterface) SetCursorMode(mode CursorMode) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) CursorShape() CursorShape {
|
func (u *UserInterface) CursorShape() CursorShape {
|
||||||
return CursorShapeDefault
|
return CursorShapeDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetCursorShape(shape CursorShape) {
|
func (u *UserInterface) SetCursorShape(shape CursorShape) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) IsFullscreen() bool {
|
func (u *UserInterface) IsFullscreen() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetFullscreen(fullscreen bool) {
|
func (u *UserInterface) SetFullscreen(fullscreen bool) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) IsFocused() bool {
|
func (u *UserInterface) IsFocused() bool {
|
||||||
return atomic.LoadInt32(&u.foreground) != 0
|
return atomic.LoadInt32(&u.foreground) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) IsRunnableOnUnfocused() bool {
|
func (u *UserInterface) IsRunnableOnUnfocused() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
|
func (u *UserInterface) SetRunnableOnUnfocused(runnableOnUnfocused bool) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetFPSMode(mode FPSModeType) {
|
func (u *UserInterface) SetFPSMode(mode FPSModeType) {
|
||||||
u.fpsMode = mode
|
u.fpsMode = mode
|
||||||
u.updateExplicitRenderingModeIfNeeded()
|
u.updateExplicitRenderingModeIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) updateExplicitRenderingModeIfNeeded() {
|
func (u *UserInterface) updateExplicitRenderingModeIfNeeded() {
|
||||||
if u.renderRequester == nil {
|
if u.renderRequester == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
u.renderRequester.SetExplicitRenderingMode(u.fpsMode == FPSModeVsyncOffMinimum)
|
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.
|
// Assume that the device scale factor never changes on mobiles.
|
||||||
u.deviceScaleFactorOnce.Do(func() {
|
u.deviceScaleFactorOnce.Do(func() {
|
||||||
u.deviceScaleFactor = deviceScaleFactorImpl()
|
u.deviceScaleFactor = deviceScaleFactorImpl()
|
||||||
@ -422,13 +422,13 @@ func (u *userInterfaceImpl) DeviceScaleFactor() float64 {
|
|||||||
return u.deviceScaleFactor
|
return u.deviceScaleFactor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
|
func (u *UserInterface) readInputState(inputState *InputState) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
defer u.m.Unlock()
|
||||||
u.inputState.copyAndReset(inputState)
|
u.inputState.copyAndReset(inputState)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) Window() Window {
|
func (u *UserInterface) Window() Window {
|
||||||
return &nullWindow{}
|
return &nullWindow{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,15 +445,15 @@ func (m *Monitor) Name() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) AppendMonitors(mons []*Monitor) []*Monitor {
|
func (u *UserInterface) AppendMonitors(mons []*Monitor) []*Monitor {
|
||||||
return append(mons, theMonitor)
|
return append(mons, theMonitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) Monitor() *Monitor {
|
func (u *UserInterface) Monitor() *Monitor {
|
||||||
return theMonitor
|
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)
|
u.updateInputStateFromOutside(keys, runes, touches)
|
||||||
if u.fpsMode == FPSModeVsyncOffMinimum {
|
if u.fpsMode == FPSModeVsyncOffMinimum {
|
||||||
u.renderRequester.RequestRenderIfNeeded()
|
u.renderRequester.RequestRenderIfNeeded()
|
||||||
@ -465,24 +465,24 @@ type RenderRequester interface {
|
|||||||
RequestRenderIfNeeded()
|
RequestRenderIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) SetRenderRequester(renderRequester RenderRequester) {
|
func (u *UserInterface) SetRenderRequester(renderRequester RenderRequester) {
|
||||||
u.renderRequester = renderRequester
|
u.renderRequester = renderRequester
|
||||||
u.updateExplicitRenderingModeIfNeeded()
|
u.updateExplicitRenderingModeIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) ScheduleFrame() {
|
func (u *UserInterface) ScheduleFrame() {
|
||||||
if u.renderRequester != nil && u.fpsMode == FPSModeVsyncOffMinimum {
|
if u.renderRequester != nil && u.fpsMode == FPSModeVsyncOffMinimum {
|
||||||
u.renderRequester.RequestRenderIfNeeded()
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ type userInterfaceImpl struct {
|
|||||||
m sync.Mutex
|
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)
|
u.context = newContext(game)
|
||||||
g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}, options.GraphicsLibrary)
|
g, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}, options.GraphicsLibrary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -132,59 +132,59 @@ func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*userInterfaceImpl) DeviceScaleFactor() float64 {
|
func (*UserInterface) DeviceScaleFactor() float64 {
|
||||||
return deviceScaleFactor
|
return deviceScaleFactor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*userInterfaceImpl) IsFocused() bool {
|
func (*UserInterface) IsFocused() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
|
func (*UserInterface) ScreenSizeInFullscreen() (int, int) {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) readInputState(inputState *InputState) {
|
func (u *UserInterface) readInputState(inputState *InputState) {
|
||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
defer u.m.Unlock()
|
defer u.m.Unlock()
|
||||||
u.inputState.copyAndReset(inputState)
|
u.inputState.copyAndReset(inputState)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*userInterfaceImpl) CursorMode() CursorMode {
|
func (*UserInterface) CursorMode() CursorMode {
|
||||||
return CursorModeHidden
|
return CursorModeHidden
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*userInterfaceImpl) SetCursorMode(mode CursorMode) {
|
func (*UserInterface) SetCursorMode(mode CursorMode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*userInterfaceImpl) CursorShape() CursorShape {
|
func (*UserInterface) CursorShape() CursorShape {
|
||||||
return CursorShapeDefault
|
return CursorShapeDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*userInterfaceImpl) SetCursorShape(shape CursorShape) {
|
func (*UserInterface) SetCursorShape(shape CursorShape) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*userInterfaceImpl) IsFullscreen() bool {
|
func (*UserInterface) IsFullscreen() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*userInterfaceImpl) SetFullscreen(fullscreen bool) {
|
func (*UserInterface) SetFullscreen(fullscreen bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*userInterfaceImpl) IsRunnableOnUnfocused() bool {
|
func (*UserInterface) IsRunnableOnUnfocused() bool {
|
||||||
return false
|
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{}
|
return &nullWindow{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,21 +201,21 @@ func (m *Monitor) Name() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) AppendMonitors(mons []*Monitor) []*Monitor {
|
func (u *UserInterface) AppendMonitors(mons []*Monitor) []*Monitor {
|
||||||
return append(mons, theMonitor)
|
return append(mons, theMonitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) Monitor() *Monitor {
|
func (u *UserInterface) Monitor() *Monitor {
|
||||||
return theMonitor
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ func dipToGLFWPixel(x float64, monitor *Monitor) float64 {
|
|||||||
return x * monitor.deviceScaleFactor()
|
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() {
|
if microsoftgdk.IsXbox() {
|
||||||
return x, y
|
return x, y
|
||||||
}
|
}
|
||||||
@ -178,28 +178,28 @@ func monitorFromWin32Window(w windows.HWND) *Monitor {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) nativeWindow() (uintptr, error) {
|
func (u *UserInterface) nativeWindow() (uintptr, error) {
|
||||||
w, err := u.window.GetWin32Window()
|
w, err := u.window.GetWin32Window()
|
||||||
return uintptr(w), err
|
return uintptr(w), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isNativeFullscreen() (bool, error) {
|
func (u *UserInterface) isNativeFullscreen() (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) isNativeFullscreenAvailable() bool {
|
func (u *UserInterface) isNativeFullscreenAvailable() bool {
|
||||||
return false
|
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))
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterfaceImpl) setWindowResizingModeForOS(mode WindowResizingMode) error {
|
func (u *UserInterface) setWindowResizingModeForOS(mode WindowResizingMode) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ func initializeWindowAfterCreation(w *glfw.Window) error {
|
|||||||
return nil
|
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.
|
// 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)) {
|
if err := windows.CoInitializeEx(0, windows.COINIT_MULTITHREADED); err != nil && !errors.Is(err, syscall.Errno(windows.S_FALSE)) {
|
||||||
return err
|
return err
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type glfwWindow struct {
|
type glfwWindow struct {
|
||||||
ui *userInterfaceImpl
|
ui *UserInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *glfwWindow) IsDecorated() bool {
|
func (w *glfwWindow) IsDecorated() bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user