[vlc-commits] [Git][videolan/vlc][master] 6 commits: macosx: Don't override drawKnob in VLCVolumeSliderCell

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Wed Jan 18 21:39:10 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
f21a63ee by Claudio Cambra at 2023-01-18T21:20:52+00:00
macosx: Don't override drawKnob in VLCVolumeSliderCell

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
1403d0d6 by Claudio Cambra at 2023-01-18T21:20:52+00:00
macosx: Simplify VLCVolumeSlider bar drawing

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
896b2d9f by Claudio Cambra at 2023-01-18T21:20:52+00:00
macosx: Fix layouting bugs for RTL mode in VLCVolumeSliderCell

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
aa2de370 by Claudio Cambra at 2023-01-18T21:20:52+00:00
macosx: Improve visibility of empty slider section

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
2d922030 by Claudio Cambra at 2023-01-18T21:20:52+00:00
macosx: Add slider background colours to NSColor extension

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -
fdd5c00c by Claudio Cambra at 2023-01-18T21:20:52+00:00
macosx: Use NSColor extension values for slider background

Signed-off-by: Claudio Cambra <developer at claudiocambra.com>

- - - - -


5 changed files:

- modules/gui/macosx/extensions/NSColor+VLCAdditions.h
- modules/gui/macosx/extensions/NSColor+VLCAdditions.m
- modules/gui/macosx/views/VLCVolumeSlider.m
- modules/gui/macosx/views/VLCVolumeSliderCell.h
- modules/gui/macosx/views/VLCVolumeSliderCell.m


Changes:

=====================================
modules/gui/macosx/extensions/NSColor+VLCAdditions.h
=====================================
@@ -42,6 +42,8 @@ NS_ASSUME_NONNULL_BEGIN
 + (instancetype)VLClibraryCollectionViewItemBackgroundLightColor;
 + (instancetype)VLClibraryCollectionViewItemBackgroundDarkColor;
 + (instancetype)VLCSliderFillColor;
++ (instancetype)VLCSliderLightBackgroundColor;
++ (instancetype)VLCSliderDarkBackgroundColor;
 
 @end
 


=====================================
modules/gui/macosx/extensions/NSColor+VLCAdditions.m
=====================================
@@ -101,7 +101,18 @@
 
 + (instancetype)VLCSliderFillColor
 {
-    return [NSColor colorWithRed:1. green:0.38039 blue:0.03921 alpha:1.];
+    return [NSColor VLCAccentColor];
+}
+
+
++ (instancetype)VLCSliderLightBackgroundColor
+{
+    return [NSColor colorWithCalibratedWhite:0.5 alpha:0.5];
+}
+
++ (instancetype)VLCSliderDarkBackgroundColor
+{
+    return [NSColor colorWithCalibratedWhite:1 alpha:0.2];
 }
 
 @end


=====================================
modules/gui/macosx/views/VLCVolumeSlider.m
=====================================
@@ -34,6 +34,7 @@
     if (self) {
         NSAssert([self.cell isKindOfClass:[VLCVolumeSliderCell class]],
                  @"VLCVolumeSlider cell is not VLCVolumeSliderCell");
+
         if (@available(macOS 10.14, *)) {
             [self viewDidChangeEffectiveAppearance];
         } else {


=====================================
modules/gui/macosx/views/VLCVolumeSliderCell.h
=====================================
@@ -26,27 +26,6 @@
 
 @interface VLCVolumeSliderCell : VLCDefaultValueSliderCell
 
-// Colors
- at property NSColor *gradientColor;
- at property NSColor *gradientColor2;
- at property NSColor *trackStrokeColor;
- at property NSColor *filledTrackColor;
- at property NSColor *knobFillColor;
- at property NSColor *activeKnobFillColor;
- at property NSColor *shadowColor;
- at property NSColor *knobStrokeColor;
- at property NSColor *highlightBackground;
-
-// Gradients
- at property NSGradient *trackGradient;
- at property NSGradient *highlightGradient;
- at property NSGradient *knobGradient;
- at property CGFloat knobGradientAngle;
- at property CGFloat knobGradientAngleHighlighted;
-
-// Shadows
- at property NSShadow *knobShadow;
-
 - (void)setSliderStyleLight;
 - (void)setSliderStyleDark;
 


=====================================
modules/gui/macosx/views/VLCVolumeSliderCell.m
=====================================
@@ -28,6 +28,7 @@
 
 @interface VLCVolumeSliderCell () {
     BOOL _isRTL;
+    NSColor *_emptySliderBackgroundColor;
 }
 @end
 
@@ -55,164 +56,44 @@
 
 - (void)setSliderStyleLight
 {
-    // Color Declarations
-    _gradientColor = [NSColor colorWithCalibratedRed: 0.663 green: 0.663 blue: 0.663 alpha: 1];
-    _gradientColor2 = [NSColor colorWithCalibratedRed: 0.749 green: 0.749 blue: 0.753 alpha: 1];
-    _trackStrokeColor = [NSColor colorWithCalibratedRed: 0.619 green: 0.624 blue: 0.623 alpha: 1];
-    _filledTrackColor = [NSColor VLCSliderFillColor];
-    _knobFillColor = [NSColor colorWithCalibratedRed: 1 green: 1 blue: 1 alpha: 1];
-    _activeKnobFillColor = [NSColor colorWithCalibratedRed: 0.95 green: 0.95 blue: 0.95 alpha: 1];
-    _shadowColor = [NSColor colorWithCalibratedRed: 0.32 green: 0.32 blue: 0.32 alpha: 1];
-    _knobStrokeColor = [NSColor colorWithCalibratedRed: 0.592 green: 0.596 blue: 0.596 alpha: 1];
-
-    // Gradient Declarations
-    _trackGradient = [[NSGradient alloc] initWithColorsAndLocations:
-                      _gradientColor, 0.0,
-                      [_gradientColor blendedColorWithFraction:0.5 ofColor:_gradientColor2], 0.60,
-                      _gradientColor2, 1.0, nil];
-    _knobGradientAngleHighlighted = 270;
-    _knobGradientAngle = 90;
-
-    // Shadow Declarations
-    _knobShadow = [[NSShadow alloc] init];
-    _knobShadow.shadowColor = _shadowColor;
-    _knobShadow.shadowOffset = NSMakeSize(0, 0);
-    _knobShadow.shadowBlurRadius = 2;
-
-    _highlightBackground = [NSColor colorWithCalibratedRed:0.20 green:0.55 blue:0.91 alpha:1.0];
-    NSColor *highlightAccent = [NSColor colorWithCalibratedRed:0.4588235294 green:0.7254901961 blue:0.9882352941 alpha:1.0];
-    _highlightGradient = [[NSGradient alloc] initWithColors:@[
-                                                              _highlightBackground,
-                                                              highlightAccent,
-                                                              _highlightBackground
-                                                              ]];
+    _emptySliderBackgroundColor = [NSColor VLCSliderLightBackgroundColor];
 }
 
 - (void)setSliderStyleDark
 {
-    // Color Declarations
-    if (@available(macOS 10.14, *)) {
-        _gradientColor = [NSColor colorWithCalibratedRed: 0.20 green: 0.20 blue: 0.20 alpha: 1];
-        _knobFillColor = [NSColor colorWithCalibratedRed: 0.81 green: 0.81 blue: 0.81 alpha: 1];
-        _activeKnobFillColor = [NSColor colorWithCalibratedRed: 0.76 green: 0.76 blue: 0.76 alpha: 1];
-        _knobStrokeColor = [NSColor colorWithCalibratedRed:0.29 green:0.29 blue:0.29 alpha:1];
-        _knobGradientAngleHighlighted = 90;
-        _knobGradientAngle = 270;
-    } else {
-        _gradientColor = [NSColor colorWithCalibratedRed: 0.24 green: 0.24 blue: 0.24 alpha: 1];
-        _knobFillColor = [NSColor colorWithCalibratedRed:0.7 green:0.7 blue:0.7 alpha: 1];
-        _activeKnobFillColor = [NSColor colorWithCalibratedRed: 0.95 green: 0.95 blue: 0.95 alpha: 1];
-        _knobStrokeColor = [NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:1];
-        _knobGradientAngleHighlighted = 270;
-        _knobGradientAngle = 90;
-    }
-    _gradientColor2 = [NSColor colorWithCalibratedRed: 0.15 green: 0.15 blue: 0.15 alpha: 1];
-    _trackStrokeColor = [NSColor colorWithCalibratedRed: 0.23 green: 0.23 blue: 0.23 alpha: 1];
-    _filledTrackColor = [NSColor VLCSliderFillColor];
-    _shadowColor = [NSColor colorWithCalibratedRed: 0.32 green: 0.32 blue: 0.32 alpha: 1];
-
-    NSColor* knobGradientColor = [NSColor colorWithSRGBRed: 0.15 green: 0.15 blue: 0.15 alpha: 1];
-    NSColor* knobGradientColor2 = [NSColor colorWithSRGBRed: 0.30 green: 0.30 blue: 0.30 alpha: 1];
-
-    // Gradient Declarations
-    _trackGradient = [[NSGradient alloc] initWithColorsAndLocations:
-                      _gradientColor, 0.0,
-                      [_gradientColor blendedColorWithFraction:0.5 ofColor:_gradientColor2], 0.60,
-                      _gradientColor2, 1.0, nil];
-
-    _knobGradient = [[NSGradient alloc] initWithStartingColor:knobGradientColor
-                                                  endingColor:knobGradientColor2];
-
-
-    // Shadow Declarations
-    _knobShadow = [[NSShadow alloc] init];
-    _knobShadow.shadowColor = _shadowColor;
-    _knobShadow.shadowOffset = NSMakeSize(0, 0);
-    _knobShadow.shadowBlurRadius = 2;
-
-    _highlightBackground = [NSColor colorWithCalibratedRed:0.20 green:0.55 blue:0.91 alpha:1.0];
-    NSColor *highlightAccent = [NSColor colorWithCalibratedRed:0.4588235294 green:0.7254901961 blue:0.9882352941 alpha:1.0];
-    _highlightGradient = [[NSGradient alloc] initWithColors:@[
-                                                              _highlightBackground,
-                                                              highlightAccent,
-                                                              _highlightBackground
-                                                              ]];
-}
-
-- (void)drawKnob:(NSRect)knobRect
-{
-    // Draw knob
-    NSBezierPath* knobPath = [NSBezierPath bezierPathWithOvalInRect:NSInsetRect(knobRect, 1.0, 1.0)];
-    if (self.isHighlighted) {
-        if (_knobGradient) {
-            [_knobGradient vlc_safeDrawInBezierPath:knobPath angle:_knobGradientAngleHighlighted];
-        } else {
-            [_activeKnobFillColor setFill];
-        }
-    } else {
-        if (_knobGradient) {
-            [_knobGradient vlc_safeDrawInBezierPath:knobPath angle:_knobGradientAngle];
-        } else {
-            [_knobFillColor setFill];
-        }
-    }
-
-    if (!_knobGradient)
-        [knobPath fill];
-
-    [_knobStrokeColor setStroke];
-    knobPath.lineWidth = 0.5;
-
-    [NSGraphicsContext saveGraphicsState];
-    if (self.isHighlighted)
-        [_knobShadow set];
-    [knobPath stroke];
-    [NSGraphicsContext restoreGraphicsState];
+    _emptySliderBackgroundColor = [NSColor VLCSliderDarkBackgroundColor];
 }
 
 - (void)drawBarInside:(NSRect)rect flipped:(BOOL)flipped
 {
-    // Inset rect
-    rect = NSInsetRect(rect, 1.0, 1.0);
+    const CGFloat trackBorderRadius = 1;
 
     // Empty Track Drawing
-    NSBezierPath* emptyTrackPath = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:1 yRadius:1];
+    NSBezierPath* emptyTrackPath = [NSBezierPath bezierPathWithRoundedRect:rect
+                                                                   xRadius:trackBorderRadius
+                                                                   yRadius:trackBorderRadius];
 
     // Calculate filled track
-    NSRect leadingTrackRect = rect;
+    NSRect filledTrackRect = rect;
     NSRect knobRect = [self knobRectFlipped:NO];
     CGFloat sliderCenter = knobRect.origin.x  + (self.knobThickness / 2);
 
-    leadingTrackRect.size.width = sliderCenter;
-
-    // Filled Track Drawing
-    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.
-
-        // Empty part drawing
-        [_filledTrackColor setFill];
-        [emptyTrackPath fill];
-
-        // Filled part drawing
-        [_trackGradient vlc_safeDrawInBezierPath:leadingTrackPath angle:-90];
+        filledTrackRect.size.width = rect.origin.x + rect.size.width - sliderCenter;
+        filledTrackRect.origin.x = sliderCenter;
     } else {
-        // Empty part drawing
-        [_trackGradient vlc_safeDrawInBezierPath:emptyTrackPath angle:-90];
-
-        // Filled part drawing
-        [_filledTrackColor setFill];
-        [leadingTrackPath fill];
+        filledTrackRect.size.width = sliderCenter;
     }
 
-    [_trackStrokeColor setStroke];
-    emptyTrackPath.lineWidth = 1;
-    [emptyTrackPath stroke];
+    NSBezierPath* filledTrackPath = [NSBezierPath bezierPathWithRoundedRect:filledTrackRect
+                                                                    xRadius:trackBorderRadius
+                                                                    yRadius:trackBorderRadius];
+    NSColor *filledColor = [NSColor VLCSliderFillColor];
+
+    [_emptySliderBackgroundColor setFill];
+    [emptyTrackPath fill];
+    [filledColor setFill];
+    [filledTrackPath fill];
 }
 
 @end



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5d79ac4937737652224d94f128acbe299e46c1a6...fdd5c00c4a977c69ab107647b05304a5dd7b0780

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/5d79ac4937737652224d94f128acbe299e46c1a6...fdd5c00c4a977c69ab107647b05304a5dd7b0780
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list