iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IGraphicsMac.mm
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#include "IGraphicsMac.h"
12#import "IGraphicsMac_view.h"
13
14#if defined IGRAPHICS_GLES2 || defined IGRAPHICS_GLES3
15#import <libEGL/libEGL.h>
16#endif
17
18#include "IControl.h"
19#include "IPopupMenuControl.h"
20
21#pragma clang diagnostic ignored "-Wdeprecated-declarations"
22
23using namespace iplug;
24using namespace igraphics;
25
26static int GetSystemVersion()
27{
28 static int32_t v;
29 if (!v)
30 {
31 if (NSAppKitVersionNumber >= 1266.0)
32 {
33 if (NSAppKitVersionNumber >= 1404.0)
34 v = 0x10b0;
35 else
36 v = 0x10a0; // 10.10+ Gestalt(gsv) return 0x109x, so we bump this to 0x10a0
37 }
38 else
39 {
40 SInt32 a = 0x1040;
41 Gestalt(gestaltSystemVersion,&a);
42 v=a;
43 }
44 }
45 return v;
46}
47
48StaticStorage<CoreTextFontDescriptor> sFontDescriptorCache;
49
50#pragma mark -
51
52IGraphicsMac::IGraphicsMac(IGEditorDelegate& dlg, int w, int h, int fps, float scale)
53: IGRAPHICS_DRAW_CLASS(dlg, w, h, fps, scale)
54{
55 NSApplicationLoad();
56 StaticStorage<CoreTextFontDescriptor>::Accessor storage(sFontDescriptorCache);
57 storage.Retain();
58}
59
60IGraphicsMac::~IGraphicsMac()
61{
62 StaticStorage<CoreTextFontDescriptor>::Accessor storage(sFontDescriptorCache);
63 storage.Release();
64
65 CloseWindow();
66}
67
68PlatformFontPtr IGraphicsMac::LoadPlatformFont(const char* fontID, const char* fileNameOrResID)
69{
70 return CoreTextHelpers::LoadPlatformFont(fontID, fileNameOrResID, GetBundleID(), GetSharedResourcesSubPath());
71}
72
73PlatformFontPtr IGraphicsMac::LoadPlatformFont(const char* fontID, const char* fontName, ETextStyle style)
74{
75 return CoreTextHelpers::LoadPlatformFont(fontID, fontName, style);
76}
77
78PlatformFontPtr IGraphicsMac::LoadPlatformFont(const char* fontID, void* pData, int dataSize)
79{
80 return CoreTextHelpers::LoadPlatformFont(fontID, pData, dataSize);
81}
82
83void IGraphicsMac::CachePlatformFont(const char* fontID, const PlatformFontPtr& font)
84{
85 CoreTextHelpers::CachePlatformFont(fontID, font, sFontDescriptorCache);
86}
87
88float IGraphicsMac::MeasureText(const IText& text, const char* str, IRECT& bounds) const
89{
90 return IGRAPHICS_DRAW_CLASS::MeasureText(text, str, bounds);
91}
92
93void* IGraphicsMac::OpenWindow(void* pParent)
94{
95 TRACE
96 CloseWindow();
97 IGRAPHICS_VIEW* pView = [[IGRAPHICS_VIEW alloc] initWithIGraphics: this];
98 mView = (void*) pView;
99
100#ifdef IGRAPHICS_ACCESSKIT
101 auto pAccessibility = std::make_unique<IGraphicsAccessibilityMac>(*this, pView);
102 pView->mAccessibility = pAccessibility.get();
103 mAccessibility = std::move(pAccessibility);
104#endif
105
106 ActivateGLContext();
107 OnViewInitialized([pView layer]);
108 SetScreenScale([[NSScreen mainScreen] backingScaleFactor]);
109 GetDelegate()->LayoutUI(this);
110 UpdateTooltips();
111 GetDelegate()->OnUIOpen();
112
113 if (pParent)
114 {
115 [(NSView*) pParent addSubview: pView];
116 }
117
118 return mView;
119}
120
121void IGraphicsMac::AttachPlatformView(const IRECT& r, void* pView)
122{
123 NSView* pNewSubView = (NSView*) pView;
124 [pNewSubView setFrame:ToNSRect(this, r)];
125
126 [(IGRAPHICS_VIEW*) mView addSubview:(NSView*) pNewSubView];
127}
128
129void IGraphicsMac::RemovePlatformView(void* pView)
130{
131 [(NSView*) pView removeFromSuperview];
132}
133
134void IGraphicsMac::HidePlatformView(void* pView, bool hide)
135{
136 [(NSView*) pView setHidden:hide];
137}
138
139void IGraphicsMac::CloseWindow()
140{
141 if (mView)
142 {
143 IGRAPHICS_VIEW* pView = (IGRAPHICS_VIEW*) mView;
144
145#if defined IGRAPHICS_GL2 || defined IGRAPHICS_GL3
146 [[pView pixelFormat] release];
147 [[pView openGLContext] release];
148#elif defined IGRAPHICS_GLES2 || defined IGRAPHICS_GLES3
149 [pView deactivateGLContext];
150 eglDestroySurface([pView getEGLDisplay], [pView getEGLSurface]);
151 eglDestroyContext([pView getEGLDisplay], [pView getEGLContext]);
152 eglTerminate([pView getEGLDisplay]);
153#endif
154
155 [pView removeAllToolTips];
156 [pView killTimer];
157#ifdef IGRAPHICS_ACCESSKIT
158 pView->mAccessibility = nullptr;
159 mAccessibility = nullptr;
160#endif
161 [pView removeFromSuperview];
162 [pView release];
163
164 mView = nullptr;
165 OnViewDestroyed();
166 }
167}
168
169bool IGraphicsMac::WindowIsOpen()
170{
171 return mView;
172}
173
174void IGraphicsMac::PlatformResize(bool parentHasResized)
175{
176 if (mView)
177 {
178 NSSize size = { static_cast<CGFloat>(WindowWidth()), static_cast<CGFloat>(WindowHeight()) };
179
180 [NSAnimationContext beginGrouping]; // Prevent animated resizing
181 [[NSAnimationContext currentContext] setDuration:0.0];
182 [(IGRAPHICS_VIEW*) mView setFrameSize: size ];
183
184 [NSAnimationContext endGrouping];
185 }
186
187 UpdateTooltips();
188}
189
190void IGraphicsMac::PointToScreen(float& x, float& y) const
191{
192 if (mView)
193 {
194 x *= GetDrawScale();
195 y *= GetDrawScale();
196 NSWindow* pWindow = [(IGRAPHICS_VIEW*) mView window];
197 NSPoint wndpt = [(IGRAPHICS_VIEW*) mView convertPoint:NSMakePoint(x, y) toView:nil];
198 NSPoint pt = [pWindow convertRectToScreen: NSMakeRect(wndpt.x, wndpt.y, 0.0, 0.0)].origin;
199
200 x = pt.x;
201 y = pt.y;
202 }
203}
204
205void IGraphicsMac::ScreenToPoint(float& x, float& y) const
206{
207 if (mView)
208 {
209 NSWindow* pWindow = [(IGRAPHICS_VIEW*) mView window];
210 NSPoint wndpt = [pWindow convertRectFromScreen: NSMakeRect(x, y, 0.0, 0.0)].origin;
211 NSPoint pt = [(IGRAPHICS_VIEW*) mView convertPoint:NSMakePoint(wndpt.x, wndpt.y) fromView:nil];
212
213 x = pt.x / GetDrawScale();
214 y = pt.y / GetDrawScale();
215 }
216}
217
218void IGraphicsMac::HideMouseCursor(bool hide, bool lock)
219{
220#if defined AU_API
221 if (!IsXPCAuHost())
222#elif defined AUv3_API
223 if (!IsOOPAuv3AppExtension())
224#endif
225 {
226 if (mCursorHidden == hide)
227 return;
228
229 mCursorHidden = hide;
230
231 if (hide)
232 {
233 StoreCursorPosition();
234 CGDisplayHideCursor(kCGDirectMainDisplay);
235 mCursorLock = lock;
236 }
237 else
238 {
239 DoCursorLock(mCursorX, mCursorY, mCursorX, mCursorY);
240 CGDisplayShowCursor(kCGDirectMainDisplay);
241 mCursorLock = false;
242 }
243 }
244}
245
246void IGraphicsMac::MoveMouseCursor(float x, float y)
247{
248 if (mTabletInput)
249 return;
250
251 PointToScreen(x, y);
252 RepositionCursor(CGPoint{x, y});
253 StoreCursorPosition();
254}
255
256void IGraphicsMac::DoCursorLock(float x, float y, float& prevX, float& prevY)
257{
258 if (mCursorHidden && mCursorLock && !mTabletInput)
259 {
260 RepositionCursor(mCursorLockPosition);
261 prevX = mCursorX;
262 prevY = mCursorY;
263 }
264 else
265 {
266 mCursorX = prevX = x;
267 mCursorY = prevY = y;
268 }
269}
270
271void IGraphicsMac::RepositionCursor(CGPoint point)
272{
273 point = CGPoint{point.x, CGDisplayPixelsHigh(CGMainDisplayID()) - point.y};
274 CGAssociateMouseAndMouseCursorPosition(false);
275 CGDisplayMoveCursorToPoint(CGMainDisplayID(), point);
276 CGAssociateMouseAndMouseCursorPosition(true);
277}
278
279void IGraphicsMac::StoreCursorPosition()
280{
281 // Get position in screen coordinates
282 NSPoint mouse = [NSEvent mouseLocation];
283 mCursorX = mouse.x = std::round(mouse.x);
284 mCursorY = mouse.y = std::round(mouse.y);
285 mCursorLockPosition = CGPoint{mouse.x, mouse.y};
286
287 // Convert to IGraphics coordinates
288 ScreenToPoint(mCursorX, mCursorY);
289}
290
291void IGraphicsMac::GetMouseLocation(float& x, float&y) const
292{
293 // Get position in screen coordinates
294 NSPoint mouse = [NSEvent mouseLocation];
295 x = mouse.x;
296 y = mouse.y;
297
298 // Convert to IGraphics coordinates
299 ScreenToPoint(x, y);
300}
301
302EMsgBoxResult IGraphicsMac::ShowMessageBox(const char* str, const char* title, EMsgBoxType type, IMsgBoxCompletionHandlerFunc completionHandler)
303{
304 ReleaseMouseCapture();
305
306 NSString* messageContent = @(str ? str : "");
307 NSString* alertTitle = @(title ? title : "");
308
309 NSAlert* alert = [[NSAlert alloc] init];
310 [alert setMessageText:alertTitle];
311 [alert setInformativeText:messageContent];
312
313 EMsgBoxResult result = kCANCEL;
314
315 switch (type)
316 {
317 case kMB_OK:
318 [alert addButtonWithTitle:@"OK"];
319 result = kOK;
320 break;
321 case kMB_OKCANCEL:
322 [alert addButtonWithTitle:@"OK"];
323 [alert addButtonWithTitle:@"Cancel"];
324 result = kCANCEL;
325 break;
326 case kMB_YESNO:
327 [alert addButtonWithTitle:@"Yes"];
328 [alert addButtonWithTitle:@"No"];
329 result = kNO;
330 break;
331 case kMB_RETRYCANCEL:
332 [alert addButtonWithTitle:@"Retry"];
333 [alert addButtonWithTitle:@"Cancel"];
334 result = kCANCEL;
335 break;
336 case kMB_YESNOCANCEL:
337 [alert addButtonWithTitle:@"Yes"];
338 [alert addButtonWithTitle:@"No"];
339 [alert addButtonWithTitle:@"Cancel"];
340 result = kCANCEL;
341 break;
342 }
343
344 NSModalResponse response = [alert runModal];
345
346 switch (type)
347 {
348 case kMB_OK:
349 result = kOK;
350 break;
351 case kMB_OKCANCEL:
352 result = (response == NSAlertFirstButtonReturn) ? kOK : kCANCEL;
353 break;
354 case kMB_YESNO:
355 result = (response == NSAlertFirstButtonReturn) ? kYES : kNO;
356 break;
357 case kMB_RETRYCANCEL:
358 result = (response == NSAlertFirstButtonReturn) ? kRETRY : kCANCEL;
359 break;
360 case kMB_YESNOCANCEL:
361 if (response == NSAlertFirstButtonReturn) result = kYES;
362 else if (response == NSAlertSecondButtonReturn) result = kNO;
363 else result = kCANCEL;
364 break;
365 }
366
367 if (completionHandler)
368 {
369 completionHandler(result);
370 }
371
372 [alert release];
373
374 return result;
375}
376
377void IGraphicsMac::ForceEndUserEdit()
378{
379 if (mView)
380 {
381 [(IGRAPHICS_VIEW*) mView endUserInput];
382 }
383}
384
385void IGraphicsMac::UpdateTooltips()
386{
387 if (!(mView && TooltipsEnabled()))
388 return;
389
390 @autoreleasepool {
391
392 [(IGRAPHICS_VIEW*) mView removeAllToolTips];
393
394 if (GetPopupMenuControl() && GetPopupMenuControl()->GetState() > IPopupMenuControl::kCollapsed)
395 {
396 return;
397 }
398
399 auto func = [this](IControl* pControl)
400 {
401 if (pControl->GetTooltip() && !pControl->IsHidden())
402 {
403 IRECT pR = pControl->GetTargetRECT();
404 if (!pR.Empty())
405 {
406 [(IGRAPHICS_VIEW*) mView registerToolTip: pR];
407 }
408 }
409 };
410
411 ForStandardControlsFunc(func);
412
413 }
414}
415
416const char* IGraphicsMac::GetPlatformAPIStr()
417{
418 return "Cocoa";
419}
420
421bool IGraphicsMac::RevealPathInExplorerOrFinder(WDL_String& path, bool select)
422{
423 BOOL success = FALSE;
424
425 @autoreleasepool {
426
427 if(path.GetLength())
428 {
429 NSString* pPath = [NSString stringWithUTF8String:path.Get()];
430
431 if([[NSFileManager defaultManager] fileExistsAtPath : pPath] == YES)
432 {
433 if (select)
434 {
435 NSString* pParentDirectoryPath = [pPath stringByDeletingLastPathComponent];
436
437 if (pParentDirectoryPath)
438 {
439 success = [[NSWorkspace sharedWorkspace] openFile:pParentDirectoryPath];
440
441 if (success)
442 success = [[NSWorkspace sharedWorkspace] selectFile: pPath inFileViewerRootedAtPath:pParentDirectoryPath];
443 }
444 }
445 else {
446 success = [[NSWorkspace sharedWorkspace] openFile:pPath];
447 }
448
449 }
450 }
451
452 }
453 return (bool) success;
454}
455
456void IGraphicsMac::PromptForFile(WDL_String& fileName, WDL_String& path, EFileAction action, const char* ext, IFileDialogCompletionHandlerFunc completionHandler)
457{
458 if (!WindowIsOpen())
459 {
460 fileName.Set("");
461 return;
462 }
463
464 NSString* pDefaultFileName = nil;
465 NSString* pDefaultPath = nil;
466 NSArray* pFileTypes = nil;
467
468 if (fileName.GetLength())
469 pDefaultFileName = [NSString stringWithUTF8String:fileName.Get()];
470 else
471 pDefaultFileName = @"";
472
473 if (path.GetLength())
474 pDefaultPath = [NSString stringWithUTF8String:path.Get()];
475 else
476 pDefaultPath = @"";
477
478 fileName.Set(""); // reset it
479
480 if (CStringHasContents(ext))
481 pFileTypes = [[NSString stringWithUTF8String:ext] componentsSeparatedByString: @" "];
482
483 auto doHandleResponse = [](NSPanel* pPanel, NSModalResponse response, WDL_String& fileName, WDL_String& path, IFileDialogCompletionHandlerFunc completionHandler){
484 if (response == NSOKButton)
485 {
486 NSString* pFullPath = [(NSSavePanel*) pPanel filename] ;
487 fileName.Set([pFullPath UTF8String]);
488
489 NSString* pTruncatedPath = [pFullPath stringByDeletingLastPathComponent];
490
491 if (pTruncatedPath)
492 {
493 path.Set([pTruncatedPath UTF8String]);
494 path.Append("/");
495 }
496 }
497
498 if (completionHandler)
499 completionHandler(fileName, path);
500 };
501
502 NSPanel* pPanel = nullptr;
503
504 if (action == EFileAction::Save)
505 {
506 pPanel = [NSSavePanel savePanel];
507
508 [(NSSavePanel*) pPanel setAllowedFileTypes: pFileTypes];
509 [(NSSavePanel*) pPanel setDirectoryURL: [NSURL fileURLWithPath: pDefaultPath]];
510 [(NSSavePanel*) pPanel setNameFieldStringValue: pDefaultFileName];
511 [(NSSavePanel*) pPanel setAllowsOtherFileTypes: NO];
512 }
513 else
514 {
515 pPanel = [NSOpenPanel openPanel];
516
517 [(NSOpenPanel*) pPanel setAllowedFileTypes: pFileTypes];
518 [(NSOpenPanel*) pPanel setDirectoryURL: [NSURL fileURLWithPath: pDefaultPath]];
519 [(NSOpenPanel*) pPanel setCanChooseFiles:YES];
520 [(NSOpenPanel*) pPanel setCanChooseDirectories:NO];
521 [(NSOpenPanel*) pPanel setResolvesAliases:YES];
522 }
523 [pPanel setFloatingPanel: YES];
524
525 if (completionHandler)
526 {
527 NSWindow* pWindow = [(IGRAPHICS_VIEW*) mView window];
528
529 [(NSSavePanel*) pPanel beginSheetModalForWindow:pWindow completionHandler:^(NSModalResponse response) {
530 WDL_String fileNameAsync, pathAsync;
531 doHandleResponse(pPanel, response, fileNameAsync, pathAsync, completionHandler);
532 }];
533 }
534 else
535 {
536 NSModalResponse response = [(NSSavePanel*) pPanel runModal];
537 doHandleResponse(pPanel, response, fileName, path, nullptr);
538 }
539}
540
541void IGraphicsMac::PromptForDirectory(WDL_String& dir, IFileDialogCompletionHandlerFunc completionHandler)
542{
543 NSString* defaultPath;
544
545 if (dir.GetLength())
546 {
547 defaultPath = [NSString stringWithUTF8String:dir.Get()];
548 }
549 else
550 {
551 defaultPath = [NSString stringWithUTF8String:DEFAULT_PATH];
552 dir.Set(DEFAULT_PATH);
553 }
554
555 NSOpenPanel* panelOpen = [NSOpenPanel openPanel];
556
557 [panelOpen setTitle:@"Choose a Directory"];
558 [panelOpen setCanChooseFiles:NO];
559 [panelOpen setCanChooseDirectories:YES];
560 [panelOpen setResolvesAliases:YES];
561 [panelOpen setCanCreateDirectories:YES];
562 [panelOpen setFloatingPanel: YES];
563 [panelOpen setDirectoryURL: [NSURL fileURLWithPath: defaultPath]];
564
565 auto doHandleResponse = [](NSOpenPanel* pPanel, NSModalResponse response, WDL_String& pathAsync, IFileDialogCompletionHandlerFunc completionHandler){
566 if (response == NSOKButton)
567 {
568 NSString* fullPath = [pPanel filename] ;
569 pathAsync.Set([fullPath UTF8String]);
570 pathAsync.Append("/");
571 }
572 else
573 {
574 pathAsync.Set("");
575 }
576
577 if (completionHandler)
578 {
579 WDL_String fileNameAsync; // not used
580 completionHandler(fileNameAsync, pathAsync);
581 }
582 };
583
584 if (completionHandler)
585 {
586 NSWindow* pWindow = [(IGRAPHICS_VIEW*) mView window];
587
588 [panelOpen beginSheetModalForWindow:pWindow completionHandler:^(NSModalResponse response) {
589 WDL_String pathAsync;
590 doHandleResponse(panelOpen, response, pathAsync, completionHandler);
591 }];
592 }
593 else
594 {
595 NSModalResponse response = [panelOpen runModal];
596 doHandleResponse(panelOpen, response, dir, nullptr);
597 }
598}
599
600bool IGraphicsMac::PromptForColor(IColor& color, const char* str, IColorPickerHandlerFunc func)
601{
602 if (mView)
603 return [(IGRAPHICS_VIEW*) mView promptForColor:color : func];
604
605 return false;
606}
607
608IPopupMenu* IGraphicsMac::CreatePlatformPopupMenu(IPopupMenu& menu, const IRECT bounds, bool& isAsync)
609{
610 isAsync = true;
611
612 dispatch_async(dispatch_get_main_queue(), ^{
613 IPopupMenu* pReturnMenu = nullptr;
614
615 if (mView)
616 {
617 NSRect areaRect = ToNSRect(this, bounds);
618 pReturnMenu = [(IGRAPHICS_VIEW*) mView createPopupMenu: menu: areaRect];
619 }
620
621 if (pReturnMenu && pReturnMenu->GetFunction())
622 pReturnMenu->ExecFunction();
623
624 this->SetControlValueAfterPopupMenu(pReturnMenu);
625 });
626
627 return nullptr;
628}
629
630void IGraphicsMac::CreatePlatformTextEntry(int paramIdx, const IText& text, const IRECT& bounds, int length, const char* str)
631{
632 if (mView)
633 {
634 NSRect areaRect = ToNSRect(this, bounds);
635 [(IGRAPHICS_VIEW*) mView createTextEntry: paramIdx : text: str: length: areaRect];
636 }
637}
638
639ECursor IGraphicsMac::SetMouseCursor(ECursor cursorType)
640{
641 if (mView)
642 [(IGRAPHICS_VIEW*) mView setMouseCursor: cursorType];
643
644 return IGraphics::SetMouseCursor(cursorType);
645}
646
647bool IGraphicsMac::OpenURL(const char* url, const char* msgWindowTitle, const char* confirmMsg, const char* errMsgOnFailure)
648{
649 #pragma REMINDER("Warning and error messages for OpenURL not implemented")
650 NSURL* pNSURL = nullptr;
651 if (strstr(url, "http"))
652 pNSURL = [NSURL URLWithString:[NSString stringWithUTF8String:url]];
653 else
654 pNSURL = [NSURL fileURLWithPath:[NSString stringWithUTF8String:url]];
655
656 if (pNSURL)
657 {
658 bool ok = ([[NSWorkspace sharedWorkspace] openURL:pNSURL]);
659 return ok;
660 }
661 return true;
662}
663
664void* IGraphicsMac::GetWindow()
665{
666 if (mView) return mView;
667 else return 0;
668}
669
670// static
671int IGraphicsMac::GetUserOSVersion() // Returns a number like 0x1050 (10.5).
672{
673 return (int) GetSystemVersion();
674}
675
676bool IGraphicsMac::GetTextFromClipboard(WDL_String& str)
677{
678 NSString* pTextOnClipboard = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
679
680 if (pTextOnClipboard == nil)
681 {
682 str.Set("");
683 return false;
684 }
685 else
686 {
687 str.Set([pTextOnClipboard UTF8String]);
688 return true;
689 }
690}
691
692bool IGraphicsMac::SetTextInClipboard(const char* str)
693{
694 NSString* pTextForClipboard = [NSString stringWithUTF8String:str];
695 [[NSPasteboard generalPasteboard] clearContents];
696 return [[NSPasteboard generalPasteboard] setString:pTextForClipboard forType:NSStringPboardType];
697}
698
699bool IGraphicsMac::SetFilePathInClipboard(const char* path)
700{
701 NSPasteboard* pPasteboard = [NSPasteboard generalPasteboard];
702 [pPasteboard clearContents]; // clear pasteboard to take ownership
703 NSURL* pFileURL = [NSURL fileURLWithPath: [NSString stringWithUTF8String:path]];
704 BOOL success = [pPasteboard writeObjects: [NSArray arrayWithObject:pFileURL]];
705 return (bool)success;
706}
707
708bool IGraphicsMac::InitiateExternalFileDragDrop(const char* path, const IRECT& iconBounds)
709{
710 NSPasteboardItem* pasteboardItem = [[NSPasteboardItem alloc] init];
711 NSURL* fileURL = [NSURL fileURLWithPath: [NSString stringWithUTF8String:path]];
712 [pasteboardItem setString:fileURL.absoluteString forType:NSPasteboardTypeFileURL];
713
714 NSDraggingItem* draggingItem = [[NSDraggingItem alloc] initWithPasteboardWriter:pasteboardItem];
715 NSRect draggingFrame = ToNSRect(this, iconBounds);
716 NSImage* iconImage = [[NSWorkspace sharedWorkspace] iconForFile:fileURL.path];
717 [iconImage setSize:NSMakeSize(64, 64)];
718 [draggingItem setDraggingFrame:draggingFrame contents: iconImage];
719
720 IGRAPHICS_VIEW* view = (IGRAPHICS_VIEW*) mView;
721 NSDraggingSession* draggingSession = [view beginDraggingSessionWithItems:@[draggingItem] event:[NSApp currentEvent] source: view];
722 draggingSession.animatesToStartingPositionsOnCancelOrFail = YES;
723 draggingSession.draggingFormation = NSDraggingFormationNone;
724
725 ReleaseMouseCapture();
726
727 return true;
728}
729
730EUIAppearance IGraphicsMac::GetUIAppearance() const
731{
732 if (@available(macOS 10.14, *)) {
733 if(mView)
734 {
735 IGRAPHICS_VIEW* pView = (IGRAPHICS_VIEW*) mView;
736 BOOL isDarkMode = [[[pView effectiveAppearance] name] isEqualToString: (NSAppearanceNameDarkAqua)];
737 return isDarkMode ? EUIAppearance::Dark : EUIAppearance::Light;
738 }
739 }
740
741 return EUIAppearance::Light;
742}
743
744void IGraphicsMac::ActivateGLContext()
745{
746 IGRAPHICS_VIEW* pView = (IGRAPHICS_VIEW*) mView;
747 [pView activateGLContext];
748}
749
750void IGraphicsMac::DeactivateGLContext()
751{
752 IGRAPHICS_VIEW* pView = (IGRAPHICS_VIEW*) mView;
753 [pView deactivateGLContext];
754}
755
756#if defined IGRAPHICS_NANOVG
757 #include "IGraphicsNanoVG.cpp"
758#elif defined IGRAPHICS_SKIA
759 #include "IGraphicsSkia.cpp"
760#else
761 #error Either NO_IGRAPHICS or one and only one choice of graphics library must be defined!
762#endif
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics control.
Definition: IControl.h:49
An editor delegate base class that uses IGraphics for the UI.
virtual ECursor SetMouseCursor(ECursor cursorType=ECursor::ARROW)
Sets the mouse cursor to one of ECursor (implementations should return the result of the base impleme...
Definition: IGraphics.h:829
A class for setting the contents of a pop up menu.
Used to manage color data, independent of draw class/platform.
Used to manage a rectangular area, independent of draw class/platform.
bool Empty() const
IText is used to manage font and text/text entry style for a piece of text on the UI,...