| | 258 | - (NSBezierPath *)arrowPathInSize:(NSSize)arrowSize pointingDown:(BOOL)pointItDown |
|---|
| | 259 | { |
|---|
| | 260 | if(!arrowPath) { |
|---|
| | 261 | arrowPath = [[NSBezierPath bezierPath] retain]; |
|---|
| | 262 | |
|---|
| | 263 | /* 5 |
|---|
| | 264 | * / \ |
|---|
| | 265 | * / \ 1-7 = points |
|---|
| | 266 | *6-7 3-4 the point of the triangle is 100% from the bottom. |
|---|
| | 267 | * | the back edge of the triangle is 50% from the bottom. |
|---|
| | 268 | * 1-2 |
|---|
| | 269 | */ |
|---|
| | 270 | |
|---|
| | 271 | # define ONE_THIRD (1.0/3.0) |
|---|
| | 272 | # define TWO_THIRDS (2.0/3.0) |
|---|
| | 273 | # define ONE_HALF 0.5 |
|---|
| | 274 | |
|---|
| | 275 | //start with the bottom vertex. |
|---|
| | 276 | [arrowPath moveToPoint:NSMakePoint(ONE_THIRD, 0.0)]; //1 |
|---|
| | 277 | [arrowPath lineToPoint:NSMakePoint(TWO_THIRDS, 0.0)]; //2 |
|---|
| | 278 | //up to the inner right corner. |
|---|
| | 279 | [arrowPath relativeLineToPoint:NSMakePoint(0.0, ONE_HALF)]; //3 |
|---|
| | 280 | //far right. |
|---|
| | 281 | [arrowPath relativeLineToPoint:NSMakePoint(ONE_THIRD, 0.0)]; //4 |
|---|
| | 282 | //top center - the point of the arrow. |
|---|
| | 283 | [arrowPath lineToPoint:NSMakePoint(ONE_HALF, 1.0)]; //5 |
|---|
| | 284 | //far left. |
|---|
| | 285 | [arrowPath lineToPoint:NSMakePoint(0.0, ONE_HALF)]; //6 |
|---|
| | 286 | //inner left corner. |
|---|
| | 287 | [arrowPath relativeLineToPoint:NSMakePoint(ONE_THIRD, 0.0)]; //7 |
|---|
| | 288 | //to the finish line! yay! |
|---|
| | 289 | [arrowPath closePath]; |
|---|
| | 290 | } |
|---|
| | 291 | |
|---|
| | 292 | NSBezierPath *path = [arrowPath copy]; |
|---|
| | 293 | |
|---|
| | 294 | NSAffineTransform *transform = [NSAffineTransform transform]; |
|---|
| | 295 | |
|---|
| | 296 | if(pointItDown) { |
|---|
| | 297 | //http://developer.apple.com/documentation/Carbon/Conceptual/QuickDrawToQuartz2D/tq_other/chapter_3_section_2.html |
|---|
| | 298 | [transform translateXBy:0.0 yBy:1.0]; |
|---|
| | 299 | [transform scaleXBy:1.0 yBy:-1.0]; |
|---|
| | 300 | |
|---|
| | 301 | [path transformUsingAffineTransform:transform]; |
|---|
| | 302 | |
|---|
| | 303 | transform = [NSAffineTransform transform]; |
|---|
| | 304 | } |
|---|
| | 305 | |
|---|
| | 306 | [transform scaleXBy:arrowSize.width yBy:arrowSize.height]; |
|---|
| | 307 | |
|---|
| | 308 | [path transformUsingAffineTransform:transform]; |
|---|
| | 309 | |
|---|
| | 310 | return [path autorelease]; |
|---|
| | 311 | } |
|---|
| | 312 | |
|---|