internal/uidriver/glfw: Refactring: Rename InDP -> InDIP

This change also renames some functions and variables.
This commit is contained in:
Hajime Hoshi 2021-10-10 15:38:13 +09:00
parent da6b75bc6d
commit 4580f9fa16
6 changed files with 147 additions and 143 deletions

View File

@ -306,8 +306,8 @@ func (i *Input) update(window *glfw.Window, context driver.UIContext) {
// TODO: This is tricky. Rename the function? // TODO: This is tricky. Rename the function?
m := i.ui.currentMonitor() m := i.ui.currentMonitor()
s := i.ui.deviceScaleFactor(m) s := i.ui.deviceScaleFactor(m)
cx = i.ui.fromGLFWPixel(cx, m) cx = i.ui.dipFromGLFWPixel(cx, m)
cy = i.ui.fromGLFWPixel(cy, m) cy = i.ui.dipFromGLFWPixel(cy, m)
cx, cy = context.AdjustPosition(cx, cy, s) cx, cy = context.AdjustPosition(cx, cy, s)
// AdjustPosition can return NaN at the initialization. // AdjustPosition can return NaN at the initialization.

View File

@ -53,16 +53,16 @@ type UserInterface struct {
title string title string
window *glfw.Window window *glfw.Window
// windowWidthInDP and windowHeightInDP represents a window size. // windowWidthInDIP and windowHeightInDIP represents a window size.
// The units are device-independent pixels. // The units are device-independent pixels.
windowWidthInDP int windowWidthInDIP int
windowHeightInDP int windowHeightInDIP int
// The units are device-independent pixels. // The units are device-independent pixels.
minWindowWidthInDP int minWindowWidthInDIP int
minWindowHeightInDP int minWindowHeightInDIP int
maxWindowWidthInDP int maxWindowWidthInDIP int
maxWindowHeightInDP int maxWindowHeightInDIP int
running uint32 running uint32
toChangeSize bool toChangeSize bool
@ -86,8 +86,8 @@ type UserInterface struct {
// These values are not changed after initialized. // These values are not changed after initialized.
// TODO: the fullscreen size should be updated when the initial window position is changed? // TODO: the fullscreen size should be updated when the initial window position is changed?
initMonitor *glfw.Monitor initMonitor *glfw.Monitor
initFullscreenWidthInDP int initFullscreenWidthInDIP int
initFullscreenHeightInDP int initFullscreenHeightInDIP int
initTitle string initTitle string
initFPSMode driver.FPSMode initFPSMode driver.FPSMode
@ -95,10 +95,10 @@ type UserInterface struct {
initCursorMode driver.CursorMode initCursorMode driver.CursorMode
initWindowDecorated bool initWindowDecorated bool
initWindowResizable bool initWindowResizable bool
initWindowPositionXInDP int initWindowPositionXInDIP int
initWindowPositionYInDP int initWindowPositionYInDIP int
initWindowWidthInDP int initWindowWidthInDIP int
initWindowHeightInDP int initWindowHeightInDIP int
initWindowFloating bool initWindowFloating bool
initWindowMaximized bool initWindowMaximized bool
initScreenTransparent bool initScreenTransparent bool
@ -127,19 +127,19 @@ const (
var ( var (
theUI = &UserInterface{ theUI = &UserInterface{
runnableOnUnfocused: true, runnableOnUnfocused: true,
minWindowWidthInDP: glfw.DontCare, minWindowWidthInDIP: glfw.DontCare,
minWindowHeightInDP: glfw.DontCare, minWindowHeightInDIP: glfw.DontCare,
maxWindowWidthInDP: glfw.DontCare, maxWindowWidthInDIP: glfw.DontCare,
maxWindowHeightInDP: glfw.DontCare, maxWindowHeightInDIP: glfw.DontCare,
origPosX: invalidPos, origPosX: invalidPos,
origPosY: invalidPos, origPosY: invalidPos,
initFPSMode: driver.FPSModeVsyncOn, initFPSMode: driver.FPSModeVsyncOn,
initCursorMode: driver.CursorModeVisible, initCursorMode: driver.CursorModeVisible,
initWindowDecorated: true, initWindowDecorated: true,
initWindowPositionXInDP: invalidPos, initWindowPositionXInDIP: invalidPos,
initWindowPositionYInDP: invalidPos, initWindowPositionYInDIP: invalidPos,
initWindowWidthInDP: 640, initWindowWidthInDIP: 640,
initWindowHeightInDP: 480, initWindowHeightInDIP: 480,
initFocused: true, initFocused: true,
fpsMode: driver.FPSModeVsyncOn, fpsMode: driver.FPSModeVsyncOn,
} }
@ -190,8 +190,8 @@ func initialize() error {
m := initialMonitor(w) m := initialMonitor(w)
theUI.initMonitor = m theUI.initMonitor = m
v := m.GetVideoMode() v := m.GetVideoMode()
theUI.initFullscreenWidthInDP = int(theUI.fromGLFWMonitorPixel(float64(v.Width), m)) theUI.initFullscreenWidthInDIP = int(theUI.dipFromGLFWMonitorPixel(float64(v.Width), m))
theUI.initFullscreenHeightInDP = int(theUI.fromGLFWMonitorPixel(float64(v.Height), m)) theUI.initFullscreenHeightInDIP = int(theUI.dipFromGLFWMonitorPixel(float64(v.Height), m))
// Create system cursors. These cursors are destroyed at glfw.Terminate(). // Create system cursors. These cursors are destroyed at glfw.Terminate().
glfwSystemCursors[driver.CursorShapeDefault] = nil glfwSystemCursors[driver.CursorShapeDefault] = nil
@ -269,22 +269,22 @@ func (u *UserInterface) setRunning(running bool) {
} }
} }
func (u *UserInterface) getWindowSizeLimitsInDP() (minw, minh, maxw, maxh int) { func (u *UserInterface) getWindowSizeLimitsInDIP() (minw, minh, maxw, maxh int) {
u.m.RLock() u.m.RLock()
defer u.m.RUnlock() defer u.m.RUnlock()
return u.minWindowWidthInDP, u.minWindowHeightInDP, u.maxWindowWidthInDP, u.maxWindowHeightInDP return u.minWindowWidthInDIP, u.minWindowHeightInDIP, u.maxWindowWidthInDIP, u.maxWindowHeightInDIP
} }
func (u *UserInterface) setWindowSizeLimitsInDP(minw, minh, maxw, maxh int) bool { func (u *UserInterface) setWindowSizeLimitsInDIP(minw, minh, maxw, maxh int) bool {
u.m.RLock() u.m.RLock()
defer u.m.RUnlock() defer u.m.RUnlock()
if u.minWindowWidthInDP == minw && u.minWindowHeightInDP == minh && u.maxWindowWidthInDP == maxw && u.maxWindowHeightInDP == maxh { if u.minWindowWidthInDIP == minw && u.minWindowHeightInDIP == minh && u.maxWindowWidthInDIP == maxw && u.maxWindowHeightInDIP == maxh {
return false return false
} }
u.minWindowWidthInDP = minw u.minWindowWidthInDIP = minw
u.minWindowHeightInDP = minh u.minWindowHeightInDIP = minh
u.maxWindowWidthInDP = maxw u.maxWindowWidthInDIP = maxw
u.maxWindowHeightInDP = maxh u.maxWindowHeightInDIP = maxh
return true return true
} }
@ -414,33 +414,33 @@ func (u *UserInterface) setIconImages(iconImages []image.Image) {
u.m.Unlock() u.m.Unlock()
} }
func (u *UserInterface) getInitWindowPosition() (int, int) { func (u *UserInterface) getInitWindowPositionInDIP() (int, int) {
u.m.RLock() u.m.RLock()
defer u.m.RUnlock() defer u.m.RUnlock()
if u.initWindowPositionXInDP != invalidPos && u.initWindowPositionYInDP != invalidPos { if u.initWindowPositionXInDIP != invalidPos && u.initWindowPositionYInDIP != invalidPos {
return u.initWindowPositionXInDP, u.initWindowPositionYInDP return u.initWindowPositionXInDIP, u.initWindowPositionYInDIP
} }
return invalidPos, invalidPos return invalidPos, invalidPos
} }
func (u *UserInterface) setInitWindowPosition(x, y int) { func (u *UserInterface) setInitWindowPositionInDIP(x, y int) {
u.m.Lock() u.m.Lock()
defer u.m.Unlock() defer u.m.Unlock()
u.initWindowPositionXInDP = x u.initWindowPositionXInDIP = x
u.initWindowPositionYInDP = y u.initWindowPositionYInDIP = y
} }
func (u *UserInterface) getInitWindowSizeInDP() (int, int) { func (u *UserInterface) getInitWindowSizeInDIP() (int, int) {
u.m.Lock() u.m.Lock()
w, h := u.initWindowWidthInDP, u.initWindowHeightInDP w, h := u.initWindowWidthInDIP, u.initWindowHeightInDIP
u.m.Unlock() u.m.Unlock()
return w, h return w, h
} }
func (u *UserInterface) setInitWindowSize(width, height int) { func (u *UserInterface) setInitWindowSizeInDIP(width, height int) {
u.m.Lock() u.m.Lock()
u.initWindowWidthInDP, u.initWindowHeightInDP = width, height u.initWindowWidthInDIP, u.initWindowHeightInDIP = width, height
u.m.Unlock() u.m.Unlock()
} }
@ -505,15 +505,15 @@ func (u *UserInterface) setInitFocused(focused bool) {
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.initFullscreenWidthInDIP, u.initFullscreenHeightInDIP
} }
var w, h int var w, h int
_ = u.t.Call(func() error { _ = u.t.Call(func() error {
m := u.currentMonitor() m := u.currentMonitor()
v := m.GetVideoMode() v := m.GetVideoMode()
w = int(u.fromGLFWMonitorPixel(float64(v.Width), m)) w = int(u.dipFromGLFWMonitorPixel(float64(v.Width), m))
h = int(u.fromGLFWMonitorPixel(float64(v.Height), m)) h = int(u.dipFromGLFWMonitorPixel(float64(v.Height), m))
return nil return nil
}) })
return w, h return w, h
@ -555,8 +555,8 @@ func (u *UserInterface) SetFullscreen(fullscreen bool) {
} }
_ = u.t.Call(func() error { _ = u.t.Call(func() error {
w, h := u.windowWidthInDP, u.windowHeightInDP w, h := u.windowWidthInDIP, u.windowHeightInDIP
u.setWindowSizeInDP(w, h, fullscreen) u.setWindowSizeInDIP(w, h, fullscreen)
return nil return nil
}) })
} }
@ -771,9 +771,9 @@ func (u *UserInterface) registerWindowSetSizeCallback() {
_ = u.t.Call(func() error { _ = u.t.Call(func() error {
if width != 0 || height != 0 { if width != 0 || height != 0 {
w := int(u.fromGLFWPixel(float64(width), u.currentMonitor())) w := int(u.dipFromGLFWPixel(float64(width), u.currentMonitor()))
h := int(u.fromGLFWPixel(float64(height), u.currentMonitor())) h := int(u.dipFromGLFWPixel(float64(height), u.currentMonitor()))
u.setWindowSizeInDP(w, h, u.isFullscreen()) u.setWindowSizeInDIP(w, h, u.isFullscreen())
} }
outsideWidth, outsideHeight, outsideSizeChanged = u.updateSize() outsideWidth, outsideHeight, outsideSizeChanged = u.updateSize()
@ -871,14 +871,14 @@ func (u *UserInterface) init() error {
u.setSizeCallbackEnabled = true u.setSizeCallbackEnabled = true
setSize := func() { setSize := func() {
ww, wh := u.getInitWindowSizeInDP() ww, wh := u.getInitWindowSizeInDIP()
u.setWindowSizeInDP(ww, wh, u.isFullscreen()) u.setWindowSizeInDIP(ww, wh, u.isFullscreen())
} }
// Set the window size and the window position in this order on Linux or other UNIX using X (#1118), // Set the window size and the window position in this order on Linux or other UNIX using X (#1118),
// but this should be inverted on Windows. This is very tricky, but there is no obvious way to solve // but this should be inverted on Windows. This is very tricky, but there is no obvious way to solve
// this. This doesn't matter on macOS. // this. This doesn't matter on macOS.
wx, wy := u.getInitWindowPosition() wx, wy := u.getInitWindowPositionInDIP()
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
u.setWindowPosition(wx, wy, u.initMonitor) u.setWindowPosition(wx, wy, u.initMonitor)
setSize() setSize()
@ -906,8 +906,8 @@ func (u *UserInterface) init() error {
} }
func (u *UserInterface) updateSize() (float64, float64, bool) { func (u *UserInterface) updateSize() (float64, float64, bool) {
ww, wh := u.windowWidthInDP, u.windowHeightInDP ww, wh := u.windowWidthInDIP, u.windowHeightInDIP
u.setWindowSizeInDP(ww, wh, u.isFullscreen()) u.setWindowSizeInDIP(ww, wh, u.isFullscreen())
if !u.toChangeSize { if !u.toChangeSize {
return 0, 0, false return 0, 0, false
@ -923,15 +923,15 @@ func (u *UserInterface) updateSize() (float64, float64, bool) {
m := u.currentMonitor() m := u.currentMonitor()
v := m.GetVideoMode() v := m.GetVideoMode()
ww, wh := v.Width, v.Height ww, wh := v.Width, v.Height
w = u.fromGLFWMonitorPixel(float64(ww), m) w = u.dipFromGLFWMonitorPixel(float64(ww), m)
h = u.fromGLFWMonitorPixel(float64(wh), m) h = u.dipFromGLFWMonitorPixel(float64(wh), m)
} else { } else {
// Instead of u.windowWidthInDP and u.windowHeightInDP, use the actual window size // Instead of u.windowWidthInDIP and u.windowHeightInDIP, use the actual window size
// here. On Windows, the specified size at SetSize and the actual window size might // here. On Windows, the specified size at SetSize and the actual window size might
// not match (#1163). // not match (#1163).
ww, wh := u.window.GetSize() ww, wh := u.window.GetSize()
w = u.fromGLFWPixel(float64(ww), u.currentMonitor()) w = u.dipFromGLFWPixel(float64(ww), u.currentMonitor())
h = u.fromGLFWPixel(float64(wh), u.currentMonitor()) h = u.dipFromGLFWPixel(float64(wh), u.currentMonitor())
} }
return w, h, true return w, h, true
@ -962,9 +962,9 @@ func (u *UserInterface) update() (float64, float64, bool, error) {
if u.isInitFullscreen() { if u.isInitFullscreen() {
w, h := u.window.GetSize() w, h := u.window.GetSize()
ww := int(u.fromGLFWPixel(float64(w), u.currentMonitor())) ww := int(u.dipFromGLFWPixel(float64(w), u.currentMonitor()))
wh := int(u.fromGLFWPixel(float64(h), u.currentMonitor())) wh := int(u.dipFromGLFWPixel(float64(h), u.currentMonitor()))
u.setWindowSizeInDP(ww, wh, true) u.setWindowSizeInDIP(ww, wh, true)
u.setInitFullscreen(false) u.setInitFullscreen(false)
} }
@ -1117,34 +1117,34 @@ func (u *UserInterface) swapBuffers() {
// updateWindowSizeLimits must be called from the main thread. // updateWindowSizeLimits must be called from the main thread.
func (u *UserInterface) updateWindowSizeLimits() { func (u *UserInterface) updateWindowSizeLimits() {
m := u.currentMonitor() m := u.currentMonitor()
minw, minh, maxw, maxh := u.getWindowSizeLimitsInDP() minw, minh, maxw, maxh := u.getWindowSizeLimitsInDIP()
if minw < 0 { if minw < 0 {
minw = glfw.DontCare minw = glfw.DontCare
} else { } else {
minw = int(u.toGLFWPixel(float64(minw), m)) minw = int(u.dipToGLFWPixel(float64(minw), m))
} }
if minh < 0 { if minh < 0 {
minh = glfw.DontCare minh = glfw.DontCare
} else { } else {
minh = int(u.toGLFWPixel(float64(minh), m)) minh = int(u.dipToGLFWPixel(float64(minh), m))
} }
if maxw < 0 { if maxw < 0 {
maxw = glfw.DontCare maxw = glfw.DontCare
} else { } else {
maxw = int(u.toGLFWPixel(float64(maxw), m)) maxw = int(u.dipToGLFWPixel(float64(maxw), m))
} }
if maxh < 0 { if maxh < 0 {
maxh = glfw.DontCare maxh = glfw.DontCare
} else { } else {
maxh = int(u.toGLFWPixel(float64(maxh), m)) maxh = int(u.dipToGLFWPixel(float64(maxh), m))
} }
u.window.SetSizeLimits(minw, minh, maxw, maxh) u.window.SetSizeLimits(minw, minh, maxw, maxh)
} }
// adjustWindowSizeBasedOnSizeLimitsInDP adjust the size based on the window size limits. // adjustWindowSizeBasedOnSizeLimitsInDIP adjust the size based on the window size limits.
// width and height are in device-independent pixels. // width and height are in device-independent pixels.
func (u *UserInterface) adjustWindowSizeBasedOnSizeLimitsInDP(width, height int) (int, int) { func (u *UserInterface) adjustWindowSizeBasedOnSizeLimitsInDIP(width, height int) (int, int) {
minw, minh, maxw, maxh := u.getWindowSizeLimitsInDP() minw, minh, maxw, maxh := u.getWindowSizeLimitsInDIP()
if minw >= 0 && width < minw { if minw >= 0 && width < minw {
width = minw width = minw
} }
@ -1161,13 +1161,13 @@ func (u *UserInterface) adjustWindowSizeBasedOnSizeLimitsInDP(width, height int)
} }
// setWindowSize must be called from the main thread. // setWindowSize must be called from the main thread.
func (u *UserInterface) setWindowSizeInDP(width, height int, fullscreen bool) { func (u *UserInterface) setWindowSizeInDIP(width, height int, fullscreen bool) {
width, height = u.adjustWindowSizeBasedOnSizeLimitsInDP(width, height) width, height = u.adjustWindowSizeBasedOnSizeLimitsInDIP(width, height)
u.Graphics().SetFullscreen(fullscreen) u.Graphics().SetFullscreen(fullscreen)
scale := u.deviceScaleFactor(u.currentMonitor()) scale := u.deviceScaleFactor(u.currentMonitor())
if u.windowWidthInDP == width && u.windowHeightInDP == height && u.isFullscreen() == fullscreen && u.lastDeviceScaleFactor == scale { if u.windowWidthInDIP == width && u.windowHeightInDIP == height && u.isFullscreen() == fullscreen && u.lastDeviceScaleFactor == scale {
return return
} }
@ -1195,13 +1195,13 @@ func (u *UserInterface) setWindowSizeInDP(width, height int, fullscreen bool) {
}() }()
} }
windowRecreated := u.setWindowSizeInDPImpl(width, height, fullscreen) windowRecreated := u.setWindowSizeInDIPImpl(width, height, fullscreen)
u.adjustViewSize() u.adjustViewSize()
// As width might be updated, update windowWidth/Height here. // As width might be updated, update windowWidth/Height here.
u.windowWidthInDP = width u.windowWidthInDIP = width
u.windowHeightInDP = height u.windowHeightInDIP = height
u.toChangeSize = true u.toChangeSize = true
@ -1212,7 +1212,7 @@ func (u *UserInterface) setWindowSizeInDP(width, height int, fullscreen bool) {
} }
} }
func (u *UserInterface) setWindowSizeInDPImpl(width, height int, fullscreen bool) bool { func (u *UserInterface) setWindowSizeInDIPImpl(width, height int, fullscreen bool) bool {
var windowRecreated bool var windowRecreated bool
if fullscreen { if fullscreen {
@ -1253,8 +1253,8 @@ func (u *UserInterface) setWindowSizeInDPImpl(width, height int, fullscreen bool
// When OpenGL is used, swapping buffer is enough to solve the image-lag // When OpenGL is used, swapping buffer is enough to solve the image-lag
// issue (#1004). Rather, recreating window destroys GPU resources. // issue (#1004). Rather, recreating window destroys GPU resources.
// TODO: This might not work when vsync is disabled. // TODO: This might not work when vsync is disabled.
ww := int(u.toGLFWPixel(float64(width), u.currentMonitor())) ww := int(u.dipToGLFWPixel(float64(width), u.currentMonitor()))
wh := int(u.toGLFWPixel(float64(height), u.currentMonitor())) wh := int(u.dipToGLFWPixel(float64(height), u.currentMonitor()))
u.window.SetMonitor(nil, 0, 0, ww, wh, 0) u.window.SetMonitor(nil, 0, 0, ww, wh, 0)
glfw.PollEvents() glfw.PollEvents()
u.swapBuffers() u.swapBuffers()
@ -1290,8 +1290,8 @@ func (u *UserInterface) setWindowSizeInDPImpl(width, height int, fullscreen bool
// Set the window size after the position. The order matters. // Set the window size after the position. The order matters.
// In the opposite order, the window size might not be correct when going back from fullscreen with multi monitors. // In the opposite order, the window size might not be correct when going back from fullscreen with multi monitors.
oldW, oldH := u.window.GetSize() oldW, oldH := u.window.GetSize()
newW := int(u.toGLFWPixel(float64(width), u.currentMonitor())) newW := int(u.dipToGLFWPixel(float64(width), u.currentMonitor()))
newH := int(u.toGLFWPixel(float64(height), u.currentMonitor())) newH := int(u.dipToGLFWPixel(float64(height), u.currentMonitor()))
if oldW != newW || oldH != newH { if oldW != newW || oldH != newH {
u.framebufferSizeCallbackCh = make(chan struct{}, 1) u.framebufferSizeCallbackCh = make(chan struct{}, 1)
if u.framebufferSizeCallback == 0 { if u.framebufferSizeCallback == 0 {
@ -1461,7 +1461,7 @@ func (u *UserInterface) SetInitFocused(focused bool) {
} }
func (u *UserInterface) monitorPosition() (int, int) { func (u *UserInterface) monitorPosition() (int, int) {
// TODO: fromGLFWMonitorPixel might be required. // TODO: dipFromGLFWMonitorPixel might be required.
return u.currentMonitor().GetPos() return u.currentMonitor().GetPos()
} }
@ -1502,9 +1502,9 @@ func (u *UserInterface) maximizeWindow() {
// Do not call setWindowSize in the fullscreen mode since setWindowSize requires the window size // Do not call setWindowSize in the fullscreen mode since setWindowSize requires the window size
// before the fullscreen, while window.GetSize() returns the desktop screen size in the fullscreen mode. // before the fullscreen, while window.GetSize() returns the desktop screen size in the fullscreen mode.
w, h := u.window.GetSize() w, h := u.window.GetSize()
ww := int(u.fromGLFWPixel(float64(w), u.currentMonitor())) ww := int(u.dipFromGLFWPixel(float64(w), u.currentMonitor()))
wh := int(u.fromGLFWPixel(float64(h), u.currentMonitor())) wh := int(u.dipFromGLFWPixel(float64(h), u.currentMonitor()))
u.setWindowSizeInDP(ww, wh, u.isFullscreen()) u.setWindowSizeInDIP(ww, wh, u.isFullscreen())
} }
} }
@ -1555,9 +1555,9 @@ func (u *UserInterface) restoreWindow() {
// before the fullscreen, while window.GetSize() returns the desktop screen size in the fullscreen mode. // before the fullscreen, while window.GetSize() returns the desktop screen size in the fullscreen mode.
if !u.isFullscreen() { if !u.isFullscreen() {
w, h := u.window.GetSize() w, h := u.window.GetSize()
ww := int(u.fromGLFWPixel(float64(w), u.currentMonitor())) ww := int(u.dipFromGLFWPixel(float64(w), u.currentMonitor()))
wh := int(u.fromGLFWPixel(float64(h), u.currentMonitor())) wh := int(u.dipFromGLFWPixel(float64(h), u.currentMonitor()))
u.setWindowSizeInDP(ww, wh, u.isFullscreen()) u.setWindowSizeInDIP(ww, wh, u.isFullscreen())
} }
} }
@ -1612,6 +1612,10 @@ func (u *UserInterface) setWindowResizable(resizable bool) {
u.window.SetAttrib(glfw.Resizable, v) u.window.SetAttrib(glfw.Resizable, v)
} }
// setWindowPosition sets the window position.
//
// x and y are the position in device-independent pixels.
//
// setWindowPosition must be called from the main thread. // setWindowPosition must be called from the main thread.
func (u *UserInterface) setWindowPosition(x, y int, monitor *glfw.Monitor) { func (u *UserInterface) setWindowPosition(x, y int, monitor *glfw.Monitor) {
if u.setSizeCallbackEnabled { if u.setSizeCallbackEnabled {
@ -1622,8 +1626,8 @@ func (u *UserInterface) setWindowPosition(x, y int, monitor *glfw.Monitor) {
} }
mx, my := monitor.GetPos() mx, my := monitor.GetPos()
xf := u.toGLFWPixel(float64(x), monitor) xf := u.dipToGLFWPixel(float64(x), monitor)
yf := u.toGLFWPixel(float64(y), monitor) yf := u.dipToGLFWPixel(float64(y), monitor)
if x, y := u.adjustWindowPosition(mx+int(xf), my+int(yf)); u.isFullscreen() { if x, y := u.adjustWindowPosition(mx+int(xf), my+int(yf)); u.isFullscreen() {
u.setOrigPos(x, y) u.setOrigPos(x, y)
} else { } else {
@ -1639,9 +1643,9 @@ func (u *UserInterface) setWindowPosition(x, y int, monitor *glfw.Monitor) {
// before the fullscreen, while window.GetSize() returns the desktop screen size in the fullscreen mode. // before the fullscreen, while window.GetSize() returns the desktop screen size in the fullscreen mode.
if !u.isFullscreen() && runtime.GOOS == "darwin" { if !u.isFullscreen() && runtime.GOOS == "darwin" {
w, h := u.window.GetSize() w, h := u.window.GetSize()
ww := int(u.fromGLFWPixel(float64(w), u.currentMonitor())) ww := int(u.dipFromGLFWPixel(float64(w), u.currentMonitor()))
wh := int(u.fromGLFWPixel(float64(h), u.currentMonitor())) wh := int(u.dipFromGLFWPixel(float64(h), u.currentMonitor()))
u.setWindowSizeInDP(ww, wh, u.isFullscreen()) u.setWindowSizeInDIP(ww, wh, u.isFullscreen())
} }
} }

View File

@ -121,14 +121,14 @@ import (
// clearVideoModeScaleCache must be called from the main thread. // clearVideoModeScaleCache must be called from the main thread.
func clearVideoModeScaleCache() {} func clearVideoModeScaleCache() {}
// fromGLFWMonitorPixel must be called from the main thread. // dipFromGLFWMonitorPixel must be called from the main thread.
func (u *UserInterface) fromGLFWMonitorPixel(x float64, monitor *glfw.Monitor) float64 { func (u *UserInterface) dipFromGLFWMonitorPixel(x float64, monitor *glfw.Monitor) float64 {
// videoModeScale is always 1 on macOS. // videoModeScale is always 1 on macOS.
return x return x
} }
// fromGLFWPixel must be called from the main thread. // dipFromGLFWPixel must be called from the main thread.
func (u *UserInterface) fromGLFWPixel(x float64, monitor *glfw.Monitor) float64 { func (u *UserInterface) dipFromGLFWPixel(x float64, monitor *glfw.Monitor) float64 {
// NOTE: On macOS, GLFW exposes the device independent coordinate system. // NOTE: On macOS, GLFW exposes the device independent coordinate system.
// Thus, the conversion functions are unnecessary, // Thus, the conversion functions are unnecessary,
// however we still need the deviceScaleFactor internally // however we still need the deviceScaleFactor internally
@ -136,8 +136,8 @@ func (u *UserInterface) fromGLFWPixel(x float64, monitor *glfw.Monitor) float64
return x return x
} }
// toGLFWPixel must be called from the main thread. // dipToGLFWPixel must be called from the main thread.
func (u *UserInterface) toGLFWPixel(x float64, monitor *glfw.Monitor) float64 { func (u *UserInterface) dipToGLFWPixel(x float64, monitor *glfw.Monitor) float64 {
return x return x
} }

View File

@ -116,18 +116,18 @@ func videoModeScaleUncached(m *glfw.Monitor) float64 {
return 1 return 1
} }
// fromGLFWMonitorPixel must be called from the main thread. // dipFromGLFWMonitorPixel must be called from the main thread.
func (u *UserInterface) fromGLFWMonitorPixel(x float64, monitor *glfw.Monitor) float64 { func (u *UserInterface) dipFromGLFWMonitorPixel(x float64, monitor *glfw.Monitor) float64 {
return x / (videoModeScale(monitor) * u.deviceScaleFactor(monitor)) return x / (videoModeScale(monitor) * u.deviceScaleFactor(monitor))
} }
// fromGLFWPixel must be called from the main thread. // dipFromGLFWPixel must be called from the main thread.
func (u *UserInterface) fromGLFWPixel(x float64, monitor *glfw.Monitor) float64 { func (u *UserInterface) dipFromGLFWPixel(x float64, monitor *glfw.Monitor) float64 {
return x / u.deviceScaleFactor(monitor) return x / u.deviceScaleFactor(monitor)
} }
// toGLFWPixel must be called from the main thread. // dipToGLFWPixel must be called from the main thread.
func (u *UserInterface) toGLFWPixel(x float64, monitor *glfw.Monitor) float64 { func (u *UserInterface) dipToGLFWPixel(x float64, monitor *glfw.Monitor) float64 {
return x * u.deviceScaleFactor(monitor) return x * u.deviceScaleFactor(monitor)
} }

View File

@ -93,18 +93,18 @@ func getMonitorInfoW(hMonitor uintptr, lpmi *monitorInfo) error {
// clearVideoModeScaleCache must be called from the main thread. // clearVideoModeScaleCache must be called from the main thread.
func clearVideoModeScaleCache() {} func clearVideoModeScaleCache() {}
// fromGLFWMonitorPixel must be called from the main thread. // dipFromGLFWMonitorPixel must be called from the main thread.
func (u *UserInterface) fromGLFWMonitorPixel(x float64, monitor *glfw.Monitor) float64 { func (u *UserInterface) dipFromGLFWMonitorPixel(x float64, monitor *glfw.Monitor) float64 {
return x / u.deviceScaleFactor(monitor) return x / u.deviceScaleFactor(monitor)
} }
// fromGLFWPixel must be called from the main thread. // dipFromGLFWPixel must be called from the main thread.
func (u *UserInterface) fromGLFWPixel(x float64, monitor *glfw.Monitor) float64 { func (u *UserInterface) dipFromGLFWPixel(x float64, monitor *glfw.Monitor) float64 {
return x / u.deviceScaleFactor(monitor) return x / u.deviceScaleFactor(monitor)
} }
// toGLFWPixel must be called from the main thread. // dipToGLFWPixel must be called from the main thread.
func (u *UserInterface) toGLFWPixel(x float64, monitor *glfw.Monitor) float64 { func (u *UserInterface) dipToGLFWPixel(x float64, monitor *glfw.Monitor) float64 {
return x * u.deviceScaleFactor(monitor) return x * u.deviceScaleFactor(monitor)
} }

View File

@ -185,8 +185,8 @@ func (w *window) Position() (int, int) {
mx, my := m.GetPos() mx, my := m.GetPos()
wx -= mx wx -= mx
wy -= my wy -= my
xf := w.ui.fromGLFWPixel(float64(wx), m) xf := w.ui.dipFromGLFWPixel(float64(wx), m)
yf := w.ui.fromGLFWPixel(float64(wy), m) yf := w.ui.dipFromGLFWPixel(float64(wy), m)
x, y = int(xf), int(yf) x, y = int(xf), int(yf)
return nil return nil
}) })
@ -195,7 +195,7 @@ func (w *window) Position() (int, int) {
func (w *window) SetPosition(x, y int) { func (w *window) SetPosition(x, y int) {
if !w.ui.isRunning() { if !w.ui.isRunning() {
w.ui.setInitWindowPosition(x, y) w.ui.setInitWindowPositionInDIP(x, y)
return return
} }
_ = w.ui.t.Call(func() error { _ = w.ui.t.Call(func() error {
@ -206,13 +206,13 @@ func (w *window) SetPosition(x, y int) {
func (w *window) Size() (int, int) { func (w *window) Size() (int, int) {
if !w.ui.isRunning() { if !w.ui.isRunning() {
ww, wh := w.ui.getInitWindowSizeInDP() ww, wh := w.ui.getInitWindowSizeInDIP()
return w.ui.adjustWindowSizeBasedOnSizeLimitsInDP(ww, wh) return w.ui.adjustWindowSizeBasedOnSizeLimitsInDIP(ww, wh)
} }
ww, wh := 0, 0 ww, wh := 0, 0
_ = w.ui.t.Call(func() error { _ = w.ui.t.Call(func() error {
ww = w.ui.windowWidthInDP ww = w.ui.windowWidthInDIP
wh = w.ui.windowHeightInDP wh = w.ui.windowHeightInDIP
return nil return nil
}) })
return ww, wh return ww, wh
@ -220,7 +220,7 @@ func (w *window) Size() (int, int) {
func (w *window) SetSize(width, height int) { func (w *window) SetSize(width, height int) {
if !w.ui.isRunning() { if !w.ui.isRunning() {
w.ui.setInitWindowSize(width, height) w.ui.setInitWindowSizeInDIP(width, height)
return return
} }
_ = w.ui.t.Call(func() error { _ = w.ui.t.Call(func() error {
@ -230,17 +230,17 @@ func (w *window) SetSize(width, height int) {
return nil return nil
} }
w.ui.setWindowSizeInDP(width, height, w.ui.isFullscreen()) w.ui.setWindowSizeInDIP(width, height, w.ui.isFullscreen())
return nil return nil
}) })
} }
func (w *window) SizeLimits() (minw, minh, maxw, maxh int) { func (w *window) SizeLimits() (minw, minh, maxw, maxh int) {
return w.ui.getWindowSizeLimitsInDP() return w.ui.getWindowSizeLimitsInDIP()
} }
func (w *window) SetSizeLimits(minw, minh, maxw, maxh int) { func (w *window) SetSizeLimits(minw, minh, maxw, maxh int) {
if !w.ui.setWindowSizeLimitsInDP(minw, minh, maxw, maxh) { if !w.ui.setWindowSizeLimitsInDIP(minw, minh, maxw, maxh) {
return return
} }
if !w.ui.isRunning() { if !w.ui.isRunning() {