Skip to content

Commit 4393f3d

Browse files
committed
Glow performance fix
1 parent 4833990 commit 4393f3d

File tree

4 files changed

+16
-45
lines changed

4 files changed

+16
-45
lines changed

OGCircularBar-Demo/ViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class ViewController: NSViewController {
2121
barView.addCircleBar(radius: 100, width: 10, color: pink.withAlphaComponent(0.1))
2222
barView.addCircleBar(radius: 120, width: 15, color: blue.withAlphaComponent(0.1))
2323
barView.addCircleBar(radius: 80, width: 10, color: green.withAlphaComponent(0.1))
24-
barView.addBar(progress: 0.80, radius: 100, width: 10, color: pink, animate: true, glowColor: pink.withAlphaComponent(0.5), glowRadius: 5)
25-
barView.addBar(progress: 0.45, radius: 120, width: 15, color: blue, animate: true, glowColor: blue.withAlphaComponent(0.5), glowRadius: 5)
26-
barView.addBar(progress: 0.65, radius: 80, width: 10, color: green, animate: true, glowColor: green.withAlphaComponent(0.5), glowRadius: 5)
24+
barView.addBar(progress: 0.80, radius: 100, width: 10, color: pink, animate: true, duration: 1.5, glowOpacity: 0.4, glowRadius: 8)
25+
barView.addBar(progress: 0.45, radius: 120, width: 15, color: blue, animate: true, duration: 1.5, glowOpacity: 0.4, glowRadius: 8)
26+
barView.addBar(progress: 0.65, radius: 80, width: 10, color: green, animate: true, duration: 1.5, glowOpacity: 0.4, glowRadius: 8)
2727
}
2828

2929
override var representedObject: Any? {

OGCircularBar.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = 'OGCircularBar'
4-
s.version = '1.0'
4+
s.version = '1.1'
55
s.summary = 'Circular progress bar for macOS'
66
s.homepage = 'https://github.com/OskarGroth/OGCircularBar'
77
s.license = {

OGCircularBar.xcodeproj/xcuserdata/oskar.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,11 @@
1010
ignoreCount = "0"
1111
continueAfterRunningActions = "No"
1212
filePath = "OGCircularBar/OGCircularBarView.swift"
13-
timestampString = "514193270.468607"
13+
timestampString = "514203286.75082"
1414
startingColumnNumber = "9223372036854775807"
1515
endingColumnNumber = "9223372036854775807"
16-
startingLineNumber = "45"
17-
endingLineNumber = "45"
18-
landmarkName = "addBar(progress:radius:width:color:animate:glowColor:glowRadius:)"
19-
landmarkType = "7">
20-
</BreakpointContent>
21-
</BreakpointProxy>
22-
<BreakpointProxy
23-
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
24-
<BreakpointContent
25-
shouldBeEnabled = "Yes"
26-
ignoreCount = "0"
27-
continueAfterRunningActions = "No"
28-
filePath = "OGCircularBar/OGCircularBarView.swift"
29-
timestampString = "514193312.915579"
30-
startingColumnNumber = "9223372036854775807"
31-
endingColumnNumber = "9223372036854775807"
32-
startingLineNumber = "121"
33-
endingLineNumber = "121"
16+
startingLineNumber = "110"
17+
endingLineNumber = "110"
3418
landmarkName = "setProgress(_:duration:completion:)"
3519
landmarkType = "7">
3620
<Locations>

OGCircularBar/OGCircularBarView.swift

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class OGCircularBarView: NSView, Sequence {
2222
super.awakeFromNib()
2323
setup()
2424
}
25-
25+
2626
override public init(frame frameRect: NSRect) {
2727
super.init(frame: frameRect)
2828
setup()
@@ -35,28 +35,19 @@ public class OGCircularBarView: NSView, Sequence {
3535

3636
func setup() {
3737
wantsLayer = true
38-
layerUsesCoreImageFilters = true
3938
}
4039

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) {
4241
let endAngle = 2*CGFloat.pi*progress
4342
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)
5849
bars.append(barLayer)
59-
barLayer.setProgress(progress, duration: 1.5)
50+
barLayer.setProgress(progress, duration: duration)
6051
}
6152

6253
public func addCircleBar(radius: CGFloat, width: CGFloat, color: NSColor) {
@@ -77,7 +68,6 @@ public class OGCircularBarView: NSView, Sequence {
7768

7869
open class CircularBarLayer: CAShapeLayer, CALayerDelegate, CAAnimationDelegate {
7970
var completion: ((Void) -> Void)?
80-
var glowLayer: CircularBarLayer?
8171

8272
open var progress: CGFloat? {
8373
get {
@@ -118,9 +108,6 @@ open class CircularBarLayer: CAShapeLayer, CALayerDelegate, CAAnimationDelegate
118108
}
119109

120110
open func setProgress(_ progress: CGFloat, duration: CGFloat, completion: ((Void) -> Void)? = nil) {
121-
if let glowLayer = glowLayer {
122-
glowLayer.setProgress(progress, duration: duration)
123-
}
124111
let animation = CABasicAnimation(keyPath: "strokeEnd")
125112
animation.fromValue = strokeEnd
126113
animation.toValue = progress

0 commit comments

Comments
 (0)