[vlc-commits] [Git][videolan/vlc][master] macosx: Rewrite VLCMainVideoViewOverlayView using CA layer
Felix Paul Kühne (@fkuehne)
gitlab at videolan.org
Mon Jul 21 15:50:36 UTC 2025
Felix Paul Kühne pushed to branch master at VideoLAN / VLC
Commits:
24db4216 by Claudio Cambra at 2025-07-21T15:18:33+00:00
macosx: Rewrite VLCMainVideoViewOverlayView using CA layer
Fixes rendering issues
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
2 changed files:
- modules/gui/macosx/windows/video/VLCMainVideoViewOverlayView.h
- modules/gui/macosx/windows/video/VLCMainVideoViewOverlayView.m
Changes:
=====================================
modules/gui/macosx/windows/video/VLCMainVideoViewOverlayView.h
=====================================
@@ -28,8 +28,8 @@ NS_ASSUME_NONNULL_BEGIN
* NOTE: Needs to occupy the entirety, and exactly, the area of the VLCMainVideoView */
@interface VLCMainVideoViewOverlayView : NSView
- at property (readwrite, assign) BOOL drawGradientForTopControls;
- at property (readwrite, strong) NSColor *darkestGradientColor;
+ at property (readwrite, nonatomic, assign) BOOL drawGradientForTopControls;
+ at property (readwrite, nonatomic, strong) NSColor *darkestGradientColor;
@end
=====================================
modules/gui/macosx/windows/video/VLCMainVideoViewOverlayView.m
=====================================
@@ -22,33 +22,76 @@
#import "VLCMainVideoViewOverlayView.h"
+#import <QuartzCore/QuartzCore.h>
+
@implementation VLCMainVideoViewOverlayView
+{
+ CAGradientLayer *_gradientLayer;
+}
- (void)awakeFromNib
{
self.darkestGradientColor = [NSColor colorWithCalibratedWhite:0 alpha:0.4];
+
+ self.wantsLayer = YES;
+ self.layer = [CALayer layer];
+
+ _gradientLayer = [CAGradientLayer layer];
+ _gradientLayer.frame = self.bounds;
+ _gradientLayer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
+
+ [self.layer addSublayer:_gradientLayer];
+ [self updateGradient];
+}
+
+- (void)setFrame:(NSRect)frame
+{
+ [super setFrame:frame];
+ _gradientLayer.frame = self.bounds;
+}
+
+- (void)setBounds:(NSRect)bounds
+{
+ [super setBounds:bounds];
+ _gradientLayer.frame = self.bounds;
+}
+
+- (void)setDrawGradientForTopControls:(BOOL)drawGradientForTopControls
+{
+ if (_drawGradientForTopControls != drawGradientForTopControls) {
+ _drawGradientForTopControls = drawGradientForTopControls;
+ [self updateGradient];
+ }
+}
+
+- (void)setDarkestGradientColor:(NSColor *)darkestGradientColor
+{
+ _darkestGradientColor = darkestGradientColor;
+ [self updateGradient];
}
-- (void)drawRect:(NSRect)dirtyRect
+- (void)updateGradient
{
- [super drawRect:dirtyRect];
+ if (!_gradientLayer)
+ return;
- NSGradient *gradient;
+ const CGColorRef darkColor = self.darkestGradientColor.CGColor;
+ const CGColorRef clearColor = NSColor.clearColor.CGColor;
if (self.drawGradientForTopControls) {
- gradient = [[NSGradient alloc] initWithColorsAndLocations:self.darkestGradientColor, 0.,
- NSColor.clearColor, 0.5,
- self.darkestGradientColor, 1.,
- nil];
+ _gradientLayer.colors = @[(__bridge id)darkColor,
+ (__bridge id)clearColor,
+ (__bridge id)darkColor];
+ _gradientLayer.locations = @[@0.0, @0.5, @1.0];
} else {
- gradient = [[NSGradient alloc] initWithColorsAndLocations:self.darkestGradientColor, 0.,
- NSColor.clearColor, 1.,
- nil];
+ _gradientLayer.colors = @[(__bridge id)darkColor,
+ (__bridge id)clearColor];
+ _gradientLayer.locations = @[@0.0, @1.0];
}
- // Draws bottom-up
- [gradient drawInRect:self.frame angle:90];
+ _gradientLayer.startPoint = CGPointMake(0.5, 0.0);
+ _gradientLayer.endPoint = CGPointMake(0.5, 1.0);
}
@end
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/24db4216d0045cc38e2dbb21956cc5b06edf96fa
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/24db4216d0045cc38e2dbb21956cc5b06edf96fa
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list