iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IGraphicsMac_view.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#import <QuartzCore/QuartzCore.h>
12
13#if defined IGRAPHICS_METAL
14#import <Metal/Metal.h>
15#endif
16
17#include "wdlutf8.h"
18
19#import "IGraphicsMac_view.h"
20#include "IControl.h"
21#include "IPlugParameter.h"
22#include "IPlugLogger.h"
23
24using namespace iplug;
25using namespace igraphics;
26
27static int MacKeyCodeToVK(int code)
28{
29 switch (code)
30 {
31 case 51: return kVK_BACK;
32 case 65: return kVK_DECIMAL;
33 case 67: return kVK_MULTIPLY;
34 case 69: return kVK_ADD;
35 case 71: return kVK_NUMLOCK;
36 case 75: return kVK_DIVIDE;
37 case 76: return kVK_RETURN | 0x8000;
38 case 78: return kVK_SUBTRACT;
39 case 81: return kVK_SEPARATOR;
40 case 82: return kVK_NUMPAD0;
41 case 83: return kVK_NUMPAD1;
42 case 84: return kVK_NUMPAD2;
43 case 85: return kVK_NUMPAD3;
44 case 86: return kVK_NUMPAD4;
45 case 87: return kVK_NUMPAD5;
46 case 88: return kVK_NUMPAD6;
47 case 89: return kVK_NUMPAD7;
48 case 91: return kVK_NUMPAD8;
49 case 92: return kVK_NUMPAD9;
50 case 96: return kVK_F5;
51 case 97: return kVK_F6;
52 case 98: return kVK_F7;
53 case 99: return kVK_F3;
54 case 100: return kVK_F8;
55 case 101: return kVK_F9;
56 case 109: return kVK_F10;
57 case 103: return kVK_F11;
58 case 111: return kVK_F12;
59 case 114: return kVK_INSERT;
60 case 115: return kVK_HOME;
61 case 117: return kVK_DELETE;
62 case 116: return kVK_PRIOR;
63 case 118: return kVK_F4;
64 case 119: return kVK_END;
65 case 120: return kVK_F2;
66 case 121: return kVK_NEXT;
67 case 122: return kVK_F1;
68 case 123: return kVK_LEFT;
69 case 124: return kVK_RIGHT;
70 case 125: return kVK_DOWN;
71 case 126: return kVK_UP;
72 case 0x69: return kVK_F13;
73 case 0x6B: return kVK_F14;
74 case 0x71: return kVK_F15;
75 case 0x6A: return kVK_F16;
76 }
77 return kVK_NONE;
78}
79
80static int MacKeyEventToVK(NSEvent* pEvent, int& flag)
81{
82 int code = kVK_NONE;
83
84 const NSInteger mod = [pEvent modifierFlags];
85
86 if (mod & NSShiftKeyMask) flag |= kFSHIFT;
87 if (mod & NSCommandKeyMask) flag |= kFCONTROL;
88 if (mod & NSAlternateKeyMask) flag |= kFALT;
89 if ((mod & NSControlKeyMask) /*&& !IsRightClickEmulateEnabled()*/) flag |= kFLWIN;
90
91 int rawcode = [pEvent keyCode];
92
93 code = MacKeyCodeToVK(rawcode);
94 if (code == kVK_NONE)
95 {
96 NSString *str = NULL;
97
98 if (!str || ![str length]) str = [pEvent charactersIgnoringModifiers];
99
100 if (!str || ![str length])
101 {
102 if (!code)
103 {
104 code = 1024 + rawcode; // raw code
105 flag |= kFVIRTKEY;
106 }
107 }
108 else
109 {
110 code = [str characterAtIndex:0];
111 if (code >= NSF1FunctionKey && code <= NSF24FunctionKey)
112 {
113 flag |= kFVIRTKEY;
114 code += kVK_F1 - NSF1FunctionKey;
115 }
116 else
117 {
118 if (code >= 'a' && code <= 'z') code += 'A'-'a';
119 if (code == 25 && (flag & FSHIFT)) code = kVK_TAB;
120 if (isalnum(code) || code==' ' || code == '\r' || code == '\n' || code ==27 || code == kVK_TAB) flag |= kFVIRTKEY;
121 }
122 }
123 }
124 else
125 {
126 flag |= kFVIRTKEY;
127 if (code == 8) code = '\b';
128 }
129
130 if (!(flag & kFVIRTKEY)) flag &= ~kFSHIFT;
131
132 return code;
133}
134
135#ifndef IGRAPHICS_MENU_RCVR
136#warning The iPlug2 Obj-C namespace is not customized. Did you forget to include IPlugOBJCPrefix.pch?
137#endif
138
139@implementation IGRAPHICS_MENU_RCVR
140
141- (NSMenuItem*) menuItem
142{
143 return nsMenuItem;
144}
145
146- (void) onMenuSelection:(id) sender
147{
148 nsMenuItem = sender;
149}
150
151@end
152
153@implementation IGRAPHICS_MENU
154
155- (id) initWithIPopupMenuAndReceiver: (IPopupMenu*) pMenu : (NSView*) pView
156{
157 [self initWithTitle: @""];
158
159 NSMenuItem* nsMenuItem = nil;
160 NSMutableString* nsMenuItemTitle = nil;
161
162 [self setAutoenablesItems:NO];
163
164 int numItems = pMenu->NItems();
165
166 for (int i = 0; i < numItems; ++i)
167 {
168 IPopupMenu::Item* pMenuItem = pMenu->GetItem(i);
169
170 nsMenuItemTitle = [[[NSMutableString alloc] initWithUTF8String:pMenuItem->GetText()] autorelease];
171
172 if (pMenu->GetPrefix())
173 {
174 NSString* prefixString = 0;
175
176 switch (pMenu->GetPrefix())
177 {
178 case 0: prefixString = [NSString stringWithUTF8String:""]; break;
179 case 1: prefixString = [NSString stringWithFormat:@"%1d: ", i+1]; break;
180 case 2: prefixString = [NSString stringWithFormat:@"%02d: ", i+1]; break;
181 case 3: prefixString = [NSString stringWithFormat:@"%03d: ", i+1]; break;
182 }
183
184 [nsMenuItemTitle insertString:prefixString atIndex:0];
185 }
186
187 if (pMenuItem->GetIsSeparator())
188 {
189 [self addItem:[NSMenuItem separatorItem]];
190 }
191 else if (pMenuItem->GetSubmenu())
192 {
193 nsMenuItem = [self addItemWithTitle:nsMenuItemTitle action:nil keyEquivalent:@""];
194 NSMenu* subMenu = [[IGRAPHICS_MENU alloc] initWithIPopupMenuAndReceiver:pMenuItem->GetSubmenu() :pView];
195 [self setSubmenu: subMenu forItem:nsMenuItem];
196 [subMenu release];
197 }
198 else
199 {
200 nsMenuItem = [self addItemWithTitle:nsMenuItemTitle action:@selector(onMenuSelection:) keyEquivalent:@""];
201
202 [nsMenuItem setTarget:pView];
203 }
204
205 if (nsMenuItem && !pMenuItem->GetIsSeparator())
206 {
207 [nsMenuItem setIndentationLevel:pMenuItem->GetIsTitle() ? 1 : 0 ];
208 [nsMenuItem setEnabled:pMenuItem->GetEnabled() ? YES : NO];
209 [nsMenuItem setState:pMenuItem->GetChecked() ? NSOnState : NSOffState];
210 }
211 }
212
213 mIPopupMenu = pMenu;
214
215 return self;
216}
217
218- (IPopupMenu*) iPopupMenu
219{
220 return mIPopupMenu;
221}
222
223@end
224
225@implementation IGRAPHICS_TEXTFIELD
226
227- (bool) becomeFirstResponder;
228{
229 bool success = [super becomeFirstResponder];
230 if (success)
231 {
232 NSTextView *textField = (NSTextView*) [self currentEditor];
233 if( [textField respondsToSelector: @selector(setInsertionPointColor:)] )
234 [textField setInsertionPointColor: [self textColor]];
235 }
236 return success;
237}
238
239@end
240
241// IGRAPHICS_TEXTFIELDCELL based on...
242
243// https://red-sweater.com/blog/148/what-a-difference-a-cell-makes
244
245// This source code is provided to you compliments of Red Sweater Software under the license as described below. NOTE: This is the MIT License.
246//
247// Copyright (c) 2006 Red Sweater Software
248//
249// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
250//
251// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
252//
253// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
254
255@implementation IGRAPHICS_TEXTFIELDCELL
256
257- (NSRect) drawingRectForBounds: (NSRect) inRect
258{
259 // Get the parent's idea of where we should draw
260 NSRect outRect = [super drawingRectForBounds:inRect];
261
262 // When the text field is being
263 // edited or selected, we have to turn off the magic because it screws up
264 // the configuration of the field editor. We sneak around this by
265 // intercepting selectWithFrame and editWithFrame and sneaking a
266 // reduced, centered rect in at the last minute.
267 if (mIsEditingOrSelecting == NO)
268 {
269 // Get our ideal size for current text
270 NSSize textSize = [self cellSize];
271
272 // Center that in the proposed rect
273 float heightDelta = outRect.size.height - textSize.height;
274
275 outRect.size.height -= heightDelta;
276 outRect.origin.y += (heightDelta / 2);
277 }
278
279 return outRect;
280}
281
282- (void) selectWithFrame: (NSRect) aRect inView: (NSView*) controlView editor: (NSText*) textObj delegate: (id) anObject start: (NSInteger) selStart length: (NSInteger) selLength
283{
284 aRect = [self drawingRectForBounds:aRect];
285 mIsEditingOrSelecting = YES;
286 [super selectWithFrame:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
287 mIsEditingOrSelecting = NO;
288}
289
290- (void) editWithFrame: (NSRect) aRect inView: (NSView*) controlView editor: (NSText*) textObj delegate: (id) anObject event: (NSEvent*) theEvent
291{
292 aRect = [self drawingRectForBounds:aRect];
293 mIsEditingOrSelecting = YES;
294 [super editWithFrame:aRect inView:controlView editor:textObj delegate:anObject event:theEvent];
295 mIsEditingOrSelecting = NO;
296}
297@end
298
299
300@implementation IGRAPHICS_FORMATTER
301
302- (void) dealloc
303{
304 [filterCharacterSet release];
305 [super dealloc];
306}
307
308- (BOOL) isPartialStringValid:(NSString*) partialString newEditingString:(NSString**) newString errorDescription:(NSString**) error
309{
310 if (filterCharacterSet != nil)
311 {
312 int i = 0;
313 int len = (int) [partialString length];
314
315 for (i = 0; i < len; i++)
316 {
317 if (![filterCharacterSet characterIsMember:[partialString characterAtIndex:i]])
318 {
319 return NO;
320 }
321 }
322 }
323
324 if (maxLength)
325 {
326 if ([partialString length] > maxLength)
327 {
328 return NO;
329 }
330 }
331
332 if (maxValue && [partialString intValue] > maxValue)
333 {
334 return NO;
335 }
336
337 return YES;
338}
339
340- (void) setAcceptableCharacterSet: (NSCharacterSet*) inCharacterSet
341{
342 [inCharacterSet retain];
343 [filterCharacterSet release];
344 filterCharacterSet = inCharacterSet;
345}
346
347- (void) setMaximumLength: (int) inLength
348{
349 maxLength = inLength;
350}
351
352- (void) setMaximumValue: (int) inValue
353{
354 maxValue = inValue;
355}
356
357- (NSString*) stringForObjectValue: (id) anObject
358{
359 if ([anObject isKindOfClass:[NSString class]])
360 {
361 return anObject;
362 }
363
364 return nil;
365}
366
367- (BOOL) getObjectValue: (id*) anObject forString:(NSString*) string errorDescription: (NSString **) error
368{
369 if (anObject && string)
370 {
371 *anObject = [NSString stringWithString:string];
372 }
373
374 return YES;
375}
376@end
377
378#pragma mark -
379
380extern StaticStorage<CoreTextFontDescriptor> sFontDescriptorCache;
381
382@implementation IGRAPHICS_VIEW
383
384- (id) initWithIGraphics: (IGraphicsMac*) pGraphics
385{
386 TRACE
387
388 mGraphics = pGraphics;
389 NSRect r = NSMakeRect(0.f, 0.f, (float) pGraphics->WindowWidth(), (float) pGraphics->WindowHeight());
390 self = [super initWithFrame:r];
391
392 mMouseOutDuringDrag = false;
393
394 self.wantsLayer = YES;
395 self.layer.opaque = YES;
396 self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize;
397
398 [self registerForDraggedTypes:[NSArray arrayWithObjects: NSFilenamesPboardType, nil]];
399
400 #if defined IGRAPHICS_METAL
401 self.layer = [CAMetalLayer new];
402 [(CAMetalLayer*)[self layer] setPixelFormat:MTLPixelFormatBGRA8Unorm];
403 ((CAMetalLayer*) self.layer).device = MTLCreateSystemDefaultDevice();
404
405 #elif defined IGRAPHICS_GL
406 NSOpenGLPixelFormatAttribute profile = NSOpenGLProfileVersionLegacy;
407 #if defined IGRAPHICS_GL3
408 profile = (NSOpenGLPixelFormatAttribute)NSOpenGLProfileVersion3_2Core;
409 #endif
410 const NSOpenGLPixelFormatAttribute attrs[] = {
411 NSOpenGLPFAAccelerated,
412 NSOpenGLPFANoRecovery,
413 NSOpenGLPFADoubleBuffer,
414 NSOpenGLPFAAlphaSize, 8,
415 NSOpenGLPFAColorSize, 24,
416 NSOpenGLPFADepthSize, 0,
417 NSOpenGLPFAStencilSize, 8,
418 NSOpenGLPFAOpenGLProfile, profile,
419 (NSOpenGLPixelFormatAttribute) 0
420 };
421 NSOpenGLPixelFormat* pPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
422 NSOpenGLContext* pGLContext = [[NSOpenGLContext alloc] initWithFormat:pPixelFormat shareContext:nil];
423
424 #ifdef DEBUG
425 // CGLEnable([context CGLContextObj], kCGLCECrashOnRemovedFunctions); //SKIA_GL2 will crash
426 #endif
427
428 self.pixelFormat = pPixelFormat;
429 self.openGLContext = pGLContext;
430 self.wantsBestResolutionOpenGLSurface = YES;
431 #endif // IGRAPHICS_GL
432
433 #if !defined IGRAPHICS_GL
434 [self setTimer];
435 #endif
436
437 return self;
438}
439
440#ifdef IGRAPHICS_GL
441- (void) prepareOpenGL
442{
443 [super prepareOpenGL];
444
445 [[self openGLContext] makeCurrentContext];
446
447 // Synchronize buffer swaps with vertical refresh rate
448 GLint swapInt = 1;
449 [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
450
451 [self setTimer];
452}
453#endif
454
455static CVReturn displayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext)
456{
457 dispatch_source_t source = (dispatch_source_t) displayLinkContext;
458 dispatch_source_merge_data(source, 1);
459
460 return kCVReturnSuccess;
461}
462
463- (void) onTimer: (NSTimer*) pTimer
464{
465 [self render];
466}
467
468- (void) setTimer
469{
470#ifdef IGRAPHICS_CVDISPLAYLINK
471 mDisplaySource = dispatch_source_create(DISPATCH_SOURCE_TYPE_DATA_ADD, 0, 0, dispatch_get_main_queue());
472 dispatch_source_set_event_handler(mDisplaySource, ^(){
473 [self render];
474 });
475 dispatch_resume(mDisplaySource);
476
477 CVReturn cvReturn;
478
479 cvReturn = CVDisplayLinkCreateWithActiveCGDisplays(&mDisplayLink);
480
481 assert(cvReturn == kCVReturnSuccess);
482
483 cvReturn = CVDisplayLinkSetOutputCallback(mDisplayLink, &displayLinkCallback, (void*) mDisplaySource);
484 assert(cvReturn == kCVReturnSuccess);
485
486 #ifdef IGRAPHICS_GL
487 CGLContextObj cglContext = [[self openGLContext] CGLContextObj];
488 CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
489 CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(mDisplayLink, cglContext, cglPixelFormat);
490 #endif
491
492 CGDirectDisplayID viewDisplayID =
493 (CGDirectDisplayID) [self.window.screen.deviceDescription[@"NSScreenNumber"] unsignedIntegerValue];;
494
495 cvReturn = CVDisplayLinkSetCurrentCGDisplay(mDisplayLink, viewDisplayID);
496
497 assert(cvReturn == kCVReturnSuccess);
498
499 CVDisplayLinkStart(mDisplayLink);
500#else
501 double sec = 1.0 / (double) mGraphics->FPS();
502 mTimer = [NSTimer timerWithTimeInterval:sec target:self selector:@selector(onTimer:) userInfo:nil repeats:YES];
503 [[NSRunLoop currentRunLoop] addTimer: mTimer forMode: (NSString*) kCFRunLoopCommonModes];
504#endif
505}
506
507- (void) killTimer
508{
509#ifdef IGRAPHICS_CVDISPLAYLINK
510 CVDisplayLinkStop(mDisplayLink);
511 dispatch_source_cancel(mDisplaySource);
512 CVDisplayLinkRelease(mDisplayLink);
513 mDisplayLink = nil;
514#else
515 [mTimer invalidate];
516 mTimer = nullptr;
517#endif
518}
519
520- (void) dealloc
521{
522 if([NSColorPanel sharedColorPanelExists])
523 [[NSColorPanel sharedColorPanel] close];
524
525 mColorPickerFunc = nullptr;
526 [mMoveCursor release];
527 [mTrackingArea release];
528 [[NSNotificationCenter defaultCenter] removeObserver:self];
529 [super dealloc];
530}
531
532
533- (BOOL) isOpaque
534{
535 return mGraphics ? YES : NO;
536}
537
538- (BOOL) isFlipped
539{
540 return YES;
541}
542
543- (void) viewDidChangeEffectiveAppearance
544{
545 if (@available(macOS 10.14, *)) {
546 BOOL isDarkMode = [[[self effectiveAppearance] name] isEqualToString: (NSAppearanceNameDarkAqua)];
547 mGraphics->OnAppearanceChanged(isDarkMode ? EUIAppearance::Dark : EUIAppearance::Light);
548 }
549}
550
551- (BOOL) acceptsFirstResponder
552{
553 return YES;
554}
555
556- (BOOL) acceptsFirstMouse: (NSEvent*) pEvent
557{
558 return YES;
559}
560
561- (void) viewDidMoveToWindow
562{
563 NSWindow* pWindow = [self window];
564
565 if (pWindow)
566 {
567 [pWindow makeFirstResponder: self];
568 [pWindow setAcceptsMouseMovedEvents: YES];
569
570 CGFloat newScale = [pWindow backingScaleFactor];
571
572 if (mGraphics)
573 mGraphics->SetScreenScale(newScale);
574
575 #ifdef IGRAPHICS_METAL
576 [[NSNotificationCenter defaultCenter] addObserver:self
577 selector:@selector(frameDidChange:)
578 name:NSViewFrameDidChangeNotification
579 object:self];
580 #endif
581 #ifdef IGRAPHICS_GL
582 [[NSNotificationCenter defaultCenter] addObserver:self
583 selector:@selector(frameDidChange:)
584 name:NSViewGlobalFrameDidChangeNotification
585 object:self];
586 #endif
587
588// [[NSNotificationCenter defaultCenter] addObserver:self
589// selector:@selector(windowResized:) name:NSWindowDidEndLiveResizeNotification
590// object:pWindow];
591//
592// [[NSNotificationCenter defaultCenter] addObserver:self
593// selector:@selector(windowFullscreened:) name:NSWindowDidEnterFullScreenNotification
594// object:pWindow];
595//
596// [[NSNotificationCenter defaultCenter] addObserver:self
597// selector:@selector(windowFullscreened:) name:NSWindowDidExitFullScreenNotification
598// object:pWindow];
599 }
600}
601
602- (void) viewDidChangeBackingProperties:(NSNotification*) pNotification
603{
604 NSWindow* pWindow = [self window];
605
606 if (!pWindow)
607 return;
608
609 CGFloat newScale = [pWindow backingScaleFactor];
610
611 mGraphics->SetPlatformContext(nullptr);
612
613 if (newScale != mGraphics->GetScreenScale())
614 mGraphics->SetScreenScale(newScale);
615
616#if defined IGRAPHICS_GL
617 self.layer.contentsScale = 1./newScale;
618#elif defined IGRAPHICS_METAL
619 [(CAMetalLayer*)[self layer] setDrawableSize:CGSizeMake(self.frame.size.width * newScale,
620 self.frame.size.height * newScale)];
621#endif
622}
623
624- (CGContextRef) getCGContextRef
625{
626 CGContextRef pCGC = [NSGraphicsContext currentContext].CGContext;
627 return [NSGraphicsContext graphicsContextWithCGContext: pCGC flipped: YES].CGContext;
628}
629
630// not called for layer backed views
631- (void) drawRect: (NSRect) bounds
632{
633 #if !defined IGRAPHICS_GL && !defined IGRAPHICS_METAL
634 if (mGraphics)
635 {
636 mGraphics->SetPlatformContext([self getCGContextRef]);
637
638 if (mGraphics->GetPlatformContext())
639 {
640 const NSRect *rects;
641 NSInteger numRects;
642 [self getRectsBeingDrawn:&rects count:&numRects];
643 IRECTList drawRects;
644
645 for (int i = 0; i < numRects; i++)
646 drawRects.Add(ToIRECT(mGraphics, &rects[i]));
647
648 mGraphics->Draw(drawRects);
649 }
650 }
651 #else // this gets called on resize
652 //TODO: set GL context/flush?
653 //mGraphics->Draw(mDirtyRects);
654 #endif
655}
656
657- (void) render
658{
659 mDirtyRects.Clear();
660
661 if (mGraphics->IsDirty(mDirtyRects))
662 {
663 mGraphics->SetAllControlsClean();
664
665 #if !defined IGRAPHICS_GL && !defined IGRAPHICS_METAL // for layer-backed views setNeedsDisplayInRect/drawRect is not called
666 for (int i = 0; i < mDirtyRects.Size(); i++)
667 [self setNeedsDisplayInRect:ToNSRect(mGraphics, mDirtyRects.Get(i))];
668 #else
669 #ifdef IGRAPHICS_GL
670 [[self openGLContext] makeCurrentContext];
671 #endif
672 // so just draw on each frame, if something is dirty
673 mGraphics->Draw(mDirtyRects);
674 #endif
675 #ifdef IGRAPHICS_GL
676 [[self openGLContext] flushBuffer];
677 [NSOpenGLContext clearCurrentContext];
678 #endif
679 }
680}
681
682- (void) getMouseXY: (NSEvent*) pEvent : (float&) x : (float&) y
683{
684 if (mGraphics)
685 {
686 NSPoint pt = [self convertPoint:[pEvent locationInWindow] fromView:nil];
687 x = pt.x / mGraphics->GetDrawScale();
688 y = pt.y / mGraphics->GetDrawScale();
689
690 mGraphics->DoCursorLock(x, y, mPrevX, mPrevY);
691 mGraphics->SetTabletInput(pEvent.subtype == NSTabletPointEventSubtype);
692 }
693}
694
695- (IMouseInfo) getMouseLeft: (NSEvent*) pEvent
696{
697 IMouseInfo info;
698 [self getMouseXY:pEvent : info.x : info.y];
699 int mods = (int) [pEvent modifierFlags];
700 info.ms = IMouseMod(true, (mods & NSCommandKeyMask), (mods & NSShiftKeyMask), (mods & NSControlKeyMask), (mods & NSAlternateKeyMask));
701
702 return info;
703}
704
705- (IMouseInfo) getMouseRight: (NSEvent*) pEvent
706{
707 IMouseInfo info;
708 [self getMouseXY:pEvent : info.x : info.y];
709 int mods = (int) [pEvent modifierFlags];
710 info.ms = IMouseMod(false, true, (mods & NSShiftKeyMask), (mods & NSControlKeyMask), (mods & NSAlternateKeyMask));
711
712 return info;
713}
714
715- (void) updateTrackingAreas
716{
717 [super updateTrackingAreas]; // This is needed to get mouseEntered and mouseExited
718
719 if (mTrackingArea != nil)
720 {
721 [self removeTrackingArea:mTrackingArea];
722 [mTrackingArea release];
723 }
724
725 int opts = (NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingEnabledDuringMouseDrag);
726 mTrackingArea = [ [NSTrackingArea alloc] initWithRect:[self bounds] options:opts owner:self userInfo:nil];
727 [self addTrackingArea:mTrackingArea];
728}
729
730- (void) mouseEntered: (NSEvent*) pEvent
731{
732 mMouseOutDuringDrag = false;
733
734 if (mGraphics)
735 {
736 mGraphics->OnSetCursor();
737 }
738}
739
740- (void) mouseExited: (NSEvent*) pEvent
741{
742 if (mGraphics)
743 {
744 if (!mGraphics->ControlIsCaptured())
745 {
746 mGraphics->OnMouseOut();
747 }
748 else
749 {
750 mMouseOutDuringDrag = true;
751 }
752 }
753}
754
755- (void) mouseDown: (NSEvent*) pEvent
756{
757 IMouseInfo info = [self getMouseLeft:pEvent];
758 if (mGraphics)
759 {
760 if (([pEvent clickCount] - 1) % 2)
761 {
762 mGraphics->OnMouseDblClick(info.x, info.y, info.ms);
763 }
764 else
765 {
766 std::vector<IMouseInfo> list {info};
767 mGraphics->OnMouseDown(list);
768 }
769 }
770}
771
772- (void) mouseUp: (NSEvent*) pEvent
773{
774 IMouseInfo info = [self getMouseLeft:pEvent];
775 if (mGraphics)
776 {
777 std::vector<IMouseInfo> list {info};
778 mGraphics->OnMouseUp(list);
779
780 if (mMouseOutDuringDrag)
781 {
782 mGraphics->OnMouseOut();
783 mMouseOutDuringDrag = false;
784 }
785 }
786}
787
788- (void) mouseDragged: (NSEvent*) pEvent
789{
790 // Cache previous values before retrieving the new mouse position (which will update them)
791 float prevX = mPrevX;
792 float prevY = mPrevY;
793 IMouseInfo info = [self getMouseLeft:pEvent];
794 if (mGraphics && !mGraphics->IsInPlatformTextEntry())
795 {
796 info.dX = info.x - prevX;
797 info.dY = info.y - prevY;
798 std::vector<IMouseInfo> list {info};
799 mGraphics->OnMouseDrag(list);
800 }
801}
802
803- (void) rightMouseDown: (NSEvent*) pEvent
804{
805 IMouseInfo info = [self getMouseRight:pEvent];
806 if (mGraphics)
807 {
808 if (([pEvent clickCount] - 1) % 2)
809 {
810 mGraphics->OnMouseDblClick(info.x, info.y, info.ms);
811 }
812 else
813 {
814 std::vector<IMouseInfo> list {info};
815 mGraphics->OnMouseDown(list);
816 }
817 }
818}
819
820- (void) rightMouseUp: (NSEvent*) pEvent
821{
822 IMouseInfo info = [self getMouseRight:pEvent];
823 if (mGraphics)
824 {
825 std::vector<IMouseInfo> list {info};
826 mGraphics->OnMouseUp(list);
827 }
828}
829
830- (void) rightMouseDragged: (NSEvent*) pEvent
831{
832 // Cache previous values before retrieving the new mouse position (which will update them)
833 float prevX = mPrevX;
834 float prevY = mPrevY;
835 IMouseInfo info = [self getMouseRight:pEvent];
836
837 if (mGraphics && !mTextFieldView)
838 {
839 info.dX = info.x - prevX;
840 info.dY = info.y - prevY;
841 std::vector<IMouseInfo> list {info};
842 mGraphics->OnMouseDrag(list);
843 }
844}
845
846- (void) mouseMoved: (NSEvent*) pEvent
847{
848 IMouseInfo info = [self getMouseLeft:pEvent];
849 if (mGraphics)
850 mGraphics->OnMouseOver(info.x, info.y, info.ms);
851}
852
853- (void) keyDown: (NSEvent*) pEvent
854{
855 int flag = 0;
856 int code = MacKeyEventToVK(pEvent, flag);
857 NSString *s = [pEvent charactersIgnoringModifiers];
858
859 unichar c = 0;
860
861 if ([s length] == 1)
862 c = [s characterAtIndex:0];
863
864 if(!static_cast<bool>(flag & kFVIRTKEY))
865 {
866 code = kVK_NONE;
867 }
868
869 char utf8[5];
870 WDL_MakeUTFChar(utf8, c, 4);
871
872 IKeyPress keyPress {utf8, code, static_cast<bool>(flag & kFSHIFT),
873 static_cast<bool>(flag & kFCONTROL),
874 static_cast<bool>(flag & kFALT)};
875
876 bool handle = mGraphics->OnKeyDown(mPrevX, mPrevY, keyPress);
877
878 if (!handle)
879 {
880 [[self nextResponder] keyDown:pEvent];
881 }
882}
883
884- (void) keyUp: (NSEvent*) pEvent
885{
886 int flag = 0;
887 int code = MacKeyEventToVK(pEvent, flag);
888 NSString *s = [pEvent charactersIgnoringModifiers];
889
890 unichar c = 0;
891
892 if ([s length] == 1)
893 c = [s characterAtIndex:0];
894
895 if(!static_cast<bool>(flag & kFVIRTKEY))
896 {
897 code = kVK_NONE;
898 }
899
900 char utf8[5];
901 WDL_MakeUTFChar(utf8, c, 4);
902
903 IKeyPress keyPress {utf8, code, static_cast<bool>(flag & kFSHIFT),
904 static_cast<bool>(flag & kFCONTROL),
905 static_cast<bool>(flag & kFALT)};
906
907 bool handle = mGraphics->OnKeyUp(mPrevX, mPrevY, keyPress);
908
909 if (!handle)
910 {
911 [[self nextResponder] keyUp:pEvent];
912 }
913}
914
915- (void) scrollWheel: (NSEvent*) pEvent
916{
917 if (mTextFieldView) [self endUserInput ];
918 IMouseInfo info = [self getMouseLeft:pEvent];
919 float d = [pEvent deltaY];
920 if (mGraphics)
921 mGraphics->OnMouseWheel(info.x, info.y, info.ms, d);
922}
923
924static void MakeCursorFromName(NSCursor*& cursor, const char *name)
925{
926 // get paths and intialise images etc.
927 const char* basePath = "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/Resources/cursors/";
928
929 NSString* imagePath = [NSString stringWithFormat:@"%s%s/cursor.pdf", basePath, name];
930 NSString* infoPath = [NSString stringWithFormat:@"file:%s%s/info.plist", basePath, name];
931 NSImage* fileImage = [[NSImage alloc] initByReferencingFile: imagePath];
932 NSImage *cursorImage = [[NSImage alloc] initWithSize:[fileImage size]];
933 NSDictionary* info = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:infoPath]];
934
935 // get info from dictionary
936 double hotX = [info[@"hotx-scaled"] doubleValue];
937 double hotY = [info[@"hoty-scaled"] doubleValue];
938 double blur = [info[@"blur"] doubleValue];
939 double offsetX = [info[@"shadowoffsetx"] doubleValue];
940 double offsetY = [info[@"shadowoffsety"] doubleValue];
941 double red = [info[@"shadowcolor"][0] doubleValue];
942 double green = [info[@"shadowcolor"][1] doubleValue];
943 double blue = [info[@"shadowcolor"][2] doubleValue];
944 double alpha = [info[@"shadowcolor"][3] doubleValue];
945 CGColorRef shadowColor = CGColorCreateGenericRGB(red, green, blue, alpha);
946
947 for (int scale = 1; scale <= 4; scale++)
948 {
949 // scale
950 NSAffineTransform* xform = [NSAffineTransform transform];
951 [xform scaleBy:scale];
952 id hints = @{ NSImageHintCTM: xform };
953 CGImageRef rasterCGImage = [fileImage CGImageForProposedRect:NULL context:nil hints:hints];
954
955 // apply shadow
956 size_t width = CGImageGetWidth(rasterCGImage);
957 size_t height = CGImageGetHeight(rasterCGImage);
958 CGSize offset = CGSize { static_cast<CGFloat>(offsetX * scale), static_cast<CGFloat>(offsetY * scale) };
959 CGContextRef shadowContext = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(rasterCGImage), 0, CGImageGetColorSpace(rasterCGImage), CGImageGetBitmapInfo(rasterCGImage));
960 CGContextSetShadowWithColor(shadowContext, offset, blur * scale, shadowColor);
961 CGContextDrawImage(shadowContext, CGRectMake(0, 0, width, height), rasterCGImage);
962 CGImageRef shadowCGImage = CGBitmapContextCreateImage(shadowContext);
963
964 // add to cursor inmge
965 NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] initWithCGImage:shadowCGImage];
966 [rep setSize:[fileImage size]];
967 [cursorImage addRepresentation:rep];
968
969 // release
970 [rep release];
971 CGContextRelease(shadowContext);
972 CGImageRelease(shadowCGImage);
973 }
974
975 // create cursor
976 cursor = [[NSCursor alloc] initWithImage:cursorImage hotSpot:NSMakePoint(hotX, hotY)];
977
978 // release
979 [cursorImage release];
980 [fileImage release];
981 CGColorRelease(shadowColor);
982}
983
984- (void) setMouseCursor: (ECursor) cursorType
985{
986 NSCursor* pCursor = nullptr;
987
988 bool helpCurrent = false;
989 bool helpRequested = false;
990
991 switch (cursorType)
992 {
993 case ECursor::ARROW: pCursor = [NSCursor arrowCursor]; break;
994 case ECursor::IBEAM: pCursor = [NSCursor IBeamCursor]; break;
995 case ECursor::WAIT:
996 if ([NSCursor respondsToSelector:@selector(busyButClickableCursor)])
997 pCursor = [NSCursor performSelector:@selector(busyButClickableCursor)];
998 break;
999 case ECursor::CROSS: pCursor = [NSCursor crosshairCursor]; break;
1000 case ECursor::UPARROW:
1001 if ([NSCursor respondsToSelector:@selector(_windowResizeNorthCursor)])
1002 pCursor = [NSCursor performSelector:@selector(_windowResizeNorthCursor)];
1003 else
1004 pCursor = [NSCursor resizeUpCursor];
1005 break;
1006 case ECursor::SIZENWSE:
1007 if ([NSCursor respondsToSelector:@selector(_windowResizeNorthWestSouthEastCursor)])
1008 pCursor = [NSCursor performSelector:@selector(_windowResizeNorthWestSouthEastCursor)];
1009 break;
1010 case ECursor::SIZENESW:
1011 if ([NSCursor respondsToSelector:@selector(_windowResizeNorthEastSouthWestCursor)])
1012 pCursor = [NSCursor performSelector:@selector(_windowResizeNorthEastSouthWestCursor)];
1013 break;
1014 case ECursor::SIZEWE:
1015 if ([NSCursor respondsToSelector:@selector(_windowResizeEastWestCursor)])
1016 pCursor = [NSCursor performSelector:@selector(_windowResizeEastWestCursor)];
1017 else
1018 pCursor = [NSCursor resizeLeftRightCursor];
1019 break;
1020 case ECursor::SIZENS:
1021 if ([NSCursor respondsToSelector:@selector(_windowResizeNorthSouthCursor)])
1022 pCursor = [NSCursor performSelector:@selector(_windowResizeNorthSouthCursor)];
1023 else
1024 pCursor = [NSCursor resizeUpDownCursor];
1025 break;
1026 case ECursor::SIZEALL:
1027 {
1028 if (!mMoveCursor)
1029 MakeCursorFromName(mMoveCursor, "move");
1030 pCursor = mMoveCursor;
1031 break;
1032 }
1033 case ECursor::INO: pCursor = [NSCursor operationNotAllowedCursor]; break;
1034 case ECursor::HAND: pCursor = [NSCursor pointingHandCursor]; break;
1035 case ECursor::APPSTARTING:
1036 if ([NSCursor respondsToSelector:@selector(busyButClickableCursor)])
1037 pCursor = [NSCursor performSelector:@selector(busyButClickableCursor)];
1038 break;
1039 case ECursor::HELP:
1040 if ([NSCursor respondsToSelector:@selector(_helpCursor)])
1041 pCursor = [NSCursor performSelector:@selector(_helpCursor)];
1042 helpRequested = true;
1043 break;
1044 default: pCursor = [NSCursor arrowCursor]; break;
1045 }
1046
1047 if ([NSCursor respondsToSelector:@selector(helpCursorShown)])
1048 helpCurrent = [NSCursor performSelector:@selector(helpCursorShown)];
1049
1050 if (helpCurrent && !helpRequested)
1051 {
1052 // N.B. - suppress warnings for this call only
1053#pragma clang diagnostic push
1054#pragma clang diagnostic ignored "-Wobjc-method-access"
1055 [NSCursor _setHelpCursor : false];
1056#pragma clang diagnostic pop
1057 }
1058
1059 if (!pCursor)
1060 pCursor = [NSCursor arrowCursor];
1061
1062 [pCursor set];
1063}
1064
1065- (void) removeFromSuperview
1066{
1067 if (mTextFieldView)
1068 [self endUserInput ];
1069
1070 mGraphics->SetPlatformContext(nullptr);
1071
1072 //For some APIs (AUv2) this is where we know about the window being closed, close via delegate
1073 mGraphics->GetDelegate()->CloseWindow();
1074 [super removeFromSuperview];
1075}
1076
1077- (void) controlTextDidEndEditing: (NSNotification*) aNotification
1078{
1079 char* txt = (char*)[[mTextFieldView stringValue] UTF8String];
1080
1081 mGraphics->SetControlValueAfterTextEdit(txt);
1082 mGraphics->SetAllControlsDirty();
1083
1084 [self endUserInput ];
1085}
1086
1087- (IPopupMenu*) createPopupMenu: (IPopupMenu&) menu : (NSRect) bounds;
1088{
1089 IGRAPHICS_MENU_RCVR* pDummyView = [[[IGRAPHICS_MENU_RCVR alloc] initWithFrame:bounds] autorelease];
1090 NSMenu* pNSMenu = [[[IGRAPHICS_MENU alloc] initWithIPopupMenuAndReceiver:&menu : pDummyView] autorelease];
1091 NSPoint wp = {bounds.origin.x, bounds.origin.y + bounds.size.height + 4};
1092
1093 NSMenuItem* pSelectedItem = nil;
1094
1095 auto selectedItemIdx = menu.GetChosenItemIdx();
1096
1097 if (selectedItemIdx > -1)
1098 {
1099 pSelectedItem = [pNSMenu itemAtIndex:selectedItemIdx];
1100 }
1101
1102 if (pSelectedItem != nil)
1103 {
1104 wp = {bounds.origin.x, bounds.origin.y};
1105 }
1106
1107 [pNSMenu popUpMenuPositioningItem:pSelectedItem atLocation:wp inView:self];
1108
1109 NSMenuItem* pChosenItem = [pDummyView menuItem];
1110 NSMenu* pChosenMenu = [pChosenItem menu];
1111 IPopupMenu* pIPopupMenu = [(IGRAPHICS_MENU*) pChosenMenu iPopupMenu];
1112
1113 long chosenItemIdx = [pChosenMenu indexOfItem: pChosenItem];
1114
1115 if (chosenItemIdx > -1 && pIPopupMenu)
1116 {
1117 pIPopupMenu->SetChosenItemIdx((int) chosenItemIdx);
1118 return pIPopupMenu;
1119 }
1120 else
1121 return nullptr;
1122}
1123
1124- (void) createTextEntry: (int) paramIdx : (const IText&) text : (const char*) str : (int) length : (NSRect) areaRect;
1125{
1126 if (mTextFieldView)
1127 return;
1128
1129 mTextFieldView = [[IGRAPHICS_TEXTFIELD alloc] initWithFrame: areaRect];
1130
1131 if (text.mVAlign == EVAlign::Middle)
1132 {
1133 IGRAPHICS_TEXTFIELDCELL* pCell = [[IGRAPHICS_TEXTFIELDCELL alloc] initTextCell:@"textfield"];
1134 [mTextFieldView setCell: pCell];
1135 [mTextFieldView setEditable: TRUE];
1136 [mTextFieldView setDrawsBackground: TRUE];
1137 }
1138
1139 CoreTextFontDescriptor* CTFontDescriptor = CoreTextHelpers::GetCTFontDescriptor(text, sFontDescriptorCache);
1140 double ratio = CTFontDescriptor->GetEMRatio() * mGraphics->GetDrawScale();
1141 NSFontDescriptor* fontDescriptor = (NSFontDescriptor*) CTFontDescriptor->GetDescriptor();
1142 NSFont* font = [NSFont fontWithDescriptor: fontDescriptor size: text.mSize * ratio];
1143 [mTextFieldView setFont: font];
1144
1145 switch (text.mAlign)
1146 {
1147 case EAlign::Near:
1148 [mTextFieldView setAlignment: NSLeftTextAlignment];
1149 break;
1150 case EAlign::Center:
1151 [mTextFieldView setAlignment: NSCenterTextAlignment];
1152 break;
1153 case EAlign::Far:
1154 [mTextFieldView setAlignment: NSRightTextAlignment];
1155 break;
1156 default:
1157 break;
1158 }
1159
1160 const IParam* pParam = paramIdx > kNoParameter ? mGraphics->GetDelegate()->GetParam(paramIdx) : nullptr;
1161
1162 // set up formatter
1163 if (pParam)
1164 {
1165 NSMutableCharacterSet *characterSet = [[NSMutableCharacterSet alloc] init];
1166
1167 switch ( pParam->Type() )
1168 {
1169 case IParam::kTypeEnum:
1170 case IParam::kTypeInt:
1171 case IParam::kTypeBool:
1172 [characterSet addCharactersInString:@"0123456789-+"];
1173 break;
1174 case IParam::kTypeDouble:
1175 [characterSet addCharactersInString:@"0123456789.-+"];
1176 break;
1177 default:
1178 break;
1179 }
1180
1181 [mTextFieldView setFormatter:[[[IGRAPHICS_FORMATTER alloc] init] autorelease]];
1182 [[mTextFieldView formatter] setAcceptableCharacterSet:characterSet];
1183 [[mTextFieldView formatter] setMaximumLength:length];
1184 [characterSet release];
1185 }
1186
1187 [[mTextFieldView cell] setLineBreakMode: NSLineBreakByTruncatingTail];
1188 [mTextFieldView setAllowsEditingTextAttributes:NO];
1189 [mTextFieldView setTextColor:ToNSColor(text.mTextEntryFGColor)];
1190 [mTextFieldView setBackgroundColor:ToNSColor(text.mTextEntryBGColor)];
1191
1192 [mTextFieldView setStringValue: [NSString stringWithUTF8String:str]];
1193
1194#ifndef COCOA_TEXTENTRY_BORDERED
1195 [mTextFieldView setBordered: NO];
1196 [mTextFieldView setFocusRingType:NSFocusRingTypeNone];
1197#endif
1198
1199 [mTextFieldView setDelegate: self];
1200
1201 [self addSubview: mTextFieldView];
1202 NSWindow* pWindow = [self window];
1203 [pWindow makeKeyAndOrderFront:nil];
1204 [pWindow makeFirstResponder: mTextFieldView];
1205}
1206
1207- (void) endUserInput
1208{
1209 [mTextFieldView setDelegate: nil];
1210 [mTextFieldView removeFromSuperview];
1211
1212 NSWindow* pWindow = [self window];
1213 [pWindow makeFirstResponder: self];
1214
1215 mTextFieldView = nullptr;
1216 mGraphics->ClearInTextEntryControl();
1217}
1218
1219- (BOOL) promptForColor: (IColor&) color : (IColorPickerHandlerFunc) func;
1220{
1221 NSColorPanel* colorPanel = [NSColorPanel sharedColorPanel];
1222 mColorPickerFunc = func;
1223
1224 [colorPanel setTarget:self];
1225 [colorPanel setShowsAlpha: TRUE];
1226 [colorPanel setAction:@selector(onColorPicked:)];
1227 [colorPanel setColor:ToNSColor(color)];
1228 [colorPanel orderFront:nil];
1229
1230 return colorPanel != nil;
1231}
1232
1233- (void) onColorPicked: (NSColorPanel*) pColorPanel
1234{
1235 mColorPickerFunc(FromNSColor([pColorPanel color]));
1236}
1237
1238- (NSString*) view: (NSView*) pView stringForToolTip: (NSToolTipTag) tag point: (NSPoint) point userData: (void*) pData
1239{
1240 int c = mGraphics ? GetMouseOver(mGraphics) : -1;
1241 if (c < 0) return @"";
1242
1243 const char* tooltip = mGraphics->GetControl(c)->GetTooltip();
1244 return CStringHasContents(tooltip) ? [NSString stringWithUTF8String:tooltip] : @"";
1245}
1246
1247- (void) registerToolTip: (IRECT&) bounds
1248{
1249 [self addToolTipRect: ToNSRect(mGraphics, bounds) owner: self userData: nil];
1250}
1251
1252- (NSDragOperation) draggingEntered: (id<NSDraggingInfo>) sender
1253{
1254 NSPasteboard *pPasteBoard = [sender draggingPasteboard];
1255
1256 if ([[pPasteBoard types] containsObject:NSFilenamesPboardType])
1257 return NSDragOperationGeneric;
1258 else
1259 return NSDragOperationNone;
1260}
1261
1262- (BOOL) performDragOperation: (id<NSDraggingInfo>) sender
1263{
1264 NSPasteboard* pPasteBoard = [sender draggingPasteboard];
1265
1266 if ([[pPasteBoard types] containsObject:NSFilenamesPboardType])
1267 {
1268 NSArray* pFiles = [pPasteBoard propertyListForType:NSFilenamesPboardType];
1269 NSPoint point = [sender draggingLocation];
1270 NSPoint relativePoint = [self convertPoint: point fromView:nil];
1271 // TODO - fix or remove these values
1272 float x = relativePoint.x;// - 2.f;
1273 float y = relativePoint.y;// - 3.f;
1274 if ([pFiles count] == 1)
1275 {
1276 NSString* pFirstFile = [pFiles firstObject];
1277 mGraphics->OnDrop([pFirstFile UTF8String], x, y);
1278 }
1279 else if ([pFiles count] > 1)
1280 {
1281 std::vector<const char*> paths([pFiles count]);
1282 for (auto i = 0; i < [pFiles count]; i++)
1283 {
1284 NSString* pFile = [pFiles objectAtIndex: i];
1285 paths[i] = [pFile UTF8String];
1286 }
1287 mGraphics->OnDropMultiple(paths, x, y);
1288 }
1289 }
1290 return YES;
1291}
1292
1293- (NSDragOperation)draggingSession:(NSDraggingSession*) session sourceOperationMaskForDraggingContext:(NSDraggingContext)context
1294{
1295 return NSDragOperationCopy;
1296}
1297
1298#ifdef IGRAPHICS_METAL
1299- (void) frameDidChange:(NSNotification*) pNotification
1300{
1301 CGFloat scale = [[self window] backingScaleFactor];
1302
1303 [(CAMetalLayer*)[self layer] setDrawableSize:CGSizeMake(self.frame.size.width * scale,
1304 self.frame.size.height * scale)];
1305}
1306#endif
1307#ifdef IGRAPHICS_GL
1308- (void) frameDidChange:(NSNotification*) pNotification
1309{
1310 [[self openGLContext] makeCurrentContext];
1311}
1312#endif
1313
1314//- (void) windowResized: (NSNotification*) notification;
1315//{
1316// if(!mGraphics)
1317// return;
1318//
1319// NSSize windowSize = [[self window] frame].size;
1320// NSRect viewFrameInWindowCoords = [self convertRect: [self bounds] toView: nil];
1321//
1322// float width = windowSize.width - viewFrameInWindowCoords.origin.x;
1323// float height = windowSize.height - viewFrameInWindowCoords.origin.y;
1324//
1325// float scaleX = width / mGraphics->Width();
1326// float scaleY = height / mGraphics->Height();
1327//
1328// if(mGraphics->GetUIResizerMode() == EUIResizerMode::Scale)
1329// mGraphics->Resize(width, height, mGraphics->GetDrawScale());
1330// else // EUIResizerMode::Size
1331// mGraphics->Resize(mGraphics->Width(), mGraphics->Height(), Clip(std::min(scaleX, scaleY), 0.1f, 10.f));
1332//}
1333//
1334//- (void) windowFullscreened: (NSNotification*) pNotification;
1335//{
1336// NSSize windowSize = [[self window] frame].size;
1337// NSRect viewFrameInWindowCoords = [self convertRect: [self bounds] toView: nil];
1338//
1339// float width = windowSize.width - viewFrameInWindowCoords.origin.x;
1340// float height = windowSize.height - viewFrameInWindowCoords.origin.y;
1341//
1342// float scaleX = width / mGraphics->Width();
1343// float scaleY = height / mGraphics->Height();
1344//
1345// if(mGraphics->GetUIResizerMode() == EUIResizerMode::Scale)
1346// mGraphics->Resize(width, height, mGraphics->GetDrawScale());
1347// else // EUIResizerMode::Size
1348// mGraphics->Resize(mGraphics->Width(), mGraphics->Height(), Clip(std::min(scaleX, scaleY), 0.1f, 10.f));
1349//}
1350
1351@end
This file contains the base IControl implementation, along with some base classes for specific types ...
IPlug logging a.k.a tracing functionality.
IGraphics platform class for macOS.
Definition: IGraphicsMac.h:24
IPlug's parameter class.
EParamType Type() const
Get the parameter's type.
A class to specify an item of a pop up menu.
A class for setting the contents of a pop up menu.
Used to manage a list of rectangular areas and optimize them for drawing to the screen.
Used to group mouse coordinates with mouse modifier information.
Used to manage color data, independent of draw class/platform.
Used for key press info, such as ASCII representation, virtual key (mapped to win32 codes) and modifi...
Definition: IPlugStructs.h:616
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.
IText is used to manage font and text/text entry style for a piece of text on the UI,...