[vlc-commits] macOS: Fix drawing of VLCHUDSliderCell track

Marvin Scholz git at videolan.org
Thu Jun 15 20:30:17 CEST 2017


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Thu Jun 15 13:37:27 2017 +0200| [99bd6c0239b32f78e07cfd30ef4a08f32e34b30d] | committer: Marvin Scholz

macOS: Fix drawing of VLCHUDSliderCell track

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

 modules/gui/macosx/VLCHUDSliderCell.h |  55 ++++----
 modules/gui/macosx/VLCHUDSliderCell.m | 227 +++++++++++++++++++++++++++-------
 2 files changed, 213 insertions(+), 69 deletions(-)

diff --git a/modules/gui/macosx/VLCHUDSliderCell.h b/modules/gui/macosx/VLCHUDSliderCell.h
index e0271f3a66..a9a76951ac 100644
--- a/modules/gui/macosx/VLCHUDSliderCell.h
+++ b/modules/gui/macosx/VLCHUDSliderCell.h
@@ -1,25 +1,36 @@
-/*****************************************************************************
- * VLCHUDSliderCell.h: Custom slider cell UI for dark HUD Panels
- *****************************************************************************
- * Copyright (C) 2016 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.
- *****************************************************************************/
+//
+//  VLCHUDSliderCell.m
+//  BGHUDAppKit
+//
+//  Created by BinaryGod on 5/30/08.
+//
+//  Copyright (c) 2008, Tim Davis (BinaryMethod.com, binary.god at gmail.com)
+//  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>
 
diff --git a/modules/gui/macosx/VLCHUDSliderCell.m b/modules/gui/macosx/VLCHUDSliderCell.m
index b879fbe580..244c832d3d 100644
--- a/modules/gui/macosx/VLCHUDSliderCell.m
+++ b/modules/gui/macosx/VLCHUDSliderCell.m
@@ -1,25 +1,36 @@
-/*****************************************************************************
- * VLCHUDSliderCell.m: Custom slider cell UI for dark HUD Panels
- *****************************************************************************
- * Copyright (C) 2016 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.
- *****************************************************************************/
+//
+//  VLCHUDSliderCell.m
+//  BGHUDAppKit
+//
+//  Created by BinaryGod on 5/30/08.
+//
+//  Copyright (c) 2008, Tim Davis (BinaryMethod.com, binary.god at gmail.com)
+//  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 "VLCHUDSliderCell.h"
 
@@ -144,41 +155,163 @@ NSAffineTransform* RotationTransform(const CGFloat angle, const NSPoint point)
 
 - (void)drawBarInside:(NSRect)fullRect flipped:(BOOL)flipped
 {
-    NSBezierPath *path;
+    if (self.isVertical) {
+        return [self drawVerticalBarInFrame:fullRect];
+    } else {
+        return [self drawHorizontalBarInFrame:fullRect];
+    }
+}
+#pragma clang diagnostic pop
 
-    // Determine current position of knob
-    CGFloat knobPosition = (self.doubleValue - self.minValue) / (self.maxValue - self.minValue);
+- (void)drawVerticalBarInFrame:(NSRect)frame
+{
+    // Adjust frame based on ControlSize
+    switch ([self controlSize]) {
 
-    // Copy rect
-    NSRect activeRect = fullRect;
+        case NSRegularControlSize:
 
-    // Do not draw disabled part for sliders with tickmarks
-    if (self.numberOfTickMarks == 0) {
-        if (self.isVertical) {
-            // Calculate active rect (bottom part of slider)
-            if (flipped) {
-                activeRect.origin.y = (1 - knobPosition) * activeRect.size.height;
-                activeRect.size.height -= activeRect.origin.y - 1;
+            if ([self numberOfTickMarks] != 0) {
+                if ([self tickMarkPosition] == NSTickMarkRight) {
+                    frame.origin.x += 4;
+                } else {
+                    frame.origin.x += frame.size.width - 9;
+                }
             } else {
-                activeRect.size.height -= (1 - knobPosition) * activeRect.size.height - 1;
+                frame.origin.x = frame.origin.x + (((frame.origin.x + frame.size.width) /2) - 2.5f);
             }
-        } else {
-            // Calculate active rect (left part of slider)
-            activeRect.size.width = knobPosition * (self.controlView.frame.size.width - 1.0);
-        }
+            frame.origin.x += 0.5f;
+            frame.origin.y += 2.5f;
+            frame.size.height -= 6;
+            frame.size.width = 5;
+            break;
+
+        case NSSmallControlSize:
+
+            if ([self numberOfTickMarks] != 0) {
+                if ([self tickMarkPosition] == NSTickMarkRight) {
+                    frame.origin.x += 3;
+                } else {
+                    frame.origin.x += frame.size.width - 8;
+                }
+            } else {
+                frame.origin.x = frame.origin.x + (((frame.origin.x + frame.size.width) /2) - 2.5f);
+            }
+            frame.origin.y += 0.5f;
+            frame.size.height -= 1;
+            frame.origin.x += 0.5f;
+            frame.size.width = 5;
+            break;
+
+        case NSMiniControlSize:
+
+            if ([self numberOfTickMarks] != 0) {
+                if ([self tickMarkPosition] == NSTickMarkRight) {
+                    frame.origin.x += 2.5f;
+                } else {
+                    frame.origin.x += frame.size.width - 6.5f;
+                }
+            } else {
+                frame.origin.x = frame.origin.x + (((frame.origin.x + frame.size.width) /2) - 2);
+            }
+            frame.origin.x += 1;
+            frame.origin.y += 0.5f;
+            frame.size.height -= 1;
+            frame.size.width = 3;
+            break;
+    }
+    
+    // Draw Bar
+    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect: frame xRadius: 2 yRadius: 2];
+    
+    if ([self isEnabled]) {
+        [_sliderColor set];
+        [path fill];
 
-        // Draw inactive bar
-        [_disabledSliderColor setFill];
-        path = [NSBezierPath bezierPathWithRoundedRect:fullRect xRadius:2.0 yRadius:2.0];
+        [_strokeColor set];
+        [path stroke];
+    } else {
+        [_disabledSliderColor set];
         [path fill];
+
+        [_disabledStrokeColor set];
+        [path stroke];
     }
+}
+
+- (void)drawHorizontalBarInFrame:(NSRect)frame
+{
+    // Adjust frame based on ControlSize
+    switch ([self controlSize]) {
+
+        case NSRegularControlSize:
+
+            if ([self numberOfTickMarks] != 0) {
+                if ([self tickMarkPosition] == NSTickMarkBelow) {
+                    frame.origin.y += 4;
+                } else {
+                    frame.origin.y += frame.size.height - 10;
+                }
+            } else {
+                frame.origin.y = frame.origin.y + (((frame.origin.y + frame.size.height) /2) - 2.5f);
+            }
+            frame.origin.x += 2.5f;
+            frame.origin.y += 0.5f;
+            frame.size.width -= 5;
+            frame.size.height = 5;
+            break;
+
+        case NSSmallControlSize:
+
+            if ([self numberOfTickMarks] != 0) {
+                if ([self tickMarkPosition] == NSTickMarkBelow) {
+                    frame.origin.y += 2;
+                } else {
+                    frame.origin.y += frame.size.height - 8;
+                }
+            } else {
+                frame.origin.y = frame.origin.y + (((frame.origin.y + frame.size.height) /2) - 2.5f);
+            }
+            frame.origin.x += 0.5f;
+            frame.origin.y += 0.5f;
+            frame.size.width -= 1;
+            frame.size.height = 5;
+            break;
+
+        case NSMiniControlSize:
 
-    // Draw active bar
-    [_sliderColor setFill];
-    path = [NSBezierPath bezierPathWithRoundedRect:activeRect xRadius:2.0 yRadius:2.0];
-    [path fill];
+            if ([self numberOfTickMarks] != 0) {
+                if ([self tickMarkPosition] == NSTickMarkBelow) {
+                    frame.origin.y += 2;
+                } else {
+                    frame.origin.y += frame.size.height - 6;
+                }
+            } else {
+                frame.origin.y = frame.origin.y + (((frame.origin.y + frame.size.height) /2) - 2);
+            }
+            frame.origin.x += 0.5f;
+            frame.origin.y += 0.5f;
+            frame.size.width -= 1;
+            frame.size.height = 3;
+            break;
+    }
+    
+    // Draw Bar
+    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:frame xRadius:2 yRadius:2];
+    
+    if ([self isEnabled]) {
+        [_sliderColor set];
+        [path fill];
+        
+        [_strokeColor set];
+        [path stroke];
+    } else {
+        [_disabledSliderColor set];
+        [path fill];
+        
+        [_disabledStrokeColor set];
+        [path stroke];
+    }
 }
-#pragma clang diagnostic pop
 
 - (void)drawTickMarks
 {



More information about the vlc-commits mailing list