graphicsdriver/glfw: Bug fix: Convert window size unit correctly on Linux/UNIX

Updates #1307
This commit is contained in:
Hajime Hoshi 2020-09-19 00:31:34 +09:00
parent 5278a7c6d6
commit 97607f5779
5 changed files with 25 additions and 10 deletions

View File

@ -789,19 +789,20 @@ func (u *UserInterface) updateSize() {
if sizeChanged { if sizeChanged {
var w, h float64 var w, h float64
_ = u.t.Call(func() error { _ = u.t.Call(func() error {
var ww, wh int
if u.isFullscreen() { if u.isFullscreen() {
v := currentMonitor(u.window).GetVideoMode() v := currentMonitor(u.window).GetVideoMode()
ww = v.Width ww, wh := v.Width, v.Height
wh = v.Height w = u.toDeviceIndependentPixel(float64(ww))
h = u.toDeviceIndependentPixel(float64(wh))
} else { } else {
// Instead of u.windowWidth and u.windowHeight, use the actual window size here. // Instead of u.windowWidth and u.windowHeight, use the actual window size here.
// On Windows, the specified size at SetSize and the actual window size might not // On Windows, the specified size at SetSize and the actual window size might not
// match (#1163). // match (#1163).
ww, wh = u.window.GetSize() ww, wh := u.window.GetSize()
} // TODO: Is this correct?
w = u.toDeviceIndependentPixel(float64(ww)) w = u.toDeviceIndependentPixel(float64(ww))
h = u.toDeviceIndependentPixel(float64(wh)) h = u.toDeviceIndependentPixel(float64(wh))
}
return nil return nil
}) })
u.context.Layout(w, h) u.context.Layout(w, h)

View File

@ -49,6 +49,10 @@ func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
return x return x
} }
func (u *UserInterface) fromGLFWPixel(x float64) float64 {
return x
}
func (u *UserInterface) toGLFWPixel(x float64) float64 { func (u *UserInterface) toGLFWPixel(x float64) float64 {
return x return x
} }

View File

@ -27,6 +27,11 @@ func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
return x / u.deviceScaleFactor() return x / u.deviceScaleFactor()
} }
// fromGLFWPixel must be called from the main thread.
func (u *UserInterface) fromGLFWPixel(x float64) float64 {
return x
}
// toGLFWPixel must be called from the main thread. // toGLFWPixel must be called from the main thread.
func (u *UserInterface) toGLFWPixel(x float64) float64 { func (u *UserInterface) toGLFWPixel(x float64) float64 {
return x return x

View File

@ -104,6 +104,11 @@ func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
return x / u.deviceScaleFactor() return x / u.deviceScaleFactor()
} }
// fromGLFWPixel must be called from the main thread.
func (u *UserInterface) fromGLFWPixel(x float64) float64 {
return x / u.deviceScaleFactor()
}
// toGLFWPixel must be called from the main thread. // toGLFWPixel must be called from the main thread.
func (u *UserInterface) toGLFWPixel(x float64) float64 { func (u *UserInterface) toGLFWPixel(x float64) float64 {
return x * u.deviceScaleFactor() return x * u.deviceScaleFactor()

View File

@ -192,8 +192,8 @@ func (w *window) Position() (int, int) {
mx, my := currentMonitor(w.ui.window).GetPos() mx, my := currentMonitor(w.ui.window).GetPos()
wx -= mx wx -= mx
wy -= my wy -= my
xf := w.ui.toDeviceIndependentPixel(float64(wx)) xf := w.ui.fromGLFWPixel(float64(wx))
yf := w.ui.toDeviceIndependentPixel(float64(wy)) yf := w.ui.fromGLFWPixel(float64(wy))
x, y = int(xf), int(yf) x, y = int(xf), int(yf)
return nil return nil
}) })
@ -226,8 +226,8 @@ func (w *window) Size() (int, int) {
if !w.ui.isRunning() { if !w.ui.isRunning() {
return w.ui.getInitWindowSize() return w.ui.getInitWindowSize()
} }
ww := int(w.ui.toDeviceIndependentPixel(float64(w.ui.windowWidth))) ww := int(w.ui.fromGLFWPixel(float64(w.ui.windowWidth)))
wh := int(w.ui.toDeviceIndependentPixel(float64(w.ui.windowHeight))) wh := int(w.ui.fromGLFWPixel(float64(w.ui.windowHeight)))
return ww, wh return ww, wh
} }