Skip to content

Commit

Permalink
Removing context as a parameter to the block.
Browse files Browse the repository at this point in the history
This parameter is easy to create in the block if needed.

Also updating the read me with information about custom drawing.
  • Loading branch information
kgn committed May 1, 2012
1 parent 61b2798 commit 54a7b0f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions INAppStoreWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
it would be a shame to have to re-invent that just to change the look. So this block can be used
to override the default Mac App Store style titlebar drawing with your own drawing code!
*/
typedef void (^INAppStoreWindowTitleBarDrawingBlock)(BOOL drawsAsMainWindow, CGRect drawingRect,
CGPathRef clippingPath, CGContextRef context);
typedef void (^INAppStoreWindowTitleBarDrawingBlock)(BOOL drawsAsMainWindow,
CGRect drawingRect, CGPathRef clippingPath);
@property (INAppStoreWindowCopy) INAppStoreWindowTitleBarDrawingBlock titleBarDrawingBlock;

@end
8 changes: 3 additions & 5 deletions INAppStoreWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,13 @@ - (void)drawRect:(NSRect)dirtyRect
BOOL drawsAsMainWindow = ([window isMainWindow] && [[NSApplication sharedApplication] isActive]);

NSRect drawingRect = [self bounds];
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];

if ( window.titleBarDrawingBlock ) {
CGPathRef clippingPath = createClippingPathWithRectAndRadius(drawingRect, INCornerClipRadius);
CGContextAddPath(context, clippingPath);
CGContextClip(context);
window.titleBarDrawingBlock(drawsAsMainWindow, NSRectToCGRect(drawingRect), clippingPath, context);
window.titleBarDrawingBlock(drawsAsMainWindow, NSRectToCGRect(drawingRect), clippingPath);
CGPathRelease(clippingPath);
} else {
CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];

NSColor *startColor = nil;
NSColor *endColor = nil;
if (IN_RUNNING_LION) {
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ The left padding of the traffic lights can be adjusted with `trafficLightButtons

The baseline divider can be hidden by setting `showsBaselineSeparator` to `NO`, the default value is `YES`.

### Using your own drawing code

A lot of time and effort has gone into making the custom titlebar in INAppStoreWindow function just right, it would be a shame to have to re-implement all this work just to draw your own custom title bar. So INAppStoreWindow has a `titleBarDrawingBlock` property that can be set to a block containing your own drawing code!

```obj-c
[self.window setTitleBarDrawingBlock:^(BOOL drawsAsMainWindow, CGRect drawingRect, CGPathRef clippingPath){
// Custom drawing code!
}];
```
This block gets passed some useful parameters like if the window is the main one(`drawsAsMainWindow`), the drawing rect of the title bar(`drawingRect`), and a pre-made clipping path with rounded corners at the top(`clippingPath`).
## Authors
INAppStoreWindow is maintained by [Indragie Karunaratne](http://indragie.com) and [David Keegan](http://inscopeapps.com). Special thanks to [everyone else](https://github.com/indragiek/INAppStoreWindow/contributors) who contributed various fixes and improvements to the code.
Expand Down

0 comments on commit 54a7b0f

Please sign in to comment.