14# pragma clang diagnostic ignored "-Wdeprecated-declarations"
17#ifdef WITH_METAL_BACKEND
21#ifdef WITH_VULKAN_BACKEND
25#import <Cocoa/Cocoa.h>
26#import <Metal/Metal.h>
39- (void)windowDidBecomeKey:(NSNotification *)notification;
40- (void)windowDidResignKey:(NSNotification *)notification;
41- (void)windowDidExpose:(NSNotification *)notification;
42- (void)windowDidResize:(NSNotification *)notification;
43- (void)windowDidMove:(NSNotification *)notification;
44- (void)windowWillMove:(NSNotification *)notification;
45- (BOOL)windowShouldClose:(
id)sender;
46- (void)windowDidChangeBackingProperties:(NSNotification *)notification;
61 system_cocoa_ = sysCocoa;
62 window_cocoa_ = winCocoa;
68- (void)windowDidBecomeKey:(NSNotification *)notification
75- (void)windowDidResignKey:(NSNotification *)notification
80- (void)windowDidExpose:(NSNotification *)notification
85- (void)windowDidMove:(NSNotification *)notification
90- (void)windowWillMove:(NSNotification *)notification
95- (void)windowWillEnterFullScreen:(NSNotification *)notification
100- (void)windowDidEnterFullScreen:(NSNotification *)notification
107 window_cocoa_->setImmediateDraw(
false);
110- (void)windowWillExitFullScreen:(NSNotification *)notification
112 window_cocoa_->setImmediateDraw(
true);
115- (void)windowDidExitFullScreen:(NSNotification *)notification
119 window_cocoa_->setImmediateDraw(
false);
122- (void)windowDidResize:(NSNotification *)notification
125 if (![[notification
object] inLiveResize])
133 if ([[notification
object] inLiveResize]) {
134 system_cocoa_->dispatchEvents();
138- (void)windowDidChangeBackingProperties:(NSNotification *)notification
144- (BOOL)windowShouldClose:(
id)sender;
161 contentRect:(NSRect)contentRect
162 styleMask:(NSWindowStyleMask)style
163 backing:(NSBackingStoreType)backingStoreType
176 contentRect:(NSRect)contentRect
177 styleMask:(NSWindowStyleMask)style
178 backing:(NSBackingStoreType)backingStoreType
181 self = [
super initWithContentRect:contentRect
183 backing:backingStoreType
187 system_cocoa_ = sysCocoa;
188 window_cocoa_ = winCocoa;
194- (BOOL)canBecomeKeyWindow
197 return (window_cocoa_->isDialog() || !system_cocoa_->hasDialogWindow());
201- (NSDragOperation)draggingEntered:(
id<NSDraggingInfo>)sender
204 NSPasteboard *draggingPBoard = sender.draggingPasteboard;
205 if ([[draggingPBoard types] containsObject:NSPasteboardTypeTIFF]) {
208 else if ([[draggingPBoard types] containsObject:NSFilenamesPboardType]) {
211 else if ([[draggingPBoard types] containsObject:NSPasteboardTypeString]) {
215 return NSDragOperationNone;
218 const NSPoint mouseLocation = sender.draggingLocation;
219 window_cocoa_->setAcceptDragOperation(TRUE);
221 dragged_object_type_,
227 return NSDragOperationCopy;
230- (BOOL)wantsPeriodicDraggingUpdates
235- (NSDragOperation)draggingUpdated:(
id<NSDraggingInfo>)sender
237 const NSPoint mouseLocation = [sender draggingLocation];
240 dragged_object_type_,
248- (void)draggingExited:(
id<NSDraggingInfo>)sender
250 system_cocoa_->handleDraggingEvent(
255- (BOOL)prepareForDragOperation:(
id<NSDraggingInfo>)sender
257 if (window_cocoa_->canAcceptDragOperation()) {
263- (BOOL)performDragOperation:(
id<NSDraggingInfo>)sender
266 NSPasteboard *draggingPBoard = sender.draggingPasteboard;
269 switch (dragged_object_type_) {
271 if (![NSImage canInitWithPasteboard:draggingPBoard]) {
275 NSImage *droppedImg = [[NSImage alloc] initWithPasteboard:draggingPBoard];
280 data = [draggingPBoard propertyListForType:NSFilenamesPboardType];
283 data = [draggingPBoard stringForType:NSPasteboardTypeString];
290 const NSPoint mouseLocation = sender.draggingLocation;
292 dragged_object_type_,
304#define COCOA_VIEW_CLASS CocoaOpenGLView
305#define COCOA_VIEW_BASE_CLASS NSOpenGLView
307#undef COCOA_VIEW_CLASS
308#undef COCOA_VIEW_BASE_CLASS
310#define COCOA_VIEW_CLASS CocoaMetalView
311#define COCOA_VIEW_BASE_CLASS NSView
313#undef COCOA_VIEW_CLASS
314#undef COCOA_VIEW_BASE_CLASS
347 rect.origin.x = left;
348 rect.origin.y = bottom;
349 rect.size.width = width;
350 rect.size.height = height;
352 NSWindowStyleMask styleMask = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
353 NSWindowStyleMaskResizable;
355 styleMask |= NSWindowStyleMaskMiniaturizable;
362 backing:NSBackingStoreBuffered
368 [
window_ setFrameOrigin:NSMakePoint(left, bottom)];
371 const NSSize minSize = {320, 240};
372 window_.contentMinSize = minSize;
375 id<MTLDevice> metalDevice = MTLCreateSystemDefaultDevice();
386 [metal_layer_ removeAllAnimations];
393 if (type == GHOST_kDrawingContextTypeMetal) {
402 const CFStringRef name = kCGColorSpaceExtendedSRGB;
403 CGColorSpaceRef
colorspace = CGColorSpaceCreateWithName(name);
429 window_.initialFirstResponder = view;
435 [
window_ makeKeyAndOrderFront:nil];
445 tablet_ = GHOST_TABLET_DATA_NONE;
448 initWithSystemCocoa:systemCocoa
450 window_.delegate = windowDelegate;
452 window_.acceptsMouseMovedEvents = YES;
454 NSView *contentview =
window_.contentView;
455 contentview.allowedTouchTypes = (NSTouchTypeMaskDirect | NSTouchTypeMaskIndirect);
457 [
window_ registerForDraggedTypes:[
NSArray arrayWithObjects:NSFilenamesPboardType,
458 NSPasteboardTypeString,
459 NSPasteboardTypeTIFF,
462 if (is_dialog && parent_window) {
463 [
parent_window->getViewWindow() addChildWindow:window_ ordered:NSWindowAbove];
464 window_.collectionBehavior = NSWindowCollectionBehaviorFullScreenAuxiliary;
467 window_.collectionBehavior = NSWindowCollectionBehaviorFullScreenPrimary;
478 [custom_cursor_ release];
485 [opengl_view_ release];
489 [metal_view_ release];
493 [metal_layer_ release];
503 NSArray *windowsList = [
NSApp orderedWindows];
534 NSString *windowTitle = [[
NSString alloc] initWithCString:title encoding:NSUTF8StringEncoding];
547 NSString *windowTitle =
window_.title;
548 if (windowTitle != nil) {
549 title = windowTitle.UTF8String;
560 NSString *associatedFileName = [[[
NSString alloc] initWithCString:filepath
561 encoding:NSUTF8StringEncoding]
564 window_.representedFilename = associatedFileName;
575 window_.backgroundColor = [
NSColor colorWithRed:background_color[0]
576 green:background_color[1]
577 blue:background_color[2]
585 const float hsv_v = MAX(background_color[0], MAX(background_color[1], background_color[2]));
587 const NSAppearanceName win_appearance = hsv_v > 0.5 ? NSAppearanceNameVibrantLight :
588 NSAppearanceNameVibrantDark;
591 window_.titlebarAppearsTransparent = YES;
594 window_.titlebarAppearsTransparent = NO;
606 const NSRect screenFrame = [getPrimaryScreen() visibleFrame];
607 const NSRect windowFrame =
window_.frame;
614 const int32_t screenMaxY = screenFrame.origin.y + screenFrame.size.height;
618 bounds.
b_ = screenMaxY - windowFrame.origin.y;
619 bounds.
t_ = screenMaxY - windowFrame.origin.y - windowFrame.size.height;
621 bounds.
l_ = windowFrame.origin.x;
622 bounds.
r_ = windowFrame.origin.x + windowFrame.size.width;
632 const NSRect screenFrame = [getPrimaryScreen() visibleFrame];
634 const NSRect screenContentRect = [
NSWindow contentRectForFrameRect:screenFrame
635 styleMask:[
window_ styleMask]];
637 const NSRect windowFrame =
window_.frame;
639 const NSRect windowContentRect = [
window_ contentRectForFrameRect:windowFrame];
641 const int32_t screenMaxY = screenContentRect.origin.y + screenContentRect.size.height;
645 bounds.
b_ = screenMaxY - windowContentRect.origin.y;
646 bounds.
t_ = screenMaxY - windowContentRect.origin.y - windowContentRect.size.height;
648 bounds.
l_ = windowContentRect.origin.x;
649 bounds.
r_ = windowContentRect.origin.x + windowContentRect.size.width;
661 if ((uint32_t(cBnds.
getWidth())) != width) {
662 const NSSize size = {(CGFloat)width, (CGFloat)cBnds.
getHeight()};
677 if ((uint32_t(cBnds.
getHeight())) != height) {
678 const NSSize size = {(CGFloat)cBnds.
getWidth(), (CGFloat)height};
692 if (((uint32_t(cBnds.
getWidth())) != width) || ((uint32_t(cBnds.
getHeight())) != height)) {
693 const NSSize size = {(CGFloat)width, (CGFloat)height};
705 NSUInteger masks =
window_.styleMask;
707 if (masks & NSWindowStyleMaskFullScreen) {
763 screenCoord.origin = {(CGFloat)inX, (CGFloat)inY};
765 const NSRect baseCoord = [
window_ convertRectFromScreen:screenCoord];
767 outX = baseCoord.origin.x;
768 outY = baseCoord.origin.y;
777 baseCoord.origin = {(CGFloat)inX, (CGFloat)inY};
779 const NSRect screenCoord = [
window_ convertRectToScreen:baseCoord];
781 outX = screenCoord.origin.x;
782 outY = screenCoord.origin.y;
793 return [[
NSScreen screens] firstObject];
802 CAMetalLayer *metalLayer = (CAMetalLayer *)
metal_view_.layer;
827 const NSUInteger masks =
window_.styleMask;
829 if (!(masks & NSWindowStyleMaskFullScreen)) {
830 [
window_ toggleFullScreen:nil];
837 const NSUInteger masks =
window_.styleMask;
839 if (masks & NSWindowStyleMaskFullScreen) {
841 [
window_ toggleFullScreen:nil];
843 else if (
window_.isMiniaturized) {
859 window_.documentEdited = is_unsaved_changes;
870 [
NSApp activateIgnoringOtherApps:YES];
871 [
window_ makeKeyAndOrderFront:nil];
874 NSArray *windowsList;
879 windowsList = [
NSApp orderedWindows];
880 if (windowsList.count) {
881 [[
windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
895 NSSize backingSize = viewSize;
898 backingSize = [metal_view_ convertSizeToBacking:viewSize];
901 CAMetalLayer *metalLayer = (CAMetalLayer *)
metal_view_.layer;
903 metalLayer.contentsScale = backingSize.height / viewSize.height;
904 metalLayer.drawableSize = NSSizeToCGSize(backingSize);
910#ifdef WITH_VULKAN_BACKEND
911 case GHOST_kDrawingContextTypeVulkan: {
914 if (context->initializeDrawingContext()) {
922#ifdef WITH_METAL_BACKEND
923 case GHOST_kDrawingContextTypeMetal: {
926 if (context->initializeDrawingContext()) {
950 view.needsDisplay = YES;
962 if ((progress >= 0.0) && (progress <= 1.0)) {
963 NSImage *dockIcon = [[
NSImage alloc] initWithSize:NSMakeSize(128, 128)];
967 [[
NSImage imageNamed:@"NSApplicationIcon"] drawAtPoint:NSZeroPoint
969 operation:NSCompositingOperationSourceOver
972 NSRect progressRect = {{8, 8}, {112, 14}};
973 NSBezierPath *progressPath;
976 [[[
NSColor whiteColor] colorWithAlphaComponent:0.6] setFill];
977 progressPath = [
NSBezierPath bezierPathWithRoundedRect:progressRect xRadius:7 yRadius:7];
981 [[[
NSColor blackColor] colorWithAlphaComponent:0.7] setFill];
982 progressRect = NSInsetRect(progressRect, 2, 2);
983 progressRect.size.width *= progress;
984 progressPath = [
NSBezierPath bezierPathWithRoundedRect:progressRect xRadius:5 yRadius:5];
988 [
NSApp setApplicationIconImage:dockIcon];
1006 NSImage *dockIcon = [[
NSImage alloc] initWithSize:NSMakeSize(128, 128)];
1008 [[
NSImage imageNamed:@"NSApplicationIcon"] drawAtPoint:NSZeroPoint
1010 operation:NSCompositingOperationSourceOver
1013 [
NSApp setApplicationIconImage:dockIcon];
1025@interface NSCursor (Undocumented)
1041 return [
NSCursor disappearingItemCursor];
1047 return [
NSCursor resizeUpDownCursor];
1049 return [
NSCursor resizeLeftRightCursor];
1053 return [
NSCursor resizeDownCursor];
1055 return [
NSCursor resizeLeftCursor];
1057 return [
NSCursor resizeRightCursor];
1061 return [
NSCursor operationNotAllowedCursor];
1067 return [
NSCursor closedHandCursor];
1069 return [
NSCursor pointingHandCursor];
1074 return [
NSCursor busyButClickableCursor];
1085 static bool systemCursorVisible =
true;
1088 if (visible != systemCursorVisible) {
1091 systemCursorVisible =
true;
1095 systemCursorVisible =
false;
1100 if (cursor ==
nullptr) {
1180 for (
int i = 0; i <
size[1]; ++i) {
1181 for (
int j = 0; j <
size[0]; ++j) {
1182 buffer[(i * size[0]) + j] = buffer[(i * size[0]) + j] ^ 0x00FFFFFF;
1190 const int hot_spot[2],
1191 const bool can_invert_color)
1195 [custom_cursor_ release];
1199 if (can_invert_color) {
1206 initWithBitmapDataPlanes:(unsigned char **)&bitmap
1213 colorSpaceName:NSDeviceRGBColorSpace
1214 bytesPerRow:(size[0] * 4)
1224 const NSSize imSize = {(CGFloat)size[0] /
scale, (CGFloat)size[1] /
scale};
1226 NSImage *cursorImage = [[
NSImage alloc] initWithCGImage:cgImage size:NSZeroSize];
1229 const NSPoint hotSpotPoint = {(CGFloat)hot_spot[0] /
scale, (CGFloat)hot_spot[1] /
scale};
1244#ifdef WITH_INPUT_IME
1248 [opengl_view_ beginIME:x y:y w:w h:h completed:completed];
1251 [metal_view_ beginIME:x y:y w:w h:h completed:completed];
1255void GHOST_WindowCocoa::endIME()
1258 [opengl_view_ endIME];
1261 [metal_view_ endIME];
#define GHOST_ASSERT(x, info)
@ GHOST_kWindowStateMinimized
@ GHOST_kWindowStateMaximized
@ GHOST_kWindowStateNormal
@ GHOST_kWindowStateFullScreen
@ GHOST_kStandardCursorHandClosed
@ GHOST_kStandardCursorHandOpen
@ GHOST_kStandardCursorCopy
@ GHOST_kStandardCursorWait
@ GHOST_kStandardCursorTopSide
@ GHOST_kStandardCursorStop
@ GHOST_kStandardCursorCrosshair
@ GHOST_kStandardCursorCustom
@ GHOST_kStandardCursorLeftRight
@ GHOST_kStandardCursorUpDown
@ GHOST_kStandardCursorHandPoint
@ GHOST_kStandardCursorBottomSide
@ GHOST_kStandardCursorMove
@ GHOST_kStandardCursorDefault
@ GHOST_kStandardCursorRightSide
@ GHOST_kStandardCursorDestroy
@ GHOST_kStandardCursorLeftSide
@ GHOST_kStandardCursorText
@ GHOST_kEventWindowClose
@ GHOST_kEventDraggingDropDone
@ GHOST_kEventDraggingExited
@ GHOST_kEventNativeResolutionChange
@ GHOST_kEventDraggingUpdated
@ GHOST_kEventDraggingEntered
@ GHOST_kEventWindowActivate
@ GHOST_kEventWindowUpdate
@ GHOST_kEventWindowDeactivate
GHOST_TDrawingContextType
@ GHOST_kDragnDropTypeUnknown
@ GHOST_kDragnDropTypeFilenames
@ GHOST_kDragnDropTypeBitmap
@ GHOST_kDragnDropTypeString
@ GHOST_kDecorationColoredTitleBar
static void cursor_bitmap_rgba_invert(uint32_t *buffer, const int size[2])
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
NSCursor * busyButClickableCursor()
GHOST_ContextMTL(const GHOST_ContextParams &context_params, NSView *metalView, CAMetalLayer *metalLayer)
GHOST_ContextVK(const GHOST_ContextParams &context_params, GHOST_TVulkanPlatformType platform, Window window, Display *display, wl_surface *wayland_surface, wl_display *wayland_display, const GHOST_ContextVK_WindowInfo *wayland_window_info, int contextMajorVersion, int contextMinorVersion, const GHOST_GPUDevice &preferred_device, const GHOST_WindowHDRInfo *hdr_info_=nullptr)
virtual int32_t getHeight() const
virtual int32_t getWidth() const
bool isDialog() const override
GHOST_TSuccess setProgressBar(float progress) override
GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape) override
GHOST_TSuccess setState(GHOST_TWindowState state) override
std::string getTitle() const override
GHOST_SystemCocoa * system_cocoa_
void setImmediateDraw(bool value)
GHOST_TSuccess setClientHeight(uint32_t height) override
void clientToScreen(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const override
CAMetalLayer * metal_layer_
NSScreen * getScreen() const
NSCursor * custom_cursor_
void setTitle(const char *title) override
GHOST_TSuccess invalidate() override
GHOST_TSuccess endProgressBar() override
NSCursor * getStandardCursor(GHOST_TStandardCursor cursor) const
GHOST_TWindowState getState() const override
GHOST_TSuccess setClientWidth(uint32_t width) override
GHOST_TSuccess applyWindowDecorationStyle() override
GHOST_TSuccess hasCursorShape(GHOST_TStandardCursor shape) override
void clientToScreenIntern(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const
void * getOSWindow() const override
CocoaOpenGLView * opengl_view_
void getClientBounds(GHOST_Rect &bounds) const override
GHOST_TSuccess setModifiedState(bool is_unsaved_changes) override
void screenToClient(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const override
void getWindowBounds(GHOST_Rect &bounds) const override
GHOST_Context * newDrawingContext(GHOST_TDrawingContextType type) override
GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode) override
GHOST_TSuccess setWindowCustomCursorShape(const uint8_t *bitmap, const uint8_t *mask, const int size[2], const int hot_spot[2], bool can_invert_color) override
static NSScreen * getPrimaryScreen()
GHOST_WindowCocoa(GHOST_SystemCocoa *systemCocoa, const char *title, int32_t left, int32_t bottom, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_TDrawingContextType type, const GHOST_ContextParams &context_params, bool dialog, GHOST_WindowCocoa *parent_window, const GHOST_GPUDevice &preferred_device)
~GHOST_WindowCocoa() override
GHOST_TSuccess setOrder(GHOST_TWindowOrder order) override
CocoaMetalView * metal_view_
void screenToClientIntern(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const
GHOST_GPUDevice preferred_device_
void setNativePixelSize()
void setPath(const char *filepath) override
bool getValid() const override
GHOST_TSuccess setWindowCursorVisibility(bool visible) override
void loadCursor(bool visible, GHOST_TStandardCursor cursor) const
GHOST_TSuccess setClientSize(uint32_t width, uint32_t height) override
GHOST_ContextParams want_context_params_
GHOST_TSuccess setModifiedState(bool is_unsaved_changes) override
void setCursorGrabAccum(int32_t x, int32_t y)
GHOST_WindowDecorationStyleSettings window_decoration_style_settings_
GHOST_TStandardCursor getCursorShape() const override
GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type) override
int32_t cursor_grab_init_pos_[2]
GHOST_TSuccess releaseNativeHandles()
GHOST_TWindowDecorationStyleFlags window_decoration_style_flags_
virtual bool canAcceptDragOperation() const
bool getValid() const override
bool getCursorVisibility() const override
GHOST_TSuccess activateDrawingContext() override
GHOST_TSuccess updateDrawingContext()
GHOST_Window(uint32_t width, uint32_t height, GHOST_TWindowState state, const GHOST_ContextParams &context_params, const bool exclusive=false)
GHOST_Rect cursor_grab_bounds_
bool progress_bar_visible_
GHOST_WindowHDRInfo hdr_info_
GHOST_TGrabCursorMode cursor_grab_
float3x3 scale(float3x3 mat, float2 scale)
GHOST_SystemCocoa * systemCocoa
GHOST_WindowCocoa * windowCocoa
GHOST_TDragnDropTypes draggedObjectType
GHOST_SystemCocoa * systemCocoa
GHOST_WindowCocoa * windowCocoa
BMesh const char void * data
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
float colored_titlebar_bg_color[3]