5 // Created by Sean Patrick O'Brien on 9/15/06.
6 // Copyright 2006 Sean Patrick O'Brien. All rights reserved.
11 #import "CTGradient.h"
12 #import "EtchedTextCell.h"
13 #import "NSImage+FrameworkImage.h"
15 @implementation NFIFrame
17 - (id)initWithFrame:(struct _NSRect)frame styleMask:(unsigned int)style owner:(id)o
19 self = [super initWithFrame:frame styleMask:style owner:o];
20 mTitleBarHeight = 25.0f;
25 mInnerGradient = [[CTGradient gradientWithBeginningColor: [self gradientStartColor]
26 endingColor:[self gradientEndColor]] retain];
27 mOuterGradient = [[CTGradient gradientWithBeginningColor: [self gradient2StartColor]
28 endingColor:[self gradient2EndColor]] retain];
30 titleCell = [[EtchedTextCell alloc] initTextCell: @""];
31 [titleCell setFont:[NSFont fontWithName:@"LucidaGrande" size:13.0]];
32 [titleCell setShadowColor:[NSColor whiteColor]];
37 - (NSSize)_topCornerSize
39 return NSMakeSize(0, [self titleBarHeight]);
42 + (NSBezierPath*)_clippingPathForFrame:(NSRect)aRect
44 float radius = [self cornerRadius];
45 NSBezierPath *path = [NSBezierPath alloc];
46 NSPoint topMid = NSMakePoint(NSMidX(aRect), NSMaxY(aRect));
47 NSPoint topLeft = NSMakePoint(NSMinX(aRect), NSMaxY(aRect));
48 NSPoint topRight = NSMakePoint(NSMaxX(aRect), NSMaxY(aRect));
49 NSPoint bottomRight = NSMakePoint(NSMaxX(aRect), NSMinY(aRect));
51 [path moveToPoint: topMid];
52 [path appendBezierPathWithArcFromPoint: topRight
55 [path appendBezierPathWithArcFromPoint: bottomRight
58 [path appendBezierPathWithArcFromPoint: aRect.origin
61 [path appendBezierPathWithArcFromPoint: topLeft
69 - (void)_drawTitle:(NSRect)rect
71 [self _drawTitleStringIn:rect withColor:[self titleColor]];
74 - (void)_drawTitleBar:(NSRect)rect
76 [[self topWindowEdgeColor] set];
79 [[self bottomEdgeColor] set];
83 NSRect gradientRect = rect;
84 gradientRect.origin.y++;
85 gradientRect.size.height -= 2;
86 [mOuterGradient fillRect: gradientRect angle:-90.0f];
87 gradientRect.origin.x++;
88 gradientRect.size.width -= 2;
89 [mInnerGradient fillRect: gradientRect angle:-90.0f];
91 NSImage *topLeft = [NSImage frameworkImageNamed: @"IWWindowCornerTL"];
92 NSImage *topRight = [NSImage frameworkImageNamed: @"IWWindowCornerTR"];
94 [topLeft compositeToPoint:NSMakePoint(rect.origin.x,
95 rect.origin.y + [self titleBarHeight] - [topLeft size].height) operation: NSCompositeSourceOver];
96 [topRight compositeToPoint:NSMakePoint(rect.origin.x + rect.size.width-[topRight size].width,
97 rect.origin.y + [self titleBarHeight] - [topLeft size].height) operation: NSCompositeSourceOver];
99 [self _drawTitle:rect];
102 - (void)_drawMidBar:(NSRect)rect
104 [[self bottomWindowEdgeColor] set];
108 [[self bottomEdgeColor] set];
110 rect.size.height -= 2;
112 [[self edgeColor] set];
114 rect.size.height += 3;
117 NSRect gradientRect = rect;
118 gradientRect.origin.y++;
119 gradientRect.size.height -= 3;
120 [mOuterGradient fillRect: gradientRect angle:-90.0f];
121 gradientRect.origin.x++;
122 gradientRect.size.width -= 2;
123 [mInnerGradient fillRect: gradientRect angle:-90.0f];
126 - (void)_drawBottomBar:(NSRect)rect
128 [[self bottomWindowEdgeColor] set];
132 [[self bottomEdgeColor] set];
134 rect.size.height -= 2;
136 [[self edgeColor] set];
138 rect.size.height += 3;
141 NSRect gradientRect = rect;
142 gradientRect.origin.y++;
143 gradientRect.size.height -= 3;
144 [mOuterGradient fillRect: gradientRect angle:-90.0f];
145 gradientRect.origin.x++;
146 gradientRect.size.width -= 2;
147 [mInnerGradient fillRect: gradientRect angle:-90.0f];
149 NSImage *bottomLeft = [NSImage frameworkImageNamed: @"IWWindowCornerBL"];
150 NSImage *bottomRight = [NSImage frameworkImageNamed: @"IWWindowCornerBR"];
152 [bottomLeft compositeToPoint:NSMakePoint(rect.origin.x, rect.origin.y) operation: NSCompositeSourceOver];
153 [bottomRight compositeToPoint:NSMakePoint(rect.origin.x + rect.size.width-[bottomRight size].width, rect.origin.y) operation: NSCompositeSourceOver];
156 - (void)drawRect:(struct _NSRect)_rect
158 NSRect rect = [self bounds];
159 [[NSColor clearColor] set];
163 NSBezierPath *path = [[self class] _clippingPathForFrame: rect];
166 [[self backgroundColor] set];
170 NSRect titleBarRect = rect;
171 titleBarRect.origin.y += rect.size.height - [self titleBarHeight];
172 titleBarRect.size.height = [self titleBarHeight];
174 NSRect bottomBarRect = rect;
175 bottomBarRect.size.height = [self bottomBarHeight];
177 NSRect midBarRect = rect;
178 midBarRect.origin.y += [self midBarOriginY];
179 midBarRect.size.height = [self midBarHeight];
181 [self _drawMidBar: midBarRect];
182 [self _drawTitleBar: titleBarRect];
183 [self _drawBottomBar: bottomBarRect];
186 - (void)_drawGrowBoxWithClip:(struct _NSRect)rect
190 NSImage *resize = [NSImage frameworkImageNamed:@"IWWindowResizeControl"];
191 [resize compositeToPoint:rect.origin operation: NSCompositeSourceOver];
194 - (float)titleBarHeight
196 if([self _toolbarIsShown])
197 return mTitleBarHeight + [self _distanceFromToolbarBaseToTitlebar];
198 return mTitleBarHeight;
201 - (void)setTitleBarHeight:(float)height
203 mTitleBarHeight = height;
204 [self setNeedsDisplay:YES];
207 - (float)bottomBarHeight
209 return mBottomBarHeight;
212 - (void)setBottomBarHeight:(float)height
214 mBottomBarHeight = height;
215 [self setNeedsDisplay:YES];
218 - (float)midBarHeight
220 return mMidBarHeight;
223 - (float)midBarOriginY
225 return mMidBarOriginY;
228 - (void)setMidBarHeight:(float)height origin:(float)origin
230 mMidBarHeight = height;
231 mMidBarOriginY = origin;
232 [self setNeedsDisplay:YES];
235 - (NSRect)contentRectForFrameRect:(NSRect)frameRect styleMask:(unsigned int)aStyle
237 frameRect.size.height -= 25;//[self titleBarHeight];
241 - (NSRect)frameRectForContentRect:(NSRect)windowContent styleMask:(unsigned int)aStyle
243 windowContent.size.height += 25;//[self titleBarHeight];
244 return windowContent;
247 - (void)_showToolbarWithAnimation:(BOOL)animate
249 [super _showToolbarWithAnimation:animate];
250 [self setNeedsDisplay:YES];
253 - (id)backgroundColor
255 return [NSColor colorWithCalibratedWhite: 224/255.0 alpha: 1.0];
258 - (id)gradientStartColor
260 return [NSColor colorWithCalibratedWhite: 197/255.0 alpha: 1.0];
263 - (id)gradientEndColor
265 return [NSColor colorWithCalibratedWhite: 150/255.0 alpha: 1.0];
268 - (id)gradient2StartColor
270 return [NSColor colorWithCalibratedWhite: 179/255.0 alpha: 1.0];
273 - (id)gradient2EndColor
275 return [NSColor colorWithCalibratedWhite: 139/255.0 alpha: 1.0];
280 return [NSColor colorWithCalibratedWhite: 226/255.0 alpha: 1.0];
283 - (id)bottomEdgeColor
285 return [NSColor colorWithCalibratedWhite: 102/255.0 alpha: 1.0];
288 - (id)topWindowEdgeColor
290 return [NSColor colorWithCalibratedWhite: 222/255.0 alpha: 1.0];
293 - (id)bottomWindowEdgeColor
295 return [NSColor colorWithCalibratedWhite: 65/255.0 alpha: 1.0];
300 if([[self window] isMainWindow])
301 return [NSColor colorWithCalibratedWhite:0 alpha:0.9];
302 return [NSColor colorWithCalibratedWhite:0 alpha:0.50];
305 + (float)cornerRadius