[vlc-commits] macosx: Improve VLCSlider knob positioning

Marvin Scholz git at videolan.org
Tue Jul 18 21:53:36 CEST 2017


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Tue Jul 18 16:05:40 2017 +0200| [3698ec842972a6e0b3efaed80425897650c56829] | committer: Marvin Scholz

macosx: Improve VLCSlider knob positioning

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3698ec842972a6e0b3efaed80425897650c56829
---

 modules/gui/macosx/VLCSliderCell.m | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/modules/gui/macosx/VLCSliderCell.m b/modules/gui/macosx/VLCSliderCell.m
index 0d234d6d4d..8333c5aed7 100644
--- a/modules/gui/macosx/VLCSliderCell.m
+++ b/modules/gui/macosx/VLCSliderCell.m
@@ -28,7 +28,6 @@
     NSInteger _animationPosition;
     double _lastTime;
     double _deltaToLastFrame;
-    NSRect _lastKnobRect;
     CVDisplayLinkRef _displayLink;
 }
 @end
@@ -112,16 +111,41 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
     CVDisplayLinkSetOutputCallback(_displayLink, DisplayLinkCallback, (__bridge void*) self);
 }
 
+- (double)myNormalizedDouble
+{
+    double min;
+    double max;
+    double current;
+
+    min = [self minValue];
+    max = [self maxValue];
+    current = [self doubleValue];
+
+    max -= min;
+    current -= min;
+
+    return current / max;
+}
+
+- (NSRect)knobRectFlipped:(BOOL)flipped
+{
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpartial-availability"
+    // This is our own implementation, so no need to guard it on < 10.9
+    NSRect barRect = [self barRectFlipped:NO];
+#pragma clang diagnostic pop
+    CGFloat knobThickness = barRect.size.height;
+    double val = [self myNormalizedDouble];
+
+    NSRect rect = NSMakeRect((NSWidth(barRect) - knobThickness) * val, 0, knobThickness, knobThickness);
+    return [[self controlView] backingAlignedRect:rect options:NSAlignAllEdgesNearest];
+}
+
 #pragma mark -
 #pragma mark Normal slider drawing
 
 - (void)drawKnob:(NSRect)knobRect
 {
-    _lastKnobRect = knobRect;
-    // 10.7 - 10.10 hack
-    if (!OSX_YOSEMITE_AND_HIGHER)
-        knobRect.size.height += 1.5;
-
     // Draw knob
     NSBezierPath* knobPath = [NSBezierPath bezierPathWithOvalInRect:NSInsetRect(knobRect, 2.0, 2.0)];
     if (self.isHighlighted) {



More information about the vlc-commits mailing list