diff --git a/Macaw.xcodeproj/project.pbxproj b/Macaw.xcodeproj/project.pbxproj index cf43b1b7..c358a132 100644 --- a/Macaw.xcodeproj/project.pbxproj +++ b/Macaw.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ 574BDD9C1CAAA5D60031D313 /* TransformInterpolation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 574BDD9B1CAAA5D60031D313 /* TransformInterpolation.swift */; }; 5754E63F1CB3B70D00657DA3 /* EasingAnimations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5754E63E1CB3B70D00657DA3 /* EasingAnimations.swift */; }; 57982D531CB508E600111DAA /* PathAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57982D521CB508E600111DAA /* PathAnimation.swift */; }; + 57B9DDD81CDDEEDE004300C2 /* CGExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57B9DDD71CDDEEDE004300C2 /* CGExtensions.swift */; }; 585C04481C27CFB100335FF2 /* MacawView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 585C04471C27CFB100335FF2 /* MacawView.swift */; }; B0086C561C789758008A4F69 /* GroupRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0086C551C789758008A4F69 /* GroupRenderer.swift */; }; B0097E081C706CAB00350E43 /* ObservableValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0097E071C706CAB00350E43 /* ObservableValue.swift */; }; @@ -110,6 +111,7 @@ 574BDD9B1CAAA5D60031D313 /* TransformInterpolation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransformInterpolation.swift; sourceTree = ""; }; 5754E63E1CB3B70D00657DA3 /* EasingAnimations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EasingAnimations.swift; sourceTree = ""; }; 57982D521CB508E600111DAA /* PathAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PathAnimation.swift; sourceTree = ""; }; + 57B9DDD71CDDEEDE004300C2 /* CGExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGExtensions.swift; sourceTree = ""; }; 585C04471C27CFB100335FF2 /* MacawView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MacawView.swift; sourceTree = ""; }; B0086C551C789758008A4F69 /* GroupRenderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupRenderer.swift; sourceTree = ""; }; B0097E071C706CAB00350E43 /* ObservableValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObservableValue.swift; sourceTree = ""; }; @@ -189,6 +191,7 @@ 572661591CD233C50010D971 /* PathBounds.swift */, 571C63381CD37204008F4257 /* FuncBounds.swift */, 571C633A1CD373D0008F4257 /* PathFunctions.swift */, + 57B9DDD71CDDEEDE004300C2 /* CGExtensions.swift */, ); path = layer_animation; sourceTree = ""; @@ -506,6 +509,7 @@ 5754E63F1CB3B70D00657DA3 /* EasingAnimations.swift in Sources */, B03275F41C78772F000BDD33 /* Circle.swift in Sources */, B03276011C78772F000BDD33 /* Point.swift in Sources */, + 57B9DDD81CDDEEDE004300C2 /* CGExtensions.swift in Sources */, B03276141C78772F000BDD33 /* Text.swift in Sources */, B03276051C78772F000BDD33 /* Rect.swift in Sources */, 571C63391CD37204008F4257 /* FuncBounds.swift in Sources */, diff --git a/Source/animation/AnimationProducer.swift b/Source/animation/AnimationProducer.swift index d5312503..fd4d7d1b 100644 --- a/Source/animation/AnimationProducer.swift +++ b/Source/animation/AnimationProducer.swift @@ -24,6 +24,10 @@ public class AnimationProducer { return } + guard let shape = animation.shape else { + return + } + // guard let bounds = animation.shape?.bounds() else { // return // } @@ -74,8 +78,15 @@ public class AnimationProducer { let layer = ShapeLayer() // layer.backgroundColor = UIColor.greenColor().CGColor - layer.frame = CGRectMake(0.0, 0.0, 100.0, 100.0) - layer.shape = animation.shape + layer.borderWidth = 1.0 + layer.borderColor = UIColor.blueColor().CGColor + + if let shapeBounds = shape.bounds() { + // layer.frame = shapeBounds.cgRect() + layer.frame = CGRectMake(0.0, 0.0, 100.0, 100.0) + } + + layer.shape = shape layer.setNeedsDisplay() sceneLayer.addSublayer(layer) diff --git a/Source/animation/layer_animation/CGExtensions.swift b/Source/animation/layer_animation/CGExtensions.swift new file mode 100644 index 00000000..9786e0df --- /dev/null +++ b/Source/animation/layer_animation/CGExtensions.swift @@ -0,0 +1,13 @@ +import UIKit + +extension Rect { + func cgRect() -> CGRect { + return CGRect(x: self.x, y: self.y, width: self.w, height: self.h) + } +} + +extension Point { + func cgPoint() -> CGPoint { + return CGPoint(x: self.x, y: self.y) + } +} diff --git a/Source/animation/layer_animation/PathBounds.swift b/Source/animation/layer_animation/PathBounds.swift index b383ad9f..c4d65eeb 100644 --- a/Source/animation/layer_animation/PathBounds.swift +++ b/Source/animation/layer_animation/PathBounds.swift @@ -1,5 +1,5 @@ -func pathBounds(path: Path) -> Rect? { +func pathBounds(path: Path) -> Rect? { guard let firstSegment = path.segments.first else { return .None @@ -7,15 +7,25 @@ func pathBounds(path: Path) -> Rect? { let firstSegmentInfo = pathSegmenInfo(firstSegment) var bounds = firstSegmentInfo.0 - var currentPoint = firstSegmentInfo.1 + var currentPoint = firstSegmentInfo.1 ?? Point.zero() for segment in path.segments { let segmentInfo = pathSegmenInfo(segment) if let segmentBounds = segmentInfo.0 { - bounds = bounds?.union(segmentBounds) + if segment.absolute { + bounds = bounds?.union(segmentBounds) + } else { + bounds = bounds?.union(segmentBounds).move(currentPoint) + } } - currentPoint = segmentInfo.1 + if let segmentLastPoint = segmentInfo.1 { + if segment.absolute { + currentPoint = segmentLastPoint + } else { + currentPoint = currentPoint.add(segmentLastPoint) + } + } } return bounds diff --git a/Source/model/geom2d/Point.swift b/Source/model/geom2d/Point.swift index 6c8cec3a..19a85eed 100644 --- a/Source/model/geom2d/Point.swift +++ b/Source/model/geom2d/Point.swift @@ -1,13 +1,22 @@ import Foundation -public class Point: Locus { +public class Point: Locus { public let x: Double public let y: Double public init(x: Double = 0, y: Double = 0) { - self.x = x - self.y = y + self.x = x + self.y = y } + class func zero() -> Point { + return Point(x: 0.0, y: 0.0) + } + + func add(point: Point) -> Point { + return Point( + x: self.x + point.x, + y: self.y + point.y) + } } diff --git a/Source/model/geom2d/Rect.swift b/Source/model/geom2d/Rect.swift index 7ee01591..8f2762c3 100644 --- a/Source/model/geom2d/Rect.swift +++ b/Source/model/geom2d/Rect.swift @@ -32,6 +32,15 @@ public class Rect: Locus { h: max(self.y + self.h, rect.y + rect.h)) } + // GENERATED NOT + public func move(offset: Point) -> Rect { + return Rect( + x: self.x + offset.x, + y: self.y + offset.y, + w: self.w, + h: self.h) + } + class func zero() -> Rect { return Rect(x: 0.0, y: 0.0, w: 0.0, h: 0.0) } diff --git a/Source/model/scene/Shape.swift b/Source/model/scene/Shape.swift index b6ebd32a..7f15ed32 100644 --- a/Source/model/scene/Shape.swift +++ b/Source/model/scene/Shape.swift @@ -34,6 +34,11 @@ public class Shape: Node { } override public func bounds() -> Rect? { + + if let path = form as? Path { + return pathBounds(path) + } + return form.bounds() } }