-
Notifications
You must be signed in to change notification settings - Fork 3
/
Stepper.j
137 lines (109 loc) · 3.27 KB
/
Stepper.j
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
@import <AppKit/CPControl.j>
@import <AppKit/CPButton.j>
@implementation Stepper : CPControl
{
CPButton _upButton;
CPButton _bottomButton;
CPView _splitter;
double _minValue;
double _maxValue;
double _increment;
BOOL _valueWraps;
BOOL _autorepeat;
}
-(id)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if(self){
[self setMaxValue:59.0];
[self setMinValue:0.0];
[self setIncrement:1.0];
[self setAutorepeat:YES];
[self setValueWraps:YES];
[self setDoubleValue:0.0];
_upButton = [[CPButton alloc] initWithFrame: CGRectMake(0.0, 0.0, 12.0, 10.0)];
_bottomButton = [[CPButton alloc] initWithFrame: CGRectMake(0.0, 11.0, 12.0, 12.0)];
_splitter = [[CPView alloc] initWithFrame: CGRectMake(0.0, 10.0, 12.0, 1.0)];
[_upButton setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"Stepper/stepper_up.png"] size:CGSizeMake(12.0, 10.0)]];
[_bottomButton setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"Stepper/stepper_down.png"] size:CGSizeMake(12.0, 12.0)]];
[_splitter setBackgroundColor:[[CPColor alloc] _initWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"Stepper/stepper_middle.png"] size:CGSizeMake(12.0, 1.0)]]];
[_upButton setAlternateImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"Stepper/stepper_up_highlighted.png"] size:CGSizeMake(12.0, 10.0)]];
[_bottomButton setAlternateImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"Stepper/stepper_down_highlighted.png"] size:CGSizeMake(12.0, 12.0)]];
[_upButton setBordered:NO];
[_bottomButton setBordered:NO];
[_upButton setTarget:self];
[_bottomButton setTarget:self];
[_upButton setContinuous:YES];
[_bottomButton setContinuous:YES];
[_upButton setAction:@selector(buttonUpAction:)];
[_bottomButton setAction:@selector(buttonDownAction:)];
[self addSubview:_upButton];
[self addSubview:_splitter];
[self addSubview:_bottomButton];
}
return self;
}
- (double)minValue
{
return _minValue;
}
- (void)setMinValue:(double)minValue
{
_minValue = minValue;
}
- (double)maxValue
{
return _maxValue;
}
- (void)setMaxValue:(double)maxValue
{
_maxValue = maxValue;
}
- (double)increment
{
return _increment;
}
- (void)setIncrement:(double)increment
{
_increment = increment;
}
- (BOOL)valueWraps
{
return _valueWraps;
}
- (void)setValueWraps:(BOOL)valueWraps
{
_valueWraps = valueWraps
}
- (BOOL)autorepeat
{
return _autorepeat
}
- (void)setAutorepeat:(BOOL)autorepeat
{
_autorepeat = autorepeat;
}
/*button actions*/
-(void)buttonUpAction:(id)sender
{
if(([self doubleValue] + [self increment]) > [self maxValue]){
if([self valueWraps]){
[self setDoubleValue:[self minValue]];
}
}else{
[self setDoubleValue: [self doubleValue] + [self increment]];
}
[self sendAction:[self action] to:[self target]];
}
-(void)buttonDownAction:(id)sender
{
if(([self doubleValue] - [self increment]) < [self minValue]){
if([self valueWraps]){
[self setDoubleValue:[self maxValue]];
}
}else{
[self setDoubleValue: [self doubleValue] - [self increment]];
}
//console.log([self doubleValue]);
[self sendAction:[self action] to:[self target]];
}