Permalink
Browse files

Removing context as a parameter to the block.

This parameter is easy to create in the block if needed.

Also updating the read me with information about custom drawing.
  • Loading branch information...
1 parent 61b2798 commit 54a7b0f1fbfdcbebf5dd7ee1effb4cfe4b05d276 @kgn kgn committed May 1, 2012
Showing with 17 additions and 7 deletions.
  1. +2 −2 INAppStoreWindow.h
  2. +3 −5 INAppStoreWindow.m
  3. +12 −0 README.md
View
@@ -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
View
@@ -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) {
View
@@ -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.

0 comments on commit 54a7b0f

Please sign in to comment.