[vlc-commits] macosx: Add VLCBottomBarView

Marvin Scholz git at videolan.org
Wed Aug 16 00:47:27 CEST 2017


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Tue Aug 15 21:53:35 2017 +0200| [3144986d63c6d9e8b9e2322d4bf52aced5dbbd52] | committer: Marvin Scholz

macosx: Add VLCBottomBarView

This adds a new View subclass, the VLCBottomBarView, which mimics the
Window border drawing of macOS windows.

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

 .../package/macosx/VLC.xcodeproj/project.pbxproj   |   6 +
 modules/gui/macosx/Makefile.am                     |   3 +-
 modules/gui/macosx/VLCBottomBarView.h              |  36 ++++++
 modules/gui/macosx/VLCBottomBarView.m              | 133 +++++++++++++++++++++
 4 files changed, 177 insertions(+), 1 deletion(-)

diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
index c7e4c23115..04720188b0 100644
--- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
@@ -71,6 +71,7 @@
 		1C31140D1E508C8800D4DD76 /* SPMediaKeyTap.m in Sources */ = {isa = PBXBuildFile; fileRef = CCF0777C13659A8000AF19FD /* SPMediaKeyTap.m */; };
 		1C69FDF61EAB30C7007724ED /* Windows.m in Sources */ = {isa = PBXBuildFile; fileRef = E06CF7F516020F6200C698B7 /* Windows.m */; };
 		1CFE8D591EA0D42A00E94451 /* VLCErrorWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1CFE8D581EA0D42A00E94451 /* VLCErrorWindowController.m */; };
+		6B0292E61F43256300A50082 /* VLCBottomBarView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B0292E51F43256300A50082 /* VLCBottomBarView.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 */; };
@@ -128,6 +129,8 @@
 		5CCED71514C0D4A90057F8D1 /* VLCUIWidgets.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCUIWidgets.m; sourceTree = "<group>"; };
 		633121CA1B51122700E636DA /* VLCResumeDialogController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCResumeDialogController.h; sourceTree = "<group>"; };
 		633121CB1B51122700E636DA /* VLCResumeDialogController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCResumeDialogController.m; sourceTree = "<group>"; };
+		6B0292E41F43256300A50082 /* VLCBottomBarView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCBottomBarView.h; sourceTree = "<group>"; };
+		6B0292E51F43256300A50082 /* VLCBottomBarView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCBottomBarView.m; sourceTree = "<group>"; };
 		6B0AB0EC1F1AC8B3003A1B4E /* VLCSlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCSlider.h; sourceTree = "<group>"; };
 		6B0AB0ED1F1AC8B3003A1B4E /* VLCSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCSlider.m; sourceTree = "<group>"; };
 		6B0AB0EE1F1AC8B3003A1B4E /* VLCSliderCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCSliderCell.h; sourceTree = "<group>"; };
@@ -813,6 +816,8 @@
 		08FB77AFFE84173DC02AAC07 /* Classes */ = {
 			isa = PBXGroup;
 			children = (
+				6B0292E41F43256300A50082 /* VLCBottomBarView.h */,
+				6B0292E51F43256300A50082 /* VLCBottomBarView.m */,
 				6B7F1FDD1F07DA920002BDD8 /* VLCHexNumberFormatter.h */,
 				6B7F1FDE1F07DA920002BDD8 /* VLCHexNumberFormatter.m */,
 				6B3BE42A1E6217CB008D098A /* VLCImageButton.h */,
@@ -1806,6 +1811,7 @@
 				1C3113BF1E508C6900D4DD76 /* VLCMainMenu.m in Sources */,
 				6B5978C51EFBFBF2003D9C80 /* VLCHUDPopUpButtonCell.m in Sources */,
 				1C3113C11E508C6900D4DD76 /* VLCMainWindow.m in Sources */,
+				6B0292E61F43256300A50082 /* VLCBottomBarView.m in Sources */,
 				1C3113C31E508C6900D4DD76 /* VLCMainWindowTitleView.m in Sources */,
 				1C3113C51E508C6900D4DD76 /* misc.m in Sources */,
 				1C18BE471F2926700053D329 /* keychain.m in Sources */,
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index c24c902eea..70dfbe1d84 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -102,7 +102,8 @@ libmacosx_plugin_la_SOURCES = \
 	gui/macosx/VLCSlider.h gui/macosx/VLCSlider.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
+	gui/macosx/VLCVolumeSliderCell.h gui/macosx/VLCVolumeSliderCell.m \
+	gui/macosx/VLCBottomBarView.h gui/macosx/VLCBottomBarView.m
 
 # User interface compilation
 
diff --git a/modules/gui/macosx/VLCBottomBarView.h b/modules/gui/macosx/VLCBottomBarView.h
new file mode 100644
index 0000000000..28980c1c7f
--- /dev/null
+++ b/modules/gui/macosx/VLCBottomBarView.h
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * VLCBottomBarView.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>
+
+ at interface VLCBottomBarView : NSView
+
+ at property NSGradient *lightGradient;
+ at property NSGradient *darkGradient;
+
+ at property NSColor *lightStroke;
+ at property NSColor *darkStroke;
+
+ at property (setter=setDark:) BOOL isDark;
+
+ at end
diff --git a/modules/gui/macosx/VLCBottomBarView.m b/modules/gui/macosx/VLCBottomBarView.m
new file mode 100644
index 0000000000..c9fab004f4
--- /dev/null
+++ b/modules/gui/macosx/VLCBottomBarView.m
@@ -0,0 +1,133 @@
+/*****************************************************************************
+ * VLCBottomBarView.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 "VLCBottomBarView.h"
+
+ at interface VLCBottomBarView () {
+    NSBezierPath *_rectanglePath;
+    NSBezierPath *_separatorPath;
+    NSRect _oldBounds;
+}
+
+ at end
+
+ at implementation VLCBottomBarView
+
+- (instancetype)initWithCoder:(NSCoder *)coder
+{
+    self = [super initWithCoder:coder];
+
+    if (self) {
+        [self commonInit];
+    }
+
+    return self;
+}
+
+- (instancetype)initWithFrame:(NSRect)frameRect
+{
+    self = [super initWithFrame:frameRect];
+
+    if (self) {
+        [self commonInit];
+    }
+
+    return self;
+}
+
+- (instancetype)init
+{
+    self = [super init];
+
+    if (self ) {
+        [self commonInit];
+    }
+
+    return self;
+}
+
+- (void)commonInit
+{
+    _lightGradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithSRGBRed:0.90 green:0.90 blue:0.90 alpha:1.0]
+                                                   endingColor:[NSColor colorWithSRGBRed:0.82 green:0.82 blue:0.82 alpha:1.0]];
+    _lightStroke = [NSColor colorWithSRGBRed:0.65 green:0.65 blue:0.65 alpha:1.0];
+
+    _darkGradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithSRGBRed:0.24 green:0.24 blue:0.24 alpha:1.0]
+                                                  endingColor:[NSColor colorWithSRGBRed:0.07 green:0.07 blue:0.07 alpha:1.0]];
+    _darkStroke = [NSColor blackColor];
+}
+
+- (void)calculatePaths
+{
+    if (CGRectEqualToRect(_oldBounds, self.bounds))
+        return;
+
+    _oldBounds = self.bounds;
+
+    NSRect barRect = _oldBounds;
+    CGFloat rectangleCornerRadius = 4;
+
+    // Calculate bottom bar path
+    NSRect rectangleInnerRect = NSInsetRect(barRect, rectangleCornerRadius, rectangleCornerRadius);
+
+    _rectanglePath = [NSBezierPath bezierPath];
+    [_rectanglePath appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(rectangleInnerRect), NSMinY(rectangleInnerRect)) radius: rectangleCornerRadius startAngle: 180 endAngle: 270];
+    [_rectanglePath appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(rectangleInnerRect), NSMinY(rectangleInnerRect)) radius: rectangleCornerRadius startAngle: 270 endAngle: 360];
+    [_rectanglePath lineToPoint: NSMakePoint(NSMaxX(barRect), NSMaxY(barRect))];
+    [_rectanglePath lineToPoint: NSMakePoint(NSMinX(barRect), NSMaxY(barRect))];
+    [_rectanglePath closePath];
+
+    // Calculate bottom bar separator stroke
+    _separatorPath = [NSBezierPath bezierPath];
+    [_separatorPath moveToPoint:NSMakePoint(NSMinX(barRect), NSMaxY(barRect) - 0.5)];
+    [_separatorPath lineToPoint:NSMakePoint(NSMaxX(barRect), NSMaxY(barRect) - 0.5)];
+    [_separatorPath setLineWidth:1.0];
+    [_separatorPath stroke];
+}
+
+- (void)drawRect:(NSRect)dirtyRect
+{
+    [self calculatePaths];
+
+    NSRect barRect = self.bounds;
+
+    [[NSColor clearColor] setFill];
+    NSRectFill(barRect);
+
+    if (_isDark) {
+        [_darkGradient drawInBezierPath:_rectanglePath angle:270.0];
+        [_darkStroke setStroke];
+    } else {
+        [_lightGradient drawInBezierPath:_rectanglePath angle:270.0];
+        [_lightStroke setStroke];
+    }
+
+    [_separatorPath stroke];
+}
+
+- (BOOL)isFlipped
+{
+    return NO;
+}
+
+ at end



More information about the vlc-commits mailing list