11#include "ui_VuoEditorWindow.h"
25#include <AppKit/AppKit.h>
32 QMacToolBarItem *_toolBarItem;
42- (id)initWithQMacToolBarItem:(QMacToolBarItem *)toolBarItem isCodeEditor:(
bool)codeEditor
44 if (!(self = [super init]))
47 _toolBarItem = toolBarItem;
49 _isCodeEditor = codeEditor;
51 self.accessibilityLabel = [NSString stringWithUTF8String:VuoEditor::tr("Zoom").toUtf8().data()];
53 NSImage *zoomOutImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"zoom-out" ofType:@"pdf"]];
54 [zoomOutImage setTemplate:YES];
55 NSImage *zoomFitImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"zoom-fit" ofType:@"pdf"]];
56 [zoomFitImage setTemplate:YES];
57 NSImage *zoomActualImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"zoom-actual" ofType:@"pdf"]];
58 [zoomActualImage setTemplate:YES];
59 NSImage *zoomInImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"zoom-in" ofType:@"pdf"]];
60 [zoomInImage setTemplate:YES];
62 [
self setSegmentCount:4];
65 [
self setImage:zoomOutImage forSegment:segmentCount];
66 [
self.cell setToolTip:[NSString stringWithUTF8String:VuoEditor::tr("Zoom Out").toUtf8().data()] forSegment:segmentCount];
67 [zoomOutImage release];
70 [
self setImage:zoomActualImage forSegment:segmentCount];
71 [
self.cell setToolTip:[NSString stringWithUTF8String:VuoEditor::tr("Actual Size").toUtf8().data()] forSegment:segmentCount];
72 [zoomActualImage release];
77 [
self setImage:zoomFitImage forSegment:segmentCount];
78 [
self.cell setToolTip:[NSString stringWithUTF8String:VuoEditor::tr("Zoom to Fit").toUtf8().data()] forSegment:segmentCount];
79 [zoomFitImage release];
83 [
self setImage:zoomInImage forSegment:segmentCount];
84 [
self.cell setToolTip:[NSString stringWithUTF8String:VuoEditor::tr("Zoom In").toUtf8().data()] forSegment:segmentCount];
85 [zoomInImage release];
88 [
self setSegmentCount:segmentCount];
90 [[
self cell] setTrackingMode:NSSegmentSwitchTrackingMomentary];
100 return NSMakeRect(0, 0, [self segmentCount] == 4 ? 149 : 109, 24);
106- (NSString *)itemIdentifier
111 if ([self isSelectedForSegment:0])
112 window->getZoomOutAction()->trigger();
113 else if ([self isSelectedForSegment:1])
114 window->getZoom11Action()->trigger();
115 else if ([self isSelectedForSegment:2])
116 window->getZoomInAction()->trigger();
121 if ([self isSelectedForSegment:0])
122 window->getZoomOutAction()->trigger();
123 else if ([self isSelectedForSegment:1])
124 window->getZoom11Action()->trigger();
125 else if ([self isSelectedForSegment:2])
126 window->getZoomToFitAction()->trigger();
127 else if ([self isSelectedForSegment:3])
128 window->getZoomInAction()->trigger();
131 return QString::number(qulonglong(_toolBarItem)).toNSString();
137- (void)drawRect:(NSRect)dirtyRect
139 NSColor *color = [NSColor colorWithCalibratedWhite:0 alpha:(_isDark ? .1 : .06)];
141 [NSBezierPath setDefaultLineWidth:1];
142 NSRect rect = [
self bounds];
146 float bottom = NSHeight(rect) - 2;
147 float right = NSWidth(rect);
148 int buttonCount = _isCodeEditor ? 3 : 4;
149 for (
int i = 1; i < buttonCount; ++i)
150 [NSBezierPath strokeLineFromPoint:NSMakePoint(round(right * (
float)i/buttonCount) - 2.5, top) toPoint:NSMakePoint(round(right * (
float)i/buttonCount) - 2.5, bottom)];
152 [[
self cell] drawInteriorWithFrame:dirtyRect inView:self];
158- (void)updateColor:(
bool)isDark
163 int segments = self.segmentCount;
164 for (
int i = 0; i < segments; ++i)
165 [[self imageForSegment:i] setTemplate:!isDark];
167 self.needsDisplay = YES;
177 QMacToolBarItem *_toolBarItem;
181- (id)initWithQMacToolBarItem:(QMacToolBarItem *)toolBarItem;
182- (NSString *)itemIdentifier;
183- (void)setState:(
bool)state;
191- (id)initWithQMacToolBarItem:(QMacToolBarItem *)toolBarItem
193 if (!(self = [super init]))
196 _toolBarItem = toolBarItem;
200 [button setFrame:NSMakeRect(0,1,32,24)];
202 [button setButtonType:NSButtonTypeMomentaryChange];
203 [button setBordered:NO];
205 [button setAction:@selector(itemIdentifier)];
206 [button setTarget:self];
208 [[button cell] setImageScaling:NSImageScaleNone];
209 [[button cell] setShowsStateBy:NSContentsCellMask];
211 button.cell.accessibilityLabel = [NSString stringWithUTF8String:VuoEditor::tr("Show Events").toUtf8().data()];
214 [
self setFrame:NSMakeRect(0,0,32,24)];
215 [
self addSubview:button];
229 VuoEditorEventsButton_Pro();
232 NSRect frame =
button.frame;
233 frame.origin.x = (width - frame.size.width) / 2.;
236 return NSMakeRect(0, 0, width, 24);
247 return QString::number(qulonglong(_toolBarItem)).toNSString();
253- (void)setState:(
bool)state
255 [button setState:state];
257 NSImage *offImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"showEvents" ofType:@"pdf"]];
261 NSImage *onImage = [offImage copy];
263 [[NSColor colorWithCalibratedRed:29./255 green:106./255 blue:229./255 alpha:1] set];
264 NSRectFillUsingOperation(NSMakeRect(0, 0, [onImage size].width, [onImage size].height), NSCompositingOperationSourceAtop);
265 [onImage unlockFocus];
266 [button setImage:onImage];
271 [offImage setTemplate:YES];
272 [button setImage:offImage];
291- (void)drawRect:(NSRect)dirtyRect
295 NSColor *color = [NSColor colorWithCalibratedWhite:1 alpha:(_isDark ? .2 : 1)];
298 NSRect rect = [button frame];
300 rect.size.height -= 1;
301 NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:5.0 yRadius:5.0];
305 [
super drawRect:dirtyRect];
311- (void)updateColor:(
bool)isDark
314 self.needsDisplay = YES;
334 this->isCodeEditor = isCodeEditor;
336 activityIndicatorTimer = NULL;
339 buildInProgress =
false;
340 buildPending =
false;
341 stopInProgress =
false;
344 VuoEditorWindowToolbar_Pro();
354 runImage11 = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"run-1x1" ofType:@"pdf"]];
355 runImage1611 = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"run-16x11" ofType:@"pdf"]];
356 [runImage11 setTemplate:YES];
357 [runImage1611 setTemplate:YES];
358 runImage = runImage11;
360 toolbarRunItem =
qtToolbar->addItem(QIcon(), VuoEditor::tr(
"Run"));
361 NSToolbarItem *ti = toolbarRunItem->nativeToolBarItem();
362 [ti setImage:runImage];
363 [ti setAutovalidates:NO];
364 ti.toolTip = [NSString stringWithUTF8String:VuoEditor::tr("Compile and launch this composition.").toUtf8().data()];
366 connect(toolbarRunItem, SIGNAL(activated()),
window, SLOT(on_runComposition_triggered()));
371 stopImage11 = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"stop-1x1" ofType:@"pdf"]];
372 stopImage1611 = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"stop-16x11" ofType:@"pdf"]];
373 [stopImage11 setTemplate:YES];
374 [stopImage1611 setTemplate:YES];
375 stopImage = stopImage11;
377 toolbarStopItem =
qtToolbar->addItem(QIcon(), VuoEditor::tr(
"Stop"));
378 NSToolbarItem *ti = toolbarStopItem->nativeToolBarItem();
379 [ti setImage:stopImage];
380 [ti setAutovalidates:NO];
381 ti.toolTip = [NSString stringWithUTF8String:VuoEditor::tr("Shut down this composition.").toUtf8().data()];
383 connect(toolbarStopItem, SIGNAL(activated()),
window, SLOT(on_stopComposition_triggered()));
390 toolbarEventsItem = NULL;
395 toolbarEventsItem =
qtToolbar->addItem(QIcon(), VuoEditor::tr(
"Show Events"));
396 NSToolbarItem *ti = toolbarEventsItem->nativeToolBarItem();
398 [ti setView:eventsButton];
399#pragma clang diagnostic push
400#pragma clang diagnostic ignored "-Wdeprecated-declarations"
402 [ti setMinSize:[eventsButton bounds].size];
403#pragma clang diagnostic pop
404 ti.toolTip = [NSString stringWithUTF8String:VuoEditor::tr("Toggle whether the canvas shows event flow by highlighting trigger ports and nodes.").toUtf8().data()];
409 toolbarZoomItem =
qtToolbar->addItem(QIcon(), VuoEditor::tr(
"Zoom"));
410 NSToolbarItem *ti = toolbarZoomItem->nativeToolBarItem();
411 zoomButtons = [[
VuoEditorZoomButtons alloc] initWithQMacToolBarItem:toolbarZoomItem isCodeEditor:isCodeEditor];
412 [ti setView:zoomButtons];
413#pragma clang diagnostic push
414#pragma clang diagnostic ignored "-Wdeprecated-declarations"
416 [ti setMinSize:[zoomButtons bounds].size];
417#pragma clang diagnostic pop
422 addToolbarItems_Pro();
432 VuoEditorWindowToolbarDestructor_Pro();
449 return @"Vuo Composition";
464 NSToolbarItem *runItem = toolbarRunItem->nativeToolBarItem();
465 NSToolbarItem *stopItem = toolbarStopItem->nativeToolBarItem();
469 [runItem setEnabled:!buildPending];
470 [stopItem setEnabled:NO];
472 else if (buildInProgress)
474 [runItem setEnabled:NO];
475 [stopItem setEnabled:YES];
479 [runItem setEnabled:NO];
480 [stopItem setEnabled:YES];
484 [runItem setEnabled:YES];
485 [stopItem setEnabled:NO];
488 if (toolbarEventsItem)
490 NSToolbarItem *eventsItem = toolbarEventsItem->nativeToolBarItem();
491 [eventsItem setLabel:[NSString stringWithUTF8String:VuoEditor::tr("Show Events").toUtf8().data()]];
493 [eventsButton
setState:eventsShown];
497 [(NSSegmentedControl *)[toolbarZoomItem->nativeToolBarItem() view] setEnabled:!zoomedToActualSize forSegment:1];
500 [(NSSegmentedControl *)[toolbarZoomItem->nativeToolBarItem() view] setEnabled:!zoomedToFit forSegment:2];
502 updateActivityIndicators();
519 buildPending =
false;
520 buildInProgress =
true;
528 buildInProgress =
false;
537 stopInProgress =
true;
545 buildInProgress =
false;
547 stopInProgress =
false;
563 return buildInProgress;
579 return stopInProgress;
588 return [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay;
594void VuoEditorWindowToolbar::updateActivityIndicators(
void)
596 if (buildInProgress || stopInProgress)
598 if (! activityIndicatorTimer)
600 activityIndicatorFrame = 0;
602 activityIndicatorTimer =
new QTimer(
this);
603 activityIndicatorTimer->setObjectName(
"VuoEditorWindowToolbar::activityIndicatorTimer");
604 connect(activityIndicatorTimer, SIGNAL(timeout()),
this, SLOT(updateActivityIndicators()));
605 activityIndicatorTimer->start(250);
610 if (activityIndicatorTimer)
612 activityIndicatorTimer->stop();
613 delete activityIndicatorTimer;
614 activityIndicatorTimer = NULL;
621 toolbarRunItem->setIcon(QIcon(iconEngine));
624 [(NSToolbarItem *)toolbarRunItem->nativeToolBarItem() setImage:runImage];
629 toolbarStopItem->setIcon(QIcon(iconEngine));
632 [(NSToolbarItem *)toolbarStopItem->nativeToolBarItem() setImage:stopImage];