[vlc-commits] macosx: Fix DefaultValueSlider tickmark position in RTL layout

Marvin Scholz git at videolan.org
Wed Aug 9 11:21:17 CEST 2017


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Wed Aug  9 11:20:46 2017 +0200| [8aa0cd85add61476344d789931bcaa2eb50297c0] | committer: Marvin Scholz

macosx: Fix DefaultValueSlider tickmark position in RTL layout

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

 modules/gui/macosx/VLCDefaultValueSliderCell.m | 51 +++++++++++---------------
 modules/gui/macosx/VLCVolumeSliderCell.m       | 19 ----------
 2 files changed, 22 insertions(+), 48 deletions(-)

diff --git a/modules/gui/macosx/VLCDefaultValueSliderCell.m b/modules/gui/macosx/VLCDefaultValueSliderCell.m
index b9e817eea4..b46f9d4cbf 100644
--- a/modules/gui/macosx/VLCDefaultValueSliderCell.m
+++ b/modules/gui/macosx/VLCDefaultValueSliderCell.m
@@ -117,46 +117,39 @@
 }
 
 /*
- * Adapted from GNUstep NSSliderCell
- * - (NSRect)knobRectFlipped:(BOOL)flipped
- *
  * Calculates the knobRect for a given position
  * This is later used to draw the default tick mark in the center of
  * where the knob would be, when it is at the default value.
  */
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wpartial-availability"
-- (NSRect)knobRectFlipped:(BOOL)flipped forValue:(double)doubleValue
-{
-    NSRect superRect = [super knobRectFlipped:flipped];
-    NSPoint	origin = _trackRect.origin;
-    NSSize size = superRect.size;
 
-    if ([self isVertical] && flipped) {
-        doubleValue = _maxValue + _minValue - doubleValue;
-    }
-
-    doubleValue = (doubleValue - _minValue) / (_maxValue - _minValue);
-
-    if ([self isVertical] == YES) {
-        origin.x = superRect.origin.x;
-        origin.y += (_trackRect.size.height - size.height) * doubleValue;
-    } else {
-        origin.x += ((_trackRect.size.width - size.width) * doubleValue);
-        origin.y = superRect.origin.y;
-    }
-
-    return NSMakeRect(origin.x, origin.y, size.width, size.height);
-}
+- (NSRect)knobRectFlipped:(BOOL)flipped forValue:(double)doubleValue
+ {
+     NSRect resultRect;
+     double val = [self normalizedValue:doubleValue] / 100;
+
+     if (self.isVertical) {
+         resultRect.origin.x = -1;
+         resultRect.origin.y = (NSHeight(_trackRect) - self.knobThickness) * val;
+         if (_isRTL)
+             resultRect.origin.y = (NSHeight(_trackRect) - self.knobThickness) - resultRect.origin.y;
+     } else {
+         resultRect.origin.x = (NSWidth(_trackRect) - self.knobThickness) * val;
+         resultRect.origin.y = -1;
+         if (_isRTL)
+             resultRect.origin.x = (NSWidth(_trackRect) - self.knobThickness) - resultRect.origin.x;
+     }
+
+     resultRect.size.height = self.knobThickness;
+     resultRect.size.width = self.knobThickness;
+
+     return [self.controlView backingAlignedRect:resultRect options:NSAlignAllEdgesNearest];
+ }
 
 #pragma mark -
 #pragma mark Overwritten super methods
 
-- (NSRect)knobRectFlipped:(BOOL)flipped
-{
-    return [self knobRectFlipped:flipped forValue:[self doubleValue]];
-}
-
 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
 {
     // Do all other drawing
diff --git a/modules/gui/macosx/VLCVolumeSliderCell.m b/modules/gui/macosx/VLCVolumeSliderCell.m
index 93b2dad22f..6646358b65 100644
--- a/modules/gui/macosx/VLCVolumeSliderCell.m
+++ b/modules/gui/macosx/VLCVolumeSliderCell.m
@@ -155,25 +155,6 @@
     [NSGraphicsContext restoreGraphicsState];
 }
 
-- (double)myNormalizedDouble
-{
-    double min = [self minValue];
-    double max = [self maxValue];
-    double current = [self doubleValue];
-
-    max -= min;
-    current -= min;
-
-    return current / max;
-}
-
-- (NSRect)knobRectFlipped:(BOOL)flipped
-{
-    double val = [self myNormalizedDouble];
-    NSRect rect = NSMakeRect((NSWidth(_trackRect) - self.knobThickness) * val, -1, self.knobThickness, self.knobThickness);
-    return [[self controlView] backingAlignedRect:rect options:NSAlignAllEdgesNearest];
-}
-
 - (void)drawBarInside:(NSRect)rect flipped:(BOOL)flipped
 {
     // Inset rect



More information about the vlc-commits mailing list