This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
RoundPointView.m
83 lines (67 loc) · 2.71 KB
/
RoundPointView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// RoundPointView.m
// PointWindow
//
// Created by Ben Gummer on 22/04/08.
// Copyright 2008 Ben Gummer. All rights reserved.
//
#import "RoundPointView.h"
#import "CTGradient.h"
@implementation RoundPointView
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.triangleCenter = frame.size.width/2;
self.triangleHeight = 15.0;
self.cornerRadius = 8.0;
self.triangleWidth = 25.0;
}
return self;
}
- (void)drawRect:(NSRect)rect {
NSRect realSize = [self bounds];
float entireWidth = realSize.size.width;
float entireHeight = realSize.size.height;
NSBezierPath *bezierPath = [NSBezierPath bezierPath];
[bezierPath setLineWidth:0.5];
//bottom left
[bezierPath appendBezierPathWithArcWithCenter:NSMakePoint(cornerRadius, cornerRadius) radius:cornerRadius startAngle:180.0 endAngle:270.0];
//bottom right
[bezierPath appendBezierPathWithArcWithCenter:NSMakePoint(entireWidth-cornerRadius, cornerRadius) radius:cornerRadius startAngle:270.0 endAngle:360.0];
//top right
[bezierPath appendBezierPathWithArcWithCenter:NSMakePoint(entireWidth-cornerRadius, entireHeight-cornerRadius-triangleHeight) radius:cornerRadius startAngle: 0.0 endAngle: 90.0];
//triangle
[bezierPath lineToPoint:NSMakePoint(triangleCenter+(triangleWidth/2),entireHeight-triangleHeight)];
[bezierPath lineToPoint:NSMakePoint(triangleCenter,entireHeight)];
[bezierPath lineToPoint:NSMakePoint(triangleCenter-(triangleWidth/2),entireHeight-triangleHeight)];
//top left
[bezierPath appendBezierPathWithArcWithCenter:NSMakePoint(cornerRadius, entireHeight-cornerRadius-triangleHeight) radius:cornerRadius startAngle: 90.0 endAngle:180.0];
[bezierPath closePath];
[[CTGradient unifiedNormalGradient] fillBezierPath:bezierPath angle:90.0];
[[NSColor darkGrayColor] set];
[bezierPath setFlatness:0.1];
[bezierPath stroke];
/* NSBezierPath *highlightLine = [NSBezierPath bezierPath];
[highlightLine moveToPoint:NSMakePoint(cornerRadius, entireHeight-triangleHeight-2)];
[highlightLine lineToPoint:NSMakePoint(triangleCenter-(triangleWidth/2), entireHeight-triangleHeight-2)];
[highlightLine moveToPoint:NSMakePoint(triangleCenter+(triangleWidth/2), entireHeight-triangleHeight-2)];
[highlightLine lineToPoint:NSMakePoint(entireWidth-cornerRadius, entireHeight-triangleHeight-2)];
[highlightLine closePath];
[[NSColor colorWithCalibratedWhite:1.0 alpha:1.0] set];
[highlightLine setLineWidth:0.5];
[highlightLine stroke];*/
}
-(BOOL)acceptsFirstResponder {
return YES;
}
-(BOOL)canBecomeKeyView {
return YES;
}
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent {
return YES;
}
@synthesize triangleCenter;
@synthesize triangleHeight;
@synthesize triangleWidth;
@synthesize cornerRadius;
@end