5 // Created by Sean Patrick O'Brien on 9/23/06.
6 // Copyright 2006 Sean Patrick O'Brien. All rights reserved.
10 #import "EtchedTextCell.h"
11 #import "NSImage+FrameworkImage.h"
13 @implementation NFHUDFrame
15 - (id)initWithFrame:(NSRect)frame styleMask:(unsigned int)style owner:(id)owner
17 if([super initWithFrame:frame styleMask:style owner:owner])
19 // Some of Apple's HUD windows have a slight shadow below the title
20 EtchedTextCell *cell = [[EtchedTextCell alloc] initTextCell: @""];
21 [cell setFont:[NSFont fontWithName:@"LucidaGrande" size:11.0]];
22 [cell setShadowColor:[NSColor colorWithCalibratedWhite:32/255.0 alpha:0.5]];
25 // get the regular controls out of the picture
26 [closeButton setHidden:YES];
27 [minimizeButton setHidden:YES];
28 [zoomButton setHidden:YES];
30 // according to Andy Matuschak, the superclass doesn't do it's job here...
31 [[self window] setShowsResizeIndicator:(style & NSResizableWindowMask)];
33 // close button, in the style of Matt Gemmell's HUD Window implementation
34 NSButton *closeWidget = [[NSButton alloc] initWithFrame:NSMakeRect(3.0, [self frame].size.height - 16.0,
36 [self addSubview:closeWidget];
37 [closeWidget setButtonType:NSMomentaryChangeButton];
38 [closeWidget setBordered:NO];
39 [closeWidget setImage:[NSImage frameworkImageNamed:@"HUDCloseButton.tiff"]];
40 [closeWidget setImagePosition:NSImageOnly];
41 [closeWidget setTarget:[self window]];
42 [closeWidget setFocusRingType:NSFocusRingTypeNone];
43 [closeWidget setAction:@selector(orderOut:)];
44 [closeWidget setAutoresizingMask:NSViewMinYMargin];
45 [closeWidget release];
53 + (NSBezierPath*)_clippingPathForFrame:(NSRect)aRect
56 NSBezierPath *path = [NSBezierPath alloc];
57 NSPoint topMid = NSMakePoint(NSMidX(aRect), NSMaxY(aRect));
58 NSPoint topLeft = NSMakePoint(NSMinX(aRect), NSMaxY(aRect));
59 NSPoint topRight = NSMakePoint(NSMaxX(aRect), NSMaxY(aRect));
60 NSPoint bottomRight = NSMakePoint(NSMaxX(aRect), NSMinY(aRect));
62 [path moveToPoint: topMid];
63 [path appendBezierPathWithArcFromPoint: topRight
66 [path appendBezierPathWithArcFromPoint: bottomRight
69 [path appendBezierPathWithArcFromPoint: aRect.origin
72 [path appendBezierPathWithArcFromPoint: topLeft
80 - (NSRect)_titlebarTitleRect
82 NSRect rect = [super _titlebarTitleRect];
88 - (void)_drawTitle:(NSRect)rect
90 [self _drawTitleStringIn:rect withColor:[NSColor whiteColor]];
93 - (void)_drawTitleBar:(NSRect)rect
95 [[NSColor colorWithCalibratedWhite: 64/255.0 alpha:0.85] set];
98 [self _drawTitle:rect];
101 - (void)drawRect:(NSRect)_rect
103 NSRect rect = [self frame];
104 [[NSColor clearColor] set];
108 NSBezierPath *path = [[self class] _clippingPathForFrame: rect];
111 [[NSColor colorWithCalibratedWhite:32/255.0 alpha:213/255.0] set];
115 NSRect titleBarRect = rect;
116 titleBarRect.origin.y += rect.size.height - [self titleBarHeight];
117 titleBarRect.size.height = [self titleBarHeight];
119 [self _drawTitleBar: titleBarRect];
122 - (NSRect)contentRectForFrameRect:(NSRect)frameRect styleMask:(unsigned int)aStyle
124 frameRect.size.width -= 2;
125 frameRect.origin.x += 1;
126 frameRect.size.height -= [self titleBarHeight];
131 - (NSRect)frameRectForContentRect:(NSRect)windowContent styleMask:(unsigned int)aStyle
133 windowContent.size.width += 2;
134 windowContent.origin.x -= 1;
135 windowContent.size.height += [self titleBarHeight];
136 return windowContent;
139 - (NSSize)_topCornerSize
141 return NSMakeSize(0, [self titleBarHeight]);
144 -(float)titleBarHeight
149 // Taken directly from Andy Matuschak's implementation
150 - (void)_drawResizeIndicators:(NSRect)rect
152 if (![[self window] showsResizeIndicator])
154 NSPoint resizeOrigin = NSMakePoint(NSMaxX([self frame]) - 3, 3);
155 NSBezierPath *resizeGrip = [NSBezierPath bezierPath];
156 [resizeGrip moveToPoint:NSMakePoint(resizeOrigin.x, resizeOrigin.y + 2)];
157 [resizeGrip lineToPoint:NSMakePoint(resizeOrigin.x - 3, resizeOrigin.y)];
158 [resizeGrip moveToPoint:NSMakePoint(resizeOrigin.x, resizeOrigin.y + 6)];
159 [resizeGrip lineToPoint:NSMakePoint(resizeOrigin.x - 7, resizeOrigin.y)];
160 [resizeGrip moveToPoint:NSMakePoint(resizeOrigin.x, resizeOrigin.y + 10)];
161 [resizeGrip lineToPoint:NSMakePoint(resizeOrigin.x - 11, resizeOrigin.y)];
162 [resizeGrip setLineWidth:1.0];
164 [[NSColor lightGrayColor] set];