@@ -22,7 +22,7 @@ public class OGCircularBarView: NSView, Sequence {
22
22
super. awakeFromNib ( )
23
23
setup ( )
24
24
}
25
-
25
+
26
26
override public init ( frame frameRect: NSRect ) {
27
27
super. init ( frame: frameRect)
28
28
setup ( )
@@ -35,28 +35,19 @@ public class OGCircularBarView: NSView, Sequence {
35
35
36
36
func setup( ) {
37
37
wantsLayer = true
38
- layerUsesCoreImageFilters = true
39
38
}
40
39
41
- public func addBar( progress: CGFloat , radius: CGFloat , width: CGFloat , color: NSColor , animate: Bool , glowColor : NSColor ? , glowRadius: CGFloat ) {
40
+ public func addBar( progress: CGFloat , radius: CGFloat , width: CGFloat , color: NSColor , animate: Bool , duration : CGFloat , glowOpacity : Float , glowRadius: CGFloat ) {
42
41
let endAngle = 2 * CGFloat. pi*progress
43
42
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)
46
- let groupLayer = CALayer ( )
47
- groupLayer. frame = barLayer. frame
48
- let filter = CIFilter ( name: " CIGaussianBlur " ) !
49
- filter. setValue ( glowRadius, forKey: kCIInputRadiusKey)
50
- glowLayer. filters = [ filter]
51
- groupLayer. addSublayer ( glowLayer)
52
- groupLayer. addSublayer ( barLayer)
53
- barLayer. glowLayer = glowLayer
54
- layer!. addSublayer ( groupLayer)
55
- } else {
56
- layer? . addSublayer ( barLayer)
57
- }
43
+ barLayer. shadowColor = color. cgColor
44
+ barLayer. shadowRadius = glowRadius
45
+ barLayer. shadowOpacity = glowOpacity
46
+ barLayer. shadowOffset = NSSize . zero
47
+
48
+ layer? . addSublayer ( barLayer)
58
49
bars. append ( barLayer)
59
- barLayer. setProgress ( progress, duration: 1.5 )
50
+ barLayer. setProgress ( progress, duration: duration )
60
51
}
61
52
62
53
public func addCircleBar( radius: CGFloat , width: CGFloat , color: NSColor ) {
@@ -77,7 +68,6 @@ public class OGCircularBarView: NSView, Sequence {
77
68
78
69
open class CircularBarLayer : CAShapeLayer , CALayerDelegate , CAAnimationDelegate {
79
70
var completion : ( ( Void ) -> Void ) ?
80
- var glowLayer : CircularBarLayer ?
81
71
82
72
open var progress : CGFloat ? {
83
73
get {
@@ -118,9 +108,6 @@ open class CircularBarLayer: CAShapeLayer, CALayerDelegate, CAAnimationDelegate
118
108
}
119
109
120
110
open func setProgress( _ progress: CGFloat , duration: CGFloat , completion: ( ( Void ) -> Void ) ? = nil ) {
121
- if let glowLayer = glowLayer {
122
- glowLayer. setProgress ( progress, duration: duration)
123
- }
124
111
let animation = CABasicAnimation ( keyPath: " strokeEnd " )
125
112
animation. fromValue = strokeEnd
126
113
animation. toValue = progress
0 commit comments