-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTMSliderControlSmall.m
86 lines (71 loc) · 2.03 KB
/
TMSliderControlSmall.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
//
// TMSliderControlSmall.m
// TMSliderControl
//
// Created by Rick Fillion on 10-12-19.
// All code is provided under the New BSD license.
//
#import "TMSliderControlSmall.h"
@interface TMSliderControlSmall (Private)
- (void)drawBacking;
- (void)drawHandle;
@end
@implementation TMSliderControlSmall (Private)
- (void)drawBacking
{
[sliderWellOff drawInRect:[self bounds] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
CGFloat percentOn = (handleControlRect.origin.x - handleControlRectOff.origin.x) / (handleControlRectOn.origin.x - handleControlRectOff.origin.x);
[sliderWellOn drawInRect:[self bounds] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:percentOn];
}
- (void)drawHandle
{
NSImage *sliderImage;
if (controlState == kTMSliderControlState_Active)
{
sliderImage = sliderHandleDown;
}
else
{
sliderImage = sliderHandle;
}
[sliderHandleView setImage: sliderImage];
}
- (void)layoutHandle
{
handleControlRectOff = NSMakeRect(0,0, 27, 18);
handleControlRectOn = NSMakeRect([self bounds].size.width - 27, 0, 27, 18);
handleControlRect = handleControlRectOff;
}
@end
@implementation TMSliderControlSmall
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
sliderWellOn = [[NSImage imageNamed:@"SmallSliderWellOn"] retain];
sliderWellOff = [[NSImage imageNamed:@"SmallSliderWellOff"] retain];
[sliderHandle release];
sliderHandle = [[NSImage imageNamed:@"SmallSliderHandle"] retain];
[sliderHandleDown release];
sliderHandleDown = [[NSImage imageNamed:@"SmallSliderHandleDown"] retain];
[self layoutHandle];
}
return self;
}
- (void)dealloc
{
[sliderWellOn release];
[sliderWellOff release];
[sliderHandle release];
[sliderHandleDown release];
[super dealloc];
}
- (void)drawRect:(NSRect)rect {
[self drawBacking];
[self drawHandle];
}
- (BOOL)isFlipped
{
return NO;
}
@end