mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
uidriver/glfw: Refactoring
This commit is contained in:
parent
9f8054c2d5
commit
ed3a4a734e
@ -145,12 +145,14 @@ func initialize() error {
|
||||
panic("glfw: glfw.CreateWindow must not return nil")
|
||||
}
|
||||
|
||||
// Create a window and leave it as it is: this affects the result of currentMonitorFromPosition.
|
||||
// Create a window and set it: this affects toDeviceIndependentPixel and deviceScaleFactor.
|
||||
theUI.window = w
|
||||
theUI.initMonitor = theUI.currentMonitor()
|
||||
theUI.initMonitor = currentMonitorByOS(w)
|
||||
v := theUI.initMonitor.GetVideoMode()
|
||||
theUI.initFullscreenWidthInDP = int(theUI.toDeviceIndependentPixel(float64(v.Width)))
|
||||
theUI.initFullscreenHeightInDP = int(theUI.toDeviceIndependentPixel(float64(v.Height)))
|
||||
theUI.window.Destroy()
|
||||
theUI.window = nil
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -671,10 +673,6 @@ func (u *UserInterface) createWindow() error {
|
||||
|
||||
func (u *UserInterface) run() error {
|
||||
if err := u.t.Call(func() error {
|
||||
// The window is created at initialize().
|
||||
u.window.Destroy()
|
||||
u.window = nil
|
||||
|
||||
if u.Graphics().IsGL() {
|
||||
glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLAPI)
|
||||
glfw.WindowHint(glfw.ContextVersionMajor, 2)
|
||||
@ -1100,9 +1098,9 @@ func (u *UserInterface) currentMonitor() *glfw.Monitor {
|
||||
}
|
||||
|
||||
// Getting a monitor from a window position is not reliable in general (e.g., when a window is put across
|
||||
// multiple monitors).
|
||||
// multiple monitors. A window position is not reliable before SetWindowPosition is called.).
|
||||
// Get the monitor which the current window belongs to. This requires OS API.
|
||||
return u.currentMonitorFromPosition()
|
||||
return currentMonitorByOS(u.window)
|
||||
}
|
||||
|
||||
func (u *UserInterface) SetScreenTransparent(transparent bool) {
|
||||
|
@ -55,11 +55,11 @@ func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
|
||||
return x, y
|
||||
}
|
||||
|
||||
func (u *UserInterface) currentMonitorFromPosition() *glfw.Monitor {
|
||||
func currentMonitorByOS(w *glfw.Window) *glfw.Monitor {
|
||||
x := C.int(0)
|
||||
y := C.int(0)
|
||||
// Note: [NSApp mainWindow] is nil when it doesn't have its border. Use u.window here.
|
||||
win := u.window.GetCocoaWindow()
|
||||
// Note: [NSApp mainWindow] is nil when it doesn't have its border. Use w here.
|
||||
win := w.GetCocoaWindow()
|
||||
C.currentMonitorPos(win, &x, &y)
|
||||
for _, m := range glfw.GetMonitors() {
|
||||
mx, my := m.GetPos()
|
||||
@ -68,7 +68,7 @@ func (u *UserInterface) currentMonitorFromPosition() *glfw.Monitor {
|
||||
}
|
||||
}
|
||||
|
||||
if m, ok := getCachedMonitor(u.window.GetPos()); ok {
|
||||
if m, ok := getCachedMonitor(w.GetPos()); ok {
|
||||
return m.m
|
||||
}
|
||||
return glfw.GetPrimaryMonitor()
|
||||
|
@ -32,9 +32,9 @@ func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
|
||||
return x, y
|
||||
}
|
||||
|
||||
func (u *UserInterface) currentMonitorFromPosition() *glfw.Monitor {
|
||||
func currentMonitorByOS(w *glfw.Window) *glfw.Monitor {
|
||||
// TODO: Implement this correctly. (#1119).
|
||||
if cm, ok := getCachedMonitor(u.window.GetPos()); ok {
|
||||
if cm, ok := getCachedMonitor(w.GetPos()); ok {
|
||||
return cm.m
|
||||
}
|
||||
return glfw.GetPrimaryMonitor()
|
||||
|
@ -120,15 +120,15 @@ func (u *UserInterface) adjustWindowPosition(x, y int) (int, int) {
|
||||
return x, y
|
||||
}
|
||||
|
||||
func (u *UserInterface) currentMonitorFromPosition() *glfw.Monitor {
|
||||
func currentMonitorByOS(glfww *glfw.Window) *glfw.Monitor {
|
||||
fallback := func() *glfw.Monitor {
|
||||
if m, ok := getCachedMonitor(u.window.GetPos()); ok {
|
||||
if m, ok := getCachedMonitor(glfww.GetPos()); ok {
|
||||
return m.m
|
||||
}
|
||||
return glfw.GetPrimaryMonitor()
|
||||
}
|
||||
|
||||
// TODO: Should we use u.window.GetWin32Window() here?
|
||||
// TODO: Should we use glfww.GetWin32Window() here?
|
||||
w, err := getActiveWindow()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Loading…
Reference in New Issue
Block a user