Prominent notice in UIElements.m.
[MacTF.git] / iLifeControls / NFIFrame.m
blob37ccc661cf8b3ff699890b3920f0ecc37e6cd449
1 //
2 //  NFIFrame.m
3 //  CustomWindow
4 //
5 //  Created by Sean Patrick O'Brien on 9/15/06.
6 //  Copyright 2006 Sean Patrick O'Brien. All rights reserved.
7 //
9 #import "NFIFrame.h"
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;
21         mBottomBarHeight = 0;
22         mMidBarOriginY = 0;
23         mMidBarHeight = 0;
24         
25         mInnerGradient = [[CTGradient gradientWithBeginningColor: [self gradientStartColor]
26                                                 endingColor:[self gradientEndColor]] retain];
27         mOuterGradient = [[CTGradient gradientWithBeginningColor: [self gradient2StartColor]
28                                                 endingColor:[self gradient2EndColor]] retain];
29                                                                 
30         titleCell = [[EtchedTextCell alloc] initTextCell: @""];
31         [titleCell setFont:[NSFont fontWithName:@"LucidaGrande" size:13.0]];
32         [titleCell setShadowColor:[NSColor whiteColor]];
33         
34         return self;
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
53                 toPoint: bottomRight
54                 radius: radius];
55         [path appendBezierPathWithArcFromPoint: bottomRight
56                 toPoint: aRect.origin
57                 radius: radius];
58         [path appendBezierPathWithArcFromPoint: aRect.origin
59                 toPoint: topLeft
60                 radius: radius];
61         [path appendBezierPathWithArcFromPoint: topLeft
62                 toPoint: topRight
63                 radius: radius];
64         [path closePath];
65         
66         return path;
69 - (void)_drawTitle:(NSRect)rect
71         [self _drawTitleStringIn:rect withColor:[self titleColor]];
74 - (void)_drawTitleBar:(NSRect)rect
76         [[self topWindowEdgeColor] set];
77         NSRectFill(rect);
78         rect.size.height--;
79         [[self bottomEdgeColor] set];
80         NSRectFill(rect);
81         rect.size.height++;
82         
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];
90         
91         NSImage *topLeft = [NSImage frameworkImageNamed: @"IWWindowCornerTL"];
92         NSImage *topRight = [NSImage frameworkImageNamed: @"IWWindowCornerTR"];
93         
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];
98         
99         [self _drawTitle:rect];
102 - (void)_drawMidBar:(NSRect)rect
104         [[self bottomWindowEdgeColor] set];
105         NSRectFill(rect);
106         rect.origin.y++;
107         rect.size.height--;
108         [[self bottomEdgeColor] set];
109         NSRectFill(rect);
110         rect.size.height -= 2;
111         rect.origin.y++;
112         [[self edgeColor] set];
113         NSRectFill(rect);
114         rect.size.height += 3;
115         rect.origin.y -= 2;
116         
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];
129         NSRectFill(rect);
130         rect.origin.y++;
131         rect.size.height--;
132         [[self bottomEdgeColor] set];
133         NSRectFill(rect);
134         rect.size.height -= 2;
135         rect.origin.y++;
136         [[self edgeColor] set];
137         NSRectFill(rect);
138         rect.size.height += 3;
139         rect.origin.y -= 2;
140         
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];
148         
149         NSImage *bottomLeft = [NSImage frameworkImageNamed: @"IWWindowCornerBL"];
150         NSImage *bottomRight = [NSImage frameworkImageNamed: @"IWWindowCornerBR"];
151         
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];
160         NSRectFill(rect);
161         NSRectFill(_rect);
162         
163         NSBezierPath *path = [[self class] _clippingPathForFrame: rect];
164         [path addClip];
165         
166         [[self backgroundColor] set];
167         
168         NSRectFill(rect);
169         
170         NSRect titleBarRect = rect;
171         titleBarRect.origin.y += rect.size.height - [self titleBarHeight];
172         titleBarRect.size.height = [self titleBarHeight];
173         
174         NSRect bottomBarRect = rect;
175         bottomBarRect.size.height = [self bottomBarHeight];
176         
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
188         rect.origin.x += 3;
189         rect.origin.y += 2;
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];
238     return frameRect;
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];
278 - (id)edgeColor
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];
298 - (id)titleColor
300         if([[self window] isMainWindow])
301                 return [NSColor colorWithCalibratedWhite:0 alpha:0.9];
302         return [NSColor colorWithCalibratedWhite:0 alpha:0.50];
305 + (float)cornerRadius
307         return 5.0;
310 @end