Skip to content

Commit 4833990

Browse files
committed
Expose glowcolor and radius
1 parent 8f503f6 commit 4833990

File tree

3 files changed

+86
-14
lines changed

3 files changed

+86
-14
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, glow: true)
25-
barView.addBar(progress: 0.45, radius: 120, width: 15, color: blue, animate: true, glow: true)
26-
barView.addBar(progress: 0.65, radius: 80, width: 10, color: green, animate: true, glow: true)
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)
2727
}
2828

2929
override var representedObject: Any? {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Bucket
3+
type = "1"
4+
version = "2.0">
5+
<Breakpoints>
6+
<BreakpointProxy
7+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8+
<BreakpointContent
9+
shouldBeEnabled = "Yes"
10+
ignoreCount = "0"
11+
continueAfterRunningActions = "No"
12+
filePath = "OGCircularBar/OGCircularBarView.swift"
13+
timestampString = "514193270.468607"
14+
startingColumnNumber = "9223372036854775807"
15+
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"
34+
landmarkName = "setProgress(_:duration:completion:)"
35+
landmarkType = "7">
36+
<Locations>
37+
<Location
38+
shouldBeEnabled = "Yes"
39+
ignoreCount = "0"
40+
continueAfterRunningActions = "No"
41+
symbolName = "OGCircularBar_Demo.CircularBarLayer.setProgress (CoreGraphics.CGFloat, duration : CoreGraphics.CGFloat, completion : Swift.Optional&lt;() -&gt; ()&gt;) -&gt; ()"
42+
moduleName = "OGCircularBar-Demo"
43+
usesParentBreakpointCondition = "Yes"
44+
urlString = "file:///Users/oskar/OGCircularBar/OGCircularBar/OGCircularBarView.swift"
45+
timestampString = "514193312.919155"
46+
startingColumnNumber = "9223372036854775807"
47+
endingColumnNumber = "9223372036854775807"
48+
startingLineNumber = "121"
49+
endingLineNumber = "121"
50+
offsetFromSymbolStart = "40">
51+
</Location>
52+
<Location
53+
shouldBeEnabled = "Yes"
54+
ignoreCount = "0"
55+
continueAfterRunningActions = "No"
56+
symbolName = "OGCircularBar_Demo.CircularBarLayer.setProgress (CoreGraphics.CGFloat, duration : CoreGraphics.CGFloat, completion : Swift.Optional&lt;() -&gt; ()&gt;) -&gt; ()"
57+
moduleName = "OGCircularBar-Demo"
58+
usesParentBreakpointCondition = "Yes"
59+
urlString = "file:///Users/oskar/OGCircularBar/OGCircularBar/OGCircularBarView.swift"
60+
timestampString = "514193312.920781"
61+
startingColumnNumber = "9223372036854775807"
62+
endingColumnNumber = "9223372036854775807"
63+
startingLineNumber = "121"
64+
endingLineNumber = "121"
65+
offsetFromSymbolStart = "118">
66+
</Location>
67+
</Locations>
68+
</BreakpointContent>
69+
</BreakpointProxy>
70+
</Breakpoints>
71+
</Bucket>

OGCircularBar/OGCircularBarView.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,24 @@ public class OGCircularBarView: NSView, Sequence {
3838
layerUsesCoreImageFilters = true
3939
}
4040

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) {
4242
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)
4746
let groupLayer = CALayer()
4847
groupLayer.frame = barLayer.frame
4948
let filter = CIFilter(name: "CIGaussianBlur")!
50-
filter.setValue(6, forKey: kCIInputRadiusKey)
49+
filter.setValue(glowRadius, forKey: kCIInputRadiusKey)
5150
glowLayer.filters = [filter]
5251
groupLayer.addSublayer(glowLayer)
5352
groupLayer.addSublayer(barLayer)
53+
barLayer.glowLayer = glowLayer
5454
layer!.addSublayer(groupLayer)
5555
} else {
5656
layer?.addSublayer(barLayer)
5757
}
58+
bars.append(barLayer)
5859
barLayer.setProgress(progress, duration: 1.5)
5960
}
6061

@@ -76,7 +77,8 @@ public class OGCircularBarView: NSView, Sequence {
7677

7778
open class CircularBarLayer: CAShapeLayer, CALayerDelegate, CAAnimationDelegate {
7879
var completion: ((Void) -> Void)?
79-
var glowBarLayer: CircularBarLayer?
80+
var glowLayer: CircularBarLayer?
81+
8082
open var progress: CGFloat? {
8183
get {
8284
return strokeEnd
@@ -86,9 +88,8 @@ open class CircularBarLayer: CAShapeLayer, CALayerDelegate, CAAnimationDelegate
8688
}
8789
}
8890

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) {
9092
super.init()
91-
glowBarLayer = glowLayer
9293
let bezier = NSBezierPath()
9394
bezier.appendArc(withCenter: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: true)
9495
bezier.transform(using: AffineTransform(rotationByDegrees: 90))
@@ -105,7 +106,7 @@ open class CircularBarLayer: CAShapeLayer, CALayerDelegate, CAAnimationDelegate
105106
}
106107

107108
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)
109110
}
110111

111112
public required init?(coder aDecoder: NSCoder) {
@@ -117,7 +118,7 @@ open class CircularBarLayer: CAShapeLayer, CALayerDelegate, CAAnimationDelegate
117118
}
118119

119120
open func setProgress(_ progress: CGFloat, duration: CGFloat, completion: ((Void) -> Void)? = nil) {
120-
if let glowLayer = glowBarLayer {
121+
if let glowLayer = glowLayer {
121122
glowLayer.setProgress(progress, duration: duration)
122123
}
123124
let animation = CABasicAnimation(keyPath: "strokeEnd")

0 commit comments

Comments
 (0)