[vlc-commits] [Git][videolan/vlc][master] 9 commits: macosx: Base VLCSubtleBorderColor off of text color
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Jul 14 02:34:38 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
650f6c02 by Claudio Cambra at 2023-07-14T02:12:36+00:00
macosx: Base VLCSubtleBorderColor off of text color
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
3c8cbb03 by Claudio Cambra at 2023-07-14T02:12:36+00:00
macosx: Modernise VLCImageView setImageUrl
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
95e8c419 by Claudio Cambra at 2023-07-14T02:12:36+00:00
macosx: Fix setter for contentGravity property in VLCImageView
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
35521886 by Claudio Cambra at 2023-07-14T02:12:36+00:00
macosx: Separate layer update from setImage method into separate method
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
471684e2 by Claudio Cambra at 2023-07-14T02:12:36+00:00
macosx: Separate cropping of rounded image corners at layer elvel from cropping property BOOL setter
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
25fcdb6f by Claudio Cambra at 2023-07-14T02:12:36+00:00
macosx: Separate layer update for content gravity from content gravity setter
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
b08ffdac by Claudio Cambra at 2023-07-14T02:12:36+00:00
macosx: Separate setting of image layer contents from setting of image prop
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
b4774662 by Claudio Cambra at 2023-07-14T02:12:36+00:00
macosx: Split VLCSubtleBorderColor into dark and light colours
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
8c4d0393 by Claudio Cambra at 2023-07-14T02:12:36+00:00
macosx: Automatically update layer border colour via updateLayer method in VLCImageView
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
4 changed files:
- modules/gui/macosx/extensions/NSColor+VLCAdditions.h
- modules/gui/macosx/extensions/NSColor+VLCAdditions.m
- modules/gui/macosx/views/VLCImageView.h
- modules/gui/macosx/views/VLCImageView.m
Changes:
=====================================
modules/gui/macosx/extensions/NSColor+VLCAdditions.h
=====================================
@@ -38,7 +38,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (class, readonly) NSColor *VLCSliderFillColor;
@property (class, readonly) NSColor *VLCSliderLightBackgroundColor;
@property (class, readonly) NSColor *VLCSliderDarkBackgroundColor;
- at property (class, readonly) NSColor *VLCSubtleBorderColor;
+ at property (class, readonly) NSColor *VLCLightSubtleBorderColor;
+ at property (class, readonly) NSColor *VLCDarkSubtleBorderColor;
@end
=====================================
modules/gui/macosx/extensions/NSColor+VLCAdditions.m
=====================================
@@ -94,9 +94,14 @@
return [NSColor colorWithCalibratedWhite:1 alpha:0.2];
}
-+ (NSColor *)VLCSubtleBorderColor
++ (NSColor *)VLCLightSubtleBorderColor
{
- return [NSColor colorWithWhite:0 alpha:0.1];
+ return [NSColor colorWithCalibratedWhite:0 alpha:0.2];
+}
+
++ (NSColor *)VLCDarkSubtleBorderColor
+{
+ return [NSColor colorWithCalibratedWhite:1 alpha:0.2];
}
@end
=====================================
modules/gui/macosx/views/VLCImageView.h
=====================================
@@ -40,7 +40,7 @@ typedef NS_ENUM(NSInteger, VLCImageViewContentGravity) {
@interface VLCImageView : NSView
@property (readwrite, retain, nonatomic, nullable) NSImage *image;
- at property (readwrite) VLCImageViewContentGravity contentGravity;
+ at property (readwrite, nonatomic) VLCImageViewContentGravity contentGravity;
@property (readwrite) BOOL cropsImagesToRoundedCorners;
- (void)setImageURL:(NSURL * _Nonnull)url placeholderImage:(NSImage * _Nullable)image;
=====================================
modules/gui/macosx/views/VLCImageView.m
=====================================
@@ -39,7 +39,7 @@
{
self = [super initWithFrame:frameRect];
if (self) {
- [self setupLayer];
+ [self setup];
}
return self;
}
@@ -48,55 +48,76 @@
{
self = [super initWithCoder:decoder];
if (self) {
- [self setupLayer];
+ [self setup];
}
return self;
}
-- (void)setupLayer
+- (void)setup
{
- self.layer = [[CALayer alloc] init];
- self.layer.borderColor = NSColor.VLCSubtleBorderColor.CGColor;
-
- self.contentGravity = VLCImageViewContentGravityResizeAspectFill;
self.wantsLayer = YES;
- [self setCropsImagesToRoundedCorners:YES];
+ self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay;
+ self.contentGravity = VLCImageViewContentGravityResizeAspectFill;
+ self.cropsImagesToRoundedCorners = YES;
+ self.needsDisplay = YES;
}
-- (void)setCropsImagesToRoundedCorners:(BOOL)cropsImagesToRoundedCorners
+- (void)updateLayer
+{
+ self.layer.borderColor = self.shouldShowDarkAppearance ? NSColor.VLCDarkSubtleBorderColor.CGColor : NSColor.VLCLightSubtleBorderColor.CGColor;
+ [self updateLayerImageCornerCropping];
+ [self updateLayerContentGravity];
+ [self updateLayerImage];
+}
+
+- (BOOL)wantsUpdateLayer
{
- if (cropsImagesToRoundedCorners) {
+ return YES;
+}
+
+- (void)updateLayerImageCornerCropping
+{
+ if (self.cropsImagesToRoundedCorners) {
self.layer.cornerRadius = 5.;
- self.layer.masksToBounds = YES;
self.layer.borderWidth = 1.;
} else {
self.layer.cornerRadius = 0.;
- self.layer.masksToBounds = NO;
self.layer.borderWidth = 0.;
}
}
+- (void)setCropsImagesToRoundedCorners:(BOOL)cropsImagesToRoundedCorners
+{
+ self.layer.masksToBounds = cropsImagesToRoundedCorners;
+ [self updateLayerImageCornerCropping];
+}
+
- (BOOL)cropsImagesToRoundedCorners
{
return self.layer.masksToBounds;
}
-- (void)setImage:(NSImage *)image
+- (void)updateLayerImage
{
- _image = image;
- CGFloat desiredScaleFactor = [self.window backingScaleFactor];
- CGFloat actualScaleFactor = [image recommendedLayerContentsScale:desiredScaleFactor];
+ const CGFloat desiredScaleFactor = [self.window backingScaleFactor];
+ const CGFloat actualScaleFactor = [_image recommendedLayerContentsScale:desiredScaleFactor];
- id layerContents = [image layerContentsForContentsScale:actualScaleFactor];
+ const id layerContents = [_image layerContentsForContentsScale:actualScaleFactor];
- [self setCAContentGravity:_contentGravity];
- [self.layer setContents:layerContents];
- [self.layer setContentsScale:actualScaleFactor];
+ [self updateLayerContentGravity];
+ self.layer.contents = layerContents;
+ self.layer.contentsScale = actualScaleFactor;
}
-- (void)setCAContentGravity:(VLCImageViewContentGravity)contentGravity
+- (void)setImage:(NSImage *)image
{
- switch (contentGravity) {
+ _image = image;
+ [self updateLayerImage];
+}
+
+- (void)updateLayerContentGravity
+{
+ switch (_contentGravity) {
case VLCImageViewContentGravityCenter:
self.layer.contentsGravity = kCAGravityCenter;
break;
@@ -137,6 +158,12 @@
}
}
+- (void)setContentGravity:(VLCImageViewContentGravity)contentGravity
+{
+ _contentGravity = contentGravity;
+ [self updateLayerContentGravity];
+}
+
- (void)setImageURL:(NSURL * _Nonnull)artworkURL placeholderImage:(NSImage * _Nullable)image
{
if([_currentArtworkURL isEqual:artworkURL]) {
@@ -144,12 +171,12 @@
}
_currentArtworkURL = artworkURL;
- [self setImage:image];
+ self.image = image;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
- NSImage *downloadedImage = [[NSImage alloc] initWithContentsOfURL:artworkURL];
+ NSImage * const downloadedImage = [[NSImage alloc] initWithContentsOfURL:artworkURL];
dispatch_async(dispatch_get_main_queue(), ^{
- [self setImage:downloadedImage];
+ self.image = downloadedImage;
});
});
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/728eb8aeea16a1aaa95674b12e40d6d07871c84e...8c4d0393ad32688f9811031536e0842c18cda503
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/728eb8aeea16a1aaa95674b12e40d6d07871c84e...8c4d0393ad32688f9811031536e0842c18cda503
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