mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
uidriver/glfw: Bug fix: Unscale the size for framebuffers on Linux/UNIX
Fixes #1307
This commit is contained in:
parent
97607f5779
commit
40e35fa047
@ -333,8 +333,9 @@ func (i *Input) update(window *glfw.Window, context driver.UIContext) {
|
||||
i.mouseButtonPressed[gb] = window.GetMouseButton(gb) == glfw.Press
|
||||
}
|
||||
cx, cy = window.GetCursorPos()
|
||||
cx = i.ui.toDeviceIndependentPixel(cx)
|
||||
cy = i.ui.toDeviceIndependentPixel(cy)
|
||||
// TODO: This is tricky. Rename the function?
|
||||
cx = i.ui.fromGLFWMonitorPixel(cx)
|
||||
cy = i.ui.fromGLFWMonitorPixel(cy)
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -22,6 +22,7 @@ package glfw
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"math"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
@ -143,12 +144,12 @@ func initialize() error {
|
||||
panic("glfw: glfw.CreateWindow must not return nil")
|
||||
}
|
||||
|
||||
// Create a window and set it: this affects toDeviceIndependentPixel and deviceScaleFactor.
|
||||
// Create a window and set it: this affects fromGLFWMonitorPixel and deviceScaleFactor.
|
||||
theUI.window = w
|
||||
theUI.initMonitor = currentMonitor(w)
|
||||
v := theUI.initMonitor.GetVideoMode()
|
||||
theUI.initFullscreenWidthInDP = int(theUI.toDeviceIndependentPixel(float64(v.Width)))
|
||||
theUI.initFullscreenHeightInDP = int(theUI.toDeviceIndependentPixel(float64(v.Height)))
|
||||
theUI.initFullscreenWidthInDP = int(theUI.fromGLFWMonitorPixel(float64(v.Width)))
|
||||
theUI.initFullscreenHeightInDP = int(theUI.fromGLFWMonitorPixel(float64(v.Height)))
|
||||
theUI.window.Destroy()
|
||||
theUI.window = nil
|
||||
|
||||
@ -398,8 +399,8 @@ func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
|
||||
var w, h int
|
||||
_ = u.t.Call(func() error {
|
||||
v := currentMonitor(u.window).GetVideoMode()
|
||||
w = int(u.toDeviceIndependentPixel(float64(v.Width)))
|
||||
h = int(u.toDeviceIndependentPixel(float64(v.Height)))
|
||||
w = int(u.fromGLFWMonitorPixel(float64(v.Width)))
|
||||
h = int(u.fromGLFWMonitorPixel(float64(v.Height)))
|
||||
return nil
|
||||
})
|
||||
return w, h
|
||||
@ -792,17 +793,19 @@ func (u *UserInterface) updateSize() {
|
||||
if u.isFullscreen() {
|
||||
v := currentMonitor(u.window).GetVideoMode()
|
||||
ww, wh := v.Width, v.Height
|
||||
w = u.toDeviceIndependentPixel(float64(ww))
|
||||
h = u.toDeviceIndependentPixel(float64(wh))
|
||||
w = u.fromGLFWMonitorPixel(float64(ww))
|
||||
h = u.fromGLFWMonitorPixel(float64(wh))
|
||||
} else {
|
||||
// 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
|
||||
// match (#1163).
|
||||
ww, wh := u.window.GetSize()
|
||||
// TODO: Is this correct?
|
||||
w = u.toDeviceIndependentPixel(float64(ww))
|
||||
h = u.toDeviceIndependentPixel(float64(wh))
|
||||
w = u.fromGLFWPixel(float64(ww))
|
||||
h = u.fromGLFWPixel(float64(wh))
|
||||
}
|
||||
// On Linux/UNIX, further adjusting is required (#1307).
|
||||
w = math.Ceil(u.toFramebufferPixel(w))
|
||||
h = math.Ceil(u.toFramebufferPixel(h))
|
||||
return nil
|
||||
})
|
||||
u.context.Layout(w, h)
|
||||
@ -1152,7 +1155,7 @@ func (u *UserInterface) SetInitFocused(focused bool) {
|
||||
}
|
||||
|
||||
func (u *UserInterface) monitorPosition() (int, int) {
|
||||
// TODO: toDeviceIndependentPixel might be required.
|
||||
// TODO: fromGLFWMonitorPixel might be required.
|
||||
return currentMonitor(u.window).GetPos()
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/internal/glfw"
|
||||
)
|
||||
|
||||
func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
|
||||
func (u *UserInterface) fromGLFWMonitorPixel(x float64) float64 {
|
||||
return x
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/internal/glfw"
|
||||
)
|
||||
|
||||
// toDeviceIndependentPixel must be called from the main thread.
|
||||
func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
|
||||
// fromGLFWMonitorPixel must be called from the main thread.
|
||||
func (u *UserInterface) fromGLFWMonitorPixel(x float64) float64 {
|
||||
return x / u.deviceScaleFactor()
|
||||
}
|
||||
|
||||
@ -37,6 +37,11 @@ func (u *UserInterface) toGLFWPixel(x float64) float64 {
|
||||
return x
|
||||
}
|
||||
|
||||
// toFramebufferPixel must be called from the main thread.
|
||||
func (u *UserInterface) toFramebufferPixel(x float64) float64 {
|
||||
return x / u.deviceScaleFactor()
|
||||
}
|
||||
|
||||
func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
|
||||
return x, y
|
||||
}
|
||||
|
@ -99,8 +99,8 @@ func getMonitorInfoW(hMonitor uintptr, lpmi *monitorInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// toDeviceIndependentPixel must be called from the main thread.
|
||||
func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
|
||||
// fromGLFWMonitorPixel must be called from the main thread.
|
||||
func (u *UserInterface) fromGLFWMonitorPixel(x float64) float64 {
|
||||
return x / u.deviceScaleFactor()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user