macOS: Add VLCHUDStepperCell
authorMarvin Scholz <epirat07@gmail.com>
Sat, 24 Jun 2017 02:50:10 +0000 (04:50 +0200)
committerMarvin Scholz <epirat07@gmail.com>
Sat, 24 Jun 2017 02:50:39 +0000 (04:50 +0200)
extras/package/macosx/VLC.xcodeproj/project.pbxproj
modules/gui/macosx/Makefile.am
modules/gui/macosx/VLCHUDStepperCell.h [new file with mode: 0644]
modules/gui/macosx/VLCHUDStepperCell.m [new file with mode: 0644]

index fa93372..5e960a2 100644 (file)
@@ -87,6 +87,7 @@
                6BBB05E01EEFF165003A1019 /* VLCHUDTableCornerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BBB05DF1EEFF165003A1019 /* VLCHUDTableCornerView.m */; };
                6BBB05E31EF08181003A1019 /* VLCHUDSegmentedCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BBB05E21EF08181003A1019 /* VLCHUDSegmentedCell.m */; };
                6BF093F91EE0182B0049D8B0 /* VLCTimeField.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BF093F81EE0182B0049D8B0 /* VLCTimeField.m */; };
+               6BF5C5011EFE03CF008A9C12 /* VLCHUDStepperCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6BF5C5001EFE03CF008A9C12 /* VLCHUDStepperCell.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
                6BF093F71EE0182B0049D8B0 /* VLCTimeField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCTimeField.h; sourceTree = "<group>"; };
                6BF093F81EE0182B0049D8B0 /* VLCTimeField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCTimeField.m; sourceTree = "<group>"; };
                6BF557CF1E4E0E2500C03C9D /* VLCPauseTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = VLCPauseTemplate.pdf; path = "Button-Icons/VLCPauseTemplate.pdf"; sourceTree = "<group>"; };
+               6BF5C4FF1EFE03CF008A9C12 /* VLCHUDStepperCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCHUDStepperCell.h; sourceTree = "<group>"; };
+               6BF5C5001EFE03CF008A9C12 /* VLCHUDStepperCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCHUDStepperCell.m; sourceTree = "<group>"; };
                7D5678EB1D5BA1DC002698F3 /* VLCApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCApplication.h; sourceTree = "<group>"; };
                7D5678EC1D5BA1DC002698F3 /* VLCApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCApplication.m; sourceTree = "<group>"; };
                7D5678EE1D5BA397002698F3 /* VLCMainWindowControlsBar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCMainWindowControlsBar.h; sourceTree = "<group>"; };
                                6B846FDD1CF5D88C00112E54 /* VLCHUDButtonCell.m */,
                                6B846FDE1CF5D88C00112E54 /* VLCHUDCheckboxCell.h */,
                                6B846FDF1CF5D88C00112E54 /* VLCHUDCheckboxCell.m */,
+                               6BF5C4FF1EFE03CF008A9C12 /* VLCHUDStepperCell.h */,
+                               6BF5C5001EFE03CF008A9C12 /* VLCHUDStepperCell.m */,
                                6B846FE01CF5D88C00112E54 /* VLCHUDRadiobuttonCell.h */,
                                6B846FE11CF5D88C00112E54 /* VLCHUDRadiobuttonCell.m */,
                                6B846FE21CF5D88C00112E54 /* VLCHUDSliderCell.h */,
                                1C3113B11E508C6900D4DD76 /* VLCFSPanelDraggableView.m in Sources */,
                                1C3113B41E508C6900D4DD76 /* VLCInputManager.m in Sources */,
                                1C3113B61E508C6900D4DD76 /* VLCMain+OldPrefs.m in Sources */,
+                               6BF5C5011EFE03CF008A9C12 /* VLCHUDStepperCell.m in Sources */,
                                1C3113B81E508C6900D4DD76 /* VLCMain.m in Sources */,
                                1C3113BA1E508C6900D4DD76 /* VLCApplication.m in Sources */,
                                1C3113BC1E508C6900D4DD76 /* VLCKeyboardBacklightControl.m in Sources */,
index 579bf4f..72a2b52 100644 (file)
@@ -82,6 +82,7 @@ libmacosx_plugin_la_SOURCES = \
        gui/macosx/VLCHUDTableCornerView.h gui/macosx/VLCHUDTableCornerView.m \
        gui/macosx/VLCHUDTableHeaderCell.h gui/macosx/VLCHUDTableHeaderCell.m \
        gui/macosx/VLCHUDSegmentedCell.h gui/macosx/VLCHUDSegmentedCell.m \
+       gui/macosx/VLCHUDStepperCell.h gui/macosx/VLCHUDStepperCell.m \
        gui/macosx/VLCPopUpButtonCell.h gui/macosx/VLCPopUpButtonCell.m \
        gui/macosx/VLCInputManager.h gui/macosx/VLCInputManager.m \
        gui/macosx/VLCMainWindow.h gui/macosx/VLCMainWindow.m \
diff --git a/modules/gui/macosx/VLCHUDStepperCell.h b/modules/gui/macosx/VLCHUDStepperCell.h
new file mode 100644 (file)
index 0000000..552a59b
--- /dev/null
@@ -0,0 +1,49 @@
+//
+//  BGHUDStepperCell.m
+//  BGHUDAppKit
+//
+//  Created by BinaryGod on 4/6/09.
+//
+//  Copyright 2009 Tyler Bunnell and Steve Audette
+//     All rights reserved.
+//
+//  Redistribution and use in source and binary forms, with or without modification,
+//  are permitted provided that the following conditions are met:
+//
+//             Redistributions of source code must retain the above copyright notice, this
+//     list of conditions and the following disclaimer.
+//
+//             Redistributions in binary form must reproduce the above copyright notice,
+//     this list of conditions and the following disclaimer in the documentation and/or
+//     other materials provided with the distribution.
+//
+//             Neither the name of the BinaryMethod.com nor the names of its contributors
+//     may be used to endorse or promote products derived from this software without
+//     specific prior written permission.
+//
+//     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND
+//     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+//     IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+//     INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+//     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+//     OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+//     WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+//     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+//     POSSIBILITY OF SUCH DAMAGE.
+
+#import <Cocoa/Cocoa.h>
+
+@interface VLCHUDStepperCell : NSStepperCell
+
+@property NSGradient *normalGradient;
+@property NSGradient *disabledNormalComplexGradient;
+
+@property NSColor *pushedSolidFill;
+@property NSColor *darkStrokeColor;
+@property NSColor *strokeColor;
+@property NSColor *disabledStrokeColor;
+
+@property NSShadow *dropShadow;
+
+@end
diff --git a/modules/gui/macosx/VLCHUDStepperCell.m b/modules/gui/macosx/VLCHUDStepperCell.m
new file mode 100644 (file)
index 0000000..30306c6
--- /dev/null
@@ -0,0 +1,334 @@
+//
+//  BGHUDStepperCell.m
+//  BGHUDAppKit
+//
+//  Created by BinaryGod on 4/6/09.
+//
+//  Copyright 2009 Tyler Bunnell and Steve Audette
+//     All rights reserved.
+//
+//  Redistribution and use in source and binary forms, with or without modification,
+//  are permitted provided that the following conditions are met:
+//
+//             Redistributions of source code must retain the above copyright notice, this
+//     list of conditions and the following disclaimer.
+//
+//             Redistributions in binary form must reproduce the above copyright notice,
+//     this list of conditions and the following disclaimer in the documentation and/or
+//     other materials provided with the distribution.
+//
+//             Neither the name of the BinaryMethod.com nor the names of its contributors
+//     may be used to endorse or promote products derived from this software without
+//     specific prior written permission.
+//
+//     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND
+//     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+//     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+//     IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+//     INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+//     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+//     OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+//     WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+//     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+//     POSSIBILITY OF SUCH DAMAGE.
+
+#import "VLCHUDStepperCell.h"
+
+@implementation VLCHUDStepperCell {
+    int topButtonFlag;
+    int bottomButtonFlag;
+
+    BOOL topPressed;
+    BOOL bottomPressed;
+    BOOL isTopDown;
+    BOOL isBottomDown;
+}
+
+- (instancetype)initWithCoder:(NSCoder *)coder
+{
+    self = [super initWithCoder:coder];
+    if (self) {
+        _dropShadow = [[NSShadow alloc] init];
+        [_dropShadow setShadowColor: [NSColor blackColor]];
+        [_dropShadow setShadowBlurRadius: 2];
+        [_dropShadow setShadowOffset: NSMakeSize( 0, -1)];
+
+        _strokeColor = [NSColor colorWithDeviceRed: 0.749f green: 0.761f blue: 0.788f alpha: 1.0f];
+        _disabledStrokeColor = [NSColor colorWithDeviceRed: 0.749f green: 0.761f blue: 0.788f alpha:0.2f];
+
+        _normalGradient    = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceRed:0.251f green:0.251f blue:0.255f alpha:1.0f]
+                                                           endingColor:[NSColor colorWithDeviceRed:0.118f green:0.118f blue:0.118f alpha:1.0f]];
+        _disabledNormalComplexGradient = [[NSGradient alloc] initWithColorsAndLocations: [NSColor colorWithDeviceRed: 0.324f green: 0.331f blue: 0.347f alpha:0.5f],
+                                           (CGFloat)0, [NSColor colorWithDeviceRed: 0.245f green: 0.253f blue: 0.269f alpha: 0.5f], (CGFloat).5,
+                                           [NSColor colorWithDeviceRed: 0.206f green: 0.214f blue: 0.233f alpha: 0.5f], (CGFloat).5,
+                                           [NSColor colorWithDeviceRed: 0.139f green: 0.147f blue: 0.167f alpha: 0.5f], (CGFloat)1.0f, nil];
+        _pushedSolidFill = [NSColor colorWithDeviceRed: 0.941f green: 0.941f blue: 0.941f alpha: 0.5f];
+        _darkStrokeColor = [NSColor colorWithDeviceRed: 0.141f green: 0.141f blue: 0.141f alpha: 0.5f];
+    }
+    return self;
+}
+
+-(void)drawWithFrame:(NSRect) frame inView:(NSView *) controlView {
+    [self drawRoundRectButtonInFrame:frame];
+    [self drawArrowsInRect:frame];
+}
+
+-(NSRect)adjustFrame:(NSRect)frame
+{
+    frame.origin.x += 3.5f;
+    frame.origin.y += 2.0f;
+    frame.size.width -= 7.0f;
+    frame.size.height -= 4.0f;
+    return frame;
+}
+
+-(BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
+{
+    NSRect frame = [controlView bounds];
+
+    NSRect bottomRect = NSMakeRect(frame.origin.x,frame.origin.y,frame.size.width,frame.size.height/2);
+    NSRect topRect = NSMakeRect(frame.origin.x,frame.origin.y+(frame.size.height/2),frame.size.width,frame.size.height/2);
+
+    if(NSPointInRect(startPoint,topRect))
+    {
+        topPressed = isTopDown = YES;
+    }
+    if(NSPointInRect(startPoint,bottomRect))
+    {
+        bottomPressed = isBottomDown = YES;
+    }
+    [[self controlView] setNeedsDisplay:YES];
+
+    return [super startTrackingAt:startPoint inView:controlView];
+}
+-(BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView
+{
+    NSRect frame = [controlView bounds];
+
+    NSRect bottomRect = NSMakeRect(frame.origin.x,frame.origin.y,frame.size.width,frame.size.height/2);
+    NSRect topRect = NSMakeRect(frame.origin.x,frame.origin.y+(frame.size.height/2),frame.size.width,frame.size.height/2);
+
+    if(isTopDown && topPressed && !NSPointInRect(currentPoint,topRect))
+    {
+        isTopDown = NO;
+        [[self controlView] setNeedsDisplay:YES];
+    }
+    if(!isTopDown && topPressed && NSPointInRect(currentPoint,topRect))
+    {
+        isTopDown = YES;
+        [[self controlView] setNeedsDisplay:YES];
+    }
+    if(isBottomDown && bottomPressed && !NSPointInRect(currentPoint,bottomRect))
+    {
+        isBottomDown = NO;
+        [[self controlView] setNeedsDisplay:YES];
+    }
+    if(!isBottomDown && bottomPressed && NSPointInRect(currentPoint,bottomRect))
+    {
+        isBottomDown = YES;
+        [[self controlView] setNeedsDisplay:YES];
+    }
+
+    return [super continueTracking:lastPoint at:currentPoint inView:controlView];
+}
+-(void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag
+{
+    isTopDown = isBottomDown = topPressed = bottomPressed = NO;
+    [[self controlView] setNeedsDisplay:YES];
+    [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
+}
+
+-(void)drawRoundRectButtonInFrame:(NSRect)frame {
+
+    frame = [self adjustFrame:frame];
+
+    float cornerRadius = 4.0f;
+
+    //Draw the complete button
+
+    //Create Path
+    NSBezierPath *path = [[NSBezierPath alloc] init];
+
+    //Bottom Right Corner
+    [path moveToPoint:NSMakePoint(NSMaxX(frame), NSMinY(frame) + cornerRadius)];
+
+    //Right Edge
+    [path lineToPoint:NSMakePoint(NSMaxX(frame), NSMaxY(frame) - cornerRadius)];
+
+    //Top Right Curve
+    [path appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(frame) - cornerRadius, NSMaxY(frame) - cornerRadius)
+                                     radius: cornerRadius
+                                 startAngle: 0
+                                   endAngle: 90];
+
+    //Top Edge
+    [path lineToPoint:NSMakePoint(NSMinX(frame) + cornerRadius, NSMaxY(frame))];
+
+    //Top Left Curve
+    [path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(frame) + cornerRadius, NSMaxY(frame) - cornerRadius)
+                                     radius: cornerRadius
+                                 startAngle: 90
+                                   endAngle: 180];
+
+    //Left Edge
+    [path lineToPoint:NSMakePoint(NSMinX(frame), NSMinY(frame) + cornerRadius)];
+
+    //Left Bottom Curve
+    [path appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(frame) + cornerRadius, NSMinY(frame) + cornerRadius)
+                                     radius: cornerRadius
+                                 startAngle: 180
+                                   endAngle: 270];
+
+    //Bottom Edge
+    [path lineToPoint:NSMakePoint(NSMaxX(frame) - cornerRadius, NSMinY(frame))];
+
+    //Right Bottom Curve
+    [path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(frame) - cornerRadius, NSMinY(frame) + cornerRadius)
+                                     radius: cornerRadius
+                                 startAngle: 270
+                                   endAngle: 0];
+
+    [path closePath];
+
+
+    if([self isEnabled]) {
+
+        [_normalGradient drawInBezierPath:path relativeCenterPosition:NSZeroPoint];
+
+    } else {
+
+        [_disabledNormalComplexGradient drawInBezierPath:path relativeCenterPosition:NSZeroPoint];
+    }
+
+
+
+    //Check for anything being pushed
+    if([self isEnabled])
+    {
+        if(isTopDown)
+        {
+            NSRect topRect = NSMakeRect(frame.origin.x,frame.origin.y+(frame.size.height/2),frame.size.width,frame.size.height/2);
+            NSBezierPath *path = [[NSBezierPath alloc] init];
+            [path moveToPoint:NSMakePoint(NSMaxX(topRect), NSMinY(topRect))];
+            [path lineToPoint:NSMakePoint(NSMaxX(topRect), NSMaxY(topRect) - cornerRadius)];
+            [path appendBezierPathWithArcWithCenter: NSMakePoint(NSMaxX(topRect) - cornerRadius, NSMaxY(topRect) - cornerRadius)
+                                             radius: cornerRadius
+                                         startAngle: 0
+                                           endAngle: 90];
+            [path lineToPoint:NSMakePoint(NSMinX(topRect) + cornerRadius, NSMaxY(topRect))];
+            [path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(topRect) + cornerRadius, NSMaxY(topRect) - cornerRadius)
+                                             radius: cornerRadius
+                                         startAngle: 90
+                                           endAngle: 180];
+            [path lineToPoint:NSMakePoint(NSMinX(topRect), NSMinY(topRect))];
+
+            [path closePath];
+
+            [_pushedSolidFill set];
+            [path fill];
+        }
+        else if(isBottomDown)
+        {
+            NSRect bottomRect = NSMakeRect(frame.origin.x,frame.origin.y,frame.size.width,frame.size.height/2);
+            NSBezierPath* path = [[NSBezierPath alloc] init];
+
+            [path moveToPoint:NSMakePoint(NSMinX(bottomRect), NSMaxY(bottomRect))];
+            [path lineToPoint:NSMakePoint(NSMinX(bottomRect), NSMinY(bottomRect) + cornerRadius)];
+            [path appendBezierPathWithArcWithCenter: NSMakePoint(NSMinX(bottomRect) + cornerRadius, NSMinY(bottomRect) + cornerRadius)
+                                             radius: cornerRadius
+                                         startAngle: 180
+                                           endAngle: 270];
+            [path lineToPoint:NSMakePoint(NSMaxX(bottomRect) - cornerRadius, NSMinY(bottomRect))];
+            [path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(bottomRect) - cornerRadius, NSMinY(bottomRect) + cornerRadius)
+                                             radius: cornerRadius
+                                         startAngle: 270
+                                           endAngle: 0];
+            [path lineToPoint:NSMakePoint(NSMaxX(bottomRect), NSMaxY(bottomRect))];
+
+            [path closePath];
+            [_pushedSolidFill set];
+            [path fill];
+        }
+    }
+
+    [NSGraphicsContext saveGraphicsState];
+
+    //Draw dark border color
+    if([self isEnabled]) {
+
+        [_dropShadow set];
+    }
+    [_darkStrokeColor set];
+    [path stroke];
+
+    [NSGraphicsContext restoreGraphicsState];
+
+    if([self isEnabled]) {
+
+        [_strokeColor set];
+    } else {
+
+        [_disabledStrokeColor set];
+    }
+
+    [path setLineWidth: 1.0f];
+    [path stroke];
+
+
+}
+
+-(void)drawArrowsInRect:(NSRect) frame {
+
+    CGFloat arrowWidth = 2.5f;
+    CGFloat arrowHeight = 2.0f;
+
+    frame = [self adjustFrame:frame];
+
+    NSRect bottomRect = NSMakeRect(frame.origin.x,frame.origin.y,frame.size.width,frame.size.height/2);
+    NSRect topRect = NSMakeRect(frame.origin.x,frame.origin.y+(frame.size.height/2),frame.size.width,frame.size.height/2);
+
+    NSBezierPath *arrow = [[NSBezierPath alloc] init];
+
+    NSPoint points[3];
+
+    points[0] = NSMakePoint(topRect.origin.x + (topRect.size.width /2), topRect.origin.y + ((topRect.size.height /2) + arrowHeight));
+    points[1] = NSMakePoint(topRect.origin.x + ((topRect.size.width /2) - arrowWidth), topRect.origin.y + ((topRect.size.height /2)-arrowHeight));
+    points[2] = NSMakePoint(topRect.origin.x + ((topRect.size.width /2) + arrowWidth), topRect.origin.y + ((topRect.size.height /2)-arrowHeight));
+    
+    
+    [arrow appendBezierPathWithPoints: points count: 3];
+    
+    if([self isEnabled]) {
+        if(isTopDown)
+            [_darkStrokeColor set];
+        else
+            [_strokeColor set];
+    } else {
+        [_disabledStrokeColor set];
+    }
+    
+    
+    [arrow fill];
+    
+    
+    arrow = [[NSBezierPath alloc] init];
+    
+    points[0] = NSMakePoint(bottomRect.origin.x + ((bottomRect.size.width /2) - arrowWidth), bottomRect.origin.y + ((bottomRect.size.height /2)+arrowHeight));
+    points[1] = NSMakePoint(bottomRect.origin.x + ((bottomRect.size.width /2) + arrowWidth), bottomRect.origin.y + ((bottomRect.size.height /2)+arrowHeight));
+    points[2] = NSMakePoint(bottomRect.origin.x + (bottomRect.size.width /2), frame.origin.y + ((bottomRect.size.height /2) - arrowHeight));
+    
+    [arrow appendBezierPathWithPoints: points count: 3];
+    
+    if([self isEnabled]) {
+        if(isBottomDown)
+            [_darkStrokeColor set];
+        else
+            [_strokeColor set];
+    } else {
+        [_disabledStrokeColor set];
+    }
+    
+    [arrow fill];
+}
+
+@end