Skip to content

Commit

Permalink
Add an example of using titleBarDrawingBlock along with a control to …
Browse files Browse the repository at this point in the history
…the SampleApp
  • Loading branch information
js committed Aug 27, 2012
1 parent 1f9eb1a commit 6f567d5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions SampleApp/SampleApp/SampleWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,39 @@ - (void)windowDidLoad
INAppStoreWindow *aWindow = (INAppStoreWindow*)[self window];
aWindow.titleBarHeight = 40.0;
aWindow.trafficLightButtonsLeftMargin = 13.0;
aWindow.titleBarDrawingBlock = ^(BOOL drawsAsMainWindow, CGRect drawingRect, CGPathRef clippingPath) {
CGContextRef ctx = [[NSGraphicsContext currentContext] graphicsPort];
CGContextAddPath(ctx, clippingPath);
CGContextClip(ctx);

NSGradient *gradient = nil;
if (drawsAsMainWindow) {
gradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedRed:0 green:0.319 blue:1 alpha:1]
endingColor:[NSColor colorWithCalibratedRed:0 green:0.627 blue:1 alpha:1]];
[[NSColor darkGrayColor] setFill];
} else {
// set the default non-main window gradient colors
gradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedWhite:0.851f alpha:1]
endingColor:[NSColor colorWithCalibratedWhite:0.929f alpha:1]];
[[NSColor colorWithCalibratedWhite:0.6f alpha:1] setFill];
}
[gradient drawInRect:drawingRect angle:90];
NSRectFill(NSMakeRect(NSMinX(drawingRect), NSMinY(drawingRect), NSWidth(drawingRect), 1));
};

NSView *titleBarView = aWindow.titleBarView;
NSSize segmentSize = NSMakeSize(104, 25);
NSRect segmentFrame = NSMakeRect(NSMidX(titleBarView.bounds) - (segmentSize.width / 2.f),
NSMidY(titleBarView.bounds) - (segmentSize.height / 2.f),
segmentSize.width, segmentSize.height);
NSSegmentedControl *segment = [[NSSegmentedControl alloc] initWithFrame:segmentFrame];
[segment setSegmentCount:3];
[segment setImage:[NSImage imageNamed:NSImageNameIconViewTemplate] forSegment:0];
[segment setImage:[NSImage imageNamed:NSImageNameListViewTemplate] forSegment:1];
[segment setImage:[NSImage imageNamed:NSImageNameFlowViewTemplate] forSegment:2];
[segment setSelectedSegment:0];
[segment setSegmentStyle:NSSegmentStyleTexturedRounded];
[titleBarView addSubview:segment];
}

@end

0 comments on commit 6f567d5

Please sign in to comment.