forked from ttscoff/nv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWordCountToken.m
145 lines (121 loc) · 3.77 KB
/
WordCountToken.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//
// WordCountToken.m
// Notation
//
// Created by ElasticThreads on 3/1/11.
//
#import "WordCountToken.h"
#import "AppController.h"
//#import <QuartzCore/QuartzCore.h>
@implementation WordCountToken
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)awakeFromNib{
[self refusesFirstResponder];
//theGrad = [[[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedWhite:0.2f alpha:0.28f] endingColor:[NSColor colorWithCalibratedWhite:0.74f alpha:0.18f]] retain];
//[self setTxtColor:[[NSApp delegate] foregrndColor]];
//[self setFldColor:[[NSApp delegate] backgrndColor]];
}
- (void)mouseDown:(NSEvent *)theEvent{
[[NSApp delegate] toggleWordCount:self];
}
/*
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
//[self resetCursorRects];
//[[NSColor whiteColor] set];
//NSRectFill([self bounds]);
NSString *text = [self stringValue];
if ([text isEqualToString:@""]) {
[[NSApp delegate] updateWordCount];
}
static NSMutableParagraphStyle *alignStyle = nil;
if (!alignStyle) {
alignStyle = [[NSMutableParagraphStyle alloc] init];
[alignStyle setAlignment:NSCenterTextAlignment];
}
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:alignStyle, NSParagraphStyleAttributeName, [NSFont fontWithName:@"Helvetica" size:8.0f],NSFontAttributeName,txtColor,NSForegroundColorAttributeName, nil];
// NSAttributedString *theStr = [NSAttributedString initWithString:text attributes:options];
//[self setAttributedStringValue:theStr];
NSRect labelRect = [text boundingRectWithSize:[self bounds].size options:nil attributes:options];
NSRect aRect = labelRect;
aRect.origin = [self bounds].origin;;
aRect.origin.x = [self bounds].origin.x + [self bounds].size.width - aRect.size.width - 7.0f;
if ((aRect.size.width*1.9)>20.f) {
aRect.size.width = aRect.size.width*1.9;
}else {
aRect.size.width += 20.0f;
}
//aRect.size.height = aRect.size.height *1.2f;
CGFloat ht = aRect.size.height *.6;
CGFloat wdth = aRect.size.width * .06;
NSBezierPath *path1 = [NSBezierPath bezierPathWithRoundedRect:aRect xRadius:wdth yRadius:ht];
[path1 setLineWidth:0.8f];
[txtColor set];
[path1 stroke];
[fldColor set];
[path1 fill];
[theGrad drawInBezierPath:path1 angle:270.0f];
labelRect = [text boundingRectWithSize:aRect.size options:nil attributes:options];
NSPoint thePoint = aRect.origin;
thePoint.x += (aRect.size.width - labelRect.size.width)/2.0f;
thePoint.x -= 1.0f;
[text drawAtPoint:thePoint withAttributes:options];
}
*/
/*
- (void)setTxtColor:(NSColor *)inColor{
if (txtColor) {
[txtColor release];
}
inColor = [NSColor whiteColor];
CGFloat fWhite;
fWhite = [[inColor colorUsingColorSpaceName:NSCalibratedWhiteColorSpace] whiteComponent];
if (fWhite < 0.62f) {
if (fWhite<0.10f) {
fWhite += 0.2f;
}else {
fWhite += 0.1f;
}
}else {
fWhite -= 0.1f;
}
txtColor = [NSColor colorWithCalibratedWhite:0.28f alpha:1.0f];
//txtColor = inColor;
[txtColor retain];
[self setTextColor:txtColor];
}
- (void)setFldColor:(NSColor *)inColor{
if (fldColor) {
[fldColor release];
}
inColor = [NSColor lightGrayColor];
CGFloat fWhite;
fWhite = [[[NSColor lightGrayColor] colorUsingColorSpaceName:NSCalibratedWhiteColorSpace] whiteComponent];
if (fWhite > 0.25f) {
if (fWhite>0.90f) {
fWhite -= 0.25f;
}else {
fWhite -= 0.25f;
}
}else {
fWhite += 0.14f;
}
fldColor = [NSColor colorWithCalibratedWhite:0.66f alpha:0.65f];
//fldColor = [NSColor lightGrayColor];
[fldColor retain];
}
-(void)resetCursorRects
{
// remove the existing cursor rects
[self discardCursorRects];
[self addCursorRect:[self visibleRect] cursor:[NSCursor arrowCursor]];
}
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent{
return YES;
}*/
@end