Add macOS window impl progress

This commit is contained in:
2026-04-04 22:34:39 +02:00
parent dccfa76994
commit 4e6fde17ea
3 changed files with 67 additions and 6 deletions
@@ -362,8 +362,8 @@ namespace FlaxEditor.GUI.Docking
// Cache dock rectangles
var size = _rectDock.Size / Platform.DpiScale;
#if PLATFORM_MAC
size *= (float)Platform.Dpi / 96.0f; // TODO: refactor DPI support to skip such hacks
#if PLATFORM_MAC && !PLATFORM_SDL
size *= (float)Platform.Dpi / 96.0f; // TODO: refactor DPI support on macOS to skip such hacks
#endif
var offset = _toDock.PointFromScreen(_rectDock.Location);
var borderMargin = 10.0f;
+2 -2
View File
@@ -702,8 +702,8 @@ namespace FlaxEditor.Modules
{
// Check if there is a floating window that has the same size
var dpi = (float)Platform.Dpi / 96.0f;
#if PLATFORM_MAC
dpi = 1.0f; // TODO: refactor DPI support to skip such hacks
#if PLATFORM_MAC && !PLATFORM_SDL
dpi = 1.0f; // TODO: refactor DPI support on macOS to skip such hacks
#endif
var dpiScale = Platform.CustomDpiScale;
var defaultSize = window.DefaultSize * dpi;
+63 -2
View File
@@ -19,6 +19,9 @@
#include <AppKit/AppKit.h>
#include <QuartzCore/CAMetalLayer.h>
// TODO: finish this (missing mouse up when title bar drag ends)
#define MAC_WINDOW_TITLE_BAR_CLICK 0
#if USE_EDITOR
// Data for drawing window while doing drag&drop on Mac (engine is paused during platform tick)
CriticalSection MacDragLocker;
@@ -698,9 +701,60 @@ static void ConvertNSRect(NSScreen *screen, NSRect *r)
@end
#if MAC_WINDOW_TITLE_BAR_CLICK
@interface MacResponderImpl : NSResponder
{
MacWindow* Window;
bool TrackingMouseDown;
}
- (void)setWindow:(MacWindow*)window;
@end
@implementation MacResponderImpl
- (void)setWindow:(MacWindow*)window
{
Window = window;
TrackingMouseDown = false;
}
- (void)mouseDown:(NSEvent*)event
{
if (IsWindowInvalid(Window) || TrackingMouseDown) return;
Float2 mousePos = GetMousePosition(Window, event);
if (mousePos.Y < 0)
{
// Titlebar click
bool result = false;
Window->OnLeftButtonHit(WindowHitCodes::Caption, result);
TrackingMouseDown = result;
}
}
- (void)mouseUp:(NSEvent*)event
{
if (IsWindowInvalid(Window)) return;
//NSPoint point = [event locationInWindow];
//LOG(Warning, "Mouse up! at: {}x{}", point.x, point.y);
if (TrackingMouseDown)
{
TrackingMouseDown = false;
Float2 mousePos = GetMousePosition(Window, event);
Window->OnMouseUp(mousePos, MouseButton::Left);
}
}
@end
#endif
MacWindow::MacWindow(const CreateWindowSettings& settings)
: WindowBase(settings)
{
// Setup size and styles
_clientSize = Float2(settings.Size.X, settings.Size.Y);
Float2 pos = AppleUtils::PosToCoca(settings.Position);
NSRect frame = NSMakeRect(pos.X, pos.Y - settings.Size.Y, settings.Size.X, settings.Size.Y);
@@ -736,6 +790,7 @@ MacWindow::MacWindow(const CreateWindowSettings& settings)
frame.size.width /= screenScale;
frame.size.height /= screenScale;
// Create window
MacWindowImpl* window = [[MacWindowImpl alloc] initWithContentRect:frame
styleMask:(styleMask)
backing:NSBackingStoreBuffered
@@ -764,12 +819,18 @@ MacWindow::MacWindow(const CreateWindowSettings& settings)
[view registerForDraggedTypes:@[NSPasteboardTypeFileURL, NSPasteboardTypeString]];
}
#if MAC_WINDOW_TITLE_BAR_CLICK
// Plug into superview to receive mouse events for the title
MacResponderImpl* responder = [[MacResponderImpl alloc] init];
[responder setWindow:this];
NSView* superview = [[window contentView] superview];
[superview setNextResponder:responder];
#endif
// Rescale contents
CALayer* layer = [view layer];
if (layer)
layer.contentsScale = screenScale;
// TODO: impl ShowInTaskbar for MacWindow
}
MacWindow::~MacWindow()