1 /*****************************************************************************
2 * VLCDefaultValueSlider.m: Custom NSSlider which allows a defaultValue
3 *****************************************************************************
4 * Copyright (C) 2016 VLC authors and VideoLAN
7 * Authors: Marvin Scholz <epirat07 -at- gmail -dot- com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #import "VLCDefaultValueSlider.h"
25 #import "VLCDefaultValueSliderCell.h"
27 @implementation VLCDefaultValueSlider
29 - (instancetype)initWithCoder:(NSCoder *)coder
31 if ([coder isKindOfClass: [NSKeyedUnarchiver class]]) {
32 NSKeyedUnarchiver *keyedUnarchiver = (id)coder;
33 NSString *oldClass = NSStringFromClass([self.superclass cellClass]);
34 [keyedUnarchiver setClass:[VLCDefaultValueSliderCell class] forClassName:oldClass];
36 self = [super initWithCoder:coder];
43 - (void)scrollWheel:(NSEvent *)event
46 return [super scrollWheel:event];
48 CGFloat deltaY = [event scrollingDeltaY];
49 double range = [self maxValue] - [self minValue];
51 // Scroll less for high precision, else it's too fast
52 if (event.hasPreciseScrollingDeltas) {
53 increment = (range * 0.002) * deltaY;
57 increment = (range * 0.01 * deltaY);
60 // If scrolling is inversed, increment in other direction
61 if (!event.isDirectionInvertedFromDevice)
62 increment = -increment;
64 [self setDoubleValue:self.doubleValue - increment];
65 [self sendAction:self.action to:self.target];
68 - (void)setDefaultValue:(double)value
70 [(VLCDefaultValueSliderCell *)self.cell setDefaultValue:value];
73 - (double)defaultValue
75 return [(VLCDefaultValueSliderCell *)self.cell defaultValue];