You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
50 lines
1.5 KiB
6 years ago
|
// Copyright © 2015 Abhishek Banthia
|
||
|
|
||
|
import Cocoa
|
||
|
|
||
|
class CustomSliderCell: NSSliderCell {
|
||
|
fileprivate(set) var tracking: Bool = false
|
||
|
|
||
|
override func drawBar(inside rect: NSRect, flipped _: Bool) {
|
||
|
let barRadius: CGFloat = 2.5
|
||
|
|
||
|
let value = CGFloat((doubleValue - minValue) / (maxValue - minValue))
|
||
|
|
||
|
guard let control = controlView else {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
let finalWidth = value * (NSWidth(control.frame) - 8)
|
||
|
|
||
|
// Left Part
|
||
|
var leftRect = rect
|
||
|
leftRect.size.width = finalWidth
|
||
|
|
||
|
let bg = NSBezierPath(roundedRect: rect,
|
||
|
xRadius: barRadius,
|
||
|
yRadius: barRadius)
|
||
|
NSColor(calibratedRed: 67.0 / 255.0, green: 138.0 / 255.0, blue: 250.0 / 255.0, alpha: 1.0).setFill()
|
||
|
|
||
|
bg.fill()
|
||
|
|
||
|
// Right Part
|
||
|
|
||
|
let active = NSBezierPath(roundedRect: leftRect,
|
||
|
xRadius: barRadius,
|
||
|
yRadius: barRadius)
|
||
|
|
||
|
Themer.shared().sliderRightColor().setFill()
|
||
|
active.fill()
|
||
|
}
|
||
|
|
||
|
override func startTracking(at startPoint: NSPoint, in controlView: NSView) -> Bool {
|
||
|
tracking = true
|
||
|
return super.startTracking(at: startPoint, in: controlView)
|
||
|
}
|
||
|
|
||
|
override func stopTracking(last lastPoint: NSPoint, current stopPoint: NSPoint, in controlView: NSView, mouseIsUp flag: Bool) {
|
||
|
super.stopTracking(last: lastPoint, current: stopPoint, in: controlView, mouseIsUp: flag)
|
||
|
tracking = false
|
||
|
}
|
||
|
}
|