@@ -37,7 +37,7 @@ public class MSDoubleHandleCircularSlider: MSCircularSlider {
3737 }
3838
3939
40- // SECOND HANDLE'S PROPERTIES
40+ // DOUBLE HANDLE SLIDER PROPERTIES
4141 public var minimumHandlesDistance : CGFloat = 10 { // distance between handles
4242 didSet {
4343 let maxValue = CGFloat . pi * calculatedRadius * maximumAngle / 360.0
@@ -53,12 +53,8 @@ public class MSDoubleHandleCircularSlider: MSCircularSlider {
5353 }
5454 }
5555
56- override public var handleHighlightable : Bool {
57- didSet {
58- secondHandle. isHighlightable = handleHighlightable
59- setNeedsDisplay ( )
60- }
61- }
56+ // SECOND HANDLE'S PROPERTIES
57+ let secondHandle = MSCircularSliderHandle ( )
6258
6359 public var secondCurrentValue : Double { // second handle's value
6460 set {
@@ -78,12 +74,49 @@ public class MSDoubleHandleCircularSlider: MSCircularSlider {
7874
7975 public var secondAngle : CGFloat = 60 {
8076 didSet {
81- //assert(secondAngle >= 0 && secondAngle <= 360, "secondAngle \(secondAngle) must be between 0 and 360 inclusive")
8277 secondAngle = max ( 0.0 , secondAngle) . truncatingRemainder ( dividingBy: maximumAngle + 1 )
8378 }
8479 }
8580
86- let secondHandle = MSCircularSliderHandle ( )
81+ public var secondHandleColor : UIColor = . darkGray {
82+ didSet {
83+ setNeedsDisplay ( )
84+ }
85+ }
86+
87+ public var secondHandleType : MSCircularSliderHandleType = . largeCircle {
88+ didSet {
89+ setNeedsUpdateConstraints ( )
90+ setNeedsDisplay ( )
91+ }
92+ }
93+
94+ public var secondHandleEnlargementPoints : Int = 10 {
95+ didSet {
96+ setNeedsUpdateConstraints ( )
97+ setNeedsDisplay ( )
98+ }
99+ }
100+
101+ public var secondHandleHighlightable : Bool = true {
102+ didSet {
103+ secondHandle. isHighlightable = secondHandleHighlightable
104+ setNeedsDisplay ( )
105+ }
106+ }
107+
108+ // CALCULATED MEMBERS
109+ internal var secondHandleDiameter : CGFloat {
110+ switch handleType {
111+ case . smallCircle:
112+ return CGFloat ( Double ( lineWidth) / 2.0 )
113+ case . mediumCircle:
114+ return CGFloat ( lineWidth)
115+ case . largeCircle, . doubleCircle:
116+ return CGFloat ( lineWidth + secondHandleEnlargementPoints)
117+
118+ }
119+ }
87120
88121 // OVERRIDDEN MEMBERS
89122 override public var maximumAngle : CGFloat {
@@ -123,7 +156,7 @@ public class MSDoubleHandleCircularSlider: MSCircularSlider {
123156
124157 // Draw the second handle
125158 let handleCenter = super. pointOnCircleAt ( angle: secondAngle)
126- secondHandle. frame = self . drawHandle ( ctx: ctx!, atPoint: handleCenter, handle: secondHandle)
159+ secondHandle. frame = self . drawSecondHandle ( ctx: ctx!, atPoint: handleCenter, handle: secondHandle)
127160 }
128161
129162 override func drawLine( ctx: CGContext ) {
@@ -203,12 +236,35 @@ public class MSDoubleHandleCircularSlider: MSCircularSlider {
203236 // DRAWING METHODS
204237 //================================================================================
205238
206- override func drawHandle ( ctx: CGContext , atPoint handleCenter: CGPoint , handle: MSCircularSliderHandle ) -> CGRect {
239+ internal func drawSecondHandle ( ctx: CGContext , atPoint handleCenter: CGPoint , handle: MSCircularSliderHandle ) -> CGRect {
207240 // Comment out the call to the super class and customize the second handle here
208241 // Must set calculatedColor for secondHandle in this case to set the handle's "highlight" if needed
209242 // TODO: add separate secondHandleDiameter, secondHandleColor, and secondHandleType properties
210243
211- return super. drawHandle ( ctx: ctx, atPoint: handleCenter, handle: handle)
244+ ctx. saveGState ( )
245+ var frame : CGRect !
246+
247+ // Highlight == 0.9 alpha
248+ let calculatedHandleColor = handle. isHighlightable && handle. isPressed ? secondHandleColor. withAlphaComponent ( 0.9 ) : secondHandleColor
249+
250+ // Handle color calculation
251+ if secondHandleType == . doubleCircle {
252+ calculatedHandleColor. set ( )
253+ drawFilledCircle ( ctx: ctx, center: handleCenter, radius: 0.25 * secondHandleDiameter)
254+
255+ calculatedHandleColor. withAlphaComponent ( 0.7 ) . set ( )
256+
257+ frame = drawFilledCircle ( ctx: ctx, center: handleCenter, radius: 0.5 * secondHandleDiameter)
258+ }
259+ else {
260+ calculatedHandleColor. set ( )
261+
262+ frame = drawFilledCircle ( ctx: ctx, center: handleCenter, radius: 0.5 * secondHandleDiameter)
263+ }
264+
265+
266+ ctx. saveGState ( )
267+ return frame
212268 }
213269
214270 //================================================================================
0 commit comments