Recreate Finnish.lproj/MainMenu.nib.
[MacTF.git] / iLifeControls / NFHUDFrame.m
blob3af6d30b60a7f26047696db710aec01a53279739
1 //
2 //  NFHUDFrame.m
3 //  iLife HUD Window
4 //
5 //  Created by Sean Patrick O'Brien on 9/23/06.
6 //  Copyright 2006 Sean Patrick O'Brien. All rights reserved.
7 //
9 #import "NFHUDFrame.h"
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])
18         {
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]];
23                 titleCell = cell;
24                 
25                 // get the regular controls out of the picture
26                 [closeButton setHidden:YES];
27                 [minimizeButton setHidden:YES];
28                 [zoomButton setHidden:YES];
29                 
30                 // according to Andy Matuschak, the superclass doesn't do it's job here...
31                 [[self window] setShowsResizeIndicator:(style & NSResizableWindowMask)];
32                 
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, 
35                                                                                                                                                    13.0, 13.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];
46                 
47                 return self;
48         }
49         
50         return nil;
53 + (NSBezierPath*)_clippingPathForFrame:(NSRect)aRect
55         float radius = 6.5;
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
64                 toPoint: bottomRight
65                 radius: radius];
66         [path appendBezierPathWithArcFromPoint: bottomRight
67                 toPoint: aRect.origin
68                 radius: radius];
69         [path appendBezierPathWithArcFromPoint: aRect.origin
70                 toPoint: topLeft
71                 radius: radius];
72         [path appendBezierPathWithArcFromPoint: topLeft
73                 toPoint: topRight
74                 radius: radius];
75         [path closePath];
76         
77         return path;
80 - (NSRect)_titlebarTitleRect
82         NSRect rect = [super _titlebarTitleRect];
83         rect.origin.y++;
84         
85         return rect;
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];
96         NSRectFill(rect);
97         
98         [self _drawTitle:rect];
101 - (void)drawRect:(NSRect)_rect
103         NSRect rect = [self frame];
104         [[NSColor clearColor] set];
105         NSRectFill(rect);
106         NSRectFill(_rect);
107         
108         NSBezierPath *path = [[self class] _clippingPathForFrame: rect];
109         [path addClip];
110         
111         [[NSColor colorWithCalibratedWhite:32/255.0 alpha:213/255.0] set];
112         
113         NSRectFill(rect);
114         
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];
127     return frameRect;
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
146         return 19;
149 // Taken directly from Andy Matuschak's implementation
150 - (void)_drawResizeIndicators:(NSRect)rect
152         if (![[self window] showsResizeIndicator])
153                 return;
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];
163         
164         [[NSColor lightGrayColor] set];
165         [resizeGrip stroke];    
168 @end