ui: Bug fix: The window was not shown on the secondary monitor on launching

This change changes the behavior of WindowPosition /
SetWindowPosition. The window position is now a relative position
and the origin position is the left-upper of the current monitor.

Fixes #1115
This commit is contained in:
Hajime Hoshi 2020-03-28 19:51:44 +09:00
parent eb5f5485b3
commit 7b5fb0a0d0
7 changed files with 11 additions and 31 deletions

View File

@ -87,7 +87,6 @@ func (m *mascot) update(screen *ebiten.Image) error {
m.count++
sw, sh := ebiten.ScreenSizeInFullscreen()
// TODO: Consider multiple monitors. This requires new APIs (#1114).
ebiten.SetWindowPosition(m.x16/16, m.y16/16+sh-height)
if m.vx16 == 0 {

View File

@ -42,7 +42,6 @@ type UI interface {
IsVsyncEnabled() bool
ScreenSizeInFullscreen() (int, int)
IsScreenTransparent() bool
MonitorPosition() (int, int)
SetCursorMode(mode CursorMode)
SetFullscreen(fullscreen bool)

View File

@ -1043,23 +1043,6 @@ func (u *UserInterface) IsScreenTransparent() bool {
return val
}
func (u *UserInterface) MonitorPosition() (int, int) {
if !u.isRunning() {
return u.monitorPosition()
}
var mx, my int
_ = u.t.Call(func() error {
mx, my = u.monitorPosition()
return nil
})
return mx, my
}
func (u *UserInterface) monitorPosition() (int, int) {
// TODO: toDeviceIndependentPixel might be required.
return u.currentMonitor().GetPos()
}
func (u *UserInterface) Input() driver.Input {
return &u.input
}

View File

@ -185,6 +185,9 @@ func (w *window) Position() (int, int) {
} else {
wx, wy = w.ui.window.GetPos()
}
mx, my := w.ui.currentMonitor().GetPos()
wx -= mx
wy -= my
xf := w.ui.toDeviceIndependentPixel(float64(wx))
yf := w.ui.toDeviceIndependentPixel(float64(wy))
x, y = int(xf), int(yf)
@ -199,9 +202,10 @@ func (w *window) SetPosition(x, y int) {
return
}
_ = w.ui.t.Call(func() error {
mx, my := w.ui.currentMonitor().GetPos()
xf := w.ui.toDeviceDependentPixel(float64(x))
yf := w.ui.toDeviceDependentPixel(float64(y))
x, y := adjustWindowPosition(int(xf), int(yf))
x, y := adjustWindowPosition(mx+int(xf), my+int(yf))
if w.ui.isFullscreen() {
w.ui.origPosX, w.ui.origPosY = x, y
} else {

View File

@ -456,10 +456,6 @@ func (u *UserInterface) IsScreenTransparent() bool {
return bodyStyle.Get("backgroundColor").String() == "transparent"
}
func (u *UserInterface) MonitorPosition() (int, int) {
return 0, 0
}
func (u *UserInterface) Input() driver.Input {
return &u.input
}

View File

@ -433,10 +433,6 @@ func (u *UserInterface) IsScreenTransparent() bool {
return false
}
func (u *UserInterface) MonitorPosition() (int, int) {
return 0, 0
}
func (u *UserInterface) Input() driver.Input {
return &u.input
}

View File

@ -112,6 +112,8 @@ func SetWindowIcon(iconImages []image.Image) {
}
// WindowPosition returns the window position.
// The origin position is the left-upper corner of the current monitor.
// The unit is device-independent pixels.
//
// WindowPosition panics if the main loop does not start yet.
//
@ -131,6 +133,8 @@ func WindowPosition() (x, y int) {
}
// SetWindowPosition sets the window position.
// The origin position is the left-upper corner of the current monitor.
// The unit is device-independent pixels.
//
// SetWindowPosition does nothing on fullscreen mode.
//
@ -194,10 +198,9 @@ func fixWindowPosition(width, height int) {
}
if initWindowPosition.x == invalidPos || initWindowPosition.y == invalidPos {
mx, my := uiDriver().MonitorPosition()
sw, sh := uiDriver().ScreenSizeInFullscreen()
x := mx + (sw-width)/2
y := my + (sh-height)/3
x := (sw - width) / 2
y := (sh - height) / 3
w.SetPosition(x, y)
} else {
w.SetPosition(initWindowPosition.x, initWindowPosition.y)