forked from mchoe/SwiftSVG
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved examples to own project in a workspace
- Loading branch information
Showing
21 changed files
with
717 additions
and
611 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// CrossPlatform.swift | ||
// SwiftSVG | ||
// | ||
// Created by Michael Choe on 4/5/16. | ||
// Copyright © 2016 Strauss LLC. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
#if os(iOS) | ||
import UIKit | ||
#elseif os(OSX) | ||
import AppKit | ||
public typealias UIView = NSView | ||
public typealias UIBezierPath = NSBezierPath | ||
public typealias UIColor = NSColor | ||
#endif | ||
|
||
extension UIView { | ||
var nonOptionalLayer:CALayer { | ||
#if os(iOS) | ||
return self.layer | ||
#elseif os(OSX) | ||
if let l = self.layer { | ||
return l | ||
} else { | ||
self.layer = CALayer() | ||
self.layer?.frame = self.bounds | ||
let flip = CATransform3DMakeScale(1.0, -1.0, 1.0) | ||
let translate = CATransform3DMakeTranslation(0.0, self.bounds.size.height, 1.0) | ||
self.layer?.sublayerTransform = CATransform3DConcat(flip, translate) | ||
self.wantsLayer = true | ||
return self.layer! | ||
} | ||
#endif | ||
} | ||
} | ||
|
||
#if os(OSX) | ||
extension NSBezierPath { | ||
var addLineToPoint:((NSPoint)->Void) { | ||
return lineToPoint | ||
} | ||
|
||
var addCurveToPoint:((NSPoint, controlPoint1:NSPoint, controlPoint2:NSPoint)->Void) { | ||
return curveToPoint | ||
} | ||
|
||
func addQuadCurveToPoint(endPoint: NSPoint, controlPoint: NSPoint) { | ||
self.addCurveToPoint(endPoint, | ||
controlPoint1: CGPointMake( | ||
(controlPoint.x - currentPoint.x) * (2.0 / 3.0) + currentPoint.x, | ||
(controlPoint.y - currentPoint.y) * (2.0 / 3.0) + currentPoint.y | ||
), | ||
controlPoint2: CGPointMake( | ||
(controlPoint.x - endPoint.x) * (2.0 / 3.0) + endPoint.x, | ||
(controlPoint.y - endPoint.y) * (2.0 / 3.0) + endPoint.y | ||
)) | ||
} | ||
|
||
var CGPath:CGPathRef? { | ||
var immutablePath:CGPathRef? = nil | ||
let numElements = self.elementCount | ||
if numElements > 0 { | ||
let path = CGPathCreateMutable() | ||
let points = NSPointArray.alloc(3) | ||
var didClosePath = true | ||
|
||
for i in 0..<numElements { | ||
switch(self.elementAtIndex(i, associatedPoints: points)) { | ||
case .MoveToBezierPathElement: | ||
CGPathMoveToPoint(path, nil, points[0].x, points[0].y) | ||
case .LineToBezierPathElement: | ||
CGPathAddLineToPoint(path, nil, points[0].x, points[0].y); | ||
didClosePath = false; | ||
case .CurveToBezierPathElement: | ||
CGPathAddCurveToPoint(path, nil, points[0].x, points[0].y, | ||
points[1].x, points[1].y, | ||
points[2].x, points[2].y); | ||
didClosePath = false; | ||
case .ClosePathBezierPathElement: | ||
CGPathCloseSubpath(path); | ||
didClosePath = true; | ||
} | ||
} | ||
if !didClosePath { | ||
CGPathCloseSubpath(path) | ||
} | ||
immutablePath = CGPathCreateCopy(path) | ||
points.dealloc(3) | ||
} | ||
return immutablePath | ||
} | ||
|
||
} | ||
#endif |
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
Demo Mac/AppDelegate.swift → ...ples/SwiftSVGExampleMac/AppDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.