From 58d3655597bc02a00ce9c6f78032dad37dff5f73 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 24 Sep 2023 19:45:55 +0900 Subject: [PATCH] internal/ui: remove unnecessary receivers from methods --- internal/ui/input_glfw.go | 8 ++--- internal/ui/ui_glfw.go | 58 +++++++++++++++++----------------- internal/ui/ui_glfw_darwin.go | 6 ++-- internal/ui/ui_glfw_linbsd.go | 6 ++-- internal/ui/ui_glfw_windows.go | 6 ++-- internal/ui/window_glfw.go | 4 +-- 6 files changed, 44 insertions(+), 44 deletions(-) diff --git a/internal/ui/input_glfw.go b/internal/ui/input_glfw.go index b4a34eaf9..69a8c128e 100644 --- a/internal/ui/input_glfw.go +++ b/internal/ui/input_glfw.go @@ -78,13 +78,13 @@ func (u *userInterfaceImpl) updateInputStateImpl() error { if !math.IsNaN(cx) && !math.IsNaN(cy) { cx2, cy2 := u.context.logicalPositionToClientPosition(cx, cy, s) - cx2 = u.dipToGLFWPixel(cx2, m) - cy2 = u.dipToGLFWPixel(cy2, m) + cx2 = dipToGLFWPixel(cx2, m) + cy2 = dipToGLFWPixel(cy2, m) u.window.SetCursorPos(cx2, cy2) } else { cx2, cy2 := u.window.GetCursorPos() - cx2 = u.dipFromGLFWPixel(cx2, m) - cy2 = u.dipFromGLFWPixel(cy2, m) + cx2 = dipFromGLFWPixel(cx2, m) + cy2 = dipFromGLFWPixel(cy2, m) cx, cy = u.context.clientPositionToLogicalPosition(cx2, cy2, s) } diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 122e169b5..cfcb80b9d 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -277,12 +277,12 @@ func (u *userInterfaceImpl) setWindowMonitor(monitor *Monitor) { } } - w := u.dipToGLFWPixel(float64(ww), monitor) - h := u.dipToGLFWPixel(float64(wh), monitor) - mw := u.dipFromGLFWMonitorPixel(float64(monitor.videoMode.Width), monitor) - mh := u.dipFromGLFWMonitorPixel(float64(monitor.videoMode.Height), monitor) - mw = u.dipToGLFWPixel(mw, monitor) - mh = u.dipToGLFWPixel(mh, monitor) + w := dipToGLFWPixel(float64(ww), monitor) + h := dipToGLFWPixel(float64(wh), monitor) + mw := dipFromGLFWMonitorPixel(float64(monitor.videoMode.Width), monitor) + mh := dipFromGLFWMonitorPixel(float64(monitor.videoMode.Height), monitor) + mw = dipToGLFWPixel(mw, monitor) + mh = dipToGLFWPixel(mh, monitor) px, py := InitialWindowPosition(int(mw), int(mh), int(w), int(h)) u.window.SetPos(monitor.x+px, monitor.y+py) @@ -519,8 +519,8 @@ func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) { } if !u.isRunning() { m := u.getInitMonitor() - w := u.dipFromGLFWMonitorPixel(float64(m.videoMode.Width), m) - h := u.dipFromGLFWMonitorPixel(float64(m.videoMode.Height), m) + w := dipFromGLFWMonitorPixel(float64(m.videoMode.Width), m) + h := dipFromGLFWMonitorPixel(float64(m.videoMode.Height), m) return int(w), int(h) } @@ -533,8 +533,8 @@ func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) { if m == nil { return } - w = int(u.dipFromGLFWMonitorPixel(float64(m.videoMode.Width), m)) - h = int(u.dipFromGLFWMonitorPixel(float64(m.videoMode.Height), m)) + w = int(dipFromGLFWMonitorPixel(float64(m.videoMode.Width), m)) + h = int(dipFromGLFWMonitorPixel(float64(m.videoMode.Height), m)) }) return w, h } @@ -752,8 +752,8 @@ func (u *userInterfaceImpl) createWindow() error { monitor := u.getInitMonitor() ww, wh := u.getInitWindowSizeInDIP() - width := int(u.dipToGLFWPixel(float64(ww), monitor)) - height := int(u.dipToGLFWPixel(float64(wh), monitor)) + width := int(dipToGLFWPixel(float64(ww), monitor)) + height := int(dipToGLFWPixel(float64(wh), monitor)) window, err := glfw.CreateWindow(width, height, "", nil, nil) if err != nil { return err @@ -763,8 +763,8 @@ func (u *userInterfaceImpl) createWindow() error { // The position must be set before the size is set (#1982). // setWindowSizeInDIP refers the current monitor's device scale. wx, wy := u.getInitWindowPositionInDIP() - mw := int(u.dipFromGLFWMonitorPixel(float64(monitor.videoMode.Width), monitor)) - mh := int(u.dipFromGLFWMonitorPixel(float64(monitor.videoMode.Height), monitor)) + mw := int(dipFromGLFWMonitorPixel(float64(monitor.videoMode.Width), monitor)) + mh := int(dipFromGLFWMonitorPixel(float64(monitor.videoMode.Height), monitor)) if max := mw - ww; wx >= max { wx = max } @@ -1020,8 +1020,8 @@ func (u *userInterfaceImpl) outsideSize() (float64, float64) { if m := u.currentMonitor(); m != nil { vm := m.videoMode ww, wh := vm.Width, vm.Height - w = u.dipFromGLFWMonitorPixel(float64(ww), m) - h = u.dipFromGLFWMonitorPixel(float64(wh), m) + w = dipFromGLFWMonitorPixel(float64(ww), m) + h = dipFromGLFWMonitorPixel(float64(wh), m) } 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 // not match (#1163). ww, wh := u.window.GetSize() - w := u.dipFromGLFWPixel(float64(ww), u.currentMonitor()) - h := u.dipFromGLFWPixel(float64(wh), u.currentMonitor()) + w := dipFromGLFWPixel(float64(ww), u.currentMonitor()) + h := dipFromGLFWPixel(float64(wh), u.currentMonitor()) return w, h } @@ -1255,24 +1255,24 @@ func (u *userInterfaceImpl) updateWindowSizeLimits() { if minw < 0 { // Always set the minimum window width. - minw = int(u.dipToGLFWPixel(float64(u.minimumWindowWidth()), m)) + minw = int(dipToGLFWPixel(float64(u.minimumWindowWidth()), m)) } else { - minw = int(u.dipToGLFWPixel(float64(minw), m)) + minw = int(dipToGLFWPixel(float64(minw), m)) } if minh < 0 { minh = glfw.DontCare } else { - minh = int(u.dipToGLFWPixel(float64(minh), m)) + minh = int(dipToGLFWPixel(float64(minh), m)) } if maxw < 0 { maxw = glfw.DontCare } else { - maxw = int(u.dipToGLFWPixel(float64(maxw), m)) + maxw = int(dipToGLFWPixel(float64(maxw), m)) } if maxh < 0 { maxh = glfw.DontCare } else { - maxh = int(u.dipToGLFWPixel(float64(maxh), m)) + maxh = int(dipToGLFWPixel(float64(maxh), m)) } 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. // In the opposite order, the window size might not be correct when going back from fullscreen with multi monitors. oldW, oldH := u.window.GetSize() - newW := int(u.dipToGLFWPixel(float64(width), u.currentMonitor())) - newH := int(u.dipToGLFWPixel(float64(height), u.currentMonitor())) + newW := int(dipToGLFWPixel(float64(width), u.currentMonitor())) + newH := int(dipToGLFWPixel(float64(height), u.currentMonitor())) if oldW != newW || oldH != newH { // Just after SetSize, GetSize is not reliable especially on Linux/UNIX. // Let's wait for FramebufferSize callback in any cases. @@ -1396,8 +1396,8 @@ func (u *userInterfaceImpl) setFullscreen(fullscreen bool) { // TODO: Why? origX, origY := u.origWindowPos() - ww := int(u.dipToGLFWPixel(float64(u.origWindowWidthInDIP), u.currentMonitor())) - wh := int(u.dipToGLFWPixel(float64(u.origWindowHeightInDIP), u.currentMonitor())) + ww := int(dipToGLFWPixel(float64(u.origWindowWidthInDIP), u.currentMonitor())) + wh := int(dipToGLFWPixel(float64(u.origWindowHeightInDIP), u.currentMonitor())) if u.isNativeFullscreenAvailable() { u.setNativeFullscreen(false) // 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 - xf := u.dipToGLFWPixel(float64(x), monitor) - yf := u.dipToGLFWPixel(float64(y), monitor) + xf := dipToGLFWPixel(float64(x), monitor) + yf := dipToGLFWPixel(float64(y), monitor) if x, y := u.adjustWindowPosition(mx+int(xf), my+int(yf), monitor); u.isFullscreen() { u.setOrigWindowPos(x, y) } else { diff --git a/internal/ui/ui_glfw_darwin.go b/internal/ui/ui_glfw_darwin.go index 4e46357e3..d6f9b4aa5 100644 --- a/internal/ui/ui_glfw_darwin.go +++ b/internal/ui/ui_glfw_darwin.go @@ -189,11 +189,11 @@ func videoModeScale(monitor *glfw.Monitor) float64 { return 1 } -func (u *userInterfaceImpl) dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 { +func dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 { 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. // Thus, the conversion functions are unnecessary, // however we still need the deviceScaleFactor internally @@ -201,7 +201,7 @@ func (u *userInterfaceImpl) dipFromGLFWPixel(x float64, monitor *Monitor) float6 return x } -func (u *userInterfaceImpl) dipToGLFWPixel(x float64, monitor *Monitor) float64 { +func dipToGLFWPixel(x float64, monitor *Monitor) float64 { return x } diff --git a/internal/ui/ui_glfw_linbsd.go b/internal/ui/ui_glfw_linbsd.go index 79c85d8e6..4b4031db3 100644 --- a/internal/ui/ui_glfw_linbsd.go +++ b/internal/ui/ui_glfw_linbsd.go @@ -110,15 +110,15 @@ func videoModeScale(m *glfw.Monitor) float64 { return 1 } -func (u *userInterfaceImpl) dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 { +func dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 { 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() } -func (u *userInterfaceImpl) dipToGLFWPixel(x float64, monitor *Monitor) float64 { +func dipToGLFWPixel(x float64, monitor *Monitor) float64 { return x * monitor.deviceScaleFactor() } diff --git a/internal/ui/ui_glfw_windows.go b/internal/ui/ui_glfw_windows.go index e5350dd1e..4ff906f9c 100644 --- a/internal/ui/ui_glfw_windows.go +++ b/internal/ui/ui_glfw_windows.go @@ -91,15 +91,15 @@ func videoModeScale(monitor *glfw.Monitor) float64 { return 1 } -func (u *userInterfaceImpl) dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 { +func dipFromGLFWMonitorPixel(x float64, monitor *Monitor) float64 { return x / monitor.deviceScaleFactor() } -func (u *userInterfaceImpl) dipFromGLFWPixel(x float64, monitor *Monitor) float64 { +func dipFromGLFWPixel(x float64, monitor *Monitor) float64 { return x / monitor.deviceScaleFactor() } -func (u *userInterfaceImpl) dipToGLFWPixel(x float64, monitor *Monitor) float64 { +func dipToGLFWPixel(x float64, monitor *Monitor) float64 { return x * monitor.deviceScaleFactor() } diff --git a/internal/ui/window_glfw.go b/internal/ui/window_glfw.go index 473b0f790..c7b195686 100644 --- a/internal/ui/window_glfw.go +++ b/internal/ui/window_glfw.go @@ -266,8 +266,8 @@ func (w *glfwWindow) Position() (int, int) { m := w.ui.currentMonitor() wx -= m.x wy -= m.y - xf := w.ui.dipFromGLFWPixel(float64(wx), m) - yf := w.ui.dipFromGLFWPixel(float64(wy), m) + xf := dipFromGLFWPixel(float64(wx), m) + yf := dipFromGLFWPixel(float64(wy), m) x, y = int(xf), int(yf) }) return x, y