From 6ff3e0f48876757532e645132b6e6c7e5050fb2a Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 22 Oct 2023 20:06:54 +0200 Subject: [PATCH] Various improvements to macOS platform --- Source/Editor/GUI/Docking/DockHintWindow.cs | 28 +++++++-------- .../Engine/Platform/Linux/LinuxPlatform.cpp | 4 +-- Source/Engine/Platform/Mac/MacWindow.cpp | 35 +++++++++++++------ Source/Engine/Platform/Mac/MacWindow.h | 6 ++-- Source/Engine/Platform/iOS/iOSPlatform.cpp | 2 +- 5 files changed, 42 insertions(+), 33 deletions(-) diff --git a/Source/Editor/GUI/Docking/DockHintWindow.cs b/Source/Editor/GUI/Docking/DockHintWindow.cs index 52c5dcd3c..7d459e163 100644 --- a/Source/Editor/GUI/Docking/DockHintWindow.cs +++ b/Source/Editor/GUI/Docking/DockHintWindow.cs @@ -83,6 +83,7 @@ namespace FlaxEditor.GUI.Docking // Enable hit window presentation Proxy.Window.RenderingEnabled = true; Proxy.Window.Show(); + Proxy.Window.Focus(); } /// @@ -270,15 +271,16 @@ namespace FlaxEditor.GUI.Docking // Cache dock rectangles var size = _rectDock.Size; var offset = _rectDock.Location; - float BorderMargin = 4.0f; - float ProxyHintWindowsSize2 = Proxy.HintWindowsSize * 0.5f; - float centerX = size.X * 0.5f; - float centerY = size.Y * 0.5f; - _rUpper = new Rectangle(centerX - ProxyHintWindowsSize2, BorderMargin, Proxy.HintWindowsSize, Proxy.HintWindowsSize) + offset; - _rBottom = new Rectangle(centerX - ProxyHintWindowsSize2, size.Y - Proxy.HintWindowsSize - BorderMargin, Proxy.HintWindowsSize, Proxy.HintWindowsSize) + offset; - _rLeft = new Rectangle(BorderMargin, centerY - ProxyHintWindowsSize2, Proxy.HintWindowsSize, Proxy.HintWindowsSize) + offset; - _rRight = new Rectangle(size.X - Proxy.HintWindowsSize - BorderMargin, centerY - ProxyHintWindowsSize2, Proxy.HintWindowsSize, Proxy.HintWindowsSize) + offset; - _rCenter = new Rectangle(centerX - ProxyHintWindowsSize2, centerY - ProxyHintWindowsSize2, Proxy.HintWindowsSize, Proxy.HintWindowsSize) + offset; + var borderMargin = 4.0f; + var hintWindowsSize = Proxy.HintWindowsSize * Platform.DpiScale; + var hintWindowsSize2 = hintWindowsSize * 0.5f; + var centerX = size.X * 0.5f; + var centerY = size.Y * 0.5f; + _rUpper = new Rectangle(centerX - hintWindowsSize2, borderMargin, hintWindowsSize, hintWindowsSize) + offset; + _rBottom = new Rectangle(centerX - hintWindowsSize2, size.Y - hintWindowsSize - borderMargin, hintWindowsSize, hintWindowsSize) + offset; + _rLeft = new Rectangle(borderMargin, centerY - hintWindowsSize2, hintWindowsSize, hintWindowsSize) + offset; + _rRight = new Rectangle(size.X - hintWindowsSize - borderMargin, centerY - hintWindowsSize2, hintWindowsSize, hintWindowsSize) + offset; + _rCenter = new Rectangle(centerX - hintWindowsSize2, centerY - hintWindowsSize2, hintWindowsSize, hintWindowsSize) + offset; // Hit test DockState toSet = DockState.Float; @@ -428,7 +430,6 @@ namespace FlaxEditor.GUI.Docking { if (Window == null) { - // Create proxy window var settings = CreateWindowSettings.Default; settings.Title = "DockHint.Window"; settings.Size = initSize; @@ -440,12 +441,10 @@ namespace FlaxEditor.GUI.Docking settings.IsRegularWindow = false; settings.SupportsTransparency = true; settings.ShowInTaskbar = false; - settings.ShowAfterFirstPaint = true; + settings.ShowAfterFirstPaint = false; settings.IsTopmost = true; Window = Platform.CreateWindow(ref settings); - - // Set opacity and background color Window.Opacity = 0.6f; Window.GUI.BackgroundColor = Style.Current.DragWindow; } @@ -465,7 +464,7 @@ namespace FlaxEditor.GUI.Docking var settings = CreateWindowSettings.Default; settings.Title = name; - settings.Size = new Float2(HintWindowsSize); + settings.Size = new Float2(HintWindowsSize * Platform.DpiScale); settings.AllowInput = false; settings.AllowMaximize = false; settings.AllowMinimize = false; @@ -479,7 +478,6 @@ namespace FlaxEditor.GUI.Docking settings.ShowAfterFirstPaint = false; win = Platform.CreateWindow(ref settings); - win.Opacity = 0.6f; win.GUI.BackgroundColor = Style.Current.DragWindow; } diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index 4787b4549..36affd8c8 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -2622,9 +2622,7 @@ bool LinuxPlatform::GetHasFocus() if (window->IsFocused()) return true; } - - // Default to true if has no windows open - return WindowsManager::Windows.IsEmpty(); + return false; } bool LinuxPlatform::CanOpenUrl(const StringView& url) diff --git a/Source/Engine/Platform/Mac/MacWindow.cpp b/Source/Engine/Platform/Mac/MacWindow.cpp index 08a4e0d2f..ea38a635c 100644 --- a/Source/Engine/Platform/Mac/MacWindow.cpp +++ b/Source/Engine/Platform/Mac/MacWindow.cpp @@ -710,6 +710,8 @@ MacWindow::MacWindow(const CreateWindowSettings& settings) { styleMask |= NSWindowStyleMaskBorderless; } + if (settings.Fullscreen) + styleMask |= NSWindowStyleMaskFullScreen; if (settings.HasBorder) { styleMask |= NSWindowStyleMaskTitled; @@ -736,7 +738,8 @@ MacWindow::MacWindow(const CreateWindowSettings& settings) [window setMaxSize:NSMakeSize(settings.MaximumSize.X, settings.MaximumSize.Y)]; [window setOpaque:!settings.SupportsTransparency]; [window setContentView:view]; - [window setAcceptsMouseMovedEvents:YES]; + if (settings.AllowInput) + [window setAcceptsMouseMovedEvents:YES]; [window setDelegate:window]; _window = window; _view = view; @@ -751,8 +754,6 @@ MacWindow::MacWindow(const CreateWindowSettings& settings) layer.contentsScale = screenScale; // TODO: impl Parent for MacWindow - // TODO: impl StartPosition for MacWindow - // TODO: impl Fullscreen for MacWindow // TODO: impl ShowInTaskbar for MacWindow // TODO: impl IsTopmost for MacWindow } @@ -816,7 +817,10 @@ void MacWindow::Show() // Show NSWindow* window = (NSWindow*)_window; - [window makeKeyAndOrderFront:window]; + if (_settings.AllowInput) + [window makeKeyAndOrderFront:window]; + else + [window orderFront:window]; if (_settings.ActivateWhenFirstShown) [NSApp activateIgnoringOtherApps:YES]; _focused = true; @@ -870,14 +874,9 @@ void MacWindow::Restore() [window zoom:nil]; } -bool MacWindow::IsClosed() const -{ - return _window != nullptr; -} - bool MacWindow::IsForegroundWindow() const { - return Platform::GetHasFocus() && IsFocused(); + return IsFocused() && Platform::GetHasFocus(); } void MacWindow::BringToFront(bool force) @@ -1039,6 +1038,22 @@ DragDropEffect MacWindow::DoDragDrop(const StringView& data) return result; } +void MacWindow::StartTrackingMouse(bool useMouseScreenOffset) +{ + if (_isTrackingMouse || !_window) + return; + _isTrackingMouse = true; + _trackingMouseOffset = Float2::Zero; + _isUsingMouseOffset = useMouseScreenOffset; +} + +void MacWindow::EndTrackingMouse() +{ + if (!_isTrackingMouse || !_window) + return; + _isTrackingMouse = false; +} + void MacWindow::SetCursor(CursorType type) { CursorType prev = _cursor; diff --git a/Source/Engine/Platform/Mac/MacWindow.h b/Source/Engine/Platform/Mac/MacWindow.h index 7c3f091b4..eb1389f29 100644 --- a/Source/Engine/Platform/Mac/MacWindow.h +++ b/Source/Engine/Platform/Mac/MacWindow.h @@ -13,14 +13,12 @@ class FLAXENGINE_API MacWindow : public WindowBase { private: - void* _window = nullptr; void* _view = nullptr; bool _isMouseOver = false; String _dragText; public: - MacWindow(const CreateWindowSettings& settings); ~MacWindow(); @@ -32,7 +30,6 @@ public: } public: - // [WindowBase] void* GetNativePtr() const override; void Show() override; @@ -40,7 +37,6 @@ public: void Minimize() override; void Maximize() override; void Restore() override; - bool IsClosed() const override; bool IsForegroundWindow() const override; void BringToFront(bool force = false) override; void SetClientBounds(const Rectangle& clientArea) override; @@ -56,6 +52,8 @@ public: void Focus() override; void SetTitle(const StringView& title) override; DragDropEffect DoDragDrop(const StringView& data) override; + void StartTrackingMouse(bool useMouseScreenOffset) override; + void EndTrackingMouse() override; void SetCursor(CursorType type) override; }; diff --git a/Source/Engine/Platform/iOS/iOSPlatform.cpp b/Source/Engine/Platform/iOS/iOSPlatform.cpp index 7ca27c481..26c3b8f28 100644 --- a/Source/Engine/Platform/iOS/iOSPlatform.cpp +++ b/Source/Engine/Platform/iOS/iOSPlatform.cpp @@ -410,7 +410,7 @@ bool iOSWindow::IsClosed() const bool iOSWindow::IsForegroundWindow() const { - return Platform::GetHasFocus() && IsFocused(); + return IsFocused() && Platform::GetHasFocus(); } void iOSWindow::BringToFront(bool force)