internal/ui: remove unnecessary receivers from methods

This commit is contained in:
Hajime Hoshi 2023-09-24 19:45:55 +09:00
parent b32575b7b2
commit 58d3655597
6 changed files with 44 additions and 44 deletions

View File

@ -78,13 +78,13 @@ func (u *userInterfaceImpl) updateInputStateImpl() error {
if !math.IsNaN(cx) && !math.IsNaN(cy) { if !math.IsNaN(cx) && !math.IsNaN(cy) {
cx2, cy2 := u.context.logicalPositionToClientPosition(cx, cy, s) cx2, cy2 := u.context.logicalPositionToClientPosition(cx, cy, s)
cx2 = u.dipToGLFWPixel(cx2, m) cx2 = dipToGLFWPixel(cx2, m)
cy2 = u.dipToGLFWPixel(cy2, m) cy2 = dipToGLFWPixel(cy2, m)
u.window.SetCursorPos(cx2, cy2) u.window.SetCursorPos(cx2, cy2)
} else { } else {
cx2, cy2 := u.window.GetCursorPos() cx2, cy2 := u.window.GetCursorPos()
cx2 = u.dipFromGLFWPixel(cx2, m) cx2 = dipFromGLFWPixel(cx2, m)
cy2 = u.dipFromGLFWPixel(cy2, m) cy2 = dipFromGLFWPixel(cy2, m)
cx, cy = u.context.clientPositionToLogicalPosition(cx2, cy2, s) cx, cy = u.context.clientPositionToLogicalPosition(cx2, cy2, s)
} }

View File

@ -277,12 +277,12 @@ func (u *userInterfaceImpl) setWindowMonitor(monitor *Monitor) {
} }
} }
w := u.dipToGLFWPixel(float64(ww), monitor) w := dipToGLFWPixel(float64(ww), monitor)
h := u.dipToGLFWPixel(float64(wh), monitor) h := dipToGLFWPixel(float64(wh), monitor)
mw := u.dipFromGLFWMonitorPixel(float64(monitor.videoMode.Width), monitor) mw := dipFromGLFWMonitorPixel(float64(monitor.videoMode.Width), monitor)
mh := u.dipFromGLFWMonitorPixel(float64(monitor.videoMode.Height), monitor) mh := dipFromGLFWMonitorPixel(float64(monitor.videoMode.Height), monitor)
mw = u.dipToGLFWPixel(mw, monitor) mw = dipToGLFWPixel(mw, monitor)
mh = u.dipToGLFWPixel(mh, monitor) mh = dipToGLFWPixel(mh, monitor)
px, py := InitialWindowPosition(int(mw), int(mh), int(w), int(h)) px, py := InitialWindowPosition(int(mw), int(mh), int(w), int(h))
u.window.SetPos(monitor.x+px, monitor.y+py) u.window.SetPos(monitor.x+px, monitor.y+py)
@ -519,8 +519,8 @@ func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
} }
if !u.isRunning() { if !u.isRunning() {
m := u.getInitMonitor() m := u.getInitMonitor()
w := u.dipFromGLFWMonitorPixel(float64(m.videoMode.Width), m) w := dipFromGLFWMonitorPixel(float64(m.videoMode.Width), m)
h := u.dipFromGLFWMonitorPixel(float64(m.videoMode.Height), m) h := dipFromGLFWMonitorPixel(float64(m.videoMode.Height), m)
return int(w), int(h) return int(w), int(h)
} }
@ -533,8 +533,8 @@ func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
if m == nil { if m == nil {
return return
} }
w = int(u.dipFromGLFWMonitorPixel(float64(m.videoMode.Width), m)) w = int(dipFromGLFWMonitorPixel(float64(m.videoMode.Width), m))
h = int(u.dipFromGLFWMonitorPixel(float64(m.videoMode.Height), m)) h = int(dipFromGLFWMonitorPixel(float64(m.videoMode.Height), m))
}) })
return w, h return w, h
} }
@ -752,8 +752,8 @@ func (u *userInterfaceImpl) createWindow() error {
monitor := u.getInitMonitor() monitor := u.getInitMonitor()
ww, wh := u.getInitWindowSizeInDIP() ww, wh := u.getInitWindowSizeInDIP()
width := int(u.dipToGLFWPixel(float64(ww), monitor)) width := int(dipToGLFWPixel(float64(ww), monitor))
height := int(u.dipToGLFWPixel(float64(wh), monitor)) height := int(dipToGLFWPixel(float64(wh), monitor))
window, err := glfw.CreateWindow(width, height, "", nil, nil) window, err := glfw.CreateWindow(width, height, "", nil, nil)
if err != nil { if err != nil {
return err return err
@ -763,8 +763,8 @@ func (u *userInterfaceImpl) createWindow() error {
// The position must be set before the size is set (#1982). // The position must be set before the size is set (#1982).
// setWindowSizeInDIP refers the current monitor's device scale. // setWindowSizeInDIP refers the current monitor's device scale.
wx, wy := u.getInitWindowPositionInDIP() wx, wy := u.getInitWindowPositionInDIP()
mw := int(u.dipFromGLFWMonitorPixel(float64(monitor.videoMode.Width), monitor)) mw := int(dipFromGLFWMonitorPixel(float64(monitor.videoMode.Width), monitor))
mh := int(u.dipFromGLFWMonitorPixel(float64(monitor.videoMode.Height), monitor)) mh := int(dipFromGLFWMonitorPixel(float64(monitor.videoMode.Height), monitor))
if max := mw - ww; wx >= max { if max := mw - ww; wx >= max {
wx = max wx = max
} }
@ -1020,8 +1020,8 @@ func (u *userInterfaceImpl) outsideSize() (float64, float64) {
if m := u.currentMonitor(); m != nil { if m := u.currentMonitor(); m != nil {
vm := m.videoMode vm := m.videoMode
ww, wh := vm.Width, vm.Height ww, wh := vm.Width, vm.Height
w = u.dipFromGLFWMonitorPixel(float64(ww), m) w = dipFromGLFWMonitorPixel(float64(ww), m)
h = u.dipFromGLFWMonitorPixel(float64(wh), m) h = dipFromGLFWMonitorPixel(float64(wh), m)
} }
return w, h return w, h
} }
@ -1034,8 +1034,8 @@ func (u *userInterfaceImpl) outsideSize() (float64, float64) {
// On Windows, the specified size at SetSize and the actual window size might // 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.dipFromGLFWPixel(float64(ww), u.currentMonitor()) w := dipFromGLFWPixel(float64(ww), u.currentMonitor())
h := u.dipFromGLFWPixel(float64(wh), u.currentMonitor()) h := dipFromGLFWPixel(float64(wh), u.currentMonitor())
return w, h return w, h
} }
@ -1255,24 +1255,24 @@ func (u *userInterfaceImpl) updateWindowSizeLimits() {
if minw < 0 { if minw < 0 {
// Always set the minimum window width. // Always set the minimum window width.
minw = int(u.dipToGLFWPixel(float64(u.minimumWindowWidth()), m)) minw = int(dipToGLFWPixel(float64(u.minimumWindowWidth()), m))
} else { } else {
minw = int(u.dipToGLFWPixel(float64(minw), m)) minw = int(dipToGLFWPixel(float64(minw), m))
} }
if minh < 0 { if minh < 0 {
minh = glfw.DontCare minh = glfw.DontCare
} else { } else {
minh = int(u.dipToGLFWPixel(float64(minh), m)) minh = int(dipToGLFWPixel(float64(minh), m))
} }
if maxw < 0 { if maxw < 0 {
maxw = glfw.DontCare maxw = glfw.DontCare
} else { } else {
maxw = int(u.dipToGLFWPixel(float64(maxw), m)) maxw = int(dipToGLFWPixel(float64(maxw), m))
} }
if maxh < 0 { if maxh < 0 {
maxh = glfw.DontCare maxh = glfw.DontCare
} else { } else {
maxh = int(u.dipToGLFWPixel(float64(maxh), m)) maxh = int(dipToGLFWPixel(float64(maxh), m))
} }
u.window.SetSizeLimits(minw, minh, maxw, maxh) u.window.SetSizeLimits(minw, minh, maxw, maxh)
@ -1335,8 +1335,8 @@ func (u *userInterfaceImpl) setWindowSizeInDIP(width, height int, callSetSize bo
// 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.dipToGLFWPixel(float64(width), u.currentMonitor())) newW := int(dipToGLFWPixel(float64(width), u.currentMonitor()))
newH := int(u.dipToGLFWPixel(float64(height), u.currentMonitor())) newH := int(dipToGLFWPixel(float64(height), u.currentMonitor()))
if oldW != newW || oldH != newH { if oldW != newW || oldH != newH {
// Just after SetSize, GetSize is not reliable especially on Linux/UNIX. // Just after SetSize, GetSize is not reliable especially on Linux/UNIX.
// Let's wait for FramebufferSize callback in any cases. // Let's wait for FramebufferSize callback in any cases.
@ -1396,8 +1396,8 @@ func (u *userInterfaceImpl) setFullscreen(fullscreen bool) {
// TODO: Why? // TODO: Why?
origX, origY := u.origWindowPos() origX, origY := u.origWindowPos()
ww := int(u.dipToGLFWPixel(float64(u.origWindowWidthInDIP), u.currentMonitor())) ww := int(dipToGLFWPixel(float64(u.origWindowWidthInDIP), u.currentMonitor()))
wh := int(u.dipToGLFWPixel(float64(u.origWindowHeightInDIP), u.currentMonitor())) wh := int(dipToGLFWPixel(float64(u.origWindowHeightInDIP), u.currentMonitor()))
if u.isNativeFullscreenAvailable() { if u.isNativeFullscreenAvailable() {
u.setNativeFullscreen(false) u.setNativeFullscreen(false)
// Adjust the window size later (after adjusting the position). // Adjust the window size later (after adjusting the position).
@ -1615,8 +1615,8 @@ func (u *userInterfaceImpl) setWindowPositionInDIP(x, y int, monitor *Monitor) {
} }
mx, my := monitor.x, monitor.y mx, my := monitor.x, monitor.y
xf := u.dipToGLFWPixel(float64(x), monitor) xf := dipToGLFWPixel(float64(x), monitor)
yf := u.dipToGLFWPixel(float64(y), monitor) yf := dipToGLFWPixel(float64(y), monitor)
if x, y := u.adjustWindowPosition(mx+int(xf), my+int(yf), monitor); u.isFullscreen() { if x, y := u.adjustWindowPosition(mx+int(xf), my+int(yf), monitor); u.isFullscreen() {
u.setOrigWindowPos(x, y) u.setOrigWindowPos(x, y)
} else { } else {

View File

@ -189,11 +189,11 @@ func videoModeScale(monitor *glfw.Monitor) float64 {
return 1 return 1
} }
func (u *userInterfaceImpl) dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 { func dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 {
return x return x
} }
func (u *userInterfaceImpl) dipFromGLFWPixel(x float64, monitor *Monitor) float64 { func dipFromGLFWPixel(x float64, monitor *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
@ -201,7 +201,7 @@ func (u *userInterfaceImpl) dipFromGLFWPixel(x float64, monitor *Monitor) float6
return x return x
} }
func (u *userInterfaceImpl) dipToGLFWPixel(x float64, monitor *Monitor) float64 { func dipToGLFWPixel(x float64, monitor *Monitor) float64 {
return x return x
} }

View File

@ -110,15 +110,15 @@ func videoModeScale(m *glfw.Monitor) float64 {
return 1 return 1
} }
func (u *userInterfaceImpl) dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 { func dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 {
return x / (monitor.videoModeScale * monitor.deviceScaleFactor()) return x / (monitor.videoModeScale * monitor.deviceScaleFactor())
} }
func (u *userInterfaceImpl) dipFromGLFWPixel(x float64, monitor *Monitor) float64 { func dipFromGLFWPixel(x float64, monitor *Monitor) float64 {
return x / monitor.deviceScaleFactor() return x / monitor.deviceScaleFactor()
} }
func (u *userInterfaceImpl) dipToGLFWPixel(x float64, monitor *Monitor) float64 { func dipToGLFWPixel(x float64, monitor *Monitor) float64 {
return x * monitor.deviceScaleFactor() return x * monitor.deviceScaleFactor()
} }

View File

@ -91,15 +91,15 @@ func videoModeScale(monitor *glfw.Monitor) float64 {
return 1 return 1
} }
func (u *userInterfaceImpl) dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 { func dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 {
return x / monitor.deviceScaleFactor() return x / monitor.deviceScaleFactor()
} }
func (u *userInterfaceImpl) dipFromGLFWPixel(x float64, monitor *Monitor) float64 { func dipFromGLFWPixel(x float64, monitor *Monitor) float64 {
return x / monitor.deviceScaleFactor() return x / monitor.deviceScaleFactor()
} }
func (u *userInterfaceImpl) dipToGLFWPixel(x float64, monitor *Monitor) float64 { func dipToGLFWPixel(x float64, monitor *Monitor) float64 {
return x * monitor.deviceScaleFactor() return x * monitor.deviceScaleFactor()
} }

View File

@ -266,8 +266,8 @@ func (w *glfwWindow) Position() (int, int) {
m := w.ui.currentMonitor() m := w.ui.currentMonitor()
wx -= m.x wx -= m.x
wy -= m.y wy -= m.y
xf := w.ui.dipFromGLFWPixel(float64(wx), m) xf := dipFromGLFWPixel(float64(wx), m)
yf := w.ui.dipFromGLFWPixel(float64(wy), m) yf := dipFromGLFWPixel(float64(wy), m)
x, y = int(xf), int(yf) x, y = int(xf), int(yf)
}) })
return x, y return x, y