@@ -38,23 +38,24 @@ public class OGCircularBarView: NSView, Sequence {
38
38
layerUsesCoreImageFilters = true
39
39
}
40
40
41
- public func addBar( progress: CGFloat , radius: CGFloat , width: CGFloat , color: NSColor , animate: Bool , glow : Bool ) {
41
+ public func addBar( progress: CGFloat , radius: CGFloat , width: CGFloat , color: NSColor , animate: Bool , glowColor : NSColor ? , glowRadius : CGFloat ) {
42
42
let endAngle = 2 * CGFloat. pi*progress
43
- let glowBarLayer = glow ? CircularBarLayer ( center: center, radius: radius, width: width, startAngle: 0 , endAngle: endAngle, color: color. withAlphaComponent ( 0.6 ) , glowLayer: nil ) : nil
44
- let barLayer = CircularBarLayer ( center: center, radius: radius, width: width, startAngle: 0 , endAngle: endAngle, color: color, glowLayer: glowBarLayer)
45
- bars. append ( barLayer)
46
- if let glowLayer = glowBarLayer {
43
+ let barLayer = CircularBarLayer ( center: center, radius: radius, width: width, startAngle: 0 , endAngle: endAngle, color: color)
44
+ if let glowColor = glowColor {
45
+ let glowLayer = CircularBarLayer ( center: center, radius: radius, width: width, startAngle: 0 , endAngle: endAngle, color: glowColor)
47
46
let groupLayer = CALayer ( )
48
47
groupLayer. frame = barLayer. frame
49
48
let filter = CIFilter ( name: " CIGaussianBlur " ) !
50
- filter. setValue ( 6 , forKey: kCIInputRadiusKey)
49
+ filter. setValue ( glowRadius , forKey: kCIInputRadiusKey)
51
50
glowLayer. filters = [ filter]
52
51
groupLayer. addSublayer ( glowLayer)
53
52
groupLayer. addSublayer ( barLayer)
53
+ barLayer. glowLayer = glowLayer
54
54
layer!. addSublayer ( groupLayer)
55
55
} else {
56
56
layer? . addSublayer ( barLayer)
57
57
}
58
+ bars. append ( barLayer)
58
59
barLayer. setProgress ( progress, duration: 1.5 )
59
60
}
60
61
@@ -76,7 +77,8 @@ public class OGCircularBarView: NSView, Sequence {
76
77
77
78
open class CircularBarLayer : CAShapeLayer , CALayerDelegate , CAAnimationDelegate {
78
79
var completion : ( ( Void ) -> Void ) ?
79
- var glowBarLayer : CircularBarLayer ?
80
+ var glowLayer : CircularBarLayer ?
81
+
80
82
open var progress : CGFloat ? {
81
83
get {
82
84
return strokeEnd
@@ -86,9 +88,8 @@ open class CircularBarLayer: CAShapeLayer, CALayerDelegate, CAAnimationDelegate
86
88
}
87
89
}
88
90
89
- public init ( center: CGPoint , radius: CGFloat , width: CGFloat , startAngle: CGFloat , endAngle: CGFloat , color: NSColor , glowLayer : CircularBarLayer ? ) {
91
+ public init ( center: CGPoint , radius: CGFloat , width: CGFloat , startAngle: CGFloat , endAngle: CGFloat , color: NSColor ) {
90
92
super. init ( )
91
- glowBarLayer = glowLayer
92
93
let bezier = NSBezierPath ( )
93
94
bezier. appendArc ( withCenter: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true )
94
95
bezier. transform ( using: AffineTransform ( rotationByDegrees: 90 ) )
@@ -105,7 +106,7 @@ open class CircularBarLayer: CAShapeLayer, CALayerDelegate, CAAnimationDelegate
105
106
}
106
107
107
108
public convenience init ( center: CGPoint , radius: CGFloat , width: CGFloat , color: NSColor ) {
108
- self . init ( center: center, radius: radius, width: width, startAngle: 0 , endAngle: 2 * CGFloat. pi, color: color, glowLayer : nil )
109
+ self . init ( center: center, radius: radius, width: width, startAngle: 0 , endAngle: 2 * CGFloat. pi, color: color)
109
110
}
110
111
111
112
public required init ? ( coder aDecoder: NSCoder ) {
@@ -117,7 +118,7 @@ open class CircularBarLayer: CAShapeLayer, CALayerDelegate, CAAnimationDelegate
117
118
}
118
119
119
120
open func setProgress( _ progress: CGFloat , duration: CGFloat , completion: ( ( Void ) -> Void ) ? = nil ) {
120
- if let glowLayer = glowBarLayer {
121
+ if let glowLayer = glowLayer {
121
122
glowLayer. setProgress ( progress, duration: duration)
122
123
}
123
124
let animation = CABasicAnimation ( keyPath: " strokeEnd " )
0 commit comments