HistoryView: Don't show the 'loading commit' thing until after 500 ms.
[GitX.git] / RoundedRectangle.m
blobbba804c3a820c9db026d3d4648016a4a752529a4
1 //
2 //  RoundedRectangle.m
3 //  GitX
4 //
5 //  Created by Pieter de Bie on 24-09-08.
6 //  Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
9 #import "RoundedRectangle.h"
12 @implementation NSBezierPath (RoundedRectangle)
13 + (NSBezierPath *)bezierPathWithRoundedRect: (NSRect) aRect cornerRadius: (double) cRadius
15         double left = aRect.origin.x, bottom = aRect.origin.y, width = aRect.size.width, height = aRect.size.height;
16         
17         //now, crop the radius so we don't get weird effects
18         double lesserDim = width < height ? width : height;
19         if ( cRadius > lesserDim / 2 )
20         {
21                 cRadius = lesserDim / 2;
22         }
23         
24         //these points describe the rectangle as start and stop points of the
25         //arcs making up its corners --points c, e, & g are implicit endpoints of arcs
26         //and are unnecessary
27         NSPoint a = NSMakePoint( 0, cRadius ), b = NSMakePoint( 0, height - cRadius ),
28         d = NSMakePoint( width - cRadius, height ), f = NSMakePoint( width, cRadius ),
29         h = NSMakePoint( cRadius, 0 );
30         
31         //these points describe the center points of the corner arcs
32         NSPoint cA = NSMakePoint( cRadius, height - cRadius ),
33         cB = NSMakePoint( width - cRadius, height - cRadius ),
34         cC = NSMakePoint( width - cRadius, cRadius ),
35         cD = NSMakePoint( cRadius, cRadius );
36         
37         //start
38         NSBezierPath *bp = [NSBezierPath bezierPath];
39         [bp moveToPoint: a ];
40         [bp lineToPoint: b ];
41         [bp appendBezierPathWithArcWithCenter: cA radius: cRadius startAngle:180 endAngle:90 clockwise: YES];
42         [bp lineToPoint: d ];
43         [bp appendBezierPathWithArcWithCenter: cB radius: cRadius startAngle:90 endAngle:0 clockwise: YES];
44         [bp lineToPoint: f ];
45         [bp appendBezierPathWithArcWithCenter: cC radius: cRadius startAngle:0 endAngle:270 clockwise: YES];
46         [bp lineToPoint: h ];
47         [bp appendBezierPathWithArcWithCenter: cD radius: cRadius startAngle:270 endAngle:180 clockwise: YES];  
48         [bp closePath];
49         
50         //Transform path to rectangle's origin
51         NSAffineTransform *transform = [NSAffineTransform transform];
52         [transform translateXBy: left yBy: bottom];
53         [bp transformUsingAffineTransform: transform];
54         
55         return bp; //it's already been autoreleased
57 @end