mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
uidriver/glfw: Bug fix: Use the correct scale for GLFW APIs on Linux/UNIX
Updates #1307
This commit is contained in:
parent
7941be5f7d
commit
5278a7c6d6
@ -390,16 +390,6 @@ func (u *UserInterface) setInitFocused(focused bool) {
|
|||||||
u.m.Unlock()
|
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) {
|
func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
|
||||||
if !u.isRunning() {
|
if !u.isRunning() {
|
||||||
return u.initFullscreenWidthInDP, u.initFullscreenHeightInDP
|
return u.initFullscreenWidthInDP, u.initFullscreenHeightInDP
|
||||||
@ -736,8 +726,8 @@ func (u *UserInterface) run() error {
|
|||||||
}
|
}
|
||||||
setSize := func() {
|
setSize := func() {
|
||||||
ww, wh := u.getInitWindowSize()
|
ww, wh := u.getInitWindowSize()
|
||||||
ww = int(u.toDeviceDependentPixel(float64(ww)))
|
ww = int(u.toGLFWPixel(float64(ww)))
|
||||||
wh = int(u.toDeviceDependentPixel(float64(wh)))
|
wh = int(u.toGLFWPixel(float64(wh)))
|
||||||
u.setWindowSize(ww, wh, u.isFullscreen())
|
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).
|
// 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.
|
// To prevent hanging up, return asap if the width is too small.
|
||||||
// 126 is an arbitrary number and I guess this is small enough.
|
// 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 {
|
if u.window.GetAttrib(glfw.Decorated) == glfw.False {
|
||||||
minWindowWidth = 1
|
minWindowWidth = 1
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,12 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/glfw"
|
"github.com/hajimehoshi/ebiten/internal/glfw"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (u *UserInterface) glfwScale() float64 {
|
func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
|
||||||
return 1
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *UserInterface) toGLFWPixel(x float64) float64 {
|
||||||
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
|
func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
|
||||||
|
@ -22,8 +22,14 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/glfw"
|
"github.com/hajimehoshi/ebiten/internal/glfw"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (u *UserInterface) glfwScale() float64 {
|
// toDeviceIndependentPixel must be called from the main thread.
|
||||||
return u.deviceScaleFactor()
|
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) {
|
func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
|
||||||
|
@ -99,8 +99,14 @@ func getMonitorInfoW(hMonitor uintptr, lpmi *monitorInfo) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) glfwScale() float64 {
|
// toDeviceIndependentPixel must be called from the main thread.
|
||||||
return u.deviceScaleFactor()
|
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) {
|
func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
|
||||||
|
@ -210,8 +210,8 @@ func (w *window) SetPosition(x, y int) {
|
|||||||
w.setPositionCalled = true
|
w.setPositionCalled = true
|
||||||
}()
|
}()
|
||||||
mx, my := currentMonitor(w.ui.window).GetPos()
|
mx, my := currentMonitor(w.ui.window).GetPos()
|
||||||
xf := w.ui.toDeviceDependentPixel(float64(x))
|
xf := w.ui.toGLFWPixel(float64(x))
|
||||||
yf := w.ui.toDeviceDependentPixel(float64(y))
|
yf := w.ui.toGLFWPixel(float64(y))
|
||||||
x, y := w.ui.adjustWindowPosition(mx+int(xf), my+int(yf))
|
x, y := w.ui.adjustWindowPosition(mx+int(xf), my+int(yf))
|
||||||
if w.ui.isFullscreen() {
|
if w.ui.isFullscreen() {
|
||||||
w.ui.origPosX, w.ui.origPosY = x, y
|
w.ui.origPosX, w.ui.origPosY = x, y
|
||||||
@ -236,8 +236,8 @@ func (w *window) SetSize(width, height int) {
|
|||||||
w.ui.setInitWindowSize(width, height)
|
w.ui.setInitWindowSize(width, height)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ww := int(w.ui.toDeviceDependentPixel(float64(width)))
|
ww := int(w.ui.toGLFWPixel(float64(width)))
|
||||||
wh := int(w.ui.toDeviceDependentPixel(float64(height)))
|
wh := int(w.ui.toGLFWPixel(float64(height)))
|
||||||
w.ui.setWindowSize(ww, wh, w.ui.isFullscreen())
|
w.ui.setWindowSize(ww, wh, w.ui.isFullscreen())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user