uidriver/glfw: Bug fix: Use the correct scale for GLFW APIs on Linux/UNIX

Updates #1307
This commit is contained in:
Hajime Hoshi 2020-09-19 00:21:08 +09:00
parent 7941be5f7d
commit 5278a7c6d6
5 changed files with 29 additions and 23 deletions

View File

@ -390,16 +390,6 @@ func (u *UserInterface) setInitFocused(focused bool) {
u.m.Unlock()
}
// toDeviceIndependentPixel must be called from the main thread.
func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
return x / u.glfwScale()
}
// toDeviceDependentPixel must be called from the main thread.
func (u *UserInterface) toDeviceDependentPixel(x float64) float64 {
return x * u.glfwScale()
}
func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
if !u.isRunning() {
return u.initFullscreenWidthInDP, u.initFullscreenHeightInDP
@ -736,8 +726,8 @@ func (u *UserInterface) run() error {
}
setSize := func() {
ww, wh := u.getInitWindowSize()
ww = int(u.toDeviceDependentPixel(float64(ww)))
wh = int(u.toDeviceDependentPixel(float64(wh)))
ww = int(u.toGLFWPixel(float64(ww)))
wh = int(u.toGLFWPixel(float64(wh)))
u.setWindowSize(ww, wh, u.isFullscreen())
}
@ -1000,7 +990,7 @@ func (u *UserInterface) setWindowSize(width, height int, fullscreen bool) {
// On Windows, giving a too small width doesn't call a callback (#165).
// To prevent hanging up, return asap if the width is too small.
// 126 is an arbitrary number and I guess this is small enough.
minWindowWidth := int(u.toDeviceDependentPixel(126))
minWindowWidth := int(u.toGLFWPixel(126))
if u.window.GetAttrib(glfw.Decorated) == glfw.False {
minWindowWidth = 1
}

View File

@ -45,8 +45,12 @@ import (
"github.com/hajimehoshi/ebiten/internal/glfw"
)
func (u *UserInterface) glfwScale() float64 {
return 1
func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
return x
}
func (u *UserInterface) toGLFWPixel(x float64) float64 {
return x
}
func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {

View File

@ -22,8 +22,14 @@ import (
"github.com/hajimehoshi/ebiten/internal/glfw"
)
func (u *UserInterface) glfwScale() float64 {
return u.deviceScaleFactor()
// toDeviceIndependentPixel must be called from the main thread.
func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
return x / u.deviceScaleFactor()
}
// toGLFWPixel must be called from the main thread.
func (u *UserInterface) toGLFWPixel(x float64) float64 {
return x
}
func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {

View File

@ -99,8 +99,14 @@ func getMonitorInfoW(hMonitor uintptr, lpmi *monitorInfo) error {
return nil
}
func (u *UserInterface) glfwScale() float64 {
return u.deviceScaleFactor()
// toDeviceIndependentPixel must be called from the main thread.
func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
return x / u.deviceScaleFactor()
}
// toGLFWPixel must be called from the main thread.
func (u *UserInterface) toGLFWPixel(x float64) float64 {
return x * u.deviceScaleFactor()
}
func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {

View File

@ -210,8 +210,8 @@ func (w *window) SetPosition(x, y int) {
w.setPositionCalled = true
}()
mx, my := currentMonitor(w.ui.window).GetPos()
xf := w.ui.toDeviceDependentPixel(float64(x))
yf := w.ui.toDeviceDependentPixel(float64(y))
xf := w.ui.toGLFWPixel(float64(x))
yf := w.ui.toGLFWPixel(float64(y))
x, y := w.ui.adjustWindowPosition(mx+int(xf), my+int(yf))
if w.ui.isFullscreen() {
w.ui.origPosX, w.ui.origPosY = x, y
@ -236,8 +236,8 @@ func (w *window) SetSize(width, height int) {
w.ui.setInitWindowSize(width, height)
return
}
ww := int(w.ui.toDeviceDependentPixel(float64(width)))
wh := int(w.ui.toDeviceDependentPixel(float64(height)))
ww := int(w.ui.toGLFWPixel(float64(width)))
wh := int(w.ui.toGLFWPixel(float64(height)))
w.ui.setWindowSize(ww, wh, w.ui.isFullscreen())
}