[vlc-commits] macosx/VLCVolumeSlider: add dark mode support for mojave
Felix Paul Kühne
git at videolan.org
Mon Sep 24 18:45:58 CEST 2018
vlc/vlc-3.0 | branch: master | Felix Paul Kühne <felix at feepk.net> | Mon Sep 24 00:22:43 2018 +0200| [5b75f3dc693d220314a4c935e6a7759aaa8bc4c5] | committer: Felix Paul Kühne
macosx/VLCVolumeSlider: add dark mode support for mojave
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=5b75f3dc693d220314a4c935e6a7759aaa8bc4c5
---
modules/gui/macosx/CompatibilityFixes.h | 2 +-
modules/gui/macosx/VLCVolumeSlider.m | 16 ++++++++++++++++
modules/gui/macosx/VLCVolumeSliderCell.h | 2 ++
modules/gui/macosx/VLCVolumeSliderCell.m | 27 ++++++++++++++++++++-------
4 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/modules/gui/macosx/CompatibilityFixes.h b/modules/gui/macosx/CompatibilityFixes.h
index ae842e6fbf..84a524acae 100644
--- a/modules/gui/macosx/CompatibilityFixes.h
+++ b/modules/gui/macosx/CompatibilityFixes.h
@@ -33,7 +33,7 @@
#define OSX_EL_CAPITAN_AND_HIGHER (NSAppKitVersionNumber >= 1404)
#define OSX_SIERRA_AND_HIGHER (NSAppKitVersionNumber >= 1485)
#define OSX_HIGH_SIERRA_AND_HIGHER (NSAppKitVersionNumber >= 1560)
-
+#define OSX_MOJAVE_AND_HIGHER (NSAppKitVersionNumber >= 1639.10)
// Sierra only APIs
#ifndef MAC_OS_X_VERSION_10_12
diff --git a/modules/gui/macosx/VLCVolumeSlider.m b/modules/gui/macosx/VLCVolumeSlider.m
index b912f9c7c4..766fdc96c6 100644
--- a/modules/gui/macosx/VLCVolumeSlider.m
+++ b/modules/gui/macosx/VLCVolumeSlider.m
@@ -34,6 +34,11 @@
if (self) {
NSAssert([self.cell isKindOfClass:[VLCVolumeSliderCell class]],
@"VLCVolumeSlider cell is not VLCVolumeSliderCell");
+ if (@available(macOS 10.14, *)) {
+ [self viewDidChangeEffectiveAppearance];
+ } else {
+ [(VLCVolumeSliderCell*)self.cell setSliderStyleLight];
+ }
}
return self;
}
@@ -49,6 +54,17 @@
[super setNeedsDisplayInRect:[self bounds]];
}
+- (void)viewDidChangeEffectiveAppearance
+{
+ if (@available(macOS 10_14, *)) {
+ if ([self.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua]) {
+ [(VLCVolumeSliderCell*)self.cell setSliderStyleDark];
+ } else {
+ [(VLCVolumeSliderCell*)self.cell setSliderStyleLight];
+ }
+ }
+}
+
- (void)setUsesBrightArtwork:(BOOL)brightArtwork
{
if (brightArtwork) {
diff --git a/modules/gui/macosx/VLCVolumeSliderCell.h b/modules/gui/macosx/VLCVolumeSliderCell.h
index 48a7913ff1..b1c6dfdc52 100644
--- a/modules/gui/macosx/VLCVolumeSliderCell.h
+++ b/modules/gui/macosx/VLCVolumeSliderCell.h
@@ -42,6 +42,8 @@
@property NSGradient *trackGradient;
@property NSGradient *highlightGradient;
@property NSGradient *knobGradient;
+ at property CGFloat knobGradientAngle;
+ at property CGFloat knobGradientAngleHighlighted;
// Shadows
@property NSShadow *knobShadow;
diff --git a/modules/gui/macosx/VLCVolumeSliderCell.m b/modules/gui/macosx/VLCVolumeSliderCell.m
index 2bd98fd6b5..f84ef1e060 100644
--- a/modules/gui/macosx/VLCVolumeSliderCell.m
+++ b/modules/gui/macosx/VLCVolumeSliderCell.m
@@ -21,8 +21,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
-
#import "VLCVolumeSliderCell.h"
+#import "CompatibilityFixes.h"
@interface VLCVolumeSliderCell () {
BOOL _isRTL;
@@ -68,6 +68,8 @@
_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];
@@ -87,14 +89,25 @@
- (void)setSliderStyleDark
{
// Color Declarations
- _gradientColor = [NSColor colorWithCalibratedRed: 0.24 green: 0.24 blue: 0.24 alpha: 1];
+ if (OSX_MOJAVE_AND_HIGHER) {
+ _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 colorWithCalibratedRed: 0.15 green: 0.15 blue: 0.15 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];
_shadowColor = [NSColor colorWithCalibratedRed: 0.32 green: 0.32 blue: 0.32 alpha: 1];
- _knobStrokeColor = [NSColor colorWithCalibratedRed:0 green:0 blue:0 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];
@@ -130,13 +143,13 @@
NSBezierPath* knobPath = [NSBezierPath bezierPathWithOvalInRect:NSInsetRect(knobRect, 1.0, 1.0)];
if (self.isHighlighted) {
if (_knobGradient) {
- [_knobGradient drawInBezierPath:knobPath angle:270];
+ [_knobGradient drawInBezierPath:knobPath angle:_knobGradientAngleHighlighted];
} else {
[_activeKnobFillColor setFill];
}
} else {
if (_knobGradient) {
- [_knobGradient drawInBezierPath:knobPath angle:90];
+ [_knobGradient drawInBezierPath:knobPath angle:_knobGradientAngle];
} else {
[_knobFillColor setFill];
}
More information about the vlc-commits
mailing list