mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ui: Make (Set)WindowPosition concurrent safe
This commit is contained in:
parent
d78b4d7ffd
commit
e463f9e611
@ -271,6 +271,29 @@ func (u *UserInterface) setInitIconImages(iconImages []image.Image) {
|
||||
u.m.Unlock()
|
||||
}
|
||||
|
||||
func (u *UserInterface) getInitWindowPosition() (int, int, bool) {
|
||||
u.m.RLock()
|
||||
defer u.m.RUnlock()
|
||||
if u.initWindowPositionX != nil && u.initWindowPositionY != nil {
|
||||
return *u.initWindowPositionX, *u.initWindowPositionY, true
|
||||
}
|
||||
return 0, 0, false
|
||||
}
|
||||
|
||||
func (u *UserInterface) setInitWindowPosition(x, y int) {
|
||||
u.m.Lock()
|
||||
defer u.m.Unlock()
|
||||
|
||||
if u.initWindowPositionX == nil {
|
||||
u.initWindowPositionX = new(int)
|
||||
}
|
||||
if u.initWindowPositionY == nil {
|
||||
u.initWindowPositionY = new(int)
|
||||
}
|
||||
*u.initWindowPositionX = x
|
||||
*u.initWindowPositionY = y
|
||||
}
|
||||
|
||||
func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
|
||||
if !u.isRunning() {
|
||||
return u.initFullscreenWidth, u.initFullscreenHeight
|
||||
@ -668,11 +691,8 @@ func (u *UserInterface) run(width, height int, scale float64, title string, cont
|
||||
u.window.SetTitle(title)
|
||||
u.window.Show()
|
||||
|
||||
x, y := 0, 0
|
||||
if u.initWindowPositionX != nil && u.initWindowPositionY != nil {
|
||||
x = *u.initWindowPositionX
|
||||
y = *u.initWindowPositionY
|
||||
} else {
|
||||
x, y, ok := u.getInitWindowPosition()
|
||||
if !ok {
|
||||
x = mx + (v.Width-w)/2
|
||||
y = my + (v.Height-h)/3
|
||||
}
|
||||
@ -1006,14 +1026,7 @@ func (u *UserInterface) currentMonitor() *glfw.Monitor {
|
||||
|
||||
func (u *UserInterface) SetWindowPosition(x, y int) {
|
||||
if !u.isRunning() {
|
||||
if u.initWindowPositionX == nil {
|
||||
u.initWindowPositionX = new(int)
|
||||
}
|
||||
if u.initWindowPositionY == nil {
|
||||
u.initWindowPositionY = new(int)
|
||||
}
|
||||
*u.initWindowPositionX = x
|
||||
*u.initWindowPositionY = y
|
||||
u.setInitWindowPosition(x, y)
|
||||
return
|
||||
}
|
||||
_ = u.t.Call(func() error {
|
||||
|
@ -100,6 +100,8 @@ func SetWindowIcon(iconImages []image.Image) {
|
||||
// WindowPosition panics before Run is called.
|
||||
//
|
||||
// WindowPosition returns (0, 0) on browsers and mobiles.
|
||||
//
|
||||
// WindowPosition is concurrent-safe.
|
||||
func WindowPosition() (x, y int) {
|
||||
return uiDriver().WindowPosition()
|
||||
}
|
||||
@ -109,6 +111,8 @@ func WindowPosition() (x, y int) {
|
||||
// SetWindowPosition works before and after Run is called.
|
||||
//
|
||||
// SetWindowPosition does nothing on browsers and mobiles.
|
||||
//
|
||||
// SetWindowPosition is concurrent-safe.
|
||||
func SetWindowPosition(x, y int) {
|
||||
uiDriver().SetWindowPosition(x, y)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user