New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates code to Xc8b6 Swift #18

Merged
merged 2 commits into from Aug 15, 2016
Jump to file or symbol
Failed to load files and symbols.
+107 −107
Diff settings

Always

Just for now

@@ -30,7 +30,7 @@ class BNRArcTypesWindowController: NSWindowController {
updateSliderLabels()
}
private func updateSliderLabels() {
fileprivate func updateSliderLabels() {
let startStringValue = NSString(format: "%0.2f", arcEditingView.startAngle)
let endStringValue = NSString(format: "%0.2f", arcEditingView.endAngle)
@@ -8,7 +8,7 @@
import Cocoa
public class BNRLinesWindowController: NSWindowController {
open class BNRLinesWindowController: NSWindowController {
@IBOutlet weak var linesView: BNRLinesView!
@IBOutlet weak var swiftLinesView: LinesView!
@@ -30,7 +30,7 @@ public class BNRLinesWindowController: NSWindowController {
@IBOutlet weak var dash2Slider: NSSlider!
@IBOutlet weak var space2Slider: NSSlider!
public override func awakeFromNib() {
open override func awakeFromNib() {
linesView.preRenderHook = {
linesView, cgContext in
self.setupContext(cgContext)
@@ -47,16 +47,16 @@ public class BNRLinesWindowController: NSWindowController {
}
// Called by the line view prior to constructing and stroking the example path
public func setupContext (_ context: CGContext!) {
open func setupContext (_ context: CGContext!) {
context.setLineWidth (CGFloat(lineWidthSlider.floatValue))
context.setMiterLimit (CGFloat(miterLimitSlider.floatValue))
context.setLineCap (CGLineCap(rawValue: Int32(endCapPopUp.indexOfSelectedItem))!)
context.setLineJoin (CGLineJoin(rawValue: Int32(lineJoinPopUp.indexOfSelectedItem))!)
if self.lineAlphaCheckbox.state == NSOnState {
NSColor.blue().withAlphaComponent(0.50).set()
NSColor.blue.withAlphaComponent(0.50).set()
} else {
NSColor.blue().set()
NSColor.blue.set()
}
if linePhaseBox.isEnabled {
@@ -67,7 +67,7 @@ public class BNRLinesWindowController: NSWindowController {
dash2Slider.floatValue, space2Slider.floatValue
].map { CGFloat($0) }
context.setLineDash (phase: phase, lengths: lengths, count: lengths.count)
context.setLineDash (phase: phase, lengths: lengths)
}
}
@@ -49,7 +49,7 @@ class BNRPostScriptWindowController: NSWindowController {
}
guard let codeData = self.codeText.string?.data(using: .utf8),
let provider = CGDataProvider(data: codeData) else {
let provider = CGDataProvider(data: codeData as CFData) else {
return
}
Copy path View file
@@ -27,17 +27,17 @@ class LinesView : NSView {
}
}
private var points: [CGPoint] = [
fileprivate var points: [CGPoint] = [
CGPoint(x: 17, y: 400),
CGPoint(x: 175, y: 20),
CGPoint(x: 330, y: 275),
CGPoint(x: 150, y: 371),
]
private var draggedPointIndex: Int?
fileprivate var draggedPointIndex: Int?
private func drawNiceBackground() {
fileprivate func drawNiceBackground() {
let context = currentContext
protectGState {
@@ -46,7 +46,7 @@ class LinesView : NSView {
}
}
private func drawNiceBorder() {
fileprivate func drawNiceBorder() {
let context = currentContext
protectGState {
@@ -56,43 +56,43 @@ class LinesView : NSView {
}
private func renderAsSinglePath() {
fileprivate func renderAsSinglePath() {
let context = currentContext
let path = CGMutablePath()
path.moveTo (nil, x: points[0].x, y: points[0].y)
path.move(to: points[0])
for i in 1 ..< points.count {
path.addLineTo (nil, x: points[i].x, y: points[i].y)
path.addLine(to: points[i])
}
context?.addPath (path)
context?.strokePath ()
}
private func renderAsSinglePathByAddingLines() {
fileprivate func renderAsSinglePathByAddingLines() {
let context = currentContext
let path = CGMutablePath()
path.addLines (nil, between: self.points, count: self.points.count)
path.addLines (between: self.points)
context?.addPath (path)
context?.strokePath ()
}
private func renderAsMultiplePaths() {
fileprivate func renderAsMultiplePaths() {
let context = currentContext
for i in 0 ..< points.count - 1 {
let path = CGMutablePath()
path.moveTo (nil, x: points[i].x, y: points[i].y)
path.addLineTo (nil, x: points[i + 1].x, y: points[i + 1].y)
path.move (to: points[i])
path.addLine (to: points[i + 1])
context?.addPath (path)
context?.strokePath ()
}
}
private func renderAsSegments() {
fileprivate func renderAsSegments() {
let context = currentContext
var segments: [CGPoint] = []
@@ -103,10 +103,10 @@ class LinesView : NSView {
}
// Strokes points 0->1 2->3 4->5
context?.strokeLineSegments (between: segments, count: segments.count)
context?.strokeLineSegments (between: segments)
}
private func renderPath() {
fileprivate func renderPath() {
switch renderMode {
case .singlePath:
renderAsSinglePath()
@@ -130,7 +130,7 @@ class LinesView : NSView {
drawNiceBackground()
protectGState() {
NSColor.green().set()
NSColor.green.set()
if let hook = self.preRenderHook {
hook(self, context!)
@@ -152,7 +152,7 @@ class LinesView : NSView {
}
// Which point of the multi-segment line is close to the mouse point?
private func pointIndexForMouse (_ mousePoint: CGPoint) -> Int? {
fileprivate func pointIndexForMouse (_ mousePoint: CGPoint) -> Int? {
let kClickTolerance: Float = 10.0
var pointIndex: Int? = nil
@@ -168,22 +168,22 @@ class LinesView : NSView {
return pointIndex
}
override func mouseDown (_ event: NSEvent) {
override func mouseDown (with event: NSEvent) {
let localPoint = self.convert(event.locationInWindow, from: nil)
draggedPointIndex = self.pointIndexForMouse(localPoint)
needsDisplay = true
}
override func mouseDragged (_ event: NSEvent) {
override func mouseDragged (with event: NSEvent) {
if let pointIndex = draggedPointIndex {
let localPoint = self.convert(event.locationInWindow, from: nil)
points[pointIndex] = localPoint
needsDisplay = true
}
}
override func mouseUp (_ event: NSEvent) {
override func mouseUp (with event: NSEvent) {
draggedPointIndex = nil
}
}
Copy path View file
@@ -12,7 +12,7 @@ class PDFView: NSView {
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
NSColor.white().set()
NSColor.white.set()
NSRectFill(bounds)
if let pdf = pdfDocument {
@@ -21,7 +21,7 @@ class PDFView: NSView {
currentContext?.drawPDFPage (page1!)
}
NSColor.black().set()
NSColor.black.set()
NSFrameRect(bounds)
}
}
Copy path View file
@@ -40,42 +40,42 @@ enum ChunkType {
func controlColor() -> NSColor {
switch self {
case .moveTo: return NSColor.yellow()
case .lineTo: return NSColor.green()
case .curveTo: return NSColor.blue()
case .quadCurveTo: return NSColor.orange()
case .close: return NSColor.purple()
case .arc: return NSColor.red()
case .arcToPoint: return NSColor.lightGray()
case .relativeArc: return NSColor.magenta()
case .moveTo: return NSColor.yellow
case .lineTo: return NSColor.green
case .curveTo: return NSColor.blue
case .quadCurveTo: return NSColor.orange
case .close: return NSColor.purple
case .arc: return NSColor.red
case .arcToPoint: return NSColor.lightGray
case .relativeArc: return NSColor.magenta
}
}
func appendToPath(_ path: CGMutablePath) {
switch self {
case .moveTo(let point):
path.moveTo(nil, x: point.x, y: point.y)
path.move(to: point)
case .lineTo(let point):
path.addLineTo(nil, x: point.x, y: point.y)
path.addLine(to: point)
case .curveTo(let point, let control1, let control2):
path.addCurve(nil, cp1x: control1.x, cp1y: control1.y, cp2x: control2.x, cp2y: control2.y, endingAtX: point.x, y: point.y)
path.addCurve(to: point, control1: control1, control2: control2)
case .quadCurveTo(let point, let control):
path.addQuadCurve(nil, cpx: control.x, cpy: control.y, endingAtX: point.x, y: point.y)
path.addQuadCurve(to: point, control: control)
case .close:
path.closeSubpath()
case .arc(let center, let radius, let startAngle, let endAngle, let clockwise):
path.addArc(nil, x: center.x, y: center.y, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: clockwise)
path.addArc(center: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: clockwise)
case arcToPoint(let control1, let control2, let radius):
path.addArc(nil, x1: control1.x, y1: control1.y, x2: control2.x, y2: control2.y, radius: radius)
case .arcToPoint(let control1, let control2, let radius):
path.addArc(tangent1End: control1, tangent2End: control2, radius: radius)
case relativeArc(let center, let radius, let startAngle, let deltaAngle):
path.addRelativeArc(matrix: nil, x: center.x, y: center.y, radius: radius, startAngle: startAngle, delta: deltaAngle)
case .relativeArc(let center, let radius, let startAngle, let deltaAngle):
path.addRelativeArc(center: center, radius: radius, startAngle: startAngle, delta: deltaAngle)
}
}
@@ -127,11 +127,11 @@ enum ChunkType {
class PathSamplerView: NSView {
var chunks : [ChunkType] = [] // Love ya, Brian
private let BoxSize: CGFloat = 10.0
fileprivate let BoxSize: CGFloat = 10.0
private var trackingChunk: ChunkType?
private var trackingChunkIndex: Int?
private var trackingChunkElementIndex: Int?
fileprivate var trackingChunk: ChunkType?
fileprivate var trackingChunkIndex: Int?
fileprivate var trackingChunkElementIndex: Int?
@IBAction func dumpChunks(_: AnyObject?) {
@@ -141,14 +141,14 @@ class PathSamplerView: NSView {
}
private func boxForPoint(_ point: CGPoint) -> CGRect {
fileprivate func boxForPoint(_ point: CGPoint) -> CGRect {
let boxxy = CGRect(x: point.x - BoxSize / 2.0,
y: point.y - BoxSize / 2.0,
width: BoxSize, height: BoxSize)
return boxxy
}
private func drawBoxAt(_ point: CGPoint, color: NSColor) {
fileprivate func drawBoxAt(_ point: CGPoint, color: NSColor) {
let rect = boxForPoint(point);
protectGState {
@@ -159,22 +159,22 @@ class PathSamplerView: NSView {
}
private func drawBackground() {
fileprivate func drawBackground() {
let rect = bounds
protectGState {
self.currentContext?.addRect(rect)
NSColor.white().set()
NSColor.white.set()
self.currentContext?.fillPath()
}
}
private func drawBorder() {
fileprivate func drawBorder() {
let context = currentContext
protectGState {
NSColor.black().set()
NSColor.black.set()
context?.stroke (self.bounds)
}
}
@@ -226,14 +226,14 @@ class PathSamplerView: NSView {
}
private func startDrag(_ chunk: ChunkType, _ chunkIndex: Int, _ controlPointIndex: Int) {
fileprivate func startDrag(_ chunk: ChunkType, _ chunkIndex: Int, _ controlPointIndex: Int) {
trackingChunk = chunk
trackingChunkIndex = chunkIndex
trackingChunkElementIndex = controlPointIndex
}
private func updateDragWithPoint(_ point: CGPoint) {
fileprivate func updateDragWithPoint(_ point: CGPoint) {
guard let trackingChunk = self.trackingChunk,
let trackingChunkElementIndex = self.trackingChunkElementIndex,
let trackingChunkIndex = self.trackingChunkIndex else { return }
@@ -245,7 +245,7 @@ class PathSamplerView: NSView {
}
override func mouseDown (_ event: NSEvent) {
override func mouseDown (with event: NSEvent) {
let localPoint = self.convert(event.locationInWindow, from: nil)
for (chunkIndex, chunk) in chunks.enumerated() {
@@ -258,13 +258,13 @@ class PathSamplerView: NSView {
}
}
override func mouseDragged (_ event: NSEvent) {
override func mouseDragged (with event: NSEvent) {
let localPoint = self.convert(event.locationInWindow, from: nil)
updateDragWithPoint(localPoint)
}
override func mouseUp (_ event: NSEvent) {
override func mouseUp (with event: NSEvent) {
trackingChunk = nil
trackingChunkIndex = nil
trackingChunkElementIndex = nil
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.