Guest User

Untitled

a guest
Dec 11th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. //
  2. // MBSearchFieldCell.m
  3. // Entree
  4. //
  5. // Created by Matt Ball on 8/12/09.
  6. // Copyright 2009 Daybreak Apps. All rights reserved.
  7. //
  8.  
  9. #import "MBSearchFieldCell.h"
  10.  
  11.  
  12. @implementation MBSearchFieldCell
  13.  
  14. - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
  15. {
  16. NSColor *insetTopColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.0];
  17. NSColor *insetBottomColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.35];
  18. NSColor *strokeTopColor = [NSColor colorWithCalibratedWhite:0.240 alpha:1.0];
  19. NSColor *strokeBottomColor = [NSColor colorWithCalibratedWhite:0.380 alpha:1.0];
  20.  
  21. if (![[controlView window] isKeyWindow]) {
  22. strokeTopColor = [NSColor colorWithCalibratedWhite:0.550 alpha:1.0];
  23. strokeBottomColor = [NSColor colorWithCalibratedWhite:0.557 alpha:1.0];
  24. }
  25.  
  26. NSRect strokeRect = cellFrame;
  27. strokeRect.size.height -= 1.0;
  28. NSBezierPath *strokePath = [NSBezierPath bezierPathWithRoundedRect:strokeRect xRadius:strokeRect.size.height/2.0 yRadius:strokeRect.size.height/2.0];
  29.  
  30. NSBezierPath *insetPath = [NSBezierPath bezierPath];
  31. [insetPath appendBezierPath:strokePath];
  32. NSAffineTransform *transform = [NSAffineTransform transform];
  33. [transform translateXBy:0 yBy:1.0];
  34. [insetPath transformUsingAffineTransform:transform];
  35. NSGradient *insetGradient = [[NSGradient alloc] initWithStartingColor:insetTopColor endingColor:insetBottomColor];
  36. [insetGradient drawInBezierPath:insetPath angle:90.0];
  37. [insetGradient release];
  38.  
  39. NSGradient *strokeGradient = [[NSGradient alloc] initWithStartingColor:strokeTopColor endingColor:strokeBottomColor];
  40. [strokeGradient drawInBezierPath:strokePath angle:90.0];
  41. [strokeGradient release];
  42.  
  43. NSRect fieldRect = NSInsetRect(cellFrame, 1.0, 1.0);
  44. fieldRect.size.height -= 1.0;
  45. NSBezierPath *fieldPath = [NSBezierPath bezierPathWithRoundedRect:fieldRect xRadius:fieldRect.size.height/2.0 yRadius:fieldRect.size.height/2.0];
  46. [[NSColor whiteColor] set];
  47. [fieldPath fill];
  48.  
  49. // Draw the inner shadow
  50. [[NSGraphicsContext currentContext] saveGraphicsState];
  51. NSShadow *innerShadow = [[NSShadow alloc] init];
  52. float innerShadowAlpha = 0.4;
  53. if (![[controlView window] isKeyWindow])
  54. innerShadowAlpha = 0.2;
  55. [innerShadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0 alpha:innerShadowAlpha]];
  56. [innerShadow setShadowOffset:NSMakeSize(0, -1.0)];
  57. [innerShadow setShadowBlurRadius:1.0];
  58. [innerShadow set];
  59.  
  60. [fieldPath addClip];
  61.  
  62. NSBezierPath *outlinePath = [NSBezierPath bezierPath];
  63. [outlinePath appendBezierPath:strokePath];
  64. [outlinePath appendBezierPath:fieldPath];
  65. [outlinePath setWindingRule:NSEvenOddWindingRule];
  66. [strokeTopColor set];
  67. [outlinePath fill];
  68.  
  69. [[NSGraphicsContext currentContext] restoreGraphicsState];
  70. [innerShadow release];
  71.  
  72. [self drawInteriorWithFrame:cellFrame inView:controlView];
  73. if ([controlView respondsToSelector:@selector(currentEditor)] && [(NSControl *)controlView currentEditor]) {
  74. [[NSGraphicsContext currentContext] saveGraphicsState];
  75. NSSetFocusRingStyle([controlView focusRingType]);
  76. [strokePath fill];
  77. [[NSGraphicsContext currentContext] restoreGraphicsState];
  78. }
  79. }
  80.  
  81. @end
Add Comment
Please, Sign In to add comment