11 #include "ui_VuoEditorWindow.h"
24 #ifndef NS_RETURNS_INNER_POINTER
25 #define NS_RETURNS_INNER_POINTER
27 #include <Cocoa/Cocoa.h>
28 #include <objc/message.h>
46 - (id)initWithQMacToolBarItem:(QMacToolBarItem *)toolBarItem isCodeEditor:(
bool)codeEditor
48 if (!(
self = [super init]))
55 NSImage *zoomOutImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"zoom-out" ofType:@"pdf"]];
56 [zoomOutImage setTemplate:YES];
57 NSImage *zoomFitImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"zoom-fit" ofType:@"pdf"]];
58 [zoomFitImage setTemplate:YES];
59 NSImage *zoomActualImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"zoom-actual" ofType:@"pdf"]];
60 [zoomActualImage setTemplate:YES];
61 NSImage *zoomInImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"zoom-in" ofType:@"pdf"]];
62 [zoomInImage setTemplate:YES];
64 [
self setSegmentCount:4];
67 [
self setImage:zoomOutImage forSegment:segmentCount];
68 [
self.cell setToolTip:[NSString stringWithUTF8String:VuoEditor::tr("Zoom Out").toUtf8().data()] forSegment:segmentCount];
69 [zoomOutImage release];
72 [
self setImage:zoomActualImage forSegment:segmentCount];
73 [
self.cell setToolTip:[NSString stringWithUTF8String:VuoEditor::tr("Actual Size").toUtf8().data()] forSegment:segmentCount];
74 [zoomActualImage release];
79 [
self setImage:zoomFitImage forSegment:segmentCount];
80 [
self.cell setToolTip:[NSString stringWithUTF8String:VuoEditor::tr("Zoom to Fit").toUtf8().data()] forSegment:segmentCount];
81 [zoomFitImage release];
85 [
self setImage:zoomInImage forSegment:segmentCount];
86 [
self.cell setToolTip:[NSString stringWithUTF8String:VuoEditor::tr("Zoom In").toUtf8().data()] forSegment:segmentCount];
87 [zoomInImage release];
90 [
self setSegmentCount:segmentCount];
92 [[
self cell] setTrackingMode:NSSegmentSwitchTrackingMomentary];
102 return NSMakeRect(0, 0, [
self segmentCount] == 4 ? 149 : 109, 24);
108 - (NSString *)itemIdentifier
113 if ([
self isSelectedForSegment:0])
115 else if ([
self isSelectedForSegment:1])
117 else if ([
self isSelectedForSegment:2])
123 if ([
self isSelectedForSegment:0])
125 else if ([
self isSelectedForSegment:1])
127 else if ([
self isSelectedForSegment:2])
129 else if ([
self isSelectedForSegment:3])
133 return QString::number(qulonglong(
_toolBarItem)).toNSString();
139 - (void)drawRect:(NSRect)dirtyRect
141 NSColor *color = [NSColor colorWithCalibratedWhite:1 alpha:(_isDark ? .2 : 1)];
144 NSRect rect = [
self bounds];
146 rect.size.width -= 2;
147 rect.size.height -= 1;
148 NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:5.0 yRadius:5.0];
151 [[
self cell] drawInteriorWithFrame:dirtyRect inView:self];
157 - (void)updateColor:(
bool)isDark
162 int segments =
self.segmentCount;
163 for (
int i = 0; i < segments; ++i)
164 [[self imageForSegment:i] setTemplate:!isDark];
166 self.needsDisplay = YES;
180 - (id)initWithQMacToolBarItem:(QMacToolBarItem *)toolBarItem;
181 - (NSString *)itemIdentifier;
182 - (void)setState:(
bool)state;
183 - (NSButton *)button;
190 - (id)initWithQMacToolBarItem:(QMacToolBarItem *)toolBarItem
192 if (!(
self = [super init]))
199 [
button setFrame:NSMakeRect(0,1,32,24)];
201 [
button setButtonType:NSMomentaryChangeButton];
204 [
button setAction:@selector(itemIdentifier)];
207 [[
button cell] setImageScaling:NSImageScaleNone];
208 [[
button cell] setShowsStateBy:NSContentsCellMask];
212 [
self setFrame:NSMakeRect(0,0,32,24)];
213 [
self addSubview:button];
227 VuoEditorEventsButton_Pro();
230 NSRect frame =
button.frame;
231 frame.origin.x = (width - frame.size.width) / 2.;
234 return NSMakeRect(0, 0, width, 24);
245 return QString::number(qulonglong(
_toolBarItem)).toNSString();
251 - (void)setState:(
bool)state
255 NSImage *offImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"showEvents" ofType:@"pdf"]];
259 NSImage *onImage = [offImage copy];
261 [[NSColor colorWithCalibratedRed:29./255 green:106./255 blue:229./255 alpha:1] set];
262 NSRectFillUsingOperation(NSMakeRect(0, 0, [onImage size].width, [onImage size].height), NSCompositeSourceAtop);
263 [onImage unlockFocus];
264 [
button setImage:onImage];
269 [offImage setTemplate:YES];
270 [
button setImage:offImage];
287 - (void)drawRect:(NSRect)dirtyRect
289 NSColor *color = [NSColor colorWithCalibratedWhite:1 alpha:(_isDark ? .2 : 1)];
292 NSRect rect = [button frame];
294 rect.size.height -= 1;
295 NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:5.0 yRadius:5.0];
298 [
super drawRect:dirtyRect];
304 - (void)updateColor:(
bool)isDark
307 self.needsDisplay = YES;
319 float titleAndToolbarHeight = window.frame.size.height - [window contentRectForFrameRect:window.frame].size.height;
320 rect.origin.y -= titleAndToolbarHeight;
332 - (NSRect)titleRectForBounds:(NSRect)frame
334 CGFloat stringHeight =
self.attributedStringValue.size.height;
335 NSRect titleRect = [
super titleRectForBounds:frame];
336 CGFloat oldOriginY = frame.origin.y;
337 titleRect.origin.y = frame.origin.y + (frame.size.height - stringHeight) / 2.0;
338 titleRect.size.height = titleRect.size.height - (titleRect.origin.y - oldOriginY);
341 - (void)drawInteriorWithFrame:(NSRect)cFrame inView:(NSView*)cView
343 [
super drawInteriorWithFrame:[
self titleRectForBounds:cFrame] inView:cView];
352 NSView *nsView = (NSView *)window->winId();
353 nsWindow = [nsView window];
355 activityIndicatorTimer = NULL;
358 buildInProgress =
false;
359 buildPending =
false;
360 stopInProgress =
false;
362 titleView = [NSTextField new];
364 titleView.font = [NSFont titleBarFontOfSize:0];
365 titleView.selectable = NO;
366 titleViewController = nil;
368 toolBar =
new QMacToolBar(window);
370 NSToolbar *tb = toolBar->nativeToolbar();
375 [tb setAllowsUserCustomization:NO];
380 runImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"run" ofType:@"pdf"]];
381 [runImage setTemplate:YES];
383 toolbarRunItem = toolBar->addItem(QIcon(), VuoEditor::tr(
"Run"));
384 NSToolbarItem *ti = toolbarRunItem->nativeToolBarItem();
385 [ti setImage:runImage];
386 [ti setAutovalidates:NO];
387 ti.toolTip = [NSString stringWithUTF8String:VuoEditor::tr("Compile and launch this composition.").toUtf8().data()];
389 connect(toolbarRunItem, SIGNAL(activated()), window, SLOT(on_runComposition_triggered()));
394 stopImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"stop" ofType:@"pdf"]];
395 [stopImage setTemplate:YES];
397 toolbarStopItem = toolBar->addItem(QIcon(), VuoEditor::tr(
"Stop"));
398 NSToolbarItem *ti = toolbarStopItem->nativeToolBarItem();
399 [ti setImage:stopImage];
400 [ti setAutovalidates:NO];
401 ti.toolTip = [NSString stringWithUTF8String:VuoEditor::tr("Shut down this composition.").toUtf8().data()];
403 connect(toolbarStopItem, SIGNAL(activated()), window, SLOT(on_stopComposition_triggered()));
410 toolbarEventsItem = NULL;
411 toolBar->addSeparator();
415 toolbarEventsItem = toolBar->addItem(QIcon(), VuoEditor::tr(
"Show Events"));
416 NSToolbarItem *ti = toolbarEventsItem->nativeToolBarItem();
418 [ti setView:eventsButton];
419 [ti setMinSize:[eventsButton bounds].size];
420 ti.toolTip = [NSString stringWithUTF8String:VuoEditor::tr("Toggle whether the canvas shows event flow by highlighting trigger ports and nodes.").toUtf8().data()];
425 toolbarZoomItem = toolBar->addItem(QIcon(), VuoEditor::tr(
"Zoom"));
426 NSToolbarItem *ti = toolbarZoomItem->nativeToolBarItem();
427 zoomButtons = [[
VuoEditorZoomButtons alloc] initWithQMacToolBarItem:toolbarZoomItem isCodeEditor:isCodeEditor];
428 [ti setView:zoomButtons];
429 [ti setMinSize:[zoomButtons bounds].size];
438 VuoEditorWindowToolbar_Pro();
441 toolBar->attachToWindow(window->windowHandle());
444 if (NSProcessInfo.processInfo.operatingSystemVersion.minorVersion == 13)
445 class_addMethod(nsWindow.delegate.class,
446 @selector(window:willPositionSheet:usingRect:),
448 "{CGRect={CGPoint=dd}{CGSize=dd}}@:@@{CGRect={CGPoint=dd}{CGSize=dd}}");
457 VuoEditorWindowToolbarDestructor_Pro();
473 NSToolbarItem *runItem = toolbarRunItem->nativeToolBarItem();
474 NSToolbarItem *stopItem = toolbarStopItem->nativeToolBarItem();
478 [runItem setEnabled:!buildPending];
479 [stopItem setEnabled:NO];
481 else if (buildInProgress)
483 [runItem setEnabled:NO];
484 [stopItem setEnabled:YES];
488 [runItem setEnabled:NO];
489 [stopItem setEnabled:YES];
493 [runItem setEnabled:YES];
494 [stopItem setEnabled:NO];
497 if (toolbarEventsItem)
499 NSToolbarItem *eventsItem = toolbarEventsItem->nativeToolBarItem();
500 [eventsItem setLabel:(eventsShown
501 ? [NSString stringWithUTF8String:VuoEditor::tr("Hide Events").toUtf8().data()]
502 : [NSString stringWithUTF8String:VuoEditor::tr("Show Events").toUtf8().data()])];
504 [eventsButton
setState:eventsShown];
508 [(NSSegmentedControl *)[toolbarZoomItem->nativeToolBarItem() view] setEnabled:!zoomedToActualSize forSegment:1];
511 [(NSSegmentedControl *)[toolbarZoomItem->nativeToolBarItem() view] setEnabled:!zoomedToFit forSegment:2];
513 updateActivityIndicators();
530 buildPending =
false;
531 buildInProgress =
true;
539 buildInProgress =
false;
548 stopInProgress =
true;
556 buildInProgress =
false;
558 stopInProgress =
false;
574 return buildInProgress;
590 return stopInProgress;
599 return [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay;
605 void VuoEditorWindowToolbar::updateActivityIndicators(
void)
607 if (buildInProgress || stopInProgress)
609 if (! activityIndicatorTimer)
611 activityIndicatorFrame = 0;
613 activityIndicatorTimer =
new QTimer(
this);
614 activityIndicatorTimer->setObjectName(
"VuoEditorWindowToolbar::activityIndicatorTimer");
615 connect(activityIndicatorTimer, SIGNAL(timeout()),
this, SLOT(updateActivityIndicators()));
616 activityIndicatorTimer->start(250);
621 if (activityIndicatorTimer)
623 activityIndicatorTimer->stop();
624 delete activityIndicatorTimer;
625 activityIndicatorTimer = NULL;
632 toolbarRunItem->setIcon(QIcon(iconEngine));
635 [(NSToolbarItem *)toolbarRunItem->nativeToolBarItem() setImage:runImage];
640 toolbarStopItem->setIcon(QIcon(iconEngine));
643 [(NSToolbarItem *)toolbarStopItem->nativeToolBarItem() setImage:stopImage];
649 void VuoEditorWindowToolbar::updateColor(
bool isDark)
660 objc_msgSend(nsWindow, sel_getUid(
"setTitlebarAppearsTransparent:"),
true);
664 ((NSView *)nsWindow.contentView).wantsLayer = YES;
666 if (NSProcessInfo.processInfo.operatingSystemVersion.minorVersion >= 12)
672 objc_msgSend(nsWindow, sel_getUid(
"setTabbingMode:"), 0 );
673 objc_msgSend(nsWindow, sel_getUid(
"setTabbingIdentifier:"),
@"Vuo Composition");
678 [nsWindow setBackgroundColor:[NSColor colorWithCalibratedWhite:.47 alpha:1]];
680 [nsWindow setBackgroundColor:[NSColor colorWithCalibratedWhite:.92 alpha:1]];