[vlc-commits] macOS: No custom HUD drawing on macOS 10.10+

Marvin Scholz git at videolan.org
Sat Jun 24 11:21:41 CEST 2017


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Sat Jun 24 11:17:05 2017 +0200| [9e9f4934fced0251009b1c73363a619c4d493873] | committer: Marvin Scholz

macOS: No custom HUD drawing on macOS 10.10+

Do not do custom HUD controls drawing on macOS 10.10 and higher, as
those have vibrancy, where nearly all controls look good on the HUD
panels.

The only exception is the OutlineView, as that one does not look good.

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

 modules/gui/macosx/VLCHUDButtonCell.m      | 16 +++++++++++++++
 modules/gui/macosx/VLCHUDPopUpButtonCell.m | 14 +++++++++++++
 modules/gui/macosx/VLCHUDScroller.m        | 16 +++++++++++++++
 modules/gui/macosx/VLCHUDSliderCell.m      | 10 ++++++++++
 modules/gui/macosx/VLCHUDStepperCell.m     | 13 ++++++++++++
 modules/gui/macosx/VLCHUDTextFieldCell.m   | 32 +++++++++++++-----------------
 6 files changed, 83 insertions(+), 18 deletions(-)

diff --git a/modules/gui/macosx/VLCHUDButtonCell.m b/modules/gui/macosx/VLCHUDButtonCell.m
index 6b0eaa6202..a61023fd66 100644
--- a/modules/gui/macosx/VLCHUDButtonCell.m
+++ b/modules/gui/macosx/VLCHUDButtonCell.m
@@ -33,9 +33,25 @@
 //	POSSIBILITY OF SUCH DAMAGE.
 
 #import "VLCHUDButtonCell.h"
+#import "CompatibilityFixes.h"
 
 @implementation VLCHUDButtonCell
 
+
++ (void)load
+{
+    /* On 10.10+ we do not want custom drawing, therefore we swap out the implementation
+     * of the selectors below with their original implementations.
+     * Just calling super is not enough, as it would still result in different drawing
+     * due to lack of vibrancy.
+     */
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        swapoutOverride([VLCHUDButtonCell class], @selector(initWithCoder:));
+        swapoutOverride([VLCHUDButtonCell class], @selector(drawBezelWithFrame:inView:));
+        swapoutOverride([VLCHUDButtonCell class], @selector(drawTitle:withFrame:inView:));
+    }
+}
+
 - (instancetype)initWithCoder:(NSCoder *)coder
 {
     self = [super initWithCoder:coder];
diff --git a/modules/gui/macosx/VLCHUDPopUpButtonCell.m b/modules/gui/macosx/VLCHUDPopUpButtonCell.m
index b7248cf655..b07fd3996c 100644
--- a/modules/gui/macosx/VLCHUDPopUpButtonCell.m
+++ b/modules/gui/macosx/VLCHUDPopUpButtonCell.m
@@ -33,9 +33,23 @@
 //	POSSIBILITY OF SUCH DAMAGE.
 
 #import "VLCHUDPopUpButtonCell.h"
+#import "CompatibilityFixes.h"
 
 @implementation VLCHUDPopUpButtonCell
 
++ (void)load
+{
+    /* On 10.10+ we do not want custom drawing, therefore we swap out the implementation
+     * of the selectors below with their original implementations.
+     * Just calling super in the overridden methods is not enough, to get the same drawin
+     * a non-subclassed cell would use.
+     */
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        swapoutOverride([VLCHUDPopUpButtonCell class], @selector(initWithCoder:));
+        swapoutOverride([VLCHUDPopUpButtonCell class], @selector(drawWithFrame:inView:));
+    }
+}
+
 - (instancetype)initWithCoder:(NSCoder *)coder
 {
     self = [super initWithCoder:coder];
diff --git a/modules/gui/macosx/VLCHUDScroller.m b/modules/gui/macosx/VLCHUDScroller.m
index 9ed98c60d7..4fc4933717 100644
--- a/modules/gui/macosx/VLCHUDScroller.m
+++ b/modules/gui/macosx/VLCHUDScroller.m
@@ -35,6 +35,7 @@
 // transparent drawing issues.  Your awesome man!!!
 
 #import "VLCHUDScroller.h"
+#import "CompatibilityFixes.h"
 
 @implementation VLCHUDScroller
 
@@ -58,6 +59,9 @@
 #pragma mark Drawing Functions
 
 - (void)drawRect:(NSRect)rect {
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        return [super drawRect:rect];
+    }
     // See if we should use system default or supplied value
     if ([self arrowsPosition] == NSScrollerArrowsDefaultSetting) {
         arrowPosition = [[[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain] valueForKey: @"AppleScrollBarVariant"];
@@ -91,6 +95,9 @@
 }
 
 - (void)drawKnob {
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        return [super drawKnob];
+    }
 
     if(![self isHoriz]) {
 
@@ -173,6 +180,9 @@
 }
 
 - (void)drawArrow:(NSScrollerArrow)arrow highlightPart:(NSUInteger)part {
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        return [super drawArrow:arrow highlight:part];
+    }
 
     if (arrow == NSScrollerDecrementArrow) {
 
@@ -196,6 +206,9 @@
 }
 
 - (void)drawKnobSlotInRect:(NSRect)rect highlight:(BOOL)highlight {
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        return [super drawKnobSlotInRect:rect highlight:highlight];
+    }
 
     if (![self isHoriz]) {
 
@@ -687,6 +700,9 @@
 #pragma mark -
 #pragma mark Helper Methods
 - (NSUsableScrollerParts)usableParts {
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        return [super usableParts];
+    }
 
     if ([self arrowsPosition] != NSScrollerArrowsNone) {
 
diff --git a/modules/gui/macosx/VLCHUDSliderCell.m b/modules/gui/macosx/VLCHUDSliderCell.m
index 751a9d32a5..47ff7096c3 100644
--- a/modules/gui/macosx/VLCHUDSliderCell.m
+++ b/modules/gui/macosx/VLCHUDSliderCell.m
@@ -33,6 +33,7 @@
 //	POSSIBILITY OF SUCH DAMAGE.
 
 #import "VLCHUDSliderCell.h"
+#import "CompatibilityFixes.h"
 
 @implementation VLCHUDSliderCell
 
@@ -68,6 +69,9 @@ NSAffineTransform* RotationTransform(const CGFloat angle, const NSPoint point)
 #pragma clang diagnostic ignored "-Wpartial-availability"
 - (void)drawKnob:(NSRect)smallRect
 {
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        return [super drawKnob:smallRect];
+    }
     NSBezierPath *path = [NSBezierPath bezierPath];
     // Inset rect to have enough room for the stroke
     smallRect = NSInsetRect(smallRect, 1.0, 1.0);
@@ -155,6 +159,9 @@ NSAffineTransform* RotationTransform(const CGFloat angle, const NSPoint point)
 
 - (void)drawBarInside:(NSRect)fullRect flipped:(BOOL)flipped
 {
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        return [super drawBarInside:fullRect flipped:flipped];
+    }
     if (self.isVertical) {
         return [self drawVerticalBarInFrame:fullRect];
     } else {
@@ -315,6 +322,9 @@ NSAffineTransform* RotationTransform(const CGFloat angle, const NSPoint point)
 
 - (void)drawTickMarks
 {
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        return [super drawTickMarks];
+    }
     for (int i = 0; i < self.numberOfTickMarks; i++) {
         NSRect tickMarkRect = [self rectOfTickMarkAtIndex:i];
         if (self.isEnabled) {
diff --git a/modules/gui/macosx/VLCHUDStepperCell.m b/modules/gui/macosx/VLCHUDStepperCell.m
index 30306c6e98..1e5253e011 100644
--- a/modules/gui/macosx/VLCHUDStepperCell.m
+++ b/modules/gui/macosx/VLCHUDStepperCell.m
@@ -33,6 +33,7 @@
 //	POSSIBILITY OF SUCH DAMAGE.
 
 #import "VLCHUDStepperCell.h"
+#import "CompatibilityFixes.h"
 
 @implementation VLCHUDStepperCell {
     int topButtonFlag;
@@ -69,6 +70,9 @@
 }
 
 -(void)drawWithFrame:(NSRect) frame inView:(NSView *) controlView {
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        return [super drawWithFrame:frame inView:controlView];
+    }
     [self drawRoundRectButtonInFrame:frame];
     [self drawArrowsInRect:frame];
 }
@@ -84,6 +88,9 @@
 
 -(BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
 {
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        return [super startTrackingAt:startPoint inView:controlView];
+    }
     NSRect frame = [controlView bounds];
 
     NSRect bottomRect = NSMakeRect(frame.origin.x,frame.origin.y,frame.size.width,frame.size.height/2);
@@ -103,6 +110,9 @@
 }
 -(BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView
 {
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        return [super continueTracking:lastPoint at:currentPoint inView:controlView];
+    }
     NSRect frame = [controlView bounds];
 
     NSRect bottomRect = NSMakeRect(frame.origin.x,frame.origin.y,frame.size.width,frame.size.height/2);
@@ -133,6 +143,9 @@
 }
 -(void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag
 {
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        return [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
+    }
     isTopDown = isBottomDown = topPressed = bottomPressed = NO;
     [[self controlView] setNeedsDisplay:YES];
     [super stopTracking:lastPoint at:stopPoint inView:controlView mouseIsUp:flag];
diff --git a/modules/gui/macosx/VLCHUDTextFieldCell.m b/modules/gui/macosx/VLCHUDTextFieldCell.m
index 61104605a2..a58a131647 100644
--- a/modules/gui/macosx/VLCHUDTextFieldCell.m
+++ b/modules/gui/macosx/VLCHUDTextFieldCell.m
@@ -54,6 +54,20 @@
 
 @implementation VLCHUDTextFieldCell
 
++ (void)load
+{
+    /* On 10.10+ we do not want custom drawing, therefore we swap out the implementation
+     * of the selectors below with their original implementations.
+     */
+    if (OSX_YOSEMITE_AND_HIGHER) {
+        swapoutOverride([VLCHUDTextFieldCell class], @selector(initTextCell:));
+        swapoutOverride([VLCHUDTextFieldCell class], @selector(initWithCoder:));
+        swapoutOverride([VLCHUDTextFieldCell class], @selector(setUpFieldEditorAttributes:));
+        swapoutOverride([VLCHUDTextFieldCell class], @selector(drawWithFrame:inView:));
+        swapoutOverride([VLCHUDTextFieldCell class], @selector(_drawKeyboardFocusRingWithFrame:inView:));
+    }
+}
+
 #pragma mark Drawing Functions
 
 - (instancetype)initTextCell:(NSString *)aString
@@ -80,10 +94,6 @@
 
 - (void)commonInit
 {
-    if (OSX_YOSEMITE_AND_HIGHER) {
-        return;
-    }
-
     // Init colors
     _focusRing = [[NSShadow alloc] init];
     [_focusRing setShadowColor:NSColor.whiteColor];
@@ -114,10 +124,6 @@
 
 - (NSText *)setUpFieldEditorAttributes:(NSText *)textObj
 {
-    if (OSX_YOSEMITE_AND_HIGHER) {
-        return [super setUpFieldEditorAttributes:textObj];
-    }
-
     NSText *newText = [super setUpFieldEditorAttributes:textObj];
     NSColor *textColor = _cellTextColor;
     [(NSTextView *)newText setInsertionPointColor:textColor];
@@ -126,10 +132,6 @@
 
 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
 {
-    if (OSX_YOSEMITE_AND_HIGHER) {
-        return [super drawWithFrame:cellFrame inView:controlView];
-    }
-
     // Adjust Rect
     cellFrame = NSInsetRect(cellFrame, 0.5f, 0.5f);
 
@@ -293,12 +295,6 @@
 
 - (void)_drawKeyboardFocusRingWithFrame:(NSRect)rect inView:(NSView*)view
 {
-    if (OSX_YOSEMITE_AND_HIGHER) {
-        if ([super respondsToSelector:@selector(_drawKeyboardFocusRingWithFrame:inView:)]) {
-            [super _drawKeyboardFocusRingWithFrame:rect inView:view];
-        }
-    }
-
     // Do nothing
 }
 



More information about the vlc-commits mailing list