macosx: Add VLCVolumeSlider(Cell) classes
authorMarvin Scholz <epirat07@gmail.com>
Mon, 31 Jul 2017 16:08:23 +0000 (18:08 +0200)
committerMarvin Scholz <epirat07@gmail.com>
Mon, 31 Jul 2017 16:10:27 +0000 (18:10 +0200)
extras/package/macosx/VLC.xcodeproj/project.pbxproj
modules/gui/macosx/Makefile.am
modules/gui/macosx/VLCVolumeSlider.h [new file with mode: 0644]
modules/gui/macosx/VLCVolumeSlider.m [new file with mode: 0644]
modules/gui/macosx/VLCVolumeSliderCell.h [new file with mode: 0644]
modules/gui/macosx/VLCVolumeSliderCell.m [new file with mode: 0644]

index 136028f..7c5dfe7 100644 (file)
@@ -73,6 +73,8 @@
                1CFE8D591EA0D42A00E94451 /* VLCErrorWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1CFE8D581EA0D42A00E94451 /* VLCErrorWindowController.m */; };
                6B0AB0F01F1AC8B3003A1B4E /* VLCSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B0AB0ED1F1AC8B3003A1B4E /* VLCSlider.m */; };
                6B0AB0F11F1AC8B3003A1B4E /* VLCSliderCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B0AB0EF1F1AC8B3003A1B4E /* VLCSliderCell.m */; };
+               6B2EFC601F2819F700F3C0EA /* VLCVolumeSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B2EFC5F1F2819F700F3C0EA /* VLCVolumeSlider.m */; };
+               6B2EFC631F281A0900F3C0EA /* VLCVolumeSliderCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B2EFC621F281A0900F3C0EA /* VLCVolumeSliderCell.m */; };
                6B3BE42C1E6217CB008D098A /* VLCImageButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B3BE42B1E6217CB008D098A /* VLCImageButton.m */; };
                6B4D50901E79781F004479B5 /* VLCHotkeyChangeWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D508F1E79781F004479B5 /* VLCHotkeyChangeWindow.m */; };
                6B4D50931E7979CB004479B5 /* VLCSimplePrefsWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50921E7979CB004479B5 /* VLCSimplePrefsWindow.m */; };
                6B0AB0EF1F1AC8B3003A1B4E /* VLCSliderCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCSliderCell.m; sourceTree = "<group>"; };
                6B13E2A61BC67678001AD24A /* VLCScrollingClipView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCScrollingClipView.h; sourceTree = "<group>"; };
                6B13E2A71BC67678001AD24A /* VLCScrollingClipView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCScrollingClipView.m; sourceTree = "<group>"; };
+               6B2EFC5E1F2819F700F3C0EA /* VLCVolumeSlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCVolumeSlider.h; sourceTree = "<group>"; };
+               6B2EFC5F1F2819F700F3C0EA /* VLCVolumeSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCVolumeSlider.m; sourceTree = "<group>"; };
+               6B2EFC611F281A0900F3C0EA /* VLCVolumeSliderCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCVolumeSliderCell.h; sourceTree = "<group>"; };
+               6B2EFC621F281A0900F3C0EA /* VLCVolumeSliderCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCVolumeSliderCell.m; sourceTree = "<group>"; };
                6B3BE42A1E6217CB008D098A /* VLCImageButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCImageButton.h; sourceTree = "<group>"; };
                6B3BE42B1E6217CB008D098A /* VLCImageButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCImageButton.m; sourceTree = "<group>"; };
                6B4D508E1E79781F004479B5 /* VLCHotkeyChangeWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCHotkeyChangeWindow.h; sourceTree = "<group>"; };
                                6B0AB0ED1F1AC8B3003A1B4E /* VLCSlider.m */,
                                6B0AB0EE1F1AC8B3003A1B4E /* VLCSliderCell.h */,
                                6B0AB0EF1F1AC8B3003A1B4E /* VLCSliderCell.m */,
+                               6B2EFC5E1F2819F700F3C0EA /* VLCVolumeSlider.h */,
+                               6B2EFC5F1F2819F700F3C0EA /* VLCVolumeSlider.m */,
+                               6B2EFC611F281A0900F3C0EA /* VLCVolumeSliderCell.h */,
+                               6B2EFC621F281A0900F3C0EA /* VLCVolumeSliderCell.m */,
                                6B6A499A1DFD9B23009128AC /* VLCDefaultValueSlider.h */,
                                6B6A499B1DFD9B23009128AC /* VLCDefaultValueSlider.m */,
                                6B6A499C1DFD9B23009128AC /* VLCDefaultValueSliderCell.h */,
                                1C31139F1E508C6900D4DD76 /* VLCMainWindowControlsBar.m in Sources */,
                                1C3113A11E508C6900D4DD76 /* VLCConvertAndSaveWindowController.m in Sources */,
                                1C3113A31E508C6900D4DD76 /* VLCCoreDialogProvider.m in Sources */,
+                               6B2EFC631F281A0900F3C0EA /* VLCVolumeSliderCell.m in Sources */,
                                1C3113A51E508C6900D4DD76 /* VLCCoreInteraction.m in Sources */,
                                1C3113A71E508C6900D4DD76 /* VLCDebugMessageWindowController.m in Sources */,
                                6BF5C5071EFE7E58008A9C12 /* VLCTintedImageButtonCell.m in Sources */,
                                1C3113D51E508C6900D4DD76 /* VLCTextfieldPanelController.m in Sources */,
                                1C3113D71E508C6900D4DD76 /* VLCPopupPanelController.m in Sources */,
                                1C3113D91E508C6900D4DD76 /* VLCSimplePrefsController.m in Sources */,
+                               6B2EFC601F2819F700F3C0EA /* VLCVolumeSlider.m in Sources */,
                                1C3113DB1E508C6900D4DD76 /* VLCStringUtility.m in Sources */,
                                6B4D50A71E7AB52C004479B5 /* NSScreen+VLCAdditions.m in Sources */,
                                1C3113DD1E508C6900D4DD76 /* VLCTrackSynchronizationWindowController.m in Sources */,
index 15c9936..de11e52 100644 (file)
@@ -100,7 +100,9 @@ libmacosx_plugin_la_SOURCES = \
        gui/macosx/VLCTimeField.h gui/macosx/VLCTimeField.m \
        gui/macosx/VLCHexNumberFormatter.h gui/macosx/VLCHexNumberFormatter.m \
        gui/macosx/VLCSlider.h gui/macosx/VLCSlider.m \
-       gui/macosx/VLCSliderCell.h gui/macosx/VLCSliderCell.m
+       gui/macosx/VLCSliderCell.h gui/macosx/VLCSliderCell.m \
+       gui/macosx/VLCVolumeSlider.h gui/macosx/VLCVolumeSlider.m \
+       gui/macosx/VLCVolumeSliderCell.h gui/macosx/VLCVolumeSliderCell.m
 
 # User interface compilation
 
diff --git a/modules/gui/macosx/VLCVolumeSlider.h b/modules/gui/macosx/VLCVolumeSlider.h
new file mode 100644 (file)
index 0000000..2d00da9
--- /dev/null
@@ -0,0 +1,31 @@
+/*****************************************************************************
+ * VLCVolumeSlider.h
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Marvin Scholz <epirat07 at gmail dot com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+#import "VLCDefaultValueSlider.h"
+
+@interface VLCVolumeSlider : VLCDefaultValueSlider
+
+- (void)setUsesBrightArtwork:(BOOL)brightArtwork;
+
+@end
diff --git a/modules/gui/macosx/VLCVolumeSlider.m b/modules/gui/macosx/VLCVolumeSlider.m
new file mode 100644 (file)
index 0000000..300dbdf
--- /dev/null
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * VLCVolumeSlider.m
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Marvin Scholz <epirat07 at gmail dot com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+
+#import "VLCVolumeSlider.h"
+#import "VLCVolumeSliderCell.h"
+
+@implementation VLCVolumeSlider
+
+- (instancetype)initWithCoder:(NSCoder *)coder
+{
+    self = [super initWithCoder:coder];
+
+    if (self) {
+        if (![self.cell isKindOfClass:[VLCVolumeSliderCell class]]) {
+            self.cell = [[VLCVolumeSliderCell alloc] init];
+        }
+    }
+    return self;
+}
+
++ (Class)cellClass
+{
+    return [VLCVolumeSliderCell class];
+}
+
+// Workaround for 10.7
+// http://stackoverflow.com/questions/3985816/custom-nsslidercell
+- (void)setNeedsDisplayInRect:(NSRect)invalidRect {
+    [super setNeedsDisplayInRect:[self bounds]];
+}
+
+- (void)setUsesBrightArtwork:(BOOL)brightArtwork
+{
+    if (brightArtwork) {
+        [(VLCVolumeSliderCell*)self.cell setSliderStyleLight];
+    } else {
+        [(VLCVolumeSliderCell*)self.cell setSliderStyleDark];
+    }
+}
+
+@end
diff --git a/modules/gui/macosx/VLCVolumeSliderCell.h b/modules/gui/macosx/VLCVolumeSliderCell.h
new file mode 100644 (file)
index 0000000..48a7913
--- /dev/null
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ * VLCVolumeSliderCell.m
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Marvin Scholz <epirat07 at gmail dot com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+
+#import <Cocoa/Cocoa.h>
+#import "VLCDefaultValueSliderCell.h"
+
+@interface VLCVolumeSliderCell : VLCDefaultValueSliderCell
+
+// Colors
+@property NSColor *gradientColor;
+@property NSColor *gradientColor2;
+@property NSColor *trackStrokeColor;
+@property NSColor *filledTrackColor;
+@property NSColor *knobFillColor;
+@property NSColor *activeKnobFillColor;
+@property NSColor *shadowColor;
+@property NSColor *knobStrokeColor;
+@property NSColor *highlightBackground;
+
+// Gradients
+@property NSGradient *trackGradient;
+@property NSGradient *highlightGradient;
+@property NSGradient *knobGradient;
+
+// Shadows
+@property NSShadow *knobShadow;
+
+- (void)setSliderStyleLight;
+- (void)setSliderStyleDark;
+
+@end
diff --git a/modules/gui/macosx/VLCVolumeSliderCell.m b/modules/gui/macosx/VLCVolumeSliderCell.m
new file mode 100644 (file)
index 0000000..61c1312
--- /dev/null
@@ -0,0 +1,198 @@
+/*****************************************************************************
+ * VLCVolumeSliderCell.m
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Marvin Scholz <epirat07 at gmail dot com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+
+#import "VLCVolumeSliderCell.h"
+
+@implementation VLCVolumeSliderCell
+
+- (instancetype)init
+{
+    self = [super init];
+    if (self) {
+        [self setSliderStyleLight];
+    }
+    return self;
+}
+
+- (instancetype)initWithCoder:(NSCoder *)coder
+{
+    self = [super initWithCoder:coder];
+    if (self) {
+        [self setSliderStyleLight];
+    }
+    return self;
+}
+
+- (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 colorWithCalibratedRed: 0.55 green: 0.55 blue: 0.55 alpha: 1];
+    _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];
+
+    // 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)setSliderStyleDark
+{
+    // Color Declarations
+    _gradientColor = [NSColor colorWithCalibratedRed: 0.24 green: 0.24 blue: 0.24 alpha: 1];
+    _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];
+
+    // 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, 5.0, 5.0)];
+    if (self.isHighlighted) {
+        if (_knobGradient) {
+            [_knobGradient drawInBezierPath:knobPath angle:270];
+        } else {
+            [_activeKnobFillColor setFill];
+        }
+    } else {
+        if (_knobGradient) {
+            [_knobGradient drawInBezierPath:knobPath angle:90];
+        } else {
+            [_knobFillColor setFill];
+        }
+    }
+
+    if (!_knobGradient)
+        [knobPath fill];
+
+    [_knobStrokeColor setStroke];
+    knobPath.lineWidth = 0.5;
+
+    [NSGraphicsContext saveGraphicsState];
+    if (self.isHighlighted)
+        [_knobShadow set];
+    [knobPath stroke];
+    [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
+    rect = NSInsetRect(rect, 1.0, 1.0);
+
+    // Empty Track Drawing
+    NSBezierPath* emptyTrackPath = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:1 yRadius:1];
+    [_trackGradient drawInBezierPath:emptyTrackPath angle:-90];
+
+    // Calculate filled track
+    NSRect filledTrackRect = rect;
+    NSRect knobRect = [self knobRectFlipped:NO];
+    filledTrackRect.size.width = knobRect.origin.x + (self.knobThickness / 2);
+
+    // Filled Track Drawing
+    CGFloat filledTrackCornerRadius = 2;
+    NSBezierPath* filledTrackPath = [NSBezierPath bezierPathWithRoundedRect:filledTrackRect
+                                                                    xRadius:filledTrackCornerRadius
+                                                                    yRadius:filledTrackCornerRadius];
+
+    [_filledTrackColor setFill];
+    [filledTrackPath fill];
+
+    [_trackStrokeColor setStroke];
+    emptyTrackPath.lineWidth = 1;
+    [emptyTrackPath stroke];
+}
+
+@end