-
Notifications
You must be signed in to change notification settings - Fork 1
/
SPAnalyzerScaleSideView.mm
127 lines (95 loc) · 3.98 KB
/
SPAnalyzerScaleSideView.mm
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
#import "SPAnalyzerWindowController.h"
#import "SPAnalyzerScaleSideView.h"
@implementation SPAnalyzerScaleSideView
// ----------------------------------------------------------------------------
- (id)initWithFrame:(NSRect)frame
// ----------------------------------------------------------------------------
{
self = [super initWithFrame:frame];
if (self)
{
stepValues = nil;
}
return self;
}
// ----------------------------------------------------------------------------
- (NSArray*) stepValues
// ----------------------------------------------------------------------------
{
return stepValues;
}
// ----------------------------------------------------------------------------
- (void) setStepValues:(NSArray*)inStepValues
// ----------------------------------------------------------------------------
{
stepValues = inStepValues;
}
// ----------------------------------------------------------------------------
- (const char*) formatString
// ----------------------------------------------------------------------------
{
return formatString;
}
// ----------------------------------------------------------------------------
- (void) setFormatString:(const char*)inFormatString
// ----------------------------------------------------------------------------
{
formatString = inFormatString;
}
// ----------------------------------------------------------------------------
- (BOOL) isOpaque
// ----------------------------------------------------------------------------
{
return YES;
}
// ----------------------------------------------------------------------------
- (void)drawRect:(NSRect)rect
// ----------------------------------------------------------------------------
{
NSRect bounds = [self bounds];
[[SPAnalyzerWindowController sharedInstance] drawBackgroundInRect:bounds];
[NSBezierPath setDefaultLineWidth:1.0f];
NSColor* lineColor1 = [NSColor colorWithCalibratedWhite:0.20f alpha:1.0f];
NSColor* lineColor2 = [NSColor colorWithCalibratedWhite:0.51f alpha:1.0f];
float textIntensity = 0.51f;
CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
CGContextSelectFont(context, "Monaco", 8.0f, kCGEncodingMacRoman);
CGContextSetRGBStrokeColor(context, textIntensity, textIntensity, textIntensity, 1.0f);
CGContextSetRGBFillColor(context, textIntensity, textIntensity, textIntensity, 1.0f);
CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0f, 1.0f));
float yOffset = 6.0f;
float drawHeight = NSHeight(bounds) - yOffset * 2.0f;
NSBezierPath* path1 = [NSBezierPath bezierPath];
NSBezierPath* path2 = [NSBezierPath bezierPath];
float previousYPos = -100.0f;
if (drawHeight < 14.0f)
return;
for (int i = 0; i < [stepValues count]; i++)
{
float yPos = floorf(drawHeight * float(i) / float([stepValues count] - 1) + yOffset) + 0.5f;
[lineColor1 set];
[path1 moveToPoint:NSMakePoint(bounds.origin.x + rect.size.width - 7.0f, yPos + 1.0f)];
[path1 lineToPoint:NSMakePoint(bounds.origin.x + rect.size.width - 1.0f, yPos + 1.0f)];
[path1 stroke];
[lineColor2 set];
[path2 moveToPoint:NSMakePoint(bounds.origin.x + rect.size.width - 7.0f, yPos)];
[path2 lineToPoint:NSMakePoint(bounds.origin.x + rect.size.width - 1.0f, yPos)];
[path2 stroke];
if ((yPos - previousYPos) < 9.0f)
continue;
previousYPos = yPos;
if (drawHeight >= 18.0f)
{
char stringBuffer[16];
snprintf(stringBuffer, 15, formatString, [(NSNumber*)[stepValues objectAtIndex:i] integerValue]);
CGPoint startPoint = CGContextGetTextPosition(context);
CGContextSetTextDrawingMode(context, kCGTextInvisible);
CGContextShowTextAtPoint(context, startPoint.x, startPoint.y, stringBuffer, strlen(stringBuffer));
CGPoint endPoint = CGContextGetTextPosition(context);
float width = endPoint.x - startPoint.x;
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextShowTextAtPoint(context, bounds.origin.x + bounds.size.width - width - 9.0f, yPos - 3.0f, stringBuffer, strlen(stringBuffer));
}
}
}
@end