[vlc-commits] macosx/VLCVolumeSlider: add dark mode support for mojave
Felix Paul Kühne
git at videolan.org
Mon Sep 24 15:45:04 CEST 2018
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Mon Sep 24 00:22:43 2018 +0200| [5fca01230f54bfd96aa5477787bdc3ec515bf768] | committer: Felix Paul Kühne
macosx/VLCVolumeSlider: add dark mode support for mojave
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5fca01230f54bfd96aa5477787bdc3ec515bf768
---
modules/gui/macosx/VLCMainWindowControlsBar.m | 1 -
modules/gui/macosx/VLCVolumeSlider.h | 2 --
modules/gui/macosx/VLCVolumeSlider.m | 17 ++++++++++++-----
modules/gui/macosx/VLCVolumeSliderCell.h | 2 ++
modules/gui/macosx/VLCVolumeSliderCell.m | 27 ++++++++++++++++++++-------
5 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/modules/gui/macosx/VLCMainWindowControlsBar.m b/modules/gui/macosx/VLCMainWindowControlsBar.m
index 91805b8f04..fbfe4489f9 100644
--- a/modules/gui/macosx/VLCMainWindowControlsBar.m
+++ b/modules/gui/macosx/VLCMainWindowControlsBar.m
@@ -104,7 +104,6 @@
[self.volumeDownButton setImage: imageFromRes(@"volume-low")];
[self.volumeUpButton setImage: imageFromRes(@"volume-high")];
- [self.volumeSlider setUsesBrightArtwork: YES];
if (self.nativeFullscreenMode) {
[self.effectsButton setImage: imageFromRes(@"effects-one-button")];
diff --git a/modules/gui/macosx/VLCVolumeSlider.h b/modules/gui/macosx/VLCVolumeSlider.h
index 2d00da994f..0c2cb042aa 100644
--- a/modules/gui/macosx/VLCVolumeSlider.h
+++ b/modules/gui/macosx/VLCVolumeSlider.h
@@ -26,6 +26,4 @@
@interface VLCVolumeSlider : VLCDefaultValueSlider
-- (void)setUsesBrightArtwork:(BOOL)brightArtwork;
-
@end
diff --git a/modules/gui/macosx/VLCVolumeSlider.m b/modules/gui/macosx/VLCVolumeSlider.m
index b912f9c7c4..cd5ed92068 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,12 +54,14 @@
[super setNeedsDisplayInRect:[self bounds]];
}
-- (void)setUsesBrightArtwork:(BOOL)brightArtwork
+- (void)viewDidChangeEffectiveAppearance
{
- if (brightArtwork) {
- [(VLCVolumeSliderCell*)self.cell setSliderStyleLight];
- } else {
- [(VLCVolumeSliderCell*)self.cell setSliderStyleDark];
+ if (@available(macOS 10_14, *)) {
+ if ([self.effectiveAppearance.name isEqualToString:NSAppearanceNameDarkAqua]) {
+ [(VLCVolumeSliderCell*)self.cell setSliderStyleDark];
+ } else {
+ [(VLCVolumeSliderCell*)self.cell setSliderStyleLight];
+ }
}
}
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