let height = bounds.height
NSColor.controlShadowColor.set()
NSBezierPath.setDefaultLineWidth(1.0)
- multiline {
- [(NSPoint, NSPoint)]()
- .appended { (NSPoint(x: 3, y: height), NSPoint(x: bounds.maxX, y: height)) }
- .appended { (NSPoint(x: width, y: 0), NSPoint(x: width, y: height)) }
- }
- .map { $0.stroke() }
+ multiline(lines:
+ [
+ (NSPoint(x: 3, y: height), NSPoint(x: bounds.maxX, y: height)),
+ (NSPoint(x: width, y: 0), NSPoint(x: width, y: height))
+ ]
+ )
+ .stroke()
}
}
import Cocoa
+extension NSBezierPath {
+
+ convenience init(start point: NSPoint) {
+
+ self.init()
+ move(to: point)
+ }
+}
+
func polygon(_ point: () -> [NSPoint]) -> NSBezierPath? {
- let points = point()
- let count = points.count
- guard count > 2 else { return nil }
- let path = NSBezierPath()
- path.move(to: points[0])
- points[1..<count].forEach { path.line(to: $0) }
- path.close()
+
+ return polygon(points: point())
+}
+func polygon(points: [NSPoint]) -> NSBezierPath? {
+
+ guard points.count > 2 else { return nil }
+
+ let path = polyline(points: points)
+ path?.close()
return path
}
+
func polyline(_ point: () -> [NSPoint]) -> NSBezierPath? {
- let points = point()
- let count = points.count
- guard count > 1 else { return nil }
- let path = NSBezierPath()
- path.move(to: points[0])
- points[1..<count].forEach { path.line(to: $0) }
+ return polyline(points: point())
+}
+func polyline(points: [NSPoint]) -> NSBezierPath? {
+
+ guard points.count > 1 else { return nil }
+
+ return points.dropFirst().reduce(NSBezierPath(start: points[0]), lineToPoint)
+}
+func lineToPoint(path: NSBezierPath, point: NSPoint) -> NSBezierPath {
+
+ path.line(to: point)
return path
}
-func multiline(_ lines: () -> [(NSPoint, NSPoint)]) -> NSBezierPath? {
- let path = NSBezierPath()
- lines().forEach {
- path.move(to: $0.0)
- path.line(to: $0.1)
- }
+
+func multiline(_ lines: () -> [(NSPoint, NSPoint)]) -> NSBezierPath {
+
+ return multiline(lines: lines())
+}
+
+func multiline(lines: [(NSPoint, NSPoint)]) -> NSBezierPath {
+
+ return lines.reduce(NSBezierPath(), line)
+}
+
+func line(_ path: NSBezierPath, _ points: (NSPoint, NSPoint)) -> NSBezierPath {
+
+ path.move(to: points.0)
+ path.line(to: points.1)
return path
}
.appended { (NSPoint(x: 0, y: 34.5), NSPoint(x: width, y: 34.5)) }
.appended { (NSPoint(x: 0, y: 51.5), NSPoint(x: width, y: 51.5)) }
}
- .map { $0.stroke() }
+ .stroke()
}
}
let width = bounds.width
let height = bounds.height
let path = multiline { [(NSPoint(x: width - offset, y: 0), NSPoint(x: width - offset, y: height))] }
- path?.lineWidth = 1.0
+ path.lineWidth = 1.0
return path
}
private var levelTwoBezierPath: NSBezierPath? {
(NSPoint(x: width - offset - padding, y: 0), NSPoint(x: width - offset - padding, y: height))
}
}
- path?.lineWidth = 1.0
+ path.lineWidth = 1.0
return path
}
private var levelThreeBezierPath: NSBezierPath? {
NSPoint(x: width - offset - padding * 2, y: height))
}
}
- path?.lineWidth = 1.0
+ path.lineWidth = 1.0
return path
}
private var levelFourBezierPath: NSBezierPath? {
[(NSPoint, NSPoint)]()
.appended { (NSPoint(x: width - offset - slideOffset, y: 0), NSPoint(x: width - offset, y: height)) }
}
- path?.lineWidth = 2.0
+ path.lineWidth = 2.0
return path
}
private var levelFiveBezierPath: NSBezierPath? {
NSPoint(x: width - offset - padding, y: height))
}
}
- path?.lineWidth = 2.0
+ path.lineWidth = 2.0
return path
}
private var levelSixBezierPath: NSBezierPath? {
NSPoint(x: width - offset - padding * 2, y: height))
}
}
- path?.lineWidth = 2.0
+ path.lineWidth = 2.0
return path
}
private var levelSevenBezierPath: NSBezierPath? {
borderColor.set()
NSBezierPath.setDefaultLineWidth(borderWidth)
NSBezierPath.stroke(bounds)
- multiline {
- [(NSPoint, NSPoint)]()
- .appended { (NSPoint(x: 29.5, y: 0), NSPoint(x: 29.5, y: height)) }
- .appended { (NSPoint(x: 67.5, y: 0), NSPoint(x: 67.5, y: height)) }
- .appended { (NSPoint(x: 209.5, y: 0), NSPoint(x: 209.5, y: height)) }
- .appended { (NSPoint(x: 0, y: 17.5), NSPoint(x: width, y: 17.5)) }
- .appended { (NSPoint(x: 0, y: 34.5), NSPoint(x: width, y: 34.5)) }
- }
- .map { $0.stroke() }
+ multiline(lines:
+ [
+ (NSPoint(x: 29.5, y: 0), NSPoint(x: 29.5, y: height)),
+ (NSPoint(x: 67.5, y: 0), NSPoint(x: 67.5, y: height)),
+ (NSPoint(x: 209.5, y: 0), NSPoint(x: 209.5, y: height)),
+ (NSPoint(x: 0, y: 17.5), NSPoint(x: width, y: 17.5)),
+ (NSPoint(x: 0, y: 34.5), NSPoint(x: width, y: 34.5))
+ ]
+ )
+ .stroke()
}
}