diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 1b54aa469..dad11c5df 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -98,6 +98,11 @@ type userInterfaceImpl struct { initScreenTransparent bool initFocused bool + origWindowPosX int + origWindowPosY int + origWindowWidthInDIP int + origWindowHeightInDIP int + fpsModeInited bool input Input @@ -112,8 +117,6 @@ type userInterfaceImpl struct { // t is the main thread == the rendering thread. t thread.Thread m sync.RWMutex - - native userInterfaceImplNative } const ( @@ -137,8 +140,9 @@ func init() { initWindowHeightInDIP: 480, initFocused: true, fpsMode: FPSModeVsyncOn, + origWindowPosX: invalidPos, + origWindowPosY: invalidPos, } - theUI.native.initialize() theUI.input.ui = &theUI.userInterfaceImpl theUI.iwindow.ui = &theUI.userInterfaceImpl } @@ -1709,3 +1713,21 @@ func (u *userInterfaceImpl) forceToRefreshIfNeeded() { func (u *userInterfaceImpl) isWindowMaximized() bool { return u.window.GetAttrib(glfw.Maximized) == glfw.True && !u.isNativeFullscreen() } + +func (u *userInterfaceImpl) origWindowPos() (int, int) { + return u.origWindowPosX, u.origWindowPosY +} + +func (u *userInterfaceImpl) setOrigWindowPos(x, y int) { + u.origWindowPosX = x + u.origWindowPosY = y +} + +func (u *userInterfaceImpl) origWindowSizeInDIP() (int, int) { + return u.origWindowWidthInDIP, u.origWindowHeightInDIP +} + +func (u *userInterfaceImpl) setOrigWindowSizeInDIP(width, height int) { + u.origWindowWidthInDIP = width + u.origWindowHeightInDIP = height +} diff --git a/internal/ui/ui_glfw_darwin.go b/internal/ui/ui_glfw_darwin.go index 63c68d336..6f9c239bd 100644 --- a/internal/ui/ui_glfw_darwin.go +++ b/internal/ui/ui_glfw_darwin.go @@ -23,10 +23,6 @@ package ui // #import // // @interface EbitengineWindowDelegate : NSObject -// // origPos is the window's original position. This is valid only when the application is in the fullscreen mode. -// @property CGPoint origPos; -// // origSize is the window's original size. -// @property CGSize origSize; // @end // // @implementation EbitengineWindowDelegate { @@ -86,8 +82,6 @@ package ui // - (void)windowWillEnterFullScreen:(NSNotification *)notification { // NSWindow* window = (NSWindow*)[notification object]; // [self pushResizableState:window]; -// self->_origPos = [window frame].origin; -// self->_origSize = [window frame].size; // } // // - (void)windowDidEnterFullScreen:(NSNotification *)notification { @@ -191,40 +185,6 @@ package ui // [window setBackgroundColor: [NSColor colorWithSRGBRed:0 green:0 blue:0 alpha:0]]; // } // -// static void windowOriginalPosition(uintptr_t windowPtr, int* x, int* y) { -// NSWindow* window = (NSWindow*)windowPtr; -// EbitengineWindowDelegate* delegate = (EbitengineWindowDelegate*)window.delegate; -// CGPoint pos = delegate.origPos; -// *x = pos.x; -// *y = pos.y; -// } -// -// static void setWindowOriginalPosition(uintptr_t windowPtr, int x, int y) { -// NSWindow* window = (NSWindow*)windowPtr; -// EbitengineWindowDelegate* delegate = (EbitengineWindowDelegate*)window.delegate; -// CGPoint pos; -// pos.x = x; -// pos.y = y; -// delegate.origPos = pos; -// } -// -// static void windowOriginalSize(uintptr_t windowPtr, int* width, int* height) { -// NSWindow* window = (NSWindow*)windowPtr; -// EbitengineWindowDelegate* delegate = (EbitengineWindowDelegate*)window.delegate; -// CGSize size = delegate.origSize; -// *width = size.width; -// *height = size.height; -// } -// -// static void setWindowOriginalSize(uintptr_t windowPtr, int width, int height) { -// NSWindow* window = (NSWindow*)windowPtr; -// EbitengineWindowDelegate* delegate = (EbitengineWindowDelegate*)window.delegate; -// CGSize size; -// size.width = width; -// size.height = height; -// delegate.origSize = size; -// } -// // static void setNativeCursor(int cursorID) { // id cursor = [[NSCursor class] performSelector:@selector(arrowCursor)]; // switch (cursorID) { @@ -306,8 +266,6 @@ func (*graphicsDriverCreatorImpl) newMetal() (graphicsdriver.Graphics, error) { // clearVideoModeScaleCache must be called from the main thread. func clearVideoModeScaleCache() {} -type userInterfaceImplNative struct{} - // dipFromGLFWMonitorPixel must be called from the main thread. func (u *userInterfaceImpl) dipFromGLFWMonitorPixel(x float64, monitor *glfw.Monitor) float64 { return x @@ -411,43 +369,3 @@ func initializeWindowAfterCreation(w *glfw.Window) { // Enable resizing temporary before making the window fullscreen. C.initializeWindow(C.uintptr_t(w.GetCocoaWindow())) } - -func (u *userInterfaceImpl) origWindowPos() (int, int) { - if !u.isNativeFullscreen() { - return invalidPos, invalidPos - } - var cx, cy C.int - C.windowOriginalPosition(C.uintptr_t(u.window.GetCocoaWindow()), &cx, &cy) - x := int(cx) - _, h := u.origWindowSizeInDIP() - y := flipY(int(cy)) - h - return x, y -} - -func (u *userInterfaceImpl) setOrigWindowPos(x, y int) { - if !u.isNativeFullscreen() { - return - } - cx := C.int(x) - _, h := u.origWindowSizeInDIP() - cy := C.int(flipY(y + h)) - C.setWindowOriginalPosition(C.uintptr_t(u.window.GetCocoaWindow()), cx, cy) -} - -func (u *userInterfaceImpl) origWindowSizeInDIP() (int, int) { - // TODO: Make these values consistent with the original positions that are updated only when the app is in fullscreen. - var cw, ch C.int - C.windowOriginalSize(C.uintptr_t(u.window.GetCocoaWindow()), &cw, &ch) - w := int(u.dipFromGLFWPixel(float64(cw), u.currentMonitor())) - h := int(u.dipFromGLFWPixel(float64(ch), u.currentMonitor())) - return w, h -} - -func (u *userInterfaceImpl) setOrigWindowSizeInDIP(width, height int) { - cw := C.int(u.dipFromGLFWPixel(float64(width), u.currentMonitor())) - ch := C.int(u.dipFromGLFWPixel(float64(height), u.currentMonitor())) - C.setWindowOriginalSize(C.uintptr_t(u.window.GetCocoaWindow()), cw, ch) -} - -func (u *userInterfaceImplNative) initialize() { -} diff --git a/internal/ui/ui_glfw_unix.go b/internal/ui/ui_glfw_unix.go index 3ded868d7..ff2f952c0 100644 --- a/internal/ui/ui_glfw_unix.go +++ b/internal/ui/ui_glfw_unix.go @@ -142,13 +142,6 @@ func videoModeScaleUncached(m *glfw.Monitor) float64 { return 1 } -type userInterfaceImplNative struct { - origWindowPosX int - origWindowPosY int - origWindowWidthInDIP int - origWindowHeightInDIP int -} - // dipFromGLFWMonitorPixel must be called from the main thread. func (u *userInterfaceImpl) dipFromGLFWMonitorPixel(x float64, monitor *glfw.Monitor) float64 { return x / (videoModeScale(monitor) * u.deviceScaleFactor(monitor)) @@ -237,26 +230,3 @@ func initializeWindowAfterCreation(w *glfw.Window) { // Apparently the window state is inconsistent just after the window is created, but we are not sure. // For more details, see the discussion in #1829. } - -func (u *userInterfaceImpl) origWindowPos() (int, int) { - return u.native.origWindowPosX, u.native.origWindowPosY -} - -func (u *userInterfaceImpl) setOrigWindowPos(x, y int) { - u.native.origWindowPosX = x - u.native.origWindowPosY = y -} - -func (u *userInterfaceImpl) origWindowSizeInDIP() (int, int) { - return u.native.origWindowWidthInDIP, u.native.origWindowHeightInDIP -} - -func (u *userInterfaceImpl) setOrigWindowSizeInDIP(width, height int) { - u.native.origWindowWidthInDIP = width - u.native.origWindowHeightInDIP = height -} - -func (u *userInterfaceImplNative) initialize() { - u.origWindowPosX = invalidPos - u.origWindowPosY = invalidPos -} diff --git a/internal/ui/ui_glfw_windows.go b/internal/ui/ui_glfw_windows.go index 2bbceb842..7ebf67c96 100644 --- a/internal/ui/ui_glfw_windows.go +++ b/internal/ui/ui_glfw_windows.go @@ -62,13 +62,6 @@ func (*graphicsDriverCreatorImpl) newMetal() (graphicsdriver.Graphics, error) { return nil, nil } -type userInterfaceImplNative struct { - origWindowPosX int - origWindowPosY int - origWindowWidthInDIP int - origWindowHeightInDIP int -} - // clearVideoModeScaleCache must be called from the main thread. func clearVideoModeScaleCache() {} @@ -193,26 +186,3 @@ func (u *userInterfaceImpl) setWindowResizingModeForOS(mode WindowResizingMode) func initializeWindowAfterCreation(w *glfw.Window) { } - -func (u *userInterfaceImpl) origWindowPos() (int, int) { - return u.native.origWindowPosX, u.native.origWindowPosY -} - -func (u *userInterfaceImpl) setOrigWindowPos(x, y int) { - u.native.origWindowPosX = x - u.native.origWindowPosY = y -} - -func (u *userInterfaceImpl) origWindowSizeInDIP() (int, int) { - return u.native.origWindowWidthInDIP, u.native.origWindowHeightInDIP -} - -func (u *userInterfaceImpl) setOrigWindowSizeInDIP(width, height int) { - u.native.origWindowWidthInDIP = width - u.native.origWindowHeightInDIP = height -} - -func (u *userInterfaceImplNative) initialize() { - u.origWindowPosX = invalidPos - u.origWindowPosY = invalidPos -}