mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/uidriver/glfw: Remove the dirty hack creating a temporary UI instance
Updates #1122
This commit is contained in:
parent
fea802b39d
commit
ec912e5cad
@ -303,8 +303,9 @@ func (i *Input) update(window *glfw.Window, context driver.UIContext) {
|
||||
}
|
||||
cx, cy := window.GetCursorPos()
|
||||
// TODO: This is tricky. Rename the function?
|
||||
cx = i.ui.fromGLFWMonitorPixel(cx)
|
||||
cy = i.ui.fromGLFWMonitorPixel(cy)
|
||||
s := i.ui.deviceScaleFactor()
|
||||
cx = fromGLFWMonitorPixel(cx, s)
|
||||
cy = fromGLFWMonitorPixel(cy, s)
|
||||
cx, cy = context.AdjustPosition(cx, cy, i.ui.deviceScaleFactor())
|
||||
i.cursorX, i.cursorY = int(cx), int(cy)
|
||||
|
||||
|
@ -50,6 +50,7 @@ type UserInterface struct {
|
||||
origPosY int
|
||||
runnableOnUnfocused bool
|
||||
vsync bool
|
||||
iconImages []image.Image
|
||||
|
||||
// err must be accessed from the main thread.
|
||||
err error
|
||||
@ -73,7 +74,6 @@ type UserInterface struct {
|
||||
initWindowMaximized bool
|
||||
initScreenTransparent bool
|
||||
initFocused bool
|
||||
iconImages []image.Image
|
||||
|
||||
vsyncInited bool
|
||||
|
||||
@ -143,15 +143,14 @@ func initialize() error {
|
||||
// This can happen on Windows Remote Desktop (#903).
|
||||
panic("glfw: glfw.CreateWindow must not return nil")
|
||||
}
|
||||
defer w.Destroy()
|
||||
|
||||
// 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.fromGLFWMonitorPixel(float64(v.Width)))
|
||||
theUI.initFullscreenHeightInDP = int(theUI.fromGLFWMonitorPixel(float64(v.Height)))
|
||||
theUI.window.Destroy()
|
||||
theUI.window = nil
|
||||
m := currentMonitor(w)
|
||||
theUI.initMonitor = m
|
||||
v := m.GetVideoMode()
|
||||
scale := devicescale.GetAt(currentMonitor(w).GetPos())
|
||||
theUI.initFullscreenWidthInDP = int(fromGLFWMonitorPixel(float64(v.Width), scale))
|
||||
theUI.initFullscreenHeightInDP = int(fromGLFWMonitorPixel(float64(v.Height), scale))
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -398,8 +397,9 @@ func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
|
||||
var w, h int
|
||||
_ = u.t.Call(func() error {
|
||||
v := currentMonitor(u.window).GetVideoMode()
|
||||
w = int(u.fromGLFWMonitorPixel(float64(v.Width)))
|
||||
h = int(u.fromGLFWMonitorPixel(float64(v.Height)))
|
||||
s := u.deviceScaleFactor()
|
||||
w = int(fromGLFWMonitorPixel(float64(v.Width), s))
|
||||
h = int(fromGLFWMonitorPixel(float64(v.Height), s))
|
||||
return nil
|
||||
})
|
||||
return w, h
|
||||
@ -762,8 +762,9 @@ func (u *UserInterface) updateSize() (float64, float64, bool) {
|
||||
if u.isFullscreen() {
|
||||
v := currentMonitor(u.window).GetVideoMode()
|
||||
ww, wh := v.Width, v.Height
|
||||
w = u.fromGLFWMonitorPixel(float64(ww))
|
||||
h = u.fromGLFWMonitorPixel(float64(wh))
|
||||
s := u.deviceScaleFactor()
|
||||
w = fromGLFWMonitorPixel(float64(ww), s)
|
||||
h = fromGLFWMonitorPixel(float64(wh), s)
|
||||
} 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
|
||||
|
@ -44,7 +44,7 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
||||
)
|
||||
|
||||
func (u *UserInterface) fromGLFWMonitorPixel(x float64) float64 {
|
||||
func fromGLFWMonitorPixel(x float64, deviceScale float64) float64 {
|
||||
return x
|
||||
}
|
||||
|
||||
|
@ -24,14 +24,14 @@ import (
|
||||
)
|
||||
|
||||
// fromGLFWMonitorPixel must be called from the main thread.
|
||||
func (u *UserInterface) fromGLFWMonitorPixel(x float64) float64 {
|
||||
return math.Ceil(x / u.deviceScaleFactor())
|
||||
func fromGLFWMonitorPixel(x float64, deviceScale float64) float64 {
|
||||
return math.Ceil(x / deviceScale)
|
||||
}
|
||||
|
||||
// fromGLFWPixel must be called from the main thread.
|
||||
func (u *UserInterface) fromGLFWPixel(x float64) float64 {
|
||||
// deviceScaleFactor() is a scale by desktop environment (e.g., Cinnamon), while GetContentScale() is X's scale.
|
||||
// They are different things and then need to be treated different ways (#1350).
|
||||
// They are different things and then need to be treated in different ways (#1350).
|
||||
s, _ := currentMonitor(u.window).GetContentScale()
|
||||
return x / float64(s)
|
||||
}
|
||||
|
@ -98,8 +98,8 @@ func getMonitorInfoW(hMonitor uintptr, lpmi *monitorInfo) error {
|
||||
}
|
||||
|
||||
// fromGLFWMonitorPixel must be called from the main thread.
|
||||
func (u *UserInterface) fromGLFWMonitorPixel(x float64) float64 {
|
||||
return x / u.deviceScaleFactor()
|
||||
func fromGLFWMonitorPixel(x float64, deviceScale float64) float64 {
|
||||
return x / deviceScale
|
||||
}
|
||||
|
||||
// fromGLFWPixel must be called from the main thread.
|
||||
|
Loading…
Reference in New Issue
Block a user