[vlc-devel] [PATCH 7/8] macosx: Improve VLCSlider knob positioning
Marvin Scholz
epirat07 at gmail.com
Tue Jul 18 20:30:10 CEST 2017
---
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 @@ @interface VLCSliderCell () {
NSInteger _animationPosition;
double _lastTime;
double _deltaToLastFrame;
- NSRect _lastKnobRect;
CVDisplayLinkRef _displayLink;
}
@end
@@ -112,16 +111,41 @@ - (void)initDisplayLink
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) {
--
2.11.0 (Apple Git-81)
More information about the vlc-devel
mailing list