+/*****************************************************************************
+ * VLCVolumeSliderCommon
+ *****************************************************************************/
+
+@implementation VLCVolumeSliderCommon : NSSlider
+
+@synthesize usesBrightArtwork = _usesBrightArtwork;
+
+- (void)scrollWheel:(NSEvent *)o_event
+{
+ BOOL b_up = NO;
+ CGFloat f_deltaY = [o_event deltaY];
+ CGFloat f_deltaX = [o_event deltaX];
+
+ if (!OSX_SNOW_LEOPARD && [o_event isDirectionInvertedFromDevice])
+ f_deltaX = -f_deltaX; // optimisation, actually double invertion of f_deltaY here
+ else
+ f_deltaY = -f_deltaY;
+
+ // positive for left / down, negative otherwise
+ CGFloat f_delta = f_deltaX + f_deltaY;
+ CGFloat f_abs;
+
+ if (f_delta > 0.0f)
+ f_abs = f_delta;
+ else {
+ b_up = YES;
+ f_abs = -f_delta;
+ }
+
+ for (NSUInteger i = 0; i < (int)(f_abs/4.+1.) && f_abs > 0.05 ; i++) {
+ if (b_up)
+ [[VLCCoreInteraction sharedInstance] volumeUp];
+ else
+ [[VLCCoreInteraction sharedInstance] volumeDown];
+ }
+}
+
+- (void)drawFullVolumeMarker
+{
+ CGFloat maxAudioVol = self.maxValue / AOUT_VOLUME_DEFAULT;
+ if (maxAudioVol < 1.)
+ return;
+
+ NSColor *drawingColor;
+ // for bright artwork, a black color is used and vice versa
+ if (_usesBrightArtwork)
+ drawingColor = [[NSColor blackColor] colorWithAlphaComponent:.4];
+ else
+ drawingColor = [[NSColor whiteColor] colorWithAlphaComponent:.4];
+
+ NSBezierPath* bezierPath = [NSBezierPath bezierPath];
+ [self drawFullVolBezierPath:bezierPath];
+ [bezierPath closePath];
+
+ bezierPath.lineWidth = 1.;
+ [drawingColor setStroke];
+ [bezierPath stroke];
+}
+
+- (CGFloat)fullVolumePos
+{
+ CGFloat maxAudioVol = self.maxValue / AOUT_VOLUME_DEFAULT;
+ CGFloat sliderRange = [self frame].size.width - [self knobThickness];
+ CGFloat sliderOrigin = [self knobThickness] / 2.;
+
+ return 1. / maxAudioVol * sliderRange + sliderOrigin;
+}
+
+- (void)drawFullVolBezierPath:(NSBezierPath*)bezierPath
+{
+ CGFloat fullVolPos = [self fullVolumePos];
+ [bezierPath moveToPoint:NSMakePoint(fullVolPos, [self frame].size.height - 3.)];
+ [bezierPath lineToPoint:NSMakePoint(fullVolPos, 2.)];
+}
+
+@end
+
+@implementation VolumeSliderCell
+
+- (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView
+{
+ VLCVolumeSliderCommon *o_slider = (VLCVolumeSliderCommon *)controlView;
+ CGFloat fullVolumePos = [o_slider fullVolumePos] + 2.;
+
+ CGPoint snapToPoint = currentPoint;
+ if (ABS(fullVolumePos - currentPoint.x) <= 4.)
+ snapToPoint.x = fullVolumePos;
+
+ return [super continueTracking:lastPoint at:snapToPoint inView:controlView];
+}
+
+@end
+