Browse Source

macosx/linear progress indicator: rewrite to show a bar instead of a triangle

pull/91/head
Felix Paul Kühne 7 years ago
parent
commit
3fbd27c8db
  1. 2
      modules/gui/macosx/extensions/NSColor+VLCAdditions.h
  2. 10
      modules/gui/macosx/extensions/NSColor+VLCAdditions.m
  3. 67
      modules/gui/macosx/views/VLCLinearProgressIndicator.m

2
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

10
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

67
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

Loading…
Cancel
Save