Permalink
Browse files

Added block-based drawRect.

  • Loading branch information...
1 parent 0f0bd16 commit c81db4ad77173ca8e7131b5ee4c714d4dae602c0 @joericioppo committed Jul 9, 2011
Showing with 20 additions and 0 deletions.
  1. +12 −0 Controller/MyWindowController.m
  2. +2 −0 StyledView/MyStyledView.h
  3. +6 −0 StyledView/MyStyledView.m
View
12 Controller/MyWindowController.m
@@ -49,6 +49,18 @@ - (void)awakeFromNib {
endingColor:[NSColor colorWithCalibratedHue:0.625 saturation:0.0 brightness:0.6 alpha:1.0]];
self.toolBar.topEdgeColor = [NSColor colorWithCalibratedWhite:0.8 alpha:1.0];
self.toolBar.bottomEdgeColor = [NSColor colorWithCalibratedWhite:0.65 alpha:1.0];
+
+ NSGradient *shineGadient = [NSGradient gradientWithStartingColor:[NSColor colorWithDeviceWhite:1.0 alpha:1.0]
+ endingColor:[NSColor colorWithDeviceWhite:1.0 alpha:0.0]];
+ NSGradient *shadowGradient = [NSGradient gradientWithStartingColor:[NSColor colorWithDeviceWhite:0.0 alpha:0.0]
+ endingColor:[NSColor colorWithDeviceWhite:0.0 alpha:0.3]];
+
+ self.background.styleBlock = ^(NSRect rect) {
+ NSPoint startPoint = NSMakePoint(NSMidX(rect), NSMaxY(rect) + 150.0);
+ NSPoint endPoint = NSMakePoint(NSMidX(rect), NSMidY(rect));
+ [shadowGradient drawFromCenter:startPoint radius:0.0 toCenter:endPoint radius:rect.size.height + 20.0 options:0];
+ [shineGadient drawFromCenter:startPoint radius:0.0 toCenter:endPoint radius:rect.size.height options:0];
+ };
}
@end
View
2 StyledView/MyStyledView.h
@@ -32,6 +32,8 @@
@property (nonatomic, retain) NSShadow *innerShadow;
@property (nonatomic, retain) NSShadow *innerGlow;
+@property (nonatomic, copy) void (^styleBlock)(NSRect rect);
+
@property (nonatomic, assign) BOOL shouldRasterize;
// -------------- topEdge
View
6 StyledView/MyStyledView.m
@@ -36,6 +36,7 @@ @implementation MyStyledView
@synthesize innerShadow;
@synthesize innerGlow;
@synthesize cacheImage;
+@synthesize styleBlock;
@synthesize shouldRasterize;
@@ -56,6 +57,7 @@ - (void)dealloc {
self.innerShadow = nil;
self.innerGlow = nil;
self.cacheImage = nil;
+ self.styleBlock = nil;
[super dealloc];
}
@@ -195,6 +197,10 @@ - (void)renderStyle {
NSBezierPath *innerGlowPath = [NSBezierPath bezierPathWithRect:shadowRect];
[innerGlowPath fillWithInnerShadow:self.innerGlow];
}
+
+ if (self.styleBlock) {
+ self.styleBlock(rect);
+ }
}
- (void)setFrameSize:(NSSize)newSize {

0 comments on commit c81db4a

Please sign in to comment.