-
Notifications
You must be signed in to change notification settings - Fork 6
/
SFCursorBallonView.m
84 lines (63 loc) · 2.88 KB
/
SFCursorBallonView.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
//
// SFCursorBallonView.m
// ShinyRuler
//
// Created by Matteo Rattotti on 1/9/10.
// Copyright 2010 www.shinyfrog.net. All rights reserved.
//
#import "SFCursorBallonView.h"
@implementation SFCursorBallonView
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
currentValue = -1;
initialColor = [NSColor colorWithCalibratedRed:0.49 green:0.58 blue:0.65 alpha:1];
finalColor = [NSColor colorWithCalibratedRed:0.69 green:0.74 blue:0.77 alpha:1];
strokeColor = [[NSColor colorWithCalibratedRed:0.41 green:0.41 blue:0.41 alpha:0.9]retain];
bgGradient = [[NSGradient alloc] initWithStartingColor:initialColor endingColor:finalColor];
if(frame.size.width > frame.size.height)
orizontal = YES;
}
return self;
}
- (void) dealloc{
[bgGradient release];
[strokeColor release];
[super dealloc];
}
- (void)drawRect:(NSRect)rect {
NSRect newFrame;// = NSInsetRect(rect, 1, 1);
if(orizontal)
newFrame = NSMakeRect(currentValue, 1, 58, 18);
else
newFrame = NSMakeRect(1, rect.size.height - currentValue - 22 , 58, 18);
NSBezierPath *ballonBox = [NSBezierPath bezierPathWithRoundedRect:newFrame xRadius:9 yRadius:9];
[bgGradient drawInBezierPath:ballonBox angle:90];
[strokeColor set];
[ballonBox stroke];
NSString *valueString = [NSString stringWithFormat:@"%d", currentValue];
NSFont *textFont = [NSFont fontWithName:@"Lucida Grande" size:10];
NSMutableDictionary *textAttr = [NSMutableDictionary dictionaryWithObjectsAndKeys:
textFont, NSFontAttributeName,
[NSColor whiteColor], NSForegroundColorAttributeName,
nil];
NSMutableDictionary *shadowTextAttr = [NSMutableDictionary dictionaryWithObjectsAndKeys:
textFont, NSFontAttributeName,
[NSColor colorWithCalibratedRed:0.41 green:0.41 blue:0.41 alpha:1.0], NSForegroundColorAttributeName,
nil];
NSSize textSize = [valueString sizeWithAttributes:textAttr];
NSPoint titleTextPoint;
if(orizontal)
titleTextPoint = NSMakePoint(newFrame.origin.x + (newFrame.size.width / 2.0) - (textSize.width / 2.0) , (newFrame.size.height - textSize.height)/2.0 + 1);
else
titleTextPoint = NSMakePoint(newFrame.origin.x + (newFrame.size.width / 2.0) - (textSize.width / 2.0) , rect.size.height - currentValue - 20);
NSPoint shadowTextPoint = titleTextPoint;
shadowTextPoint.y += 1;
[valueString drawAtPoint:shadowTextPoint withAttributes:shadowTextAttr];
[valueString drawAtPoint:titleTextPoint withAttributes:textAttr];
}
- (void) setCurrentValue: (int) newValue {
currentValue = newValue;
[self display];
}
@end