macosx: Correct drawing of Volume slider in RTL mode
authorMarvin Scholz <epirat07@gmail.com>
Wed, 2 Aug 2017 14:09:34 +0000 (16:09 +0200)
committerMarvin Scholz <epirat07@gmail.com>
Wed, 2 Aug 2017 14:12:40 +0000 (16:12 +0200)
modules/gui/macosx/VLCVolumeSliderCell.m

index 61c1312..93b2dad 100644 (file)
 
 #import "VLCVolumeSliderCell.h"
 
+@interface VLCVolumeSliderCell () {
+    BOOL _isRTL;
+}
+@end
+
 @implementation VLCVolumeSliderCell
 
 - (instancetype)init
@@ -31,6 +36,7 @@
     self = [super init];
     if (self) {
         [self setSliderStyleLight];
+        _isRTL = ([self userInterfaceLayoutDirection] == NSUserInterfaceLayoutDirectionRightToLeft);
     }
     return self;
 }
@@ -40,6 +46,7 @@
     self = [super initWithCoder:coder];
     if (self) {
         [self setSliderStyleLight];
+        _isRTL = ([self userInterfaceLayoutDirection] == NSUserInterfaceLayoutDirectionRightToLeft);
     }
     return self;
 }
 
     // Empty Track Drawing
     NSBezierPath* emptyTrackPath = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:1 yRadius:1];
-    [_trackGradient drawInBezierPath:emptyTrackPath angle:-90];
 
     // Calculate filled track
-    NSRect filledTrackRect = rect;
+    NSRect leadingTrackRect = rect;
     NSRect knobRect = [self knobRectFlipped:NO];
-    filledTrackRect.size.width = knobRect.origin.x + (self.knobThickness / 2);
+    CGFloat sliderCenter = knobRect.origin.x  + (self.knobThickness / 2);
+
+    leadingTrackRect.size.width = sliderCenter;
 
     // Filled Track Drawing
-    CGFloat filledTrackCornerRadius = 2;
-    NSBezierPath* filledTrackPath = [NSBezierPath bezierPathWithRoundedRect:filledTrackRect
-                                                                    xRadius:filledTrackCornerRadius
-                                                                    yRadius:filledTrackCornerRadius];
+    CGFloat leadingTrackCornerRadius = 2;
+    NSBezierPath* leadingTrackPath = [NSBezierPath bezierPathWithRoundedRect:leadingTrackRect
+                                                                     xRadius:leadingTrackCornerRadius
+                                                                     yRadius:leadingTrackCornerRadius];
+
+    if (_isRTL) {
+        // In RTL mode, first fill the whole slider,
+        // then only redraw the empty part.
 
-    [_filledTrackColor setFill];
-    [filledTrackPath fill];
+        // Empty part drawing
+        [_filledTrackColor setFill];
+        [emptyTrackPath fill];
+
+        // Filled part drawing
+        [_trackGradient drawInBezierPath:leadingTrackPath angle:-90];
+    } else {
+        // Empty part drawing
+        [_trackGradient drawInBezierPath:emptyTrackPath angle:-90];
+
+        // Filled part drawing
+        [_filledTrackColor setFill];
+        [leadingTrackPath fill];
+    }
 
     [_trackStrokeColor setStroke];
     emptyTrackPath.lineWidth = 1;