Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // MBSearchFieldCell.m
- // Entree
- //
- // Created by Matt Ball on 8/12/09.
- // Copyright 2009 Daybreak Apps. All rights reserved.
- //
- #import "MBSearchFieldCell.h"
- @implementation MBSearchFieldCell
- - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
- {
- NSColor *insetTopColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.0];
- NSColor *insetBottomColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.35];
- NSColor *strokeTopColor = [NSColor colorWithCalibratedWhite:0.240 alpha:1.0];
- NSColor *strokeBottomColor = [NSColor colorWithCalibratedWhite:0.380 alpha:1.0];
- if (![[controlView window] isKeyWindow]) {
- strokeTopColor = [NSColor colorWithCalibratedWhite:0.550 alpha:1.0];
- strokeBottomColor = [NSColor colorWithCalibratedWhite:0.557 alpha:1.0];
- }
- NSRect strokeRect = cellFrame;
- strokeRect.size.height -= 1.0;
- NSBezierPath *strokePath = [NSBezierPath bezierPathWithRoundedRect:strokeRect xRadius:strokeRect.size.height/2.0 yRadius:strokeRect.size.height/2.0];
- NSBezierPath *insetPath = [NSBezierPath bezierPath];
- [insetPath appendBezierPath:strokePath];
- NSAffineTransform *transform = [NSAffineTransform transform];
- [transform translateXBy:0 yBy:1.0];
- [insetPath transformUsingAffineTransform:transform];
- NSGradient *insetGradient = [[NSGradient alloc] initWithStartingColor:insetTopColor endingColor:insetBottomColor];
- [insetGradient drawInBezierPath:insetPath angle:90.0];
- [insetGradient release];
- NSGradient *strokeGradient = [[NSGradient alloc] initWithStartingColor:strokeTopColor endingColor:strokeBottomColor];
- [strokeGradient drawInBezierPath:strokePath angle:90.0];
- [strokeGradient release];
- NSRect fieldRect = NSInsetRect(cellFrame, 1.0, 1.0);
- fieldRect.size.height -= 1.0;
- NSBezierPath *fieldPath = [NSBezierPath bezierPathWithRoundedRect:fieldRect xRadius:fieldRect.size.height/2.0 yRadius:fieldRect.size.height/2.0];
- [[NSColor whiteColor] set];
- [fieldPath fill];
- // Draw the inner shadow
- [[NSGraphicsContext currentContext] saveGraphicsState];
- NSShadow *innerShadow = [[NSShadow alloc] init];
- float innerShadowAlpha = 0.4;
- if (![[controlView window] isKeyWindow])
- innerShadowAlpha = 0.2;
- [innerShadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0 alpha:innerShadowAlpha]];
- [innerShadow setShadowOffset:NSMakeSize(0, -1.0)];
- [innerShadow setShadowBlurRadius:1.0];
- [innerShadow set];
- [fieldPath addClip];
- NSBezierPath *outlinePath = [NSBezierPath bezierPath];
- [outlinePath appendBezierPath:strokePath];
- [outlinePath appendBezierPath:fieldPath];
- [outlinePath setWindingRule:NSEvenOddWindingRule];
- [strokeTopColor set];
- [outlinePath fill];
- [[NSGraphicsContext currentContext] restoreGraphicsState];
- [innerShadow release];
- [self drawInteriorWithFrame:cellFrame inView:controlView];
- if ([controlView respondsToSelector:@selector(currentEditor)] && [(NSControl *)controlView currentEditor]) {
- [[NSGraphicsContext currentContext] saveGraphicsState];
- NSSetFocusRingStyle([controlView focusRingType]);
- [strokePath fill];
- [[NSGraphicsContext currentContext] restoreGraphicsState];
- }
- }
- @end
Add Comment
Please, Sign In to add comment