-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW] Migrate from PNG-based badge to vector drawing-based badge. (Tr…
…oy Gaul)
- Loading branch information
Showing
4 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// NSBezierPath-RoundedRectangle.h | ||
// Based on http://www.cocoadev.com/index.pl?RoundedRectangles | ||
// Switched to a function instead of a category class method for use in a plug-in. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
/** | ||
Returns a closed bezier path describing a rectangle with curved corners | ||
The corner radius will be trimmed to not exceed half of the lesser rectangle dimension. | ||
*/ | ||
NSBezierPath* bezierPathWithRoundedRectCornerRadius( NSRect aRect, double radius ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// NSBezierPath-RoundedRectangle.m | ||
// Based on http://www.cocoadev.com/index.pl?RoundedRectangles | ||
// Switched to a function instead of a category class method for use in a plug-in. | ||
// | ||
|
||
#import "NSBezierPath-RoundedRectangle.h" | ||
|
||
NSBezierPath* bezierPathWithRoundedRectCornerRadius( NSRect aRect, double cRadius ) | ||
{ | ||
double left = aRect.origin.x, bottom = aRect.origin.y, width = aRect.size.width, height = aRect.size.height; | ||
|
||
//now, crop the radius so we don't get weird effects | ||
double lesserDim = width < height ? width : height; | ||
if ( cRadius > lesserDim / 2 ) | ||
{ | ||
cRadius = lesserDim / 2; | ||
} | ||
|
||
//these points describe the rectangle as start and stop points of the | ||
//arcs making up its corners --points c, e, & g are implicit endpoints of arcs | ||
//and are unnecessary | ||
NSPoint a = NSMakePoint( 0, cRadius ), b = NSMakePoint( 0, height - cRadius ), | ||
d = NSMakePoint( width - cRadius, height ), f = NSMakePoint( width, cRadius ), | ||
h = NSMakePoint( cRadius, 0 ); | ||
|
||
//these points describe the center points of the corner arcs | ||
NSPoint cA = NSMakePoint( cRadius, height - cRadius ), | ||
cB = NSMakePoint( width - cRadius, height - cRadius ), | ||
cC = NSMakePoint( width - cRadius, cRadius ), | ||
cD = NSMakePoint( cRadius, cRadius ); | ||
|
||
//start | ||
NSBezierPath *bp = [NSBezierPath bezierPath]; | ||
[bp moveToPoint: a ]; | ||
[bp lineToPoint: b ]; | ||
[bp appendBezierPathWithArcWithCenter: cA radius: cRadius startAngle:180 endAngle:90 clockwise: YES]; | ||
[bp lineToPoint: d ]; | ||
[bp appendBezierPathWithArcWithCenter: cB radius: cRadius startAngle:90 endAngle:0 clockwise: YES]; | ||
[bp lineToPoint: f ]; | ||
[bp appendBezierPathWithArcWithCenter: cC radius: cRadius startAngle:0 endAngle:270 clockwise: YES]; | ||
[bp lineToPoint: h ]; | ||
[bp appendBezierPathWithArcWithCenter: cD radius: cRadius startAngle:270 endAngle:180 clockwise: YES]; | ||
[bp closePath]; | ||
|
||
//Transform path to rectangle's origin | ||
NSAffineTransform *transform = [NSAffineTransform transform]; | ||
[transform translateXBy: left yBy: bottom]; | ||
[bp transformUsingAffineTransform: transform]; | ||
|
||
return bp; //it's already been autoreleased | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters