vlc | branch: master | Felix Paul Kühne <fe...@feepk.net> | Wed May 29 17:38:41 2019 +0200| [3fbd27c8db71a62d3df01adf4c6df5d446e2a358] | committer: Felix Paul Kühne
macosx/linear progress indicator: rewrite to show a bar instead of a triangle > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3fbd27c8db71a62d3df01adf4c6df5d446e2a358 --- .../gui/macosx/extensions/NSColor+VLCAdditions.h | 2 + .../gui/macosx/extensions/NSColor+VLCAdditions.m | 10 ++++ .../gui/macosx/views/VLCLinearProgressIndicator.m | 67 ++++++++++++++-------- 3 files changed, 55 insertions(+), 24 deletions(-) diff --git a/modules/gui/macosx/extensions/NSColor+VLCAdditions.h b/modules/gui/macosx/extensions/NSColor+VLCAdditions.h index 122f44e4e9..a5bfb7105d 100644 --- a/modules/gui/macosx/extensions/NSColor+VLCAdditions.h +++ b/modules/gui/macosx/extensions/NSColor+VLCAdditions.h @@ -34,6 +34,8 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)VLClibraryAnnotationBackgroundColor; + (instancetype)VLClibrarySeparatorLightColor; + (instancetype)VLClibrarySeparatorDarkColor; ++ (instancetype)VLClibraryProgressIndicatorBackgroundColor; ++ (instancetype)VLClibraryProgressIndicatorForegroundColor; @end diff --git a/modules/gui/macosx/extensions/NSColor+VLCAdditions.m b/modules/gui/macosx/extensions/NSColor+VLCAdditions.m index 5f9db425d6..3e17ac64a9 100644 --- a/modules/gui/macosx/extensions/NSColor+VLCAdditions.m +++ b/modules/gui/macosx/extensions/NSColor+VLCAdditions.m @@ -64,4 +64,14 @@ return [NSColor colorWithRed:0.11 green:0.09 blue:0.07 alpha:1.]; } ++ (instancetype)VLClibraryProgressIndicatorBackgroundColor +{ + return [NSColor colorWithRed:37./255. green:41./255. blue:44./255. alpha:.8]; +} + ++ (instancetype)VLClibraryProgressIndicatorForegroundColor +{ + return [NSColor colorWithRed:246./255. green:127./255. blue:0. alpha:1.]; +} + @end diff --git a/modules/gui/macosx/views/VLCLinearProgressIndicator.m b/modules/gui/macosx/views/VLCLinearProgressIndicator.m index faaa022df7..fa4892b788 100644 --- a/modules/gui/macosx/views/VLCLinearProgressIndicator.m +++ b/modules/gui/macosx/views/VLCLinearProgressIndicator.m @@ -23,39 +23,58 @@ #import "VLCLinearProgressIndicator.h" #import "extensions/NSColor+VLCAdditions.h" -@implementation VLCLinearProgressIndicator - -- (void)drawRect:(NSRect)dirtyRect +@interface VLCLinearProgressIndicator() { - [super drawRect:dirtyRect]; - - CGRect rect = NSRectToCGRect(dirtyRect); - - CGContextClearRect([NSGraphicsContext currentContext].CGContext, rect); + NSView *_foregroundView; +} +@end - NSColor *drawingColor = [NSColor VLClibraryHighlightColor]; +@implementation VLCLinearProgressIndicator - NSBezierPath* bezierPath = [NSBezierPath bezierPath]; +- (instancetype)initWithFrame:(NSRect)frameRect +{ + self = [super initWithFrame:frameRect]; + if (self) { + [self setupSubviews]; + } + return self; +} - float progress_width = self.progress * rect.size.width; +- (instancetype)initWithCoder:(NSCoder *)decoder +{ + self = [super initWithCoder:decoder]; + if (self) { + [self setupSubviews]; + } + return self; +} - // Create our triangle - [bezierPath moveToPoint:CGPointMake(progress_width - rect.size.height + 3., 2.)]; - [bezierPath lineToPoint:CGPointMake(progress_width - (rect.size.height/2), rect.size.height - 5.)]; - [bezierPath lineToPoint:CGPointMake(progress_width - 3., 2.)]; - [bezierPath closePath]; +- (void)setupSubviews +{ + self.wantsLayer = YES; + self.layer.backgroundColor = [NSColor VLClibraryProgressIndicatorBackgroundColor].CGColor; - // Set the display for the path, and stroke it - bezierPath.lineWidth = 6.; - [drawingColor setStroke]; - [bezierPath stroke]; - [drawingColor setFill]; - [bezierPath fill]; + CGRect frame = self.frame; + frame.size.width = 0.; + _foregroundView = [[NSView alloc] initWithFrame:frame]; + _foregroundView.wantsLayer = YES; + _foregroundView.layer.backgroundColor = [NSColor VLClibraryProgressIndicatorForegroundColor].CGColor; + _foregroundView.autoresizingMask = NSViewWidthSizable; + _foregroundView.translatesAutoresizingMaskIntoConstraints = NO; + [self addSubview:_foregroundView]; } -- (BOOL)isFlipped +- (void)setProgress:(CGFloat)progress { - return YES; + if (progress > 1.) { + progress = 1.; + } + + CGRect rect = self.frame; + rect.size.width = rect.size.width * progress; + _foregroundView.frame = rect; + + _progress = progress; } @end _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org https://mailman.videolan.org/listinfo/vlc-commits