[vlc-commits] macosx: Correct drawing of Volume slider in RTL mode

Marvin Scholz git at videolan.org
Wed Aug 2 16:16:59 CEST 2017


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Wed Aug  2 16:09:34 2017 +0200| [ff9c8f615450b6f70c428094a4d067f7eeaf7ff3] | committer: Marvin Scholz

macosx: Correct drawing of Volume slider in RTL mode

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

 modules/gui/macosx/VLCVolumeSliderCell.m | 42 +++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 9 deletions(-)

diff --git a/modules/gui/macosx/VLCVolumeSliderCell.m b/modules/gui/macosx/VLCVolumeSliderCell.m
index 61c1312b59..93b2dad22f 100644
--- a/modules/gui/macosx/VLCVolumeSliderCell.m
+++ b/modules/gui/macosx/VLCVolumeSliderCell.m
@@ -24,6 +24,11 @@
 
 #import "VLCVolumeSliderCell.h"
 
+ at interface VLCVolumeSliderCell () {
+    BOOL _isRTL;
+}
+ at 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;
 }
@@ -174,21 +181,38 @@
 
     // 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;



More information about the vlc-commits mailing list